public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [kvm-unit-tests 0/4] Misc fixups/cleanups for nested tests
@ 2025-11-04 19:30 Yosry Ahmed
  2025-11-04 19:30 ` [kvm-unit-tests 1/4] x86/vmx: Skip vmx_pf_exception_test_fep early if FEP is not available Yosry Ahmed
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Yosry Ahmed @ 2025-11-04 19:30 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: Paolo Bonzini, Jim Mattson, kvm, linux-kernel, Yosry Ahmed

A group of misc cleanups and fixups for SVM and VMX tests.

Disclaimer for patch 3: I have no idea why #UD was used to convey
failure from the guest when report() is usable, so I might have missed
something there.

Disclaimer for patch 4: I did not look too closely into why the flake is
happening. It seemed like there was an adhoc approach to stabilize the
test (shift duration by 24 bits), so I just made the necessary
adjustment to make the test stable on Turin.

This series is based on a different SVM series to avoid conflicts:
https://lore.kernel.org/kvm/20251028221213.1937120-1-yosry.ahmed@linux.dev/

Yosry Ahmed (4):
  x86/vmx: Skip vmx_pf_exception_test_fep early if FEP is not available
  x86/svm: Print SVM test names before running tests
  x86/svm: Replace #UD on failure in LBRV tests with proper report()s
  x86/svm: Deflake svm_tsc_scale_test

 x86/svm.c       |  1 +
 x86/svm_tests.c | 19 ++++++++++---------
 x86/vmx_tests.c |  5 ++++-
 3 files changed, 15 insertions(+), 10 deletions(-)

-- 
2.51.2.1026.g39e6a42477-goog


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [kvm-unit-tests 1/4] x86/vmx: Skip vmx_pf_exception_test_fep early if FEP is not available
  2025-11-04 19:30 [kvm-unit-tests 0/4] Misc fixups/cleanups for nested tests Yosry Ahmed
@ 2025-11-04 19:30 ` Yosry Ahmed
  2025-11-04 19:30 ` [kvm-unit-tests 2/4] x86/svm: Print SVM test names before running tests Yosry Ahmed
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Yosry Ahmed @ 2025-11-04 19:30 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: Paolo Bonzini, Jim Mattson, kvm, linux-kernel, Yosry Ahmed

The check to skip the test is currently performed in the guest code.
There a few TEST_ASSERTs that happen before the guest is run, which
internally call report_passed(). The latter increases the number of
passed tests.

Hence, when vmx_pf_exception_test_fep is run, report_summary() does not
return a "skip" error code because the total number of tests is larger
than the number of skipped tests.

Skip early if FEP is not available, before any assertions, such that
report_summary() finds exactly 1 skipped test and returns the
appropriate error code.

Signed-off-by: Yosry Ahmed <yosry.ahmed@linux.dev>
---
 x86/vmx_tests.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index 0b3cfe50c6142..4f214ebdbe1d9 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -10644,7 +10644,10 @@ static void vmx_pf_exception_test(void)
 
 static void vmx_pf_exception_forced_emulation_test(void)
 {
-	__vmx_pf_exception_test(NULL, NULL, vmx_pf_exception_forced_emulation_test_guest);
+	if (is_fep_available)
+		__vmx_pf_exception_test(NULL, NULL, vmx_pf_exception_forced_emulation_test_guest);
+	else
+		report_skip("Forced emulation prefix (FEP) not available\n");
 }
 
 static void invalidate_tlb_no_vpid(void *data)
-- 
2.51.2.1026.g39e6a42477-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [kvm-unit-tests 2/4] x86/svm: Print SVM test names before running tests
  2025-11-04 19:30 [kvm-unit-tests 0/4] Misc fixups/cleanups for nested tests Yosry Ahmed
  2025-11-04 19:30 ` [kvm-unit-tests 1/4] x86/vmx: Skip vmx_pf_exception_test_fep early if FEP is not available Yosry Ahmed
@ 2025-11-04 19:30 ` Yosry Ahmed
  2025-11-04 19:30 ` [kvm-unit-tests 3/4] x86/svm: Replace #UD on failure in LBRV tests with proper report()s Yosry Ahmed
  2025-11-04 19:30 ` [kvm-unit-tests 4/4] x86/svm: Deflake svm_tsc_scale_test Yosry Ahmed
  3 siblings, 0 replies; 5+ messages in thread
From: Yosry Ahmed @ 2025-11-04 19:30 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: Paolo Bonzini, Jim Mattson, kvm, linux-kernel, Yosry Ahmed

When SVM tests are run, the log is a see of PASS/FAIL/SKIPs that are not
clearly separated by test. Sometimes it's hard to attribute a failure to
a specific test (e.g. if the same helper is reused by multiple tests).

Print the test name before running each test.

Signed-off-by: Yosry Ahmed <yosry.ahmed@linux.dev>
---
 x86/svm.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/x86/svm.c b/x86/svm.c
index 5015339ddb657..de9eb19443caa 100644
--- a/x86/svm.c
+++ b/x86/svm.c
@@ -407,6 +407,7 @@ int run_svm_tests(int ac, char **av, struct svm_test *svm_tests)
 			report_skip("%s (not supported)", svm_tests[i].name);
 			continue;
 		}
+		printf("SVM test: %s\n", svm_tests[i].name);
 		if (svm_tests[i].v2 == NULL) {
 			if (svm_tests[i].on_vcpu) {
 				if (cpu_count() <= svm_tests[i].on_vcpu)
-- 
2.51.2.1026.g39e6a42477-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [kvm-unit-tests 3/4] x86/svm: Replace #UD on failure in LBRV tests with proper report()s
  2025-11-04 19:30 [kvm-unit-tests 0/4] Misc fixups/cleanups for nested tests Yosry Ahmed
  2025-11-04 19:30 ` [kvm-unit-tests 1/4] x86/vmx: Skip vmx_pf_exception_test_fep early if FEP is not available Yosry Ahmed
  2025-11-04 19:30 ` [kvm-unit-tests 2/4] x86/svm: Print SVM test names before running tests Yosry Ahmed
@ 2025-11-04 19:30 ` Yosry Ahmed
  2025-11-04 19:30 ` [kvm-unit-tests 4/4] x86/svm: Deflake svm_tsc_scale_test Yosry Ahmed
  3 siblings, 0 replies; 5+ messages in thread
From: Yosry Ahmed @ 2025-11-04 19:30 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: Paolo Bonzini, Jim Mattson, kvm, linux-kernel, Yosry Ahmed

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [kvm-unit-tests 4/4] x86/svm: Deflake svm_tsc_scale_test
  2025-11-04 19:30 [kvm-unit-tests 0/4] Misc fixups/cleanups for nested tests Yosry Ahmed
                   ` (2 preceding siblings ...)
  2025-11-04 19:30 ` [kvm-unit-tests 3/4] x86/svm: Replace #UD on failure in LBRV tests with proper report()s Yosry Ahmed
@ 2025-11-04 19:30 ` Yosry Ahmed
  3 siblings, 0 replies; 5+ messages in thread
From: Yosry Ahmed @ 2025-11-04 19:30 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: Paolo Bonzini, Jim Mattson, kvm, linux-kernel, Yosry Ahmed

On an AMT Turin (EPYC Zen 5), svm_tsc_scale_test flakes on the last test
case with 0.0001 TSC scaling ratio, even with the 24-bit shift for
stability. On failure, the actual value is 49 instead of the expected
50.

Use a higher scaling ratio, 0.001, which makes the test pass
consistently.

Signed-off-by: Yosry Ahmed <yosry.ahmed@linux.dev>
---
 x86/svm_tests.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/x86/svm_tests.c b/x86/svm_tests.c
index 8d309860e76e5..29c899762b7a4 100644
--- a/x86/svm_tests.c
+++ b/x86/svm_tests.c
@@ -1002,7 +1002,7 @@ static void svm_tsc_scale_test(void)
 	}
 
 	svm_tsc_scale_run_testcase(50, 255, rdrand());
-	svm_tsc_scale_run_testcase(50, 0.0001, rdrand());
+	svm_tsc_scale_run_testcase(50, 0.001, rdrand());
 }
 
 static void latency_prepare(struct svm_test *test)
-- 
2.51.2.1026.g39e6a42477-goog


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-11-04 19:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-04 19:30 [kvm-unit-tests 0/4] Misc fixups/cleanups for nested tests Yosry Ahmed
2025-11-04 19:30 ` [kvm-unit-tests 1/4] x86/vmx: Skip vmx_pf_exception_test_fep early if FEP is not available Yosry Ahmed
2025-11-04 19:30 ` [kvm-unit-tests 2/4] x86/svm: Print SVM test names before running tests Yosry Ahmed
2025-11-04 19:30 ` [kvm-unit-tests 3/4] x86/svm: Replace #UD on failure in LBRV tests with proper report()s Yosry Ahmed
2025-11-04 19:30 ` [kvm-unit-tests 4/4] x86/svm: Deflake svm_tsc_scale_test Yosry Ahmed

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox