* [PATCH v3] KVM: x86: Fix the intel_pt PMI handling wrongly considered from guest
@ 2022-05-23 14:08 Yanfei Xu
2022-05-23 16:43 ` Sean Christopherson
2022-05-23 19:45 ` Paolo Bonzini
0 siblings, 2 replies; 4+ messages in thread
From: Yanfei Xu @ 2022-05-23 14:08 UTC (permalink / raw)
To: pbonzini, seanjc, vkuznets, wanpengli, jmattson, joro, tglx,
mingo, bp, dave.hansen, wei.w.wang, kan.liang
Cc: x86, kvm, linux-kernel
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
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 <yanfei.xu@intel.com>
---
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))
return 0;
kvm_make_request(KVM_REQ_PMI, vcpu);
--
2.32.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3] KVM: x86: Fix the intel_pt PMI handling wrongly considered from guest
2022-05-23 14:08 [PATCH v3] KVM: x86: Fix the intel_pt PMI handling wrongly considered from guest Yanfei Xu
@ 2022-05-23 16:43 ` Sean Christopherson
2022-05-24 2:06 ` Yanfei Xu
2022-05-23 19:45 ` Paolo Bonzini
1 sibling, 1 reply; 4+ messages in thread
From: Sean Christopherson @ 2022-05-23 16:43 UTC (permalink / raw)
To: Yanfei Xu
Cc: pbonzini, vkuznets, wanpengli, jmattson, joro, tglx, mingo, bp,
dave.hansen, wei.w.wang, kan.liang, x86, kvm, linux-kernel
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 <yanfei.xu@intel.com>
> ---
> 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 <seanjc@google.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] KVM: x86: Fix the intel_pt PMI handling wrongly considered from guest
2022-05-23 14:08 [PATCH v3] KVM: x86: Fix the intel_pt PMI handling wrongly considered from guest Yanfei Xu
2022-05-23 16:43 ` Sean Christopherson
@ 2022-05-23 19:45 ` Paolo Bonzini
1 sibling, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2022-05-23 19:45 UTC (permalink / raw)
To: Yanfei Xu
Cc: pbonzini, seanjc, vkuznets, wanpengli, jmattson, joro, tglx,
mingo, bp, dave.hansen, wei.w.wang, kan.liang, x86, kvm,
linux-kernel
Queued, thanks.
Paolo
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] KVM: x86: Fix the intel_pt PMI handling wrongly considered from guest
2022-05-23 16:43 ` Sean Christopherson
@ 2022-05-24 2:06 ` Yanfei Xu
0 siblings, 0 replies; 4+ messages in thread
From: Yanfei Xu @ 2022-05-24 2:06 UTC (permalink / raw)
To: Sean Christopherson
Cc: pbonzini, vkuznets, wanpengli, jmattson, joro, tglx, mingo, bp,
dave.hansen, wei.w.wang, kan.liang, x86, kvm, linux-kernel
On 2022/5/24 00:43, Sean Christopherson wrote:
> 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.
It's much better!
>> 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 <yanfei.xu@intel.com>
>> ---
>> 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 <seanjc@google.com>
Thanks Sean.
Regards,
Yanfei
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-05-24 2:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-23 14:08 [PATCH v3] KVM: x86: Fix the intel_pt PMI handling wrongly considered from guest Yanfei Xu
2022-05-23 16:43 ` Sean Christopherson
2022-05-24 2:06 ` Yanfei Xu
2022-05-23 19:45 ` Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).