kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: x86/pt: Do not inject TraceToPAPMI when guest PT isn't supported
@ 2021-05-14  8:44 Like Xu
  2021-05-26 17:38 ` Sean Christopherson
  0 siblings, 1 reply; 3+ messages in thread
From: Like Xu @ 2021-05-14  8:44 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Alexander Shishkin, Peter Zijlstra, Sean Christopherson,
	Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel,
	linux-kernel, kvm, Like Xu

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")
Signed-off-by: Like Xu <like.xu@linux.intel.com>
---
 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();
 	}
 
 	/*
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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] KVM: x86/pt: Do not inject TraceToPAPMI when guest PT isn't supported
  2021-05-14  8:44 [PATCH] KVM: x86/pt: Do not inject TraceToPAPMI when guest PT isn't supported Like Xu
@ 2021-05-26 17:38 ` Sean Christopherson
  2021-06-21  4:03   ` Like Xu
  0 siblings, 1 reply; 3+ messages in thread
From: Sean Christopherson @ 2021-05-26 17:38 UTC (permalink / raw)
  To: Like Xu
  Cc: Paolo Bonzini, Alexander Shishkin, Peter Zijlstra,
	Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel,
	linux-kernel, kvm

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 <like.xu@linux.intel.com>
> ---
>  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
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] KVM: x86/pt: Do not inject TraceToPAPMI when guest PT isn't supported
  2021-05-26 17:38 ` Sean Christopherson
@ 2021-06-21  4:03   ` Like Xu
  0 siblings, 0 replies; 3+ messages in thread
From: Like Xu @ 2021-06-21  4:03 UTC (permalink / raw)
  To: Sean Christopherson, Peter Zijlstra
  Cc: Paolo Bonzini, Alexander Shishkin, Vitaly Kuznetsov, Wanpeng Li,
	Jim Mattson, Joerg Roedel, linux-kernel, kvm, Like Xu

On 27/5/2021 1:38 am, Sean Christopherson wrote:
> 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 <like.xu@linux.intel.com>
>> ---
>>   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();

struct perf_guest_info_callbacks {
	...
	void				(*handle_intel_pt_intr)(void);
};


This fix is deferred until the following proposal is finalized.

https://lore.kernel.org/lkml/YKImQ2%2FDilGIkrfe@hirez.programming.kicks-ass.net/

> 
> 		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
>>
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-06-21  4:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-14  8:44 [PATCH] KVM: x86/pt: Do not inject TraceToPAPMI when guest PT isn't supported Like Xu
2021-05-26 17:38 ` Sean Christopherson
2021-06-21  4:03   ` Like Xu

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).