Skip to contentSkip to conversation

KVM: selftests: Fix MWAIT error message when guest assertion fails

PATCH Superseded Sean Christopherson 2 participants 3 messages Nov 7, 2023 – Nov 28, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Sean Christopherson

author reviewer
#0 lore raw

PATCH 1/1 KVM: selftests: Fix MWAIT error message when guest assertion fails

Print out the test and vector as intended when a guest assert fails an assertion regarding MONITOR/MWAIT faulting. Unfortunately, the guest printf support doesn't detect such issues at compile-time, so the bug manifests as a confusing error message, e.g. in the most confusing case, the test complains that it got vector "0" instead of expected vector "0".

Fixes 0f52e4aaa614 ("KVM: selftests: Convert the MONITOR/MWAIT test to use printf guest asserts")
---
 tools/testing/selftests/kvm/x86_64/monitor_mwait_test.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/testing/selftests/kvm/x86_64/monitor_mwait_test.c +4 -2
index 80aa3d8b18f8..853802641e1e 100644
@@ -27,10 +27,12 @@ do {									\
 									\
 	if (fault_wanted)						\
 		__GUEST_ASSERT((vector) == UD_VECTOR,			\
-			       "Expected #UD on " insn " for testcase '0x%x', got '0x%x'", vector); \
+			       "Expected #UD on " insn " for testcase '0x%x', got '0x%x'", \
+			       testcase, vector);			\
 	else								\
 		__GUEST_ASSERT(!(vector),				\
-			       "Expected success on " insn " for testcase '0x%x', got '0x%x'", vector); \
+			       "Expected success on " insn " for testcase '0x%x', got '0x%x'", \
+			       testcase, vector);			\
 } while (0)
 
 static void guest_monitor_wait(int testcase)

base-commit: 45b890f7689eb0aba454fc5831d2d79763781677

Signature · 1 line
2.42.0.869.gea05f2083d-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 32 lines · Sean Christopherson

Print out the test and vector as intended when a guest assert fails an assertion regarding MONITOR/MWAIT faulting. Unfortunately, the guest printf support doesn't detect such issues at compile-time, so the bug manifests as a confusing error message, e.g. in the most confusing case, the test complains that it got vector "0" instead of expected vector "0".

Fixes 0f52e4aaa614 ("KVM: selftests: Convert the MONITOR/MWAIT test to use printf guest asserts")
---
 tools/testing/selftests/kvm/x86_64/monitor_mwait_test.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/testing/selftests/kvm/x86_64/monitor_mwait_test.c +4 -2
index 80aa3d8b18f8..853802641e1e 100644
@@ -27,10 +27,12 @@ do {									\
 									\
 	if (fault_wanted)						\
 		__GUEST_ASSERT((vector) == UD_VECTOR,			\
-			       "Expected #UD on " insn " for testcase '0x%x', got '0x%x'", vector); \
+			       "Expected #UD on " insn " for testcase '0x%x', got '0x%x'", \
+			       testcase, vector);			\
 	else								\
 		__GUEST_ASSERT(!(vector),				\
-			       "Expected success on " insn " for testcase '0x%x', got '0x%x'", vector); \
+			       "Expected success on " insn " for testcase '0x%x', got '0x%x'", \
+			       testcase, vector);			\
 } while (0)
 
 static void guest_monitor_wait(int testcase)
Quoted 1 line

base-commit: 45b890f7689eb0aba454fc5831d2d79763781677

I think that these days the gcc (and llvm likely) support printf annotations, and usually complain, we should look at adding these to have a warning in such cases.

Best regards,
Maxim Levitsky

author reviewer
#2 lore raw
Quoted 31 lines · Maxim Levitsky
Quoted 30 lines · Sean Christopherson

Print out the test and vector as intended when a guest assert fails an assertion regarding MONITOR/MWAIT faulting. Unfortunately, the guest printf support doesn't detect such issues at compile-time, so the bug manifests as a confusing error message, e.g. in the most confusing case, the test complains that it got vector "0" instead of expected vector "0".

Fixes 0f52e4aaa614 ("KVM: selftests: Convert the MONITOR/MWAIT test to use printf guest asserts")
---
 tools/testing/selftests/kvm/x86_64/monitor_mwait_test.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/testing/selftests/kvm/x86_64/monitor_mwait_test.c +4 -2
index 80aa3d8b18f8..853802641e1e 100644
@@ -27,10 +27,12 @@ do {									\
 									\
 	if (fault_wanted)						\
 		__GUEST_ASSERT((vector) == UD_VECTOR,			\
-			       "Expected #UD on " insn " for testcase '0x%x', got '0x%x'", vector); \
+			       "Expected #UD on " insn " for testcase '0x%x', got '0x%x'", \
+			       testcase, vector);			\
 	else								\
 		__GUEST_ASSERT(!(vector),				\
-			       "Expected success on " insn " for testcase '0x%x', got '0x%x'", vector); \
+			       "Expected success on " insn " for testcase '0x%x', got '0x%x'", \
+			       testcase, vector);			\
 } while (0)
 
Quoted 7 lines
Quoted 3 lines
tools/testing/selftests/kvm/x86_64/monitor_mwait_test.c +0 -0
 static void guest_monitor_wait(int testcase)

base-commit: 45b890f7689eb0aba454fc5831d2d79763781677

I think that these days the gcc (and llvm likely) support printf annotations, and usually complain, we should look at adding these to have a warning in such cases.

Huh. Well now I feel quite stupid for not realizing that's what

	__attribute__((__format__(printf, ...)))

is for. There's even a handy dandy __printf() macro now. I'll post a v2 with the annotations and fixes for all existing violations.