diff options
author | Sean Christopherson <seanjc@google.com> | 2023-06-06 18:02:04 -0700 |
---|---|---|
committer | Sean Christopherson <seanjc@google.com> | 2023-08-02 16:44:36 -0700 |
commit | bc9658999b3e44cbad964fe9fbab5a25bd4f5ed3 (patch) | |
tree | 2c6de5a5bea58f5bc9791ae1f1b980daaf451590 /arch/x86/kvm/vmx/pmu_intel.c | |
parent | 0033fa35491680bce65ff78fb41445f472aa5baa (diff) |
KVM: x86/pmu: Simplify intel_hw_event_available()
Walk only the "real", i.e. non-pseudo, architectural events when checking
if a hardware event is available, i.e. isn't disabled by guest CPUID.
Skipping pseudo-arch events in the loop body is unnecessarily convoluted,
especially now that KVM has enums that delineate between real and pseudo
events.
Link: https://lore.kernel.org/r/20230607010206.1425277-3-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
Diffstat (limited to 'arch/x86/kvm/vmx/pmu_intel.c')
-rw-r--r-- | arch/x86/kvm/vmx/pmu_intel.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c index 1109cbdedcae..db23697f3141 100644 --- a/arch/x86/kvm/vmx/pmu_intel.c +++ b/arch/x86/kvm/vmx/pmu_intel.c @@ -110,17 +110,16 @@ static bool intel_hw_event_available(struct kvm_pmc *pmc) BUILD_BUG_ON(ARRAY_SIZE(intel_arch_events) != NR_INTEL_ARCH_EVENTS); - for (i = 0; i < NR_INTEL_ARCH_EVENTS; i++) { + /* + * Disallow events reported as unavailable in guest CPUID. Note, this + * doesn't apply to pseudo-architectural events. + */ + for (i = 0; i < NR_REAL_INTEL_ARCH_EVENTS; i++) { if (intel_arch_events[i].eventsel != event_select || intel_arch_events[i].unit_mask != unit_mask) continue; - /* disable event that reported as not present by cpuid */ - if ((i < PSEUDO_ARCH_REFERENCE_CYCLES) && - !(pmu->available_event_types & (1 << i))) - return false; - - break; + return pmu->available_event_types & BIT(i); } return true; |