linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] KVM: VMX: Micro-optimize vmexit time when not exposing PMU
@ 2020-03-13  3:55 Wanpeng Li
  2020-03-14 11:00 ` Paolo Bonzini
  0 siblings, 1 reply; 2+ messages in thread
From: Wanpeng Li @ 2020-03-13  3:55 UTC (permalink / raw)
  To: linux-kernel, kvm
  Cc: Paolo Bonzini, Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li,
	Jim Mattson, Joerg Roedel

From: Wanpeng Li <wanpengli@tencent.com>

PMU is not exposed to guest by most of products from cloud providers since the 
bad performance of PMU emulation and security concern. However, it calls 
perf_guest_switch_get_msrs() and clear_atomic_switch_msr() unconditionally 
even if PMU is not exposed to the guest before each vmentry. 

~2% vmexit time reduced can be observed by kvm-unit-tests/vmexit.flat on my 
SKX server.

Before patch:
vmcall 1559

After patch:
vmcall 1529

Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
---
v1 -> v2:
 * move the check before atomic_switch_perf_msrs

 arch/x86/kvm/vmx/vmx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 40b1e61..b20423c 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -6567,7 +6567,8 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu)
 
 	pt_guest_enter(vmx);
 
-	atomic_switch_perf_msrs(vmx);
+	if (vcpu_to_pmu(vcpu)->version)
+		atomic_switch_perf_msrs(vmx);
 	atomic_switch_umwait_control_msr(vmx);
 
 	if (enable_preemption_timer)
-- 
2.7.4


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

* Re: [PATCH v2] KVM: VMX: Micro-optimize vmexit time when not exposing PMU
  2020-03-13  3:55 [PATCH v2] KVM: VMX: Micro-optimize vmexit time when not exposing PMU Wanpeng Li
@ 2020-03-14 11:00 ` Paolo Bonzini
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2020-03-14 11:00 UTC (permalink / raw)
  To: Wanpeng Li, linux-kernel, kvm
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel

On 13/03/20 04:55, Wanpeng Li wrote:
> From: Wanpeng Li <wanpengli@tencent.com>
> 
> PMU is not exposed to guest by most of products from cloud providers since the 
> bad performance of PMU emulation and security concern. However, it calls 
> perf_guest_switch_get_msrs() and clear_atomic_switch_msr() unconditionally 
> even if PMU is not exposed to the guest before each vmentry. 
> 
> ~2% vmexit time reduced can be observed by kvm-unit-tests/vmexit.flat on my 
> SKX server.
> 
> Before patch:
> vmcall 1559
> 
> After patch:
> vmcall 1529
> 
> Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
> ---
> v1 -> v2:
>  * move the check before atomic_switch_perf_msrs
> 
>  arch/x86/kvm/vmx/vmx.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index 40b1e61..b20423c 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -6567,7 +6567,8 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu)
>  
>  	pt_guest_enter(vmx);
>  
> -	atomic_switch_perf_msrs(vmx);
> +	if (vcpu_to_pmu(vcpu)->version)
> +		atomic_switch_perf_msrs(vmx);
>  	atomic_switch_umwait_control_msr(vmx);
>  
>  	if (enable_preemption_timer)
> 

Queued, thanks.

Paolo


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

end of thread, other threads:[~2020-03-15  3:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-13  3:55 [PATCH v2] KVM: VMX: Micro-optimize vmexit time when not exposing PMU Wanpeng Li
2020-03-14 11:00 ` 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).