Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1581501pxb; Mon, 8 Mar 2021 00:46:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJzttSBjn72GFVfUVgx7YxEGboMQrJ/8sf5VergBG9z7CSryL/qBlAK9cfUMSbnAnaH/Ec6E X-Received: by 2002:a17:907:94cc:: with SMTP id dn12mr13959618ejc.177.1615193190954; Mon, 08 Mar 2021 00:46:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615193190; cv=none; d=google.com; s=arc-20160816; b=O0MbLSFOAUvhkCJUd6lJq+RvtfLL5UaXckAhWGs8XP4hHS6t2DjQSUgzDEGBcL1osE jh3LrtOx3Zwz1OfD/jZqI8GLfQbcZPf/pi19R1FyryXYNhG7VJsAia8d1MuxUP9Ctu4W ao4gQ5MUtOFWoX4+eK7YDlCKPkfE05e1oNLAhsmHeLEIbBfDY8jm2arZ845OncamYb2L f5WYY3SKyVwszzRx2Z91WwnLL+jMxPLomloZHd52tSWZgOdVSAVankw9YNLn4AN59jW/ fYc8WhMIVpj/ozrLiM2lr0GTPWfhfVZlrcrp4Dxe+w6HGNkL4kxzB28eYPVy5tSDnr0e T2kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:organization :from:references:cc:to:subject:ironport-sdr:ironport-sdr; bh=YzNjlr0mbixFLM9Vn3m+DqAJ8BrXa80Trn9Ol434c9M=; b=N2Sw7Z2Oz4NorEpyMjX7pTPT4n23V9/u9RvEni2iaNitSem+6vDSrwksTb0T5/yZgP +gesgK+r/y2qGV+4gXVYw5i2O76xH/OXz5Qe3Bqbna2hxfkgjOL39FViC3E6OwNzQBef d24V/2peMb7KMRTVP0Kf6+7+W2CE4CT9CNPsEOpYmyPyde1b+aAr2YWauoN/2h0hX7bz OHKEDA7VCqX37CUyRgq2OP3Zd/dmx64pMRkIC5Mzc0MH2yUuyhBPauRw3u1FTrBYda79 TYV8AO2MulJuGOG6qD9Xum7YYMa3izdtyCiCmW2f4PcAw9XRD74lUzYGJIyWev+PeqEq XFww== 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 qq23si6384089ejb.505.2021.03.08.00.46.08; Mon, 08 Mar 2021 00:46:30 -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 S231539AbhCHIgJ (ORCPT + 99 others); Mon, 8 Mar 2021 03:36:09 -0500 Received: from mga07.intel.com ([134.134.136.100]:17843 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231648AbhCHIfe (ORCPT ); Mon, 8 Mar 2021 03:35:34 -0500 IronPort-SDR: DRXyOyTObGNU4zH0hgF3tiSWqWhcGFS1I3zJAeu4GlVbvxm6fH/N5Me/DcVpYTqCmTOtqg8seG GpeCo8/V6+iQ== X-IronPort-AV: E=McAfee;i="6000,8403,9916"; a="252016808" X-IronPort-AV: E=Sophos;i="5.81,232,1610438400"; d="scan'208";a="252016808" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Mar 2021 00:35:32 -0800 IronPort-SDR: AiZbq5zNnZhAR6cBwLCCKQjqCvNWpQHEVNaESelWayOW19bVURBJsAst7whv4OF55nRmnLWGZm junbX8HuQ4ew== X-IronPort-AV: E=Sophos;i="5.81,232,1610438400"; d="scan'208";a="409215585" 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; 08 Mar 2021 00:35:15 -0800 Subject: Re: [PATCH] x86/perf: Fix guest_get_msrs static call if there is no PMU To: Dmitry Vyukov , "Xu, Like" Cc: Sean Christopherson , Peter Zijlstra , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , "H. Peter Anvin" , LKML , 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 References: <20210305223331.4173565-1-seanjc@google.com> <053d0a22-394d-90d0-8d3b-3cd37ca3f378@intel.com> From: Like Xu Organization: Intel OTC Message-ID: <2a21980b-7b0a-0de2-d417-09c7c80100cd@linux.intel.com> Date: Mon, 8 Mar 2021 16:35:07 +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: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/3/8 15:12, Dmitry Vyukov wrote: > 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 Sorry, I couldn't reproduce any VMX abort with "-cpu max,-pmu". Doe this patch fix this "unexpected kernel reboot" issue ? If so, you may add "Tested-by" for more attention. > >>> 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(); >>> >>> /* >>