public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: VMX: Micro-optimize vmexit time when not exposing PMU
@ 2020-03-12 10:05 Wanpeng Li
  2020-03-12 10:36 ` Vitaly Kuznetsov
  0 siblings, 1 reply; 8+ messages in thread
From: Wanpeng Li @ 2020-03-12 10:05 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 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. 

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

Before patch:
vmcall 1559

After patch:
vmcall 1539

Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
---
 arch/x86/kvm/vmx/vmx.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 40b1e61..fd526c8 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -6441,6 +6441,9 @@ static void atomic_switch_perf_msrs(struct vcpu_vmx *vmx)
 	int i, nr_msrs;
 	struct perf_guest_switch_msr *msrs;
 
+	if (!vcpu_to_pmu(&vmx->vcpu)->version)
+		return;
+
 	msrs = perf_guest_get_msrs(&nr_msrs);
 
 	if (!msrs)
-- 
2.7.4


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

end of thread, other threads:[~2020-03-13  9:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-12 10:05 [PATCH] KVM: VMX: Micro-optimize vmexit time when not exposing PMU Wanpeng Li
2020-03-12 10:36 ` Vitaly Kuznetsov
2020-03-12 11:05   ` Wanpeng Li
2020-03-13  3:23     ` Xu, Like
2020-03-13  3:39       ` Wanpeng Li
2020-03-13  4:57         ` Like Xu
2020-03-12 16:21   ` Jim Mattson
2020-03-13  9:08     ` Vitaly Kuznetsov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox