Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1576808pxb; Mon, 8 Mar 2021 00:36:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJyQ0jbghyOcvtQ9413JEtcfwjfdj6PtypFr4/yF8hhniU8QDmu4SLjEC3unSaWBA4J/1kpN X-Received: by 2002:a17:906:5e4a:: with SMTP id b10mr13956623eju.116.1615192583060; Mon, 08 Mar 2021 00:36:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615192583; cv=none; d=google.com; s=arc-20160816; b=LdxSPDtnMW22XD7HOVRakWnRzp0j4PSf1P4S9BMG/RYzqAgaOZr3tdX3aPB3UnsUXN jDTtmM85T4X9T/7iob8Ija240mYTHk0P90xZSNtZLBu3qRGdXyRGgyvCBVa9diWsKrWq c08yHggabP9iZJbaAmQRbRNxDzHnTBC8ILe69Vz58Swudwg5sZnLmWNjrmmAXTZgm2gC HZuU+gkkNpqOFjgilHNnvTWpRZiwD1RQQlqwWHEXn2i6x6kGIM6eD/FxOcHNiY/jhhqu KE4uo0jeTW43L6wlPn9x+UZ+f1ZIxRgqQ3QGJ8VASdzeJVLBH6jkihKBJhg8RMhC12MV 7OyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:ironport-sdr:ironport-sdr; bh=F0ioCQYIgCKBV1xD679JeZasdADwwZLLfCGzjd+X1Tc=; b=c6iqBUYzVXwDVkfmSigwaLlVTkmsiGDVMxlVue5liTLtMCV7vciS0aYPfbbuZvUfaZ A7N3O1+vxlItnl4CFP4PpvjAPjMLTB/RbWN9SsKSEa0Lnn9eTL/02F2S/0lcgU9B0mge IGarSPX/eUTq/oyUW+JYOmRZGvI9TT6OjvH64MQ2nPKjtnO77Djf8Appl2l7tzwjS0aQ IyE3NrBPflZv44fPvCCOFWUjWT4upbpC/F4WA4mRK6B2mIko617+UZY+CR8k26IW6QO5 a2uG0rQ5GldlFwlztaQPmNEa0Nns5i5pM/l6fF36HCNnfg5nON9Z1jts6XXng7BU8+YU Tfow== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w16si6632489edv.532.2021.03.08.00.36.00; Mon, 08 Mar 2021 00:36:23 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233498AbhCHC0R (ORCPT + 99 others); Sun, 7 Mar 2021 21:26:17 -0500 Received: from mga17.intel.com ([192.55.52.151]:24107 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233441AbhCHC0H (ORCPT ); Sun, 7 Mar 2021 21:26:07 -0500 IronPort-SDR: n0yWkPXabg+f8BJCFVkga4mR3hVF2IHVMZIMBQK0xDW6w4TEKZ47QWAbD3gVxNpVUWlhhNVRir UXRQ01zvXkyw== X-IronPort-AV: E=McAfee;i="6000,8403,9916"; a="167861023" X-IronPort-AV: E=Sophos;i="5.81,231,1610438400"; d="scan'208";a="167861023" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Mar 2021 18:26:07 -0800 IronPort-SDR: agRF+I/ATsQ+wOLFCyQguMyFtP39FdHEbbtUCNQ4kVrRdL1zfbuCIGmdxjtbJzIv5mfZJZ5jKy uJOFLBk8tgAA== X-IronPort-AV: E=Sophos;i="5.81,231,1610438400"; d="scan'208";a="409126690" Received: from likexu-mobl1.ccr.corp.intel.com (HELO [10.238.4.93]) ([10.238.4.93]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Mar 2021 18:26:01 -0800 Subject: Re: [PATCH] x86/perf: Fix guest_get_msrs static call if there is no PMU To: Sean Christopherson , Peter Zijlstra , Dmitry Vyukov 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 , Thomas Gleixner "(x86/pti/timer/core/smp/irq/perf/efi/locking/ras/objtool)" "(x86@kernel.org)" , Borislav Petkov , Thomas Gleixner , Arnaldo Carvalho de Melo , Ingo Molnar References: <20210305223331.4173565-1-seanjc@google.com> From: "Xu, Like" Message-ID: <053d0a22-394d-90d0-8d3b-3cd37ca3f378@intel.com> Date: Mon, 8 Mar 2021 10:25:59 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <20210305223331.4173565-1-seanjc@google.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/3/6 6:33, Sean Christopherson wrote: > 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 "If there is no PMU" ... How to set up this kind of environment, and what changes are needed in .config or boot parameters ? > 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); How about using "static_call_cond" per commit "452cddbff7" ? > + > + *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(); > > /*