Skip to contentSkip to conversation

x86: VMX: Check preconditions for RDTSC test

PATCH Applied Oliver Upton 3 participants 4 messages Jan 22, 2020 KVM

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: VMX: Check preconditions for RDTSC test

The RDTSC VM-exit test requires the 'use TSC offsetting' processor-based VM-execution control be allowed on the host. Check this precondition before running the test rather than asserting it later on to avoid erroneous failures on a host without TSC offsetting.

---
 x86/vmx_tests.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
x86/vmx_tests.c +5 -3
index 3b150323b325..de9a931216e2 100644
@@ -9161,9 +9161,6 @@ static void vmx_vmcs_shadow_test(void)
  */
 static void reset_guest_tsc_to_zero(void)
 {
-	TEST_ASSERT_MSG(ctrl_cpu_rev[0].clr & CPU_USE_TSC_OFFSET,
-			"Expected support for 'use TSC offsetting'");
-
 	vmcs_set_bits(CPU_EXEC_CTRL0, CPU_USE_TSC_OFFSET);
 	vmcs_write(TSC_OFFSET, -rdtsc());
 }
@@ -9210,6 +9207,11 @@ static void rdtsc_vmexit_diff_test(void)
 	int fail = 0;
 	int i;
 
+	if (!(ctrl_cpu_rev[0].clr & CPU_USE_TSC_OFFSET)) {
+		printf("CPU doesn't support the 'use TSC offsetting' processor-based VM-execution control.\n");
+		return;
+	}
+
 	test_set_guest(rdtsc_vmexit_diff_test_guest);
 
 	reset_guest_tsc_to_zero();
Signature · 1 line
2.25.0.341.g760bfbb309-goog
#1 lore raw
Quoted 26 lines · Oliver Upton

The RDTSC VM-exit test requires the 'use TSC offsetting' processor-based VM-execution control be allowed on the host. Check this precondition before running the test rather than asserting it later on to avoid erroneous failures on a host without TSC offsetting.

---
 x86/vmx_tests.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
x86/vmx_tests.c +0 -3
index 3b150323b325..de9a931216e2 100644
@@ -9161,9 +9161,6 @@ static void vmx_vmcs_shadow_test(void)
  */
 static void reset_guest_tsc_to_zero(void)
 {
-	TEST_ASSERT_MSG(ctrl_cpu_rev[0].clr & CPU_USE_TSC_OFFSET,
-			"Expected support for 'use TSC offsetting'");
-
 	vmcs_set_bits(CPU_EXEC_CTRL0, CPU_USE_TSC_OFFSET);
 	vmcs_write(TSC_OFFSET, -rdtsc());
 }

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

Quoted 8 lines
x86/vmx_tests.c +5 -0
@@ -9210,6 +9207,11 @@ static void rdtsc_vmexit_diff_test(void)
 	int fail = 0;
 	int i;
 
+	if (!(ctrl_cpu_rev[0].clr & CPU_USE_TSC_OFFSET)) {
+		printf("CPU doesn't support the 'use TSC offsetting' processor-based VM-execution control.\n");
+		return;
+	}
+

Can we use test_skip() instead, something like

x86/vmx_tests.c +3 -0
index dd32b3aef08b..bfecf36d37ef 100644
@@ -9166,6 +9166,9 @@ static void rdtsc_vmexit_diff_test(void)
        int fail = 0;
        int i;
 
+       if (!(ctrl_cpu_rev[0].clr & CPU_USE_TSC_OFFSET))
+               test_skip("CPU doesn't support the 'use TSC offsetting' processor-based VM-execution control.\n");
+
        test_set_guest(rdtsc_vmexit_diff_test_guest);
 
        reset_guest_tsc_to_zero();

?

Quoted 3 lines
x86/vmx_tests.c +0 -0
 	test_set_guest(rdtsc_vmexit_diff_test_guest);
 
 	reset_guest_tsc_to_zero();
Signature · 1 line
Vitaly
#2 lore raw
Quoted 54 lines · Vitaly Kuznetsov
Quoted 26 lines · Oliver Upton

The RDTSC VM-exit test requires the 'use TSC offsetting' processor-based VM-execution control be allowed on the host. Check this precondition before running the test rather than asserting it later on to avoid erroneous failures on a host without TSC offsetting.

---
 x86/vmx_tests.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
x86/vmx_tests.c +0 -3
index 3b150323b325..de9a931216e2 100644
@@ -9161,9 +9161,6 @@ static void vmx_vmcs_shadow_test(void)
  */
 static void reset_guest_tsc_to_zero(void)
 {
-	TEST_ASSERT_MSG(ctrl_cpu_rev[0].clr & CPU_USE_TSC_OFFSET,
-			"Expected support for 'use TSC offsetting'");
-
 	vmcs_set_bits(CPU_EXEC_CTRL0, CPU_USE_TSC_OFFSET);
 	vmcs_write(TSC_OFFSET, -rdtsc());
 }

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

Quoted 8 lines
x86/vmx_tests.c +5 -0
@@ -9210,6 +9207,11 @@ static void rdtsc_vmexit_diff_test(void)
 	int fail = 0;
 	int i;
 
+	if (!(ctrl_cpu_rev[0].clr & CPU_USE_TSC_OFFSET)) {
+		printf("CPU doesn't support the 'use TSC offsetting' processor-based VM-execution control.\n");
+		return;
+	}
+

Can we use test_skip() instead, something like

x86/vmx_tests.c +3 -0
index dd32b3aef08b..bfecf36d37ef 100644
@@ -9166,6 +9166,9 @@ static void rdtsc_vmexit_diff_test(void)
        int fail = 0;
        int i;
 
+       if (!(ctrl_cpu_rev[0].clr & CPU_USE_TSC_OFFSET))
+               test_skip("CPU doesn't support the 'use TSC offsetting' processor-based VM-execution control.\n");
+
        test_set_guest(rdtsc_vmexit_diff_test_guest);
 
        reset_guest_tsc_to_zero();
Quoted 1 line

?

Even better :) Thanks Vitaly!

Quoted 7 lines
Quoted 3 lines
x86/vmx_tests.c +0 -0
 	test_set_guest(rdtsc_vmexit_diff_test_guest);
 
 	reset_guest_tsc_to_zero();
Signature · 1 line
Vitaly
maintainer Applied
#3 lore raw
In reply to Oliver Upton
Quoted 28 lines · Oliver Upton

The RDTSC VM-exit test requires the 'use TSC offsetting' processor-based VM-execution control be allowed on the host. Check this precondition before running the test rather than asserting it later on to avoid erroneous failures on a host without TSC offsetting.

---
 x86/vmx_tests.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
x86/vmx_tests.c +0 -3
index 3b150323b325..de9a931216e2 100644
@@ -9161,9 +9161,6 @@ static void vmx_vmcs_shadow_test(void)
  */
 static void reset_guest_tsc_to_zero(void)
 {
-	TEST_ASSERT_MSG(ctrl_cpu_rev[0].clr & CPU_USE_TSC_OFFSET,
-			"Expected support for 'use TSC offsetting'");
-
 	vmcs_set_bits(CPU_EXEC_CTRL0, CPU_USE_TSC_OFFSET);
 	vmcs_write(TSC_OFFSET, -rdtsc());
 }
@@ -9210,6 +9207,11 @@ static void rdtsc_vmexit_diff_test(void)
 	int fail = 0;

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

Quoted 10 lines
x86/vmx_tests.c +5 -0
 	int i;
 
+	if (!(ctrl_cpu_rev[0].clr & CPU_USE_TSC_OFFSET)) {
+		printf("CPU doesn't support the 'use TSC offsetting' processor-based VM-execution control.\n");
+		return;
+	}
+
 	test_set_guest(rdtsc_vmexit_diff_test_guest);
 
 	reset_guest_tsc_to_zero();

Queued, thanks.

Paolo