Skip to content

Commit 1fcd305

Browse files
committed
KVM: selftests: Reduce number of "unavailable PMU events" combos tested
Reduce the number of combinations of unavailable PMU events masks that are testing by the PMU counters test. In reality, testing every possible combination isn't all that interesting, and certainly not worth the tens of seconds (or worse, minutes) of runtime. Fully testing the N^2 space will be especially problematic in the near future, as 5! new arch events are on their way. Use alternating bit patterns (and 0 and -1u) in the hopes that _if_ there is ever a KVM bug, it's not something horribly convoluted that shows up only with a super specific pattern/value. Reported-by: Dapeng Mi <[email protected]> Reviewed-by: Dapeng Mi <[email protected]> Tested-by: Dapeng Mi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 571fc28 commit 1fcd305

1 file changed

Lines changed: 23 additions & 15 deletions

File tree

tools/testing/selftests/kvm/x86/pmu_counters_test.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,26 @@ static void test_intel_counters(void)
577577
PMU_CAP_FW_WRITES,
578578
};
579579

580+
/*
581+
* To keep the total runtime reasonable, test only a handful of select,
582+
* semi-arbitrary values for the mask of unavailable PMU events. Test
583+
* 0 (all events available) and all ones (no events available) as well
584+
* as alternating bit sequencues, e.g. to detect if KVM is checking the
585+
* wrong bit(s).
586+
*/
587+
const uint32_t unavailable_masks[] = {
588+
0x0,
589+
0xffffffffu,
590+
0xaaaaaaaau,
591+
0x55555555u,
592+
0xf0f0f0f0u,
593+
0x0f0f0f0fu,
594+
0xa0a0a0a0u,
595+
0x0a0a0a0au,
596+
0x50505050u,
597+
0x05050505u,
598+
};
599+
580600
/*
581601
* Test up to PMU v5, which is the current maximum version defined by
582602
* Intel, i.e. is the last version that is guaranteed to be backwards
@@ -614,16 +634,7 @@ static void test_intel_counters(void)
614634

615635
pr_info("Testing arch events, PMU version %u, perf_caps = %lx\n",
616636
v, perf_caps[i]);
617-
/*
618-
* To keep the total runtime reasonable, test every
619-
* possible non-zero, non-reserved bitmap combination
620-
* only with the native PMU version and the full bit
621-
* vector length.
622-
*/
623-
if (v == pmu_version) {
624-
for (k = 1; k < (BIT(NR_INTEL_ARCH_EVENTS) - 1); k++)
625-
test_arch_events(v, perf_caps[i], NR_INTEL_ARCH_EVENTS, k);
626-
}
637+
627638
/*
628639
* Test single bits for all PMU version and lengths up
629640
* the number of events +1 (to verify KVM doesn't do
@@ -632,11 +643,8 @@ static void test_intel_counters(void)
632643
* ones i.e. all events being available and unavailable.
633644
*/
634645
for (j = 0; j <= NR_INTEL_ARCH_EVENTS + 1; j++) {
635-
test_arch_events(v, perf_caps[i], j, 0);
636-
test_arch_events(v, perf_caps[i], j, -1u);
637-
638-
for (k = 0; k < NR_INTEL_ARCH_EVENTS; k++)
639-
test_arch_events(v, perf_caps[i], j, BIT(k));
646+
for (k = 1; k < ARRAY_SIZE(unavailable_masks); k++)
647+
test_arch_events(v, perf_caps[i], j, unavailable_masks[k]);
640648
}
641649

642650
pr_info("Testing GP counters, PMU version %u, perf_caps = %lx\n",

0 commit comments

Comments
 (0)