Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: selftests: Track unavailable_mask for PMU events as 32-bit value

Track the mask of "unavailable" PMU events as a 32-bit value. While bits
31:9 are currently reserved, silently truncating those bits is unnecessary
and asking for missed coverage. To avoid running afoul of the sanity check
in vcpu_set_cpuid_property(), explicitly adjust the mask based on the
non-reserved bits as reported by KVM's supported CPUID.

Opportunistically update the "all ones" testcase to pass -1u instead of
0xff.

Reviewed-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
Tested-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
Link: https://lore.kernel.org/r/20250919214648.1585683-3-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>

+5 -2
+5 -2
tools/testing/selftests/kvm/x86/pmu_counters_test.c
··· 311 311 } 312 312 313 313 static void test_arch_events(uint8_t pmu_version, uint64_t perf_capabilities, 314 - uint8_t length, uint8_t unavailable_mask) 314 + uint8_t length, uint32_t unavailable_mask) 315 315 { 316 316 struct kvm_vcpu *vcpu; 317 317 struct kvm_vm *vm; ··· 319 319 /* Testing arch events requires a vPMU (there are no negative tests). */ 320 320 if (!pmu_version) 321 321 return; 322 + 323 + unavailable_mask &= GENMASK(X86_PROPERTY_PMU_EVENTS_MASK.hi_bit, 324 + X86_PROPERTY_PMU_EVENTS_MASK.lo_bit); 322 325 323 326 vm = pmu_vm_create_with_one_vcpu(&vcpu, guest_test_arch_events, 324 327 pmu_version, perf_capabilities); ··· 633 630 */ 634 631 for (j = 0; j <= NR_INTEL_ARCH_EVENTS + 1; j++) { 635 632 test_arch_events(v, perf_caps[i], j, 0); 636 - test_arch_events(v, perf_caps[i], j, 0xff); 633 + test_arch_events(v, perf_caps[i], j, -1u); 637 634 638 635 for (k = 0; k < NR_INTEL_ARCH_EVENTS; k++) 639 636 test_arch_events(v, perf_caps[i], j, BIT(k));