Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1580828pxb; Mon, 8 Mar 2021 00:45:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJywA+GE1qz95VObQy6TN3fqsgbriLRVqewDR0mdYfZHAS12VF6p4/DN/JDeaOSBTKQAgZxK X-Received: by 2002:aa7:d547:: with SMTP id u7mr21260019edr.347.1615193110049; Mon, 08 Mar 2021 00:45:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615193110; cv=none; d=google.com; s=arc-20160816; b=eze8/WwfhJS8wtdB+x85dDvzMhgl8JRz2hb+xvFCEV7PFMMiyXDxBy0JIwkxKAYud2 ERLbvjTf4INHC+0UCqG5pkzTCoq99YLRbaHlfjZtxDWbBik5GADc6Q0UxoQcN0pJLzSN QDJ6F5RNWMpA/xeOtZw8vkye/GOp4jUF3E7Rrb6znAAP8jG5Z5b5OCByCuD9VD4/LUQh 4VE1Tc1cHQH06/e8vSJnOG1vybdSvOA4XgWGk+jdtdek0nSVSp8d/aupNycrgeW+C9of oojG7YW5f2Ku/XJbfhPFfbzg3DYoGunu+A8YGcFDEbIwjcfabx3GCcHm9AVTl9vkFuQ4 4y+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=C08demyre3kojiX31o1Q1+SA4+m7jyiCUMEVIWTEp4U=; b=WKZixF16Ljl7FjcYdXlNZ/EtShsJ1sv0yaeTGblVIqzfUZf+A7Jh51SIbcY0IXTV0j QZVRW5csYbJoOa0UWoQPfTE73DhoZ0IBmXUb0JrD1ASpjJmYyu3OQeE2JQGq7HOcPNt6 zoxFS3scJVkkxO34xv07hWBuxGqDS44S1+h1OFTXlcQXPdBWMl+Pn1RZP3i84DivrJ1i Py06hLrV5bJyKuxqq7w21o1gDhwCZIvjGEg/2+eXnCUL5wd6wIQUDYyqzAfP7NDoXMPs VcN07Xgs23uPOf8O1SxLh6HnJ2Tk33WHeJ1nwz5O4S1jDe84Oug55Q1RMbAbuFlIXHDh WXPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=DorOoQF4; 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 cc7si6746652edb.462.2021.03.08.00.44.47; Mon, 08 Mar 2021 00:45:10 -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=DorOoQF4; 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 S235142AbhCHHNY (ORCPT + 99 others); Mon, 8 Mar 2021 02:13:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231805AbhCHHMw (ORCPT ); Mon, 8 Mar 2021 02:12:52 -0500 Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68BB4C06174A for ; Sun, 7 Mar 2021 23:12:52 -0800 (PST) Received: by mail-qk1-x72f.google.com with SMTP id b130so8339781qkc.10 for ; Sun, 07 Mar 2021 23:12:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=C08demyre3kojiX31o1Q1+SA4+m7jyiCUMEVIWTEp4U=; b=DorOoQF49lpcIwRZT0Wkw9DqN61pd61/qogSYNxeck5JgfiZKByVfVhsF9gtaH7HXc IBPHpmUiLp4VmZphTo2So47jLLq/F8tXH2zYE13lkmYyDi+I1oZQ5LrwJQW2iRT7x4Xw cBei59e3u/PJjtGUGfjWbe0YMp9C7bCuB7gAiNt53gxpXMpTq8urUnkxq/hFr3Gs8I3M FpCwfIhj9qiMKGc7Xe4a1+6zjOcyjxf6e1z6aOCJpDPAp25UQP5cBhPGsEnqgBBFoXYe nWX1SLpJvUMO9s0Q04W5HZdlAm/IXcLFAg/+IcxrJW+rq9wCc0z2EIJPJnjfsSRKdiy3 CjLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=C08demyre3kojiX31o1Q1+SA4+m7jyiCUMEVIWTEp4U=; b=LC/2/r/o375+3uSsgaEIxKD5p+cs6SqXKOWbFIZ8AnJH/FhYPxk9/8ia3A5TNiEFom Yqy0NmKY4AKUcIDJdcwjZ3aJ/ArErZKsvaUruOm4CTEmUOanFCWjLf7mFllCRkP2haY6 a5WO3zo++MigDUXYNAZzgdzxYTgtV7E8CMgLlZRdDohLN5LCUZq0t2XbltKlfCy7RwiN LKpV4xSqN5+vnuROypvjDka238CHdo1c8Yy1tXHF4uqggOedEelLrBucZadS+632I/+Z k//f9n5iLG1gXyCuxkwMMpWqqOSY5LsHiXvFRYsJHp7BDFt5ADl5pvJHFzFY+OwA13KF AX/A== X-Gm-Message-State: AOAM530XqdcHk6+L7NmATBt6XOofCZ5g3IPO03E8JtL4vezp0nTZ/zAn eEZtQF2oLuIO+Z2vLqmHFGPGTBuoC6XZKw+s1sfvAQ== X-Received: by 2002:a37:4743:: with SMTP id u64mr19589049qka.350.1615187571276; Sun, 07 Mar 2021 23:12:51 -0800 (PST) MIME-Version: 1.0 References: <20210305223331.4173565-1-seanjc@google.com> <053d0a22-394d-90d0-8d3b-3cd37ca3f378@intel.com> In-Reply-To: <053d0a22-394d-90d0-8d3b-3cd37ca3f378@intel.com> From: Dmitry Vyukov Date: Mon, 8 Mar 2021 08:12:36 +0100 Message-ID: Subject: Re: [PATCH] x86/perf: Fix guest_get_msrs static call if there is no PMU To: "Xu, Like" Cc: Sean Christopherson , Peter Zijlstra , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , "H. Peter Anvin" , LKML , Like Xu , Paolo Bonzini , Jim Mattson , KVM list , "Thomas Gleixner (x86/pti/timer/core/smp/irq/perf/efi/locking/ras/objtool) (x86@kernel.org)" , Borislav Petkov , Arnaldo Carvalho de Melo , Ingo Molnar Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 8, 2021 at 3:26 AM Xu, Like wrote: > > 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 ? Hi Xu, This can be reproduced in qemu with "-cpu max,-pmu" flag using this reproducer: https://groups.google.com/g/syzkaller-bugs/c/D8eHw3LIOd0/m/L2G0lVkVBAAJ > > 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(); > > > > /* >