Skip to contentSkip to conversation

x86: nvmx: fix bug in __enter_guest()

PATCH Superseded Marc Orr 2 participants 3 messages Sep 17, 2019

Subsystems (2)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Marc Orr

author
#0 lore raw

PATCH v4 1/2 x86: nvmx: fix bug in __enter_guest()

__enter_guest() should only set the launched flag when a launch has succeeded. Thus, don't set the launched flag when the VMX_ENTRY_FAILURE, bit 31, is set in the VMCS exit reason.

---
 x86/vmx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
x86/vmx.c +1 -1
index 6079420db33a..7313c78f15c2 100644
@@ -1820,7 +1820,7 @@ static void __enter_guest(u8 abort_flag, struct vmentry_failure *failure)
 		abort();
 	}
 
-	if (!failure->early) {
+	if (!failure->early && !(vmcs_read(EXI_REASON) & VMX_ENTRY_FAILURE)) {
 		launched = 1;
 		check_for_guest_termination();
 	}
Signature · 1 line
2.23.0.237.gc6a4ce50a0-goog
author
#1 lore raw

PATCH v4 2/2 x86: nvmx: test max atomic switch MSRs

Excerise nested VMX's atomic MSR switch code (e.g., VM-entry MSR-load list) at the maximum number of MSRs supported, as described in the SDM, in the appendix chapter titled "MISCELLANEOUS DATA".

---
v3 -> v4
* Replace spaces w/ tabs.
* Replace comment as suggested by Sean.
* Make use of MIN().
* Refactor cleanup code so that only failure code path reenters guest an extra time.

 lib/alloc_page.c  |   5 ++
 lib/alloc_page.h  |   1 +
 x86/unittests.cfg |   2 +-
 x86/vmx_tests.c   | 134 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 141 insertions(+), 1 deletion(-)
lib/alloc_page.c +5 -0
index 97d13395ff08..ed236389537e 100644
@@ -53,6 +53,11 @@ void free_pages(void *mem, unsigned long size)
 	spin_unlock(&lock);
 }
 
+void free_pages_by_order(void *mem, unsigned long order)
+{
+	free_pages(mem, 1ul << (order + PAGE_SHIFT));
+}
+
 void *alloc_page()
 {
 	void *p;
lib/alloc_page.h +1 -0
index 5cdfec57a0a8..739a91def979 100644
@@ -14,5 +14,6 @@ void *alloc_page(void);
 void *alloc_pages(unsigned long order);
 void free_page(void *page);
 void free_pages(void *mem, unsigned long size);
+void free_pages_by_order(void *mem, unsigned long order);
 
 #endif
x86/unittests.cfg +1 -1
index 694ee3d42f3a..05122cf91ea1 100644
@@ -227,7 +227,7 @@ extra_params = -cpu qemu64,+umip
 
 [vmx]
 file = vmx.flat
-extra_params = -cpu host,+vmx -append "-exit_monitor_from_l2_test -ept_access* -vmx_smp* -vmx_vmcs_shadow_test"
+extra_params = -cpu host,+vmx -append "-exit_monitor_from_l2_test -ept_access* -vmx_smp* -vmx_vmcs_shadow_test -atomic_switch_overflow_msrs_test"
 arch = x86_64
 groups = vmx
 
x86/vmx_tests.c +134 -0

145 lines not on this page · raw message

Signature · 1 line
2.23.0.237.gc6a4ce50a0-goog
Reviewed-by on v4 1/2
#2 lore raw
In reply to Marc Orr
Quoted 15 lines · Marc Orr

__enter_guest() should only set the launched flag when a launch has succeeded. Thus, don't set the launched flag when the VMX_ENTRY_FAILURE, bit 31, is set in the VMCS exit reason.

---
 x86/vmx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
x86/vmx.c +0 -0
index 6079420db33a..7313c78f15c2 100644

x86/vmx.c static void __enter_guest(u8 abort_flag, struct vmentry_failure *failure) · line 1823

Quoted 5 lines
x86/vmx.c +1 -1
@@ -1820,7 +1820,7 @@ static void __enter_guest(u8 abort_flag, struct vmentry_failure *failure)
 		abort();
 	}
 
-	if (!failure->early) {
+	if (!failure->early && !(vmcs_read(EXI_REASON) & VMX_ENTRY_FAILURE)) {

Good enough for now, but struct vmentry_failure really needs to be cleaned up and renamed.

Quoted 6 lines
x86/vmx.c +0 -0
 		launched = 1;
 		check_for_guest_termination();
 	}
Signature · 1 line
2.23.0.237.gc6a4ce50a0-goog