[kvm-unit-tests PATCH] x86: VMX: Fix the VMX-preemption timer expiration test

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When the VMX-preemption timer fires between the test for
"vmx_get_test_stage() == 0" and the subsequent rdtsc instruction, the
final VM-entry to finish the guest will inadvertently update
vmx_preemption_timer_expiry_finish.

Move the code to finish the guest until after the calculations
involving vmx_preemption_timer_expiry_finish are done, so that it
doesn't matter if vmx_preemption_timer_expiry_finish is clobbered.

Signed-off-by: Jim Mattson <jmattson@xxxxxxxxxx>
Fixes: b49a1a6d4e23 ("x86: VMX: Add a VMX-preemption timer expiration test")
---
 x86/vmx_tests.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index 4d581e7085ea..8a1393668d93 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -9194,16 +9194,16 @@ static void vmx_preemption_timer_expiry_test(void)
 	reason = (u32)vmcs_read(EXI_REASON);
 	TEST_ASSERT(reason == VMX_PREEMPT);
 
-	vmcs_clear_bits(PIN_CONTROLS, PIN_PREEMPT);
-	vmx_set_test_stage(1);
-	enter_guest();
-
 	tsc_deadline = ((vmx_preemption_timer_expiry_start >> misc.pt_bit) <<
 			misc.pt_bit) + (preemption_timer_value << misc.pt_bit);
 
 	report(vmx_preemption_timer_expiry_finish < tsc_deadline,
 	       "Last stored guest TSC (%lu) < TSC deadline (%lu)",
 	       vmx_preemption_timer_expiry_finish, tsc_deadline);
+
+	vmcs_clear_bits(PIN_CONTROLS, PIN_PREEMPT);
+	vmx_set_test_stage(1);
+	enter_guest();
 }
 
 static void vmx_db_test_guest(void)
-- 
2.37.0.rc0.161.g10f37bed90-goog




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux