Skip to content

Commit 30a6e0b

Browse files
committed
KVM: selftests: Convert VMX's PMU capabilities test to printf guest asserts
Convert x86's VMX PMU capabilities test to use printf-based guest asserts. Opportunstically add a helper to do the WRMSR+assert so as to reduce the amount of copy+paste needed to spit out debug information. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 417bfd0 commit 30a6e0b

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

tools/testing/selftests/kvm/x86_64/vmx_pmu_caps_test.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* and check it can be retrieved with KVM_GET_MSR, also test
1111
* the invalid LBR formats are rejected.
1212
*/
13+
#define USE_GUEST_ASSERT_PRINTF 1
1314

1415
#define _GNU_SOURCE /* for program_invocation_short_name */
1516
#include <sys/ioctl.h>
@@ -52,23 +53,24 @@ static const union perf_capabilities format_caps = {
5253
.pebs_format = -1,
5354
};
5455

56+
static void guest_test_perf_capabilities_gp(uint64_t val)
57+
{
58+
uint8_t vector = wrmsr_safe(MSR_IA32_PERF_CAPABILITIES, val);
59+
60+
__GUEST_ASSERT(vector == GP_VECTOR,
61+
"Expected #GP for value '0x%llx', got vector '0x%x'",
62+
val, vector);
63+
}
64+
5565
static void guest_code(uint64_t current_val)
5666
{
57-
uint8_t vector;
5867
int i;
5968

60-
vector = wrmsr_safe(MSR_IA32_PERF_CAPABILITIES, current_val);
61-
GUEST_ASSERT_2(vector == GP_VECTOR, current_val, vector);
69+
guest_test_perf_capabilities_gp(current_val);
70+
guest_test_perf_capabilities_gp(0);
6271

63-
vector = wrmsr_safe(MSR_IA32_PERF_CAPABILITIES, 0);
64-
GUEST_ASSERT_2(vector == GP_VECTOR, 0, vector);
65-
66-
for (i = 0; i < 64; i++) {
67-
vector = wrmsr_safe(MSR_IA32_PERF_CAPABILITIES,
68-
current_val ^ BIT_ULL(i));
69-
GUEST_ASSERT_2(vector == GP_VECTOR,
70-
current_val ^ BIT_ULL(i), vector);
71-
}
72+
for (i = 0; i < 64; i++)
73+
guest_test_perf_capabilities_gp(current_val ^ BIT_ULL(i));
7274

7375
GUEST_DONE();
7476
}
@@ -95,7 +97,7 @@ static void test_guest_wrmsr_perf_capabilities(union perf_capabilities host_cap)
9597

9698
switch (get_ucall(vcpu, &uc)) {
9799
case UCALL_ABORT:
98-
REPORT_GUEST_ASSERT_2(uc, "val = 0x%lx, vector = %lu");
100+
REPORT_GUEST_ASSERT(uc);
99101
break;
100102
case UCALL_DONE:
101103
break;

0 commit comments

Comments
 (0)