Skip to contentSkip to conversation

x86: nVMX: Print more (accurate) info if RDTSC diff test fails

PATCH Applied Sean Christopherson 4 participants 5 messages Jan 24, 2020 – Jul 1, 2020 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: nVMX: Print more (accurate) info if RDTSC diff test fails

Snapshot the delta of the last run and display it in the report if the test fails. Abort the run loop as soon as the threshold is reached so that the displayed delta is guaranteed to a failed delta. Displaying the delta helps triage failures, e.g. is my system completely broken or did I get unlucky, and aborting the loop early saves 99900 runs when the system is indeed broken.

---
 x86/vmx_tests.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
x86/vmx_tests.c +6 -5
index b31c360..4049dec 100644
@@ -9204,6 +9204,7 @@ static unsigned long long rdtsc_vmexit_diff_test_iteration(void)
 
 static void rdtsc_vmexit_diff_test(void)
 {
+	unsigned long long delta;
 	int fail = 0;
 	int i;
 
@@ -9226,17 +9227,17 @@ static void rdtsc_vmexit_diff_test(void)
 	vmcs_write(EXI_MSR_ST_CNT, 1);
 	vmcs_write(EXIT_MSR_ST_ADDR, virt_to_phys(exit_msr_store));
 
-	for (i = 0; i < RDTSC_DIFF_ITERS; i++) {
-		if (rdtsc_vmexit_diff_test_iteration() >=
-		    HOST_CAPTURED_GUEST_TSC_DIFF_THRESHOLD)
+	for (i = 0; i < RDTSC_DIFF_ITERS && fail < RDTSC_DIFF_FAILS; i++) {
+		delta = rdtsc_vmexit_diff_test_iteration();
+		if (delta >= HOST_CAPTURED_GUEST_TSC_DIFF_THRESHOLD)
 			fail++;
 	}
 
 	enter_guest();
 
 	report(fail < RDTSC_DIFF_FAILS,
-	       "RDTSC to VM-exit delta too high in %d of %d iterations",
-	       fail, RDTSC_DIFF_ITERS);
+	       "RDTSC to VM-exit delta too high in %d of %d iterations, last = %llu",
+	       fail, i, delta);
 }
 
 static int invalid_msr_init(struct vmcs *vmcs)
Signature · 1 line
2.24.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 39 lines · Sean Christopherson

Snapshot the delta of the last run and display it in the report if the test fails. Abort the run loop as soon as the threshold is reached so that the displayed delta is guaranteed to a failed delta. Displaying the delta helps triage failures, e.g. is my system completely broken or did I get unlucky, and aborting the loop early saves 99900 runs when the system is indeed broken.

---
  x86/vmx_tests.c | 11 ++++++-----
  1 file changed, 6 insertions(+), 5 deletions(-)
x86/vmx_tests.c +4 -3
index b31c360..4049dec 100644
@@ -9204,6 +9204,7 @@ static unsigned long long rdtsc_vmexit_diff_test_iteration(void)
 
  static void rdtsc_vmexit_diff_test(void)
  {
+	unsigned long long delta;
  	int fail = 0;
  	int i;
 
@@ -9226,17 +9227,17 @@ static void rdtsc_vmexit_diff_test(void)
  	vmcs_write(EXI_MSR_ST_CNT, 1);
  	vmcs_write(EXIT_MSR_ST_ADDR, virt_to_phys(exit_msr_store));
 
-	for (i = 0; i < RDTSC_DIFF_ITERS; i++) {
-		if (rdtsc_vmexit_diff_test_iteration() >=
-		    HOST_CAPTURED_GUEST_TSC_DIFF_THRESHOLD)
+	for (i = 0; i < RDTSC_DIFF_ITERS && fail < RDTSC_DIFF_FAILS; i++) {
+		delta = rdtsc_vmexit_diff_test_iteration();
+		if (delta >= HOST_CAPTURED_GUEST_TSC_DIFF_THRESHOLD)
  			fail++;
  	}
 

x86/vmx_tests.c static void rdtsc_vmexit_diff_test(void) · line 9243

Quoted 10 lines
x86/vmx_tests.c +2 -2
  	enter_guest();
 
  	report(fail < RDTSC_DIFF_FAILS,
-	       "RDTSC to VM-exit delta too high in %d of %d iterations",
-	       fail, RDTSC_DIFF_ITERS);
+	       "RDTSC to VM-exit delta too high in %d of %d iterations, last = %llu",
+	       fail, i, delta);
  }
 
  static int invalid_msr_init(struct vmcs *vmcs)
Reviewed-by
#2 lore raw
Quoted 51 lines · Krish Sadhukhan
Quoted 48 lines · Sean Christopherson

Snapshot the delta of the last run and display it in the report if the test fails. Abort the run loop as soon as the threshold is reached so that the displayed delta is guaranteed to a failed delta. Displaying the delta helps triage failures, e.g. is my system completely broken or did I get unlucky, and aborting the loop early saves 99900 runs when the system is indeed broken.

---
  x86/vmx_tests.c | 11 ++++++-----
  1 file changed, 6 insertions(+), 5 deletions(-)
x86/vmx_tests.c +6 -5
index b31c360..4049dec 100644
@@ -9204,6 +9204,7 @@ static unsigned long long rdtsc_vmexit_diff_test_iteration(void)
 
  static void rdtsc_vmexit_diff_test(void)
  {
+     unsigned long long delta;
      int fail = 0;
      int i;
 
@@ -9226,17 +9227,17 @@ static void rdtsc_vmexit_diff_test(void)
      vmcs_write(EXI_MSR_ST_CNT, 1);
      vmcs_write(EXIT_MSR_ST_ADDR, virt_to_phys(exit_msr_store));
 
-     for (i = 0; i < RDTSC_DIFF_ITERS; i++) {
-             if (rdtsc_vmexit_diff_test_iteration() >=
-                 HOST_CAPTURED_GUEST_TSC_DIFF_THRESHOLD)
+     for (i = 0; i < RDTSC_DIFF_ITERS && fail < RDTSC_DIFF_FAILS; i++) {
+             delta = rdtsc_vmexit_diff_test_iteration();
+             if (delta >= HOST_CAPTURED_GUEST_TSC_DIFF_THRESHOLD)
                      fail++;
      }
 
      enter_guest();
 
      report(fail < RDTSC_DIFF_FAILS,
-            "RDTSC to VM-exit delta too high in %d of %d iterations",
-            fail, RDTSC_DIFF_ITERS);
+            "RDTSC to VM-exit delta too high in %d of %d iterations, last = %llu",
+            fail, i, delta);
  }
 
Quoted 2 lines

x86/vmx_tests.c static void rdtsc_vmexit_diff_test(void) · line 9243

Quoted 1 line
x86/vmx_tests.c +0 -0
  static int invalid_msr_init(struct vmcs *vmcs)
#3 lore raw

Ping.

Quoted 57 lines · Aaron Lewis
Quoted 51 lines · Krish Sadhukhan
Quoted 48 lines · Sean Christopherson

Snapshot the delta of the last run and display it in the report if the test fails. Abort the run loop as soon as the threshold is reached so that the displayed delta is guaranteed to a failed delta. Displaying the delta helps triage failures, e.g. is my system completely broken or did I get unlucky, and aborting the loop early saves 99900 runs when the system is indeed broken.

---
  x86/vmx_tests.c | 11 ++++++-----
  1 file changed, 6 insertions(+), 5 deletions(-)
x86/vmx_tests.c +6 -5
index b31c360..4049dec 100644
@@ -9204,6 +9204,7 @@ static unsigned long long rdtsc_vmexit_diff_test_iteration(void)
 
  static void rdtsc_vmexit_diff_test(void)
  {
+     unsigned long long delta;
      int fail = 0;
      int i;
 
@@ -9226,17 +9227,17 @@ static void rdtsc_vmexit_diff_test(void)
      vmcs_write(EXI_MSR_ST_CNT, 1);
      vmcs_write(EXIT_MSR_ST_ADDR, virt_to_phys(exit_msr_store));
 
-     for (i = 0; i < RDTSC_DIFF_ITERS; i++) {
-             if (rdtsc_vmexit_diff_test_iteration() >=
-                 HOST_CAPTURED_GUEST_TSC_DIFF_THRESHOLD)
+     for (i = 0; i < RDTSC_DIFF_ITERS && fail < RDTSC_DIFF_FAILS; i++) {
+             delta = rdtsc_vmexit_diff_test_iteration();
+             if (delta >= HOST_CAPTURED_GUEST_TSC_DIFF_THRESHOLD)
                      fail++;
      }
 
      enter_guest();
 
      report(fail < RDTSC_DIFF_FAILS,
-            "RDTSC to VM-exit delta too high in %d of %d iterations",
-            fail, RDTSC_DIFF_ITERS);
+            "RDTSC to VM-exit delta too high in %d of %d iterations, last = %llu",
+            fail, i, delta);
  }
 
Quoted 2 lines

x86/vmx_tests.c static void rdtsc_vmexit_diff_test(void) · line 9243

Quoted 1 line
x86/vmx_tests.c +0 -0
  static int invalid_msr_init(struct vmcs *vmcs)
maintainer Applied
#4 lore raw
Quoted 61 lines · Sean Christopherson

Ping.

Quoted 57 lines · Aaron Lewis
Quoted 51 lines · Krish Sadhukhan
Quoted 48 lines · Sean Christopherson

Snapshot the delta of the last run and display it in the report if the test fails. Abort the run loop as soon as the threshold is reached so that the displayed delta is guaranteed to a failed delta. Displaying the delta helps triage failures, e.g. is my system completely broken or did I get unlucky, and aborting the loop early saves 99900 runs when the system is indeed broken.

---
  x86/vmx_tests.c | 11 ++++++-----
  1 file changed, 6 insertions(+), 5 deletions(-)
x86/vmx_tests.c +6 -5
index b31c360..4049dec 100644
@@ -9204,6 +9204,7 @@ static unsigned long long rdtsc_vmexit_diff_test_iteration(void)
 
  static void rdtsc_vmexit_diff_test(void)
  {
+     unsigned long long delta;
      int fail = 0;
      int i;
 
@@ -9226,17 +9227,17 @@ static void rdtsc_vmexit_diff_test(void)
      vmcs_write(EXI_MSR_ST_CNT, 1);
      vmcs_write(EXIT_MSR_ST_ADDR, virt_to_phys(exit_msr_store));
 
-     for (i = 0; i < RDTSC_DIFF_ITERS; i++) {
-             if (rdtsc_vmexit_diff_test_iteration() >=
-                 HOST_CAPTURED_GUEST_TSC_DIFF_THRESHOLD)
+     for (i = 0; i < RDTSC_DIFF_ITERS && fail < RDTSC_DIFF_FAILS; i++) {
+             delta = rdtsc_vmexit_diff_test_iteration();
+             if (delta >= HOST_CAPTURED_GUEST_TSC_DIFF_THRESHOLD)
                      fail++;
      }
 
      enter_guest();
 
      report(fail < RDTSC_DIFF_FAILS,
-            "RDTSC to VM-exit delta too high in %d of %d iterations",
-            fail, RDTSC_DIFF_ITERS);
+            "RDTSC to VM-exit delta too high in %d of %d iterations, last = %llu",
+            fail, i, delta);
  }
 
Quoted 2 lines

x86/vmx_tests.c static void rdtsc_vmexit_diff_test(void) · line 9243

Quoted 1 line
x86/vmx_tests.c +0 -0
  static int invalid_msr_init(struct vmcs *vmcs)

Queued, thanks.

Paolo