]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: selftests: Add regression test for mediated PMU fixed counter filter bug
authorSean Christopherson <seanjc@google.com>
Wed, 3 Jun 2026 23:19:05 +0000 (16:19 -0700)
committerSean Christopherson <seanjc@google.com>
Mon, 8 Jun 2026 16:18:52 +0000 (09:18 -0700)
Add a regression test where KVM would inadvertently ignore PMU event
filters on writes that change _some_ bits in FIXED_CTR_CTRL, but not the
enable bits for PMCs that are denied to the guest.

Link: https://patch.msgid.link/20260603231905.1738487-3-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/x86/pmu_event_filter_test.c

index c1232344fda89e7ac49f59db4c839cd8f63d2193..84e4c6ca67a3d69e0b95e136129a97db698b8e7c 100644 (file)
@@ -731,6 +731,8 @@ static void test_filter_ioctl(struct kvm_vcpu *vcpu)
 
 static void intel_run_fixed_counter_guest_code(u8 idx)
 {
+       u8 nr_fixed_counters = this_cpu_property(X86_PROPERTY_PMU_NR_FIXED_COUNTERS);
+
        for (;;) {
                wrmsr(MSR_CORE_PERF_GLOBAL_CTRL, 0);
                wrmsr(MSR_CORE_PERF_FIXED_CTR0 + idx, 0);
@@ -738,6 +740,10 @@ static void intel_run_fixed_counter_guest_code(u8 idx)
                /* Only OS_EN bit is enabled for fixed counter[idx]. */
                wrmsr(MSR_CORE_PERF_FIXED_CTR_CTRL, FIXED_PMC_CTRL(idx, FIXED_PMC_KERNEL));
                wrmsr(MSR_CORE_PERF_GLOBAL_CTRL, FIXED_PMC_GLOBAL_CTRL_ENABLE(idx));
+               if (nr_fixed_counters > 1)
+                       wrmsr(MSR_CORE_PERF_FIXED_CTR_CTRL,
+                             FIXED_PMC_CTRL(idx, FIXED_PMC_KERNEL) |
+                             FIXED_PMC_CTRL((idx + 1) % nr_fixed_counters, FIXED_PMC_KERNEL));
                __asm__ __volatile__("loop ." : "+c"((int){NUM_BRANCHES}));
                wrmsr(MSR_CORE_PERF_GLOBAL_CTRL, 0);