Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp2064224lfo; Fri, 20 May 2022 12:01:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0yIFPp8NyOplJgRHKZqk2lp0niPXWdGAVg5jgrhppBnNPEtGJiuRHHIjpTulP3Qr105l9 X-Received: by 2002:a17:906:1691:b0:6f3:a3bf:451a with SMTP id s17-20020a170906169100b006f3a3bf451amr10103740ejd.61.1653073305432; Fri, 20 May 2022 12:01:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653073305; cv=none; d=google.com; s=arc-20160816; b=AAR56ktNJM4k5D2QQa3w2uwxV/Jpw6KZMto64akzq4SsDLkQX7Y1KwXwdLbGUPynJ2 BkYt6Xx6vdhSkuXVsEB1cucpKKxKLWvC72l2VqkNirVEpgYp4ZVlM6n2lNyIwBmoo6j+ 509sAQ6LFuFfMtfmFcQysaj5K8mO9tx0CYKVYNCrHFDUaByQSE0lPKEw4oUSBaawczRX dbSvTkdRB1VILXMUWUEpuXf8M6vftFScEl7ulreZ5AkOj30DoJvKr6LW46kWa8C7E/36 RFiKqUa0jPStWAH9bnA4T7Us2O8jPpYe5bm0CjJwihVkFSbdmhTxa1g6AXj7LouYD0Rt 4E1Q== 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=SzItUW0RGTe8ShIv3stQK+W3HlY6O/3mA4zqLcRGqJc=; b=HbaclZvZ4ULzt9MN2WQKmxMSlFu19fKpjgMlWfhof9UCiS/44jJ9WL5bPsgmGDOKR/ ZcneRAEHfeOei6c408NH3B+B/9g/820bqLJtgPAsZ9+ySwyOKb5jmmClscYhR4soRtHZ +6yzNyrp430Eo2AhzUFXJjduisDMThBCfRM1K/imhULzmCUtUemedaUGQ8LzY0SjXn8J Kafqmpn27E0XUUtoF2so3FNoZF/AGj/qWS5RbFuK7B3fOom6rQH+txj+wkJSc81jP55i Leby7K+rVOinLnjrTh5Of9K2YeXQKR2AFv/w9TeZv+M1ycB5JPeBQtM6xZf8XJ2cOpXS NuQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=PzMJGGKM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fj4-20020a1709069c8400b006f380128f8dsi9658718ejc.158.2022.05.20.12.01.17; Fri, 20 May 2022 12:01:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=PzMJGGKM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1351643AbiETQcE (ORCPT + 99 others); Fri, 20 May 2022 12:32:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231169AbiETQcD (ORCPT ); Fri, 20 May 2022 12:32:03 -0400 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B23BF34647 for ; Fri, 20 May 2022 09:32:02 -0700 (PDT) Received: by mail-pg1-x530.google.com with SMTP id a38so5295226pgl.9 for ; Fri, 20 May 2022 09:32:02 -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=SzItUW0RGTe8ShIv3stQK+W3HlY6O/3mA4zqLcRGqJc=; b=PzMJGGKM0liKfpSZu42fuPpNSgDQEt9yH+9w2C7yME17A4Xd6iyfNhJwoP7E3p363m 3Sr2Ftd4UVbIX7L0sAfzhDR0UOClzzbQ0hxSbtTa6vipdUzBEKwb20DWi1QFoKXMbAGB FBvqJgzWqPZwZ3f7hqr194VOX3BvttIdDDqdu2FCX4GXGbtYywmAsxEtfLE+9P2KJ25f 0b68NUFjWgP0i6gJ55P1eEEN/vKEBKzNnJ9opb0eiHUvBbfMdqbAs9yfdt7ZeNK+/BGx d3PBm/t0WyDU4t8pbCOBFl87PqVpDIhCoNfawihVuZrBhZCCSk7c8GakPsoordb+5fX4 6dcQ== 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=SzItUW0RGTe8ShIv3stQK+W3HlY6O/3mA4zqLcRGqJc=; b=o0VlqqzTvzksaOD6dSTaCR3nVOJXgXU7BduqOCuKrniMmrqJ9/mEpGCcGqn21J2Fyn ubdC20PufDWOTUNRr0nFd4jBFdTbRc1HZYDG1bjK4zydsKuk23oA/0YeAPIms6ehO1JO yFqCKcNrauyeLOGTeg4lM76cgfpCfAew0JgwFf37N0X4+zS9OWVSmvubXBHErgwowxwQ hTl8JHA0lPHEIpt/GtjpNe4RL6zCy0oF4E/ABcmj37pzMxJLbq8jXcRR7My/wZrw0VwD RfbLlPJ+KNWUH6HGTmhQs+Tib2w9Nd44TOQyPLjaN8Zo6FNKp/Q4RtO46Nf3MFPdlR2o Av4A== X-Gm-Message-State: AOAM531aq3qNKa7KfMCktNIzM/ewyncmpCievhceu6PAqX/7xNLGeox1 aX5Ud7Qbqcjbp7vsH/7iWXCCiA== X-Received: by 2002:a63:d054:0:b0:3f2:50df:e008 with SMTP id s20-20020a63d054000000b003f250dfe008mr9132653pgi.317.1653064322022; Fri, 20 May 2022 09:32:02 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id o6-20020a17090a4e8600b001d840f4eee0sm2077563pjh.20.2022.05.20.09.32.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 09:32:00 -0700 (PDT) Date: Fri, 20 May 2022 16:31:56 +0000 From: Sean Christopherson To: "Xu, Yanfei" 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" , "x86@kernel.org" , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "Wang, Wei W" , "Liang, Kan" Subject: Re: [PATCH] KVM: x86: Fix the intel_pt PMI handling wrongly considered from guest Message-ID: References: <20220515171633.902901-1-yanfei.xu@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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 Please don't top-post. On Fri, May 20, 2022, Xu, Yanfei wrote: > From: Sean Christopherson > On Mon, May 16, 2022, Yanfei Xu wrote: > > diff --git a/arch/x86/include/asm/kvm_host.h > > b/arch/x86/include/asm/kvm_host.h index 4ff36610af6a..308cf19f123d > > 100644 > > --- a/arch/x86/include/asm/kvm_host.h > > +++ b/arch/x86/include/asm/kvm_host.h > > @@ -1582,8 +1582,14 @@ static inline int kvm_arch_flush_remote_tlb(struct kvm *kvm) > > return -ENOTSUPP; > > } > > > > +enum kvm_intr_type { > > + /* Values are arbitrary, but must be non-zero. */ > > + KVM_HANDLING_IRQ = 1, > > + KVM_HANDLING_NMI, > > +}; > > + > > #define kvm_arch_pmi_in_guest(vcpu) \ > > - ((vcpu) && (vcpu)->arch.handling_intr_from_guest) > > + ((vcpu) && (vcpu)->arch.handling_intr_from_guest == > > +KVM_HANDLING_NMI) > > My understanding is that this isn't correct as a general change, as perf > events can use regular IRQs in some cases. See commit dd60d217062f4 ("KVM: > x86: Fix perf timer mode IP reporting"). > > I assume there's got to be a way to know which mode perf is using, e.g. we > should be able to make this look something like: > > ((vcpu) && (vcpu)->arch.handling_intr_from_guest == kvm_pmi_vector) > Hi Sean, > You are right, the change of kvm_arch_pmi_in_guest is incorrect, because it should cover two cases of PMI. > For the PMI of intel pt, it certainly is the NMI PMI. So how about fixing it like below? Yep, that works. I did enough spelunking to figure out how we can fix the generic issue, but it's per-event and requires a decent amount of plumbing in perf. perf_guest_handle_intel_pt_intr() doesn't bother with perf_guest_state() since it's such a specialized event, so fixing this in vmx_handle_intel_pt_intr() would likely be the long-term solution even if/when the generic case is fixed.