[kvm-unit-tests 3/4] x86/svm: Replace #UD on failure in LBRV tests with proper report()s

Yosry Ahmed posted 4 patches 1 month, 2 weeks ago
[kvm-unit-tests 3/4] x86/svm: Replace #UD on failure in LBRV tests with proper report()s
Posted by Yosry Ahmed 1 month, 2 weeks ago
In LBRV tests, failures in the guest trigger a #UD and does not convey
useful debugging info (i.e. expected and actual values of MSRs). Replace
them with proper report() calls.

Admittedly, it is unclear why the choice of #UD was made given that
report() works fine in the guest.

Signed-off-by: Yosry Ahmed <yosry.ahmed@linux.dev>
---
 x86/svm_tests.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/x86/svm_tests.c b/x86/svm_tests.c
index 2981f459032cb..8d309860e76e5 100644
--- a/x86/svm_tests.c
+++ b/x86/svm_tests.c
@@ -3017,16 +3017,17 @@ do {											\
 	TEST_EXPECT_EQ((u64)to_expected, amd_get_lbr_rip(MSR_IA32_LASTBRANCHTOIP));	\
 } while (0)
 
-/*
- * FIXME: Do something other than generate an exception to communicate failure.
- * Debugging without expected vs. actual is an absolute nightmare.
- */
 #define GUEST_CHECK_LBR(from_expected, to_expected)				\
 do {										\
-	if ((u64)(from_expected) != amd_get_lbr_rip(MSR_IA32_LASTBRANCHFROMIP))	\
-		asm volatile("ud2");						\
-	if ((u64)(to_expected) != amd_get_lbr_rip(MSR_IA32_LASTBRANCHTOIP))	\
-		asm volatile("ud2");						\
+	u64 from_ip = amd_get_lbr_rip(MSR_IA32_LASTBRANCHFROMIP);		\
+	u64 to_ip = amd_get_lbr_rip(MSR_IA32_LASTBRANCHTOIP);			\
+										\
+	report((u64)(from_expected) == from_ip,					\
+	       "Expected MSR_IA32_LASTBRANCHFROMIP: 0x%lx, found: 0x%lx",	\
+	       (u64)from_expected, from_ip);					\
+	report((u64)(to_expected) == to_ip,					\
+	       "Expected MSR_IA32_LASTBRANCHTOIP: 0x%lx, found: 0x%lx",		\
+	       (u64)to_expected, to_ip);					\
 } while (0)
 
 #define REPORT_GUEST_LBR_ERROR(vmcb)						\
-- 
2.51.2.1026.g39e6a42477-goog