Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5518852pxj; Wed, 26 May 2021 12:27:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNRBkOScbU6C6JIYuTRMh4l8/olQmRDvDrfOWWOpFO3escmalfxWR4YUulSJBKEdmVnmYN X-Received: by 2002:a17:906:17d8:: with SMTP id u24mr2779226eje.106.1622057260579; Wed, 26 May 2021 12:27:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622057260; cv=none; d=google.com; s=arc-20160816; b=niZLvUmv1+44pm3cJcQRnW2U5ZpSBpY3gGU+85UJVMmKx/Zr5DyJTQRAbQh97c3bqC /+QMtRj3G+SPwA3r0GoOQkH4boVDtguIAbUs+FtZ/+mCw9z6X60wD9RQ0/B6gXeDzYlQ yqUPqN3CJoW7vISRlf0bNxEVWbpZJM0mmODoXshmV7dkdsdMsYcpFZ0TV6lH7VKqG9I8 4N6q7jKA68SmFU/fOMqSEx5xjNcWxiLmWRYwi+W8ElR16BZfqQCy8fM7XHCVYZg24k94 FkMIxjmz6yMeozE29RBqnJnYebr/CGXBHF9d5z6fEaQCd41iAnl6wH92f0nnsRb9XBTU jpJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=GJLBZVMEwbSbKIDqukcx7d1Y2z9DugvinO3Y2HE7Xb8=; b=pfcJDIJmZkAA9Y7ghPvm2+SYzj/t4KrqW6pABqiD4mIMFL0KMzwF7JpT4TVaOZ9iS2 mNTPSBipIyxKlEEaJJg8pev6xp4gC7h9j3pfn9wuQ6FB7XMG2rGFlZP2uJCr15E4sZS8 vdMolOtpMQd1/+a465toYWllS1azzfYyHAJKz39oPargE6Ln4FKxbpeh3VAjaYgE5QXk 3paouxm8YVO+4oSnfFyo3MI9M3M8mcVvQ6N4cS2atjcGFJmW7FsMxbhsIyJpBTLAxKU7 +FhXdQoVektJKB92MwttEDMOXmASCmpblr9bbUM1dwVAmZmAUj/AQvEqYAMUcwCI6EQN xnyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=qhCJ07l3; 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 y17si173747edw.191.2021.05.26.12.27.16; Wed, 26 May 2021 12:27:40 -0700 (PDT) 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=qhCJ07l3; 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 S234335AbhEZRkf (ORCPT + 99 others); Wed, 26 May 2021 13:40:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232006AbhEZRke (ORCPT ); Wed, 26 May 2021 13:40:34 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C3BEC061756 for ; Wed, 26 May 2021 10:39:03 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id u7so984085plq.4 for ; Wed, 26 May 2021 10:39:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=GJLBZVMEwbSbKIDqukcx7d1Y2z9DugvinO3Y2HE7Xb8=; b=qhCJ07l3+S5RaNOra6cGWWoLN5s4AiiMiSNsT4kmmZRWWeS3ywD0sHd0FiEtvhI6rB iDHzecKylmQV/alVl50UrPfL+lgoFTF+gwyC6OTbnRz/8S3G7cY1J+DXgCVBjokkOmQ3 MNtedZ93sVJlDjGU4e+WVUzbZz+IRpSVv+hd4dCJp8MoVlUDsFBxYiFnfQYTkH16d0kD 504lPpbw8Z6qcja/txaeMlwwOfnBJj8xaTI+/wuVhkhwDlXq+UPuO1cXMDDmQDDMvEb7 JPXNnACYkRiaa6QdmwGLcGJSpt1CRxPSxFfhE9IcGSt424UFT8e5IRuVTDTTw8FHKEP/ TZVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=GJLBZVMEwbSbKIDqukcx7d1Y2z9DugvinO3Y2HE7Xb8=; b=aUjhjizHUtINn4IInkL1b0TQ5iYV9A3QFcbteyHTQO7rqyN4t+hc762JHDRSU+sKsn P2KAZabU/yuuLERO5LIyN8+DmiJODLnQw20umpVQwdk91yvJr051vR/L4GbfJKbS7sBs 6926XrhnwiiBzoNm+D96tSlIcsVD9BgTbhx1u5OqgjjpgM8MTgACaWXTMndazCu70C5u OPkjx67SCSzfnqqkpj6iCEQjBegWl8WK9wCCbDLogEh0WpjzZwNzQMgOYYnzhSAGdDru cH/xsgUTS/WCFIrHYh46dR6wmawmSvWMJ1Hc6V3bQ6eLZ4+aStVMoQnDBJMWUgc4TGfH YK4w== X-Gm-Message-State: AOAM530swQRYkm5VYebqSJvyPT0yaveZCXNkp6qR9lmXTeXfGSPIkzoW Pjx5f8G8AqGGKIvDlpfw/4VZFQ== X-Received: by 2002:a17:902:d4cd:b029:f5:4ec0:d593 with SMTP id o13-20020a170902d4cdb02900f54ec0d593mr36661426plg.19.1622050742416; Wed, 26 May 2021 10:39:02 -0700 (PDT) Received: from google.com (240.111.247.35.bc.googleusercontent.com. [35.247.111.240]) by smtp.gmail.com with ESMTPSA id x9sm16309575pfd.66.2021.05.26.10.39.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 May 2021 10:39:01 -0700 (PDT) Date: Wed, 26 May 2021 17:38:57 +0000 From: Sean Christopherson To: Like Xu Cc: Paolo Bonzini , Alexander Shishkin , Peter Zijlstra , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: Re: [PATCH] KVM: x86/pt: Do not inject TraceToPAPMI when guest PT isn't supported Message-ID: References: <20210514084436.848396-1-like.xu@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210514084436.848396-1-like.xu@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 14, 2021, Like Xu wrote: > When a PT perf user is running in system-wide mode on the host, > the guest (w/ pt_mode=0) will warn about anonymous NMIs from > kvm_handle_intel_pt_intr(): > > [ 18.126444] Uhhuh. NMI received for unknown reason 10 on CPU 0. > [ 18.126447] Do you have a strange power saving mode enabled? > [ 18.126448] Dazed and confused, but trying to continue > > In this case, these PMIs should be handled by the host PT handler(). > When PT is used in guest-only mode, it's harmless to call host handler. > > Fix: 8479e04e7d("KVM: x86: Inject PMI for KVM guest") s/Fix/Fixes > Signed-off-by: Like Xu > --- > arch/x86/events/intel/core.c | 3 +-- > arch/x86/kvm/x86.c | 3 +++ > 2 files changed, 4 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c > index 2521d03de5e0..2f09eb0853de 100644 > --- a/arch/x86/events/intel/core.c > +++ b/arch/x86/events/intel/core.c > @@ -2853,8 +2853,7 @@ static int handle_pmi_common(struct pt_regs *regs, u64 status) > if (unlikely(perf_guest_cbs && perf_guest_cbs->is_in_guest() && > perf_guest_cbs->handle_intel_pt_intr)) > perf_guest_cbs->handle_intel_pt_intr(); > - else > - intel_pt_interrupt(); > + intel_pt_interrupt(); Would it make sense to instead do something like: bool host_pmi = true; ... if (unlikely(perf_guest_cbs && perf_guest_cbs->is_in_guest() && perf_guest_cbs->handle_intel_pt_intr) host_pmi = !perf_guest_cbs->handle_intel_pt_intr(); if (likely(host_pmi)) intel_pt_interrupt(); > } > > /* > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 6529e2023147..6660f3948cea 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -8087,6 +8087,9 @@ static void kvm_handle_intel_pt_intr(void) > { > struct kvm_vcpu *vcpu = __this_cpu_read(current_vcpu); > > + if (!guest_cpuid_has(vcpu, X86_FEATURE_INTEL_PT)) > + return; > + > kvm_make_request(KVM_REQ_PMI, vcpu); > __set_bit(MSR_CORE_PERF_GLOBAL_OVF_CTRL_TRACE_TOPA_PMI_BIT, > (unsigned long *)&vcpu->arch.pmu.global_status); > -- > 2.31.1 >