aboutsummaryrefslogtreecommitdiff
path: root/arch/x86/kvm/pmu.c
diff options
context:
space:
mode:
authorGravatar Sean Christopherson <seanjc@google.com> 2023-11-09 18:28:57 -0800
committerGravatar Sean Christopherson <seanjc@google.com> 2024-02-01 09:35:48 -0800
commit83bdfe04c968e0fe3181e4cd41b764e17ac73911 (patch)
tree1ed26527de1b6e3f979289519879d7299e9c4c3f /arch/x86/kvm/pmu.c
parentKVM: x86/pmu: Check eventsel first when emulating (branch) insns retired (diff)
downloadlinux-83bdfe04c968e0fe3181e4cd41b764e17ac73911.tar.gz
linux-83bdfe04c968e0fe3181e4cd41b764e17ac73911.tar.bz2
linux-83bdfe04c968e0fe3181e4cd41b764e17ac73911.zip
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>
Diffstat (limited to 'arch/x86/kvm/pmu.c')
-rw-r--r--arch/x86/kvm/pmu.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
index 8d81f176ab7b..c397b28e3d1b 100644
--- a/arch/x86/kvm/pmu.c
+++ b/arch/x86/kvm/pmu.c
@@ -838,6 +838,13 @@ static inline bool cpl_is_matched(struct kvm_pmc *pmc)
select_user = config & 0x2;
}
+ /*
+ * Skip the CPL lookup, which isn't free on Intel, if the result will
+ * be the same regardless of the CPL.
+ */
+ if (select_os == select_user)
+ return select_os;
+
return (static_call(kvm_x86_get_cpl)(pmc->vcpu) == 0) ? select_os : select_user;
}