Skip to content

Commit 83bdfe0

Browse files
committed
KVM: x86/pmu: Avoid CPL lookup if PMC enabline for USER and KERNEL is the same
Don't bother querying the CPL if a PMC is (not) counting for both USER and KERNEL, i.e. if the end result is guaranteed to be the same regardless of the CPL. Querying the CPL on Intel requires a VMREAD, i.e. isn't free, and a single CMP+Jcc is cheap. Link: https://lore.kernel.org/r/20231110022857.1273836-11-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent e35529f commit 83bdfe0

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

arch/x86/kvm/pmu.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,13 @@ static inline bool cpl_is_matched(struct kvm_pmc *pmc)
838838
select_user = config & 0x2;
839839
}
840840

841+
/*
842+
* Skip the CPL lookup, which isn't free on Intel, if the result will
843+
* be the same regardless of the CPL.
844+
*/
845+
if (select_os == select_user)
846+
return select_os;
847+
841848
return (static_call(kvm_x86_get_cpl)(pmc->vcpu) == 0) ? select_os : select_user;
842849
}
843850

0 commit comments

Comments
 (0)