Skip to content

Commit a925f79

Browse files
committed
KVM: selftests: Convert the nSVM software interrupt test to printf guest asserts
Convert x86's nested SVM software interrupt injection test to use printf- based guest asserts. Opportunistically use GUEST_ASSERT() and GUEST_FAIL() in a few locations to spit out more debug information. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 40b319d commit a925f79

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Copyright (C) 2021, Red Hat, Inc.
99
*
1010
*/
11+
#define USE_GUEST_ASSERT_PRINTF 1
1112

1213
#include <stdatomic.h>
1314
#include <stdio.h>
@@ -34,13 +35,12 @@ static void l2_guest_code_int(void);
3435
static void guest_int_handler(struct ex_regs *regs)
3536
{
3637
int_fired++;
37-
GUEST_ASSERT_2(regs->rip == (unsigned long)l2_guest_code_int,
38-
regs->rip, (unsigned long)l2_guest_code_int);
38+
GUEST_ASSERT_EQ(regs->rip, (unsigned long)l2_guest_code_int);
3939
}
4040

4141
static void l2_guest_code_int(void)
4242
{
43-
GUEST_ASSERT_1(int_fired == 1, int_fired);
43+
GUEST_ASSERT_EQ(int_fired, 1);
4444

4545
/*
4646
* Same as the vmmcall() function, but with a ud2 sneaked after the
@@ -53,7 +53,7 @@ static void l2_guest_code_int(void)
5353
: "rbx", "rdx", "rsi", "rdi", "r8", "r9",
5454
"r10", "r11", "r12", "r13", "r14", "r15");
5555

56-
GUEST_ASSERT_1(bp_fired == 1, bp_fired);
56+
GUEST_ASSERT_EQ(bp_fired, 1);
5757
hlt();
5858
}
5959

@@ -66,9 +66,9 @@ static void guest_nmi_handler(struct ex_regs *regs)
6666

6767
if (nmi_stage_get() == 1) {
6868
vmmcall();
69-
GUEST_ASSERT(false);
69+
GUEST_FAIL("Unexpected resume after VMMCALL");
7070
} else {
71-
GUEST_ASSERT_1(nmi_stage_get() == 3, nmi_stage_get());
71+
GUEST_ASSERT_EQ(nmi_stage_get(), 3);
7272
GUEST_DONE();
7373
}
7474
}
@@ -104,15 +104,16 @@ static void l1_guest_code(struct svm_test_data *svm, uint64_t is_nmi, uint64_t i
104104
}
105105

106106
run_guest(vmcb, svm->vmcb_gpa);
107-
GUEST_ASSERT_3(vmcb->control.exit_code == SVM_EXIT_VMMCALL,
107+
__GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_VMMCALL,
108+
"Expected VMMCAL #VMEXIT, got '0x%x', info1 = '0x%llx, info2 = '0x%llx'",
108109
vmcb->control.exit_code,
109110
vmcb->control.exit_info_1, vmcb->control.exit_info_2);
110111

111112
if (is_nmi) {
112113
clgi();
113114
x2apic_write_reg(APIC_ICR, APIC_DEST_SELF | APIC_INT_ASSERT | APIC_DM_NMI);
114115

115-
GUEST_ASSERT_1(nmi_stage_get() == 1, nmi_stage_get());
116+
GUEST_ASSERT_EQ(nmi_stage_get(), 1);
116117
nmi_stage_inc();
117118

118119
stgi();
@@ -133,7 +134,8 @@ static void l1_guest_code(struct svm_test_data *svm, uint64_t is_nmi, uint64_t i
133134
vmcb->control.next_rip = vmcb->save.rip + 2;
134135

135136
run_guest(vmcb, svm->vmcb_gpa);
136-
GUEST_ASSERT_3(vmcb->control.exit_code == SVM_EXIT_HLT,
137+
__GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_HLT,
138+
"Expected HLT #VMEXIT, got '0x%x', info1 = '0x%llx, info2 = '0x%llx'",
137139
vmcb->control.exit_code,
138140
vmcb->control.exit_info_1, vmcb->control.exit_info_2);
139141

@@ -185,7 +187,7 @@ static void run_test(bool is_nmi)
185187

186188
switch (get_ucall(vcpu, &uc)) {
187189
case UCALL_ABORT:
188-
REPORT_GUEST_ASSERT_3(uc, "vals = 0x%lx 0x%lx 0x%lx");
190+
REPORT_GUEST_ASSERT(uc);
189191
break;
190192
/* NOT REACHED */
191193
case UCALL_DONE:

0 commit comments

Comments
 (0)