Skip to contentSkip to conversation

Fix vmptrst result type

PATCH New Jim Mattson 1 participant 2 messages Jul 17, 2017 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Fix vmptrst result type

vmptrst stores a 64-bit physical address to memory (or -1 if there is no current VMCS).

---
 x86/vmx.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
x86/vmx.h +5 -2
index 392979ba8ae8..a368f31b159d 100644
@@ -5,6 +5,7 @@
 #include "processor.h"
 #include "bitops.h"
 #include "asm/page.h"
+#include "asm/io.h"
 
 struct vmcs {
 	u32 revision_id; /* vmcs revision identifier */
@@ -646,10 +647,12 @@ static inline int vmcs_write(enum Encoding enc, u64 val)
 static inline int vmcs_save(struct vmcs **vmcs)
 {
 	bool ret;
+	unsigned long pa;
 	u64 rflags = read_rflags() | X86_EFLAGS_CF | X86_EFLAGS_ZF;
 
-	asm volatile ("push %1; popf; vmptrst %2; setbe %0"
-		      : "=q" (ret) : "q" (rflags), "m" (*vmcs) : "cc");
+	asm volatile ("push %2; popf; vmptrst %1; setbe %0"
+		      : "=q" (ret), "=m" (pa) : "r" (rflags) : "cc");
+	*vmcs = (pa == -1ull) ? NULL : phys_to_virt(pa);
 	return ret;
 }
 
Signature · 1 line
2.13.2.932.g7449e964c-goog
#1 lore raw

PATCH 2/2 Test VM-entry in MOVSS shadow

VM-entry is disallowed in the shadow of a MOV-to-SS instruction. When the current-VMCS is valid, check that the instruction pointer falls through to the next instruction, the ALU flags are set to ZF (VMfailValid), and the VM-instruction error field contains 26 ("VM entry with events blocked by MOV SS.").

---
 lib/x86/processor.h | 16 +++++----
 x86/unittests.cfg   |  6 ++++
 x86/vmx_tests.c     | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 111 insertions(+), 7 deletions(-)
lib/x86/processor.h +9 -7
index 895d992a6943..631aa843b65e 100644
@@ -30,13 +30,15 @@
 #define X86_CR4_SMAP   0x00200000
 #define X86_CR4_PKE    0x00400000
 
-#define X86_EFLAGS_CF  0x00000001
-#define X86_EFLAGS_PF  0x00000004
-#define X86_EFLAGS_AF  0x00000010
-#define X86_EFLAGS_ZF  0x00000040
-#define X86_EFLAGS_SF  0x00000080
-#define X86_EFLAGS_OF  0x00000800
-#define X86_EFLAGS_AC  0x00040000
+#define X86_EFLAGS_CF    0x00000001
+#define X86_EFLAGS_FIXED 0x00000002
+#define X86_EFLAGS_PF    0x00000004
+#define X86_EFLAGS_AF    0x00000010
+#define X86_EFLAGS_ZF    0x00000040
+#define X86_EFLAGS_SF    0x00000080
+#define X86_EFLAGS_IF    0x00000200
+#define X86_EFLAGS_OF    0x00000800
+#define X86_EFLAGS_AC    0x00040000
 
 #define X86_IA32_EFER          0xc0000080
 #define X86_EFER_LMA           (1UL << 8)
x86/unittests.cfg +6 -0
index 5ab46671d631..c5b35e7eee3e 100644
@@ -494,6 +494,12 @@ extra_params = -cpu host,+vmx -m 2048 -append ept_access_test_force_2m_page
 arch = x86_64
 groups = vmx
 
+[vmx_vmentry_movss_shadow_test]
+file = vmx.flat
+extra_params = -cpu host,+vmx -m 2048 -append vmentry_movss_shadow_test
+arch = x86_64
+groups = vmx
+
 [debug]
 file = debug.flat
 arch = x86_64
x86/vmx_tests.c +96 -0

107 lines not on this page · raw message

Signature · 1 line
2.13.2.932.g7449e964c-goog