VMM: helper for VMPTRST
authorBarret Rhoden <brho@cs.berkeley.edu>
Fri, 20 Mar 2015 20:03:43 +0000 (16:03 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Tue, 7 Apr 2015 19:06:58 +0000 (15:06 -0400)
Extracts the calling core's VMCS pointer.

kern/arch/x86/vmm/intel/vmx.c
kern/arch/x86/vmm/intel/vmx.h

index 45e9047..0388c25 100644 (file)
@@ -353,6 +353,15 @@ static void vmcs_load(struct vmcs *vmcs)
                       vmcs, phys_addr);
 }
 
+/* Returns the paddr pointer of the current CPU's VMCS region, or -1 if none. */
+static physaddr_t vmcs_get_current(void)
+{
+       physaddr_t vmcs_paddr;
+       /* RAX contains the addr of the location to store the VMCS pointer.  The
+        * compiler doesn't know the ASM will deref that pointer, hence the =m */
+       asm volatile (ASM_VMX_VMPTRST_RAX : "=m"(vmcs_paddr) : "a"(&vmcs_paddr));
+       return vmcs_paddr;
+}
 
 __always_inline unsigned long vmcs_readl(unsigned long field)
 {
index 536098d..26d5800 100644 (file)
@@ -489,6 +489,7 @@ enum vmcs_field {
 #define ASM_VMX_VMLAUNCH          ".byte 0x0f, 0x01, 0xc2"
 #define ASM_VMX_VMRESUME          ".byte 0x0f, 0x01, 0xc3"
 #define ASM_VMX_VMPTRLD_RAX       ".byte 0x0f, 0xc7, 0x30"
+#define ASM_VMX_VMPTRST_RAX       ".byte 0x0f, 0xc7, 0x38"
 #define ASM_VMX_VMREAD_RDX_RAX    ".byte 0x0f, 0x78, 0xd0"
 #define ASM_VMX_VMWRITE_RAX_RDX   ".byte 0x0f, 0x79, 0xd0"
 #define ASM_VMX_VMWRITE_RSP_RDX   ".byte 0x0f, 0x79, 0xd4"