Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2084493ioo; Mon, 23 May 2022 09:43:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwPm2fYSAq+XgJgEw39JWphQ5f03FHImCSo8lODVuAxIPBvCarIUFmRO2HSe3/NixRUUb6s X-Received: by 2002:a65:4d48:0:b0:3f3:936a:7c33 with SMTP id j8-20020a654d48000000b003f3936a7c33mr21250585pgt.217.1653324239223; Mon, 23 May 2022 09:43:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653324239; cv=none; d=google.com; s=arc-20160816; b=cAmVUZs/f0UFfHj19kDuTj3bK0Cx7AC8j36qBQB6PPvVq7tVwyS/h6Cpm5My7VGcho P4F6oeIIDCZfvLoniOz11N6scqpzDmlIlRpGHW2sXkckIGoIyn+d/1QO/AavjRXUv+wg Z/cmCGx4CMuFJXjO96K6w4lYUMjtvmtaXt+FaUwiTb0krpQtGGhg3O2Jc9/lq0nPheGF 96WjddjMAgrqmYeg1BysRQLEfUiYL/1s1qz7EkwgEI83BwsQrbWojqo9Z55SOC7qItQv CzWmOSKIBJS7tCaUtdOJ6eJqYVTnL4+n7I839d64J15yeQnvmvNxbUkTsArHenuoFLln H9QQ== 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=6oTk/zM3kr5sT5hZHtfbrEZg5Wd/Dydos1apa+GKeoY=; b=eGeJVyNoWSzsM4+6TiU3bRamEuQrI/QX5R+yhi1kCvxORU78Eyu5+/bbprrfDhYOQW JOz8XjmMxK9uNpuoeX626cinrRkrq6p7He9HhbngmpGIYGGecsiMAkYpYUTL5NjoSOB7 n900HF4CFXrbtxQxylehGNphcEapoMy9YdpD2kLrA9f7sqZcGM75fIIS3tXAMjiRUlMR 0rRSFgHAV2/hGzTgi7HUG3fBvRQJ7eGtgEFkaDCCn1KWRdS2GiNVB2LyZNB+dSNxFiyr aUC0AHOgu1plyOCufZ26s+JUl6m9va2bRgubXUkGirxuu3MzMvXiOVUv5g7ampqroEm8 Qhhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=QdxOJcF3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id cm12-20020a17090afa0c00b001bf691f3264si12322255pjb.19.2022.05.23.09.43.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 09:43:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=QdxOJcF3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 61CA62018A; Mon, 23 May 2022 09:43:38 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239092AbiEWQna (ORCPT + 99 others); Mon, 23 May 2022 12:43:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239073AbiEWQnT (ORCPT ); Mon, 23 May 2022 12:43:19 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AEAC69739 for ; Mon, 23 May 2022 09:43:18 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id c14so14220131pfn.2 for ; Mon, 23 May 2022 09:43:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=6oTk/zM3kr5sT5hZHtfbrEZg5Wd/Dydos1apa+GKeoY=; b=QdxOJcF3IWnNjLf1G8T+GpDa69DBUgRlOonCO9LKXCmpCDUGK12eSBoMWHmfPB1itJ SO9BTnoJSux49GWZSK+aV0I4qTYd1S7U/pNm5CyBDxxmmE8yrQD2tRoM9KBCPJXFbflE NZVsUtR6Fkn5DV69G9JvBi/zdjLwvJGQ9yglJbCfiiSANMzIX9HUuagkInt7uIPcjef8 8HAu6iE+lLaZV7b38ndzGINx68cke3Vl/e2k2UnmsV5vPELJFfCMwJRI4iCoIS/7Tm19 6QRQ0f4PnR1z0LHZJkZqomb4NnAZPi55FK86CpGOzn2mw9KYJMgnf1aqyn7b3wg8rBz5 X6qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=6oTk/zM3kr5sT5hZHtfbrEZg5Wd/Dydos1apa+GKeoY=; b=0fDmGBcyFdjy29rraLmRfJnnGU7AwuJWVt/XCY9P7cmN1s9zW/XVIpnYX+0IGDfDX0 k4wenMGLmqKegEu5ihxa+hujpzXc7aQodO6aTlrRS7EiTqRx5H5UeJ8GrvGpFPcwZx2Q YEhsq5QMMsnU6qpQKGYGvxPL66+eHSbAtjqpjccZKgkQRmLOamQMx3r+Khh0QACI2tC/ XnUVuZR57gKjYN3mvxPFaauc5PEgeBCsQPYF/TEL3LPOuKLHKHec6N8S3HhFCmVfCjWJ lCfU4IVnC27A7ysHuZiHg/1zDw5cEjPQ9+xYFNrUfKyET/fVT0jvP0CzQ3yHNKNdqOUq rlHg== X-Gm-Message-State: AOAM533ctFnYSSGGas8/mDL1lAM/npdaqfrPQ9QcU1NSP3bqb/4xquEb VG3667rnT3Lk9AJ3X++jbKNroQ== X-Received: by 2002:a05:6a00:a0e:b0:4fd:fa6e:95fc with SMTP id p14-20020a056a000a0e00b004fdfa6e95fcmr24601061pfh.17.1653324197174; Mon, 23 May 2022 09:43:17 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id iw17-20020a170903045100b0015e8d4eb2dfsm5321204plb.297.2022.05.23.09.43.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 09:43:16 -0700 (PDT) Date: Mon, 23 May 2022 16:43:13 +0000 From: Sean Christopherson To: Yanfei Xu Cc: pbonzini@redhat.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, wei.w.wang@intel.com, kan.liang@intel.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] KVM: x86: Fix the intel_pt PMI handling wrongly considered from guest Message-ID: References: <20220523140821.1345605-1-yanfei.xu@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220523140821.1345605-1-yanfei.xu@intel.com> X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 23, 2022, Yanfei Xu wrote: > When kernel handles the vm-exit caused by external interrupts and NMI, > it always set a type of kvm_intr_type to handling_intr_from_guest to > tell if it's dealing an IRQ or NMI. For the PMI scenario, it could be > IRQ or NMI. > However the intel_pt PMI certainly is a NMI PMI, hence using It'd be helpful for future readers to explain why it's guaranteed to an NMI. E.g. However, intel_pt PMIs are only generated for HARDWARE perf events, and HARDWARE events are always configured to generate NMIs. Use kvm_handling_nmi_from_guest() to precisely identify if the intel_pt PMI came from the guest to avoid false positives if an intel_pt PMI/NMI arrives while the host is handling an unrelated IRQ VM-Exit. > kvm_handling_nmi_from_guest() to distinguish if the intel_pt PMI comes > from guest is more appropriate. This modification can avoid the host > wrongly considered the intel_pt PMI comes from a guest once the host > intel_pt PMI breaks the handling of vm-exit of external interrupts. > > Fixes: db215756ae59 ("KVM: x86: More precisely identify NMI from guest when handling PMI") > Signed-off-by: Yanfei Xu > --- > v1->v2: > 1.Fix vmx_handle_intel_pt_intr() directly instead of changing the generic function. > 2.Tune the commit message. > > v2->v3: > Add the NULL pointer check of variable "vcpu". > > arch/x86/kvm/vmx/vmx.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > index 610355b9ccce..982df9c000d3 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -7856,7 +7856,7 @@ static unsigned int vmx_handle_intel_pt_intr(void) > struct kvm_vcpu *vcpu = kvm_get_running_vcpu(); > > /* '0' on failure so that the !PT case can use a RET0 static call. */ > - if (!kvm_arch_pmi_in_guest(vcpu)) > + if (!vcpu || !kvm_handling_nmi_from_guest(vcpu)) Alternatively, if (!kvm_arch_pmi_in_guest(vcpu) || !kvm_handling_nmi_from_guest(vcpu)) The generated code is the same since the compiler is smart enough to elide the handling_intr_from_guest check from kvm_arch_pmi_in_guest. I'm not actually sure that's better than the !vcpu check though, e.g. it hides the not-NULL aspect of the check. Either way, with a tweaked changelog, Reviewed-by: Sean Christopherson