From patchwork Fri Mar 5 22:33:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12119513 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52AB4C433DB for ; Fri, 5 Mar 2021 22:35:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 26D2A650AC for ; Fri, 5 Mar 2021 22:35:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229679AbhCEWew (ORCPT ); Fri, 5 Mar 2021 17:34:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229592AbhCEWev (ORCPT ); Fri, 5 Mar 2021 17:34:51 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED2F9C06175F for ; Fri, 5 Mar 2021 14:34:50 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id p136so4089653ybc.21 for ; Fri, 05 Mar 2021 14:34:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:message-id:mime-version:subject:from:to:cc; bh=sVxveq/IidC6Dcg/UZ54CWSyr4b2i4eGAQesD0hdFkc=; b=LRZoIR5yWsUk6WnZgHh7btUexV20WDm2A/1mUk7p+kzq+cOKMTlybMhdxBGQjG4iju ytP+lxSryqNRr5sap0oL6YuOcb2nbFYujBKFRDV+nulGq7eq1AJRQEY8Qx0Mqm9rpX4X WZ2fRI3IcOkbUvCCxJ0M4htnF94hCQwrMAH2pL/hSXW0EieVCSFC1gK1fqcaIsq7DSkL 3Gh8MkUXVlTBLD1D6oZwFfhBQlKOh7iQcFiuwKhLFBPHm+NNQDKmGyGPWced1yoi/zIm wsSKmjlg3u77Lrqjo98iAo9/yZtAT8JBoZXMKnhUZSeX6zQDyxO7fUp1+uQs2xae1xws Qzuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:message-id:mime-version :subject:from:to:cc; bh=sVxveq/IidC6Dcg/UZ54CWSyr4b2i4eGAQesD0hdFkc=; b=LehggFU59EAReWxUFap1Z37FJvC/vcW77E0IGnsSuC4KhxFBj2w+OwClIUNq25AHym QQ7fKvU6xkAyjfapdrTmnE9+gDH3yv3FpmOkEjWeS4Tyh+gOYDW/M85H/O3Di58aRED+ ZdmEQDtKxlxxxk2zVSB9ot8ugSRqmjt8FxVrFwqxVDjvXUJY0iPtJGhPDSblF3GH7ghO pCfaJu5aL/XuNxQYSuN/n2g7buypQ4F08sznQhU1Rt7461YTVNm58sqTz4m7M3WGDRQy jytViWegOjB7dvlzdgiQ7mOuee01qaJo9aexUD8gbfbRWIqB8o698Db52CWqMY5OdLXf +5aA== X-Gm-Message-State: AOAM531ZBMVbULu7zjN2Zjv0G4qqOe8KU+22//rceIjGss+/W1NrXMSS tuTplRCY92XFwnQHr00xPjvejmOUCWg= X-Google-Smtp-Source: ABdhPJw3RQaY2hVP255sL6Sod8e/1piSX8ViPZaVrYSHDVS58LYHZPjCYhIgFyZ3p5QjKmztlFjECkzZvt8= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:9857:be95:97a2:e91c]) (user=seanjc job=sendgmr) by 2002:a25:ad5c:: with SMTP id l28mr15617451ybe.307.1614983689946; Fri, 05 Mar 2021 14:34:49 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 5 Mar 2021 14:33:31 -0800 Message-Id: <20210305223331.4173565-1-seanjc@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog Subject: [PATCH] x86/perf: Fix guest_get_msrs static call if there is no PMU From: Sean Christopherson To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Thomas Gleixner , Borislav Petkov , x86@kernel.org Cc: Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , "H. Peter Anvin" , linux-kernel@vger.kernel.org, Like Xu , Paolo Bonzini , Jim Mattson , kvm@vger.kernel.org, Dmitry Vyukov , Sean Christopherson Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Handle a NULL x86_pmu.guest_get_msrs at invocation instead of patching in perf_guest_get_msrs_nop() during setup. If there is no PMU, setup bails before updating the static calls, leaving x86_pmu.guest_get_msrs NULL and thus a complete nop. Ultimately, this causes VMX abort on VM-Exit due to KVM putting random garbage from the stack into the MSR load list. Fixes: abd562df94d1 ("x86/perf: Use static_call for x86_pmu.guest_get_msrs") Cc: Like Xu Cc: Paolo Bonzini Cc: Jim Mattson Cc: kvm@vger.kernel.org Reported-by: Dmitry Vyukov Signed-off-by: Sean Christopherson --- arch/x86/events/core.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index 6ddeed3cd2ac..ff874461f14c 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -671,7 +671,11 @@ void x86_pmu_disable_all(void) struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr) { - return static_call(x86_pmu_guest_get_msrs)(nr); + if (x86_pmu.guest_get_msrs) + return static_call(x86_pmu_guest_get_msrs)(nr); + + *nr = 0; + return NULL; } EXPORT_SYMBOL_GPL(perf_guest_get_msrs); @@ -1944,13 +1948,6 @@ static void _x86_pmu_read(struct perf_event *event) x86_perf_event_update(event); } -static inline struct perf_guest_switch_msr * -perf_guest_get_msrs_nop(int *nr) -{ - *nr = 0; - return NULL; -} - static int __init init_hw_perf_events(void) { struct x86_pmu_quirk *quirk; @@ -2024,9 +2021,6 @@ static int __init init_hw_perf_events(void) if (!x86_pmu.read) x86_pmu.read = _x86_pmu_read; - if (!x86_pmu.guest_get_msrs) - x86_pmu.guest_get_msrs = perf_guest_get_msrs_nop; - x86_pmu_static_call_update(); /*