Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp64513pxb; Fri, 5 Mar 2021 14:36:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJzRu4mtT8/ayinnGZ6nZU/IkvmSz0Ub/uFSiNbljIzOOfz+8Dj7TSSyJfEGIz9XxZYm720a X-Received: by 2002:a17:906:8147:: with SMTP id z7mr4259701ejw.436.1614983771996; Fri, 05 Mar 2021 14:36:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614983771; cv=none; d=google.com; s=arc-20160816; b=Sm+i6mnpIuDRciRkiSfbcvEJLqZTM0/1Ep5JzxAQ0S2x1/dFh+td2WRF1MvMgnPRR0 auArAwiDfdvuGuyIzDCcO6kAdS1nKR240BpUrjYizyENBR1Csaz7p5hprId/tPNnemf7 76iZEF5TEr3Q4j6gpOyo+LhwOFZO4Q4QrPaDG6tQ1hwDK7o1aNGx4+wUD3mWwYj1jgZg UTYJKb95M70S4hyirKHn60KPdvLPfZrwQeMetj5YUFHgblV4PONp7m6SYce6KofUcMFR IkIiHufgwe4p/TcMVtYUgoFovHwP55Udg1L9DntnX8BEONErh/kgG5DcuVFY/ZUPwmZo b+Wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :reply-to:sender:dkim-signature; bh=sVxveq/IidC6Dcg/UZ54CWSyr4b2i4eGAQesD0hdFkc=; b=h/Gl1Z+551gxGZPYD2bEkuAeeFDXPrCiUs//Q2FfkmSXTSD3muc2O6bj8vUk+8a6Yq 3GNRF4r6FkkivRSVd1I1VGfuwHTUryydISmacaTVXzSay0rG/pwuamqLWpuP8h0W+64P OGs9gVDmSZVw1wBNyGET0k2tHJ/+Yp8pDr2/wqcieT12qs+fWaMPZEphWLbG3R2vanK/ L05gX5dwhpeAcl6kmBrrX+mqnFsXC102jZxReopG34CNQvGj7pQuWKH1OI2XGZDdxFH9 ARWVl0ZRujsh1deRmM7B6Wz13Hkv7tIZ3x0Il98JrN5fqPWZYh6czQ7G37PtV8U9gY0V vrzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=LRZoIR5y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e23si2383398edu.203.2021.03.05.14.35.49; Fri, 05 Mar 2021 14:36:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=LRZoIR5y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229672AbhCEWev (ORCPT + 99 others); Fri, 5 Mar 2021 17:34:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229597AbhCEWev (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 023A2C061760 for ; Fri, 5 Mar 2021 14:34:50 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id o9so4028038yba.18 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=RkxRrrWcfu96q07m67RbRk4j6uG2nODhz0wksUqV/8jPDuv9u8uFrXEVMF14yfvHgG DtXC4yRnNVt7pBycaJtgXPBdHnFpcxI6IUf3/eBTV/j5LXNs1bK3mVTk1RwcBzg4rjzn 1+ytwsKf5jOJLwoPd4WIz3dwmb20eVNTsQiFuev6h2qkzCbOpE4luS88XrGrhlUHhrOl FLND6RKDEpKueTEsaEmegLOj6g3Rr8JFlUX8DCgdWPo+gmtuUBsuuBRzu4N4xH178lLk mxQ4rg49GYCi9RXJdC1MgMltPV3bWpAiAV9wXZljHUScVzKGRZWyfSwp5MHbqpiRM4Rk rrMQ== X-Gm-Message-State: AOAM53399FDRWZzDVEcxa7vO+okbzua+2ARt3dnC75Jg8GD6BQXEjaSN Y+yXLgVswXihsN2+bIa8sdq8ByODfmo= 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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(); /* -- 2.30.1.766.gb4fecdf3b7-goog