Skip to contentSkip to conversation

NestedVMX support

PATCH In review Eddie Dong 3 participants 44 messages Jun 2, 2011 – Jun 7, 2011

lore
Share & tools
lore

Eddie Dong

author
#0 lore raw

PATCH 1/1 NestedVMX support

This patch series enable the nestedvmx support.

patch 1-2 is a pre-cleanup.
patch 3 is for nested vmx data structure
patch 4 for nestedhvm ops
patch 5, 7,8,9, 10, 11 is for VMX instruction emulation patch 6 for virtual VMCS data structure and access APIs. patch 12 for VMCS switching
Patch 13 for vmreseume/launch emulation
patch 14 for shadow control VMCS fields
patch 15 for n1/n2 guest VMCS switch
patch 16 for interrupt/exceptions
patch 17 for nested vm exit
patch 18 for lazy FPU and patch 19 VMXE bits in CR4 patch 20 for MSR handling and capability

Thanks, Eddie

author
#1 lore raw

PATCH 1/1 pre-cleanup1: Extend nhvm_vmcx_guest_intercepts_trap to include errcode to

# HG changeset patch
# User Eddie Dong <[email protected]>
# Date 1307003600 -28800
# Node ID 332616c43f52f85893f41537e9e6324a3fa01a57
# Parent 0c446850d85e654dfde039a0a1a5acd4e6b3c278
pre-cleanup1: Extend nhvm_vmcx_guest_intercepts_trap to include errcode to assist decision of TRAP_page_fault in VMX.

xen/arch/x86/hvm/hvm.c +3 -3
diff -r 0c446850d85e -r 332616c43f52 xen/arch/x86/hvm/hvm.c
@@ -1152,7 +1152,7 @@ void hvm_inject_exception(unsigned int t
         return;
     }
 
-    if ( nhvm_vmcx_guest_intercepts_trap(v, trapnr) )
+    if ( nhvm_vmcx_guest_intercepts_trap(v, trapnr, errcode) )
     {
         enum nestedhvm_vmexits nsret;
 
@@ -4175,10 +4175,10 @@ uint32_t nhvm_vcpu_asid(struct vcpu *v)
     return -EOPNOTSUPP;
 }
 
-int nhvm_vmcx_guest_intercepts_trap(struct vcpu *v, unsigned int trap)
+int nhvm_vmcx_guest_intercepts_trap(struct vcpu *v, unsigned int trap, int errcode)
 {
     if (hvm_funcs.nhvm_vmcx_guest_intercepts_trap)
-        return hvm_funcs.nhvm_vmcx_guest_intercepts_trap(v, trap);
+        return hvm_funcs.nhvm_vmcx_guest_intercepts_trap(v, trap, errcode);
     return -EOPNOTSUPP;
 }
 
xen/arch/x86/hvm/svm/nestedsvm.c +1 -1
diff -r 0c446850d85e -r 332616c43f52 xen/arch/x86/hvm/svm/nestedsvm.c
@@ -895,7 +895,7 @@ nsvm_vmcb_guest_intercepts_exitcode(stru
 }
 
 int
-nsvm_vmcb_guest_intercepts_trap(struct vcpu *v, unsigned int trapnr)
+nsvm_vmcb_guest_intercepts_trap(struct vcpu *v, unsigned int trapnr, int errcode)
 {
     return nsvm_vmcb_guest_intercepts_exitcode(v,
         guest_cpu_user_regs(), VMEXIT_EXCEPTION_DE + trapnr);
xen/include/asm-x86/hvm/hvm.h +4 -2
diff -r 0c446850d85e -r 332616c43f52 xen/include/asm-x86/hvm/hvm.h
@@ -164,7 +164,8 @@ struct hvm_function_table {
     uint64_t (*nhvm_vcpu_guestcr3)(struct vcpu *v);
     uint64_t (*nhvm_vcpu_hostcr3)(struct vcpu *v);
     uint32_t (*nhvm_vcpu_asid)(struct vcpu *v);
-    int (*nhvm_vmcx_guest_intercepts_trap)(struct vcpu *v, unsigned int trapnr);
+    int (*nhvm_vmcx_guest_intercepts_trap)(struct vcpu *v, 
+                               unsigned int trapnr, int errcode);
 
     bool_t (*nhvm_vmcx_hap_enabled)(struct vcpu *v);
 
@@ -443,7 +444,8 @@ uint64_t nhvm_vcpu_hostcr3(struct vcpu *
 uint32_t nhvm_vcpu_asid(struct vcpu *v);
 
 /* returns true, when l1 guest intercepts the specified trap */
-int nhvm_vmcx_guest_intercepts_trap(struct vcpu *v, unsigned int trapnr);
+int nhvm_vmcx_guest_intercepts_trap(struct vcpu *v, 
+                                    unsigned int trapnr, int errcode);
 
 /* returns true when l1 guest wants to use hap to run l2 guest */
 bool_t nhvm_vmcx_hap_enabled(struct vcpu *v);
xen/include/asm-x86/hvm/svm/nestedsvm.h +2 -1
diff -r 0c446850d85e -r 332616c43f52 xen/include/asm-x86/hvm/svm/nestedsvm.h
@@ -114,7 +114,8 @@ uint64_t nsvm_vcpu_hostcr3(struct vcpu *
 uint32_t nsvm_vcpu_asid(struct vcpu *v);
 int nsvm_vmcb_guest_intercepts_exitcode(struct vcpu *v,
     struct cpu_user_regs *regs, uint64_t exitcode);
-int nsvm_vmcb_guest_intercepts_trap(struct vcpu *v, unsigned int trapnr);
+int nsvm_vmcb_guest_intercepts_trap(struct vcpu *v, unsigned int trapnr,
+                                    int errcode);
 bool_t nsvm_vmcb_hap_enabled(struct vcpu *v);
 enum hvm_intblk nsvm_intr_blocked(struct vcpu *v);
author
#2 lore raw

PATCH 1/1 pre-cleanup2: Move IDT_VECTORING processing code out of intr_assist

In reply to Eddie Dong

# HG changeset patch
# User Eddie Dong <[email protected]>
# Date 1307003600 -28800
# Node ID ce6ed8ca4ebd2f2fb96627e61f7d2ef737e7193d
# Parent 332616c43f52f85893f41537e9e6324a3fa01a57
pre-cleanup2: Move IDT_VECTORING processing code out of intr_assist.

xen/arch/x86/hvm/vmx/vmx.c +29 -23
diff -r 332616c43f52 -r ce6ed8ca4ebd xen/arch/x86/hvm/vmx/vmx.c
@@ -2098,6 +2098,33 @@ static int vmx_handle_eoi_write(void)
     return 0;
 }
 
+static void vmx_idtv_reinject(unsigned long idtv_info)
+{
+
+    /* Event delivery caused this intercept? Queue for redelivery. */
+    if ( unlikely(idtv_info & INTR_INFO_VALID_MASK) )
+    {
+        if ( hvm_event_needs_reinjection((idtv_info>>8)&7, idtv_info&0xff) )
+        {
+            /* See SDM 3B 25.7.1.1 and .2 for info about masking resvd bits. */
+            __vmwrite(VM_ENTRY_INTR_INFO,
+                      idtv_info & ~INTR_INFO_RESVD_BITS_MASK);
+            if ( idtv_info & INTR_INFO_DELIVER_CODE_MASK )
+                __vmwrite(VM_ENTRY_EXCEPTION_ERROR_CODE,
+                          __vmread(IDT_VECTORING_ERROR_CODE));
+        }
+
+        /*
+         * Clear NMI-blocking interruptibility info if an NMI delivery faulted.
+         * Re-delivery will re-set it (see SDM 3B 25.7.1.2).
+         */
+        if ( (idtv_info & INTR_INFO_INTR_TYPE_MASK) == (X86_EVENTTYPE_NMI<<8) )
+            __vmwrite(GUEST_INTERRUPTIBILITY_INFO,
+                      __vmread(GUEST_INTERRUPTIBILITY_INFO) &
+                      ~VMX_INTR_SHADOW_NMI);
+    }
+}
+
 asmlinkage void vmx_vmexit_handler(struct cpu_user_regs *regs)
 {
     unsigned int exit_reason, idtv_info, intr_info = 0, vector = 0;
@@ -2187,30 +2214,9 @@ asmlinkage void vmx_vmexit_handler(struc
 
     hvm_maybe_deassert_evtchn_irq();
 
-    /* Event delivery caused this intercept? Queue for redelivery. */
     idtv_info = __vmread(IDT_VECTORING_INFO);
-    if ( unlikely(idtv_info & INTR_INFO_VALID_MASK) &&
-         (exit_reason != EXIT_REASON_TASK_SWITCH) )
-    {
-        if ( hvm_event_needs_reinjection((idtv_info>>8)&7, idtv_info&0xff) )
-        {
-            /* See SDM 3B 25.7.1.1 and .2 for info about masking resvd bits. */
-            __vmwrite(VM_ENTRY_INTR_INFO,
-                      idtv_info & ~INTR_INFO_RESVD_BITS_MASK);
-            if ( idtv_info & INTR_INFO_DELIVER_CODE_MASK )
-                __vmwrite(VM_ENTRY_EXCEPTION_ERROR_CODE,
-                          __vmread(IDT_VECTORING_ERROR_CODE));
-        }
-
-        /*
-         * Clear NMI-blocking interruptibility info if an NMI delivery faulted.
-         * Re-delivery will re-set it (see SDM 3B 25.7.1.2).
-         */
-        if ( (idtv_info & INTR_INFO_INTR_TYPE_MASK) == (X86_EVENTTYPE_NMI<<8) )
-            __vmwrite(GUEST_INTERRUPTIBILITY_INFO,
-                      __vmread(GUEST_INTERRUPTIBILITY_INFO) &
-                      ~VMX_INTR_SHADOW_NMI);
-    }
+    if ( exit_reason != EXIT_REASON_TASK_SWITCH )
+        vmx_idtv_reinject(idtv_info);
 
     switch ( exit_reason )
     {
author
#3 lore raw

PATCH 1/1 Add data structure for nestedvmx

In reply to Eddie Dong

# HG changeset patch
# User Eddie Dong <[email protected]>
# Date 1307003600 -28800
# Node ID 4bbf0eaec85c764c7872d1cfc1c59c419dfabe0a # Parent ce6ed8ca4ebd2f2fb96627e61f7d2ef737e7193d Add data structure for nestedvmx

xen/include/asm-x86/hvm/vcpu.h +2 -0
diff -r ce6ed8ca4ebd -r 4bbf0eaec85c xen/include/asm-x86/hvm/vcpu.h
@@ -24,6 +24,7 @@
 #include <asm/hvm/io.h>
 #include <asm/hvm/vlapic.h>
 #include <asm/hvm/vmx/vmcs.h>
+#include <asm/hvm/vmx/vvmx.h>
 #include <asm/hvm/svm/vmcb.h>
 #include <asm/hvm/svm/nestedsvm.h>
 #include <asm/mtrr.h>
@@ -57,6 +58,7 @@ struct nestedvcpu {
     /* SVM/VMX arch specific */
     union {
         struct nestedsvm nsvm;
+        struct nestedvmx nvmx;
     } u;
 
     bool_t nv_flushp2m; /* True, when p2m table must be flushed */
xen/include/asm-x86/hvm/vmx/vvmx.h new file +38 -0
diff -r ce6ed8ca4ebd -r 4bbf0eaec85c xen/include/asm-x86/hvm/vmx/vvmx.h
@@ -0,0 +1,38 @@
+
+/*
+ * vvmx.h: Support virtual VMX for nested virtualization.
+ *
+ * Copyright (c) 2010, Intel Corporation.
+ * Author: Qing He <[email protected]>
+ *         Eddie Dong <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ */
+#ifndef __ASM_X86_HVM_VVMX_H__
+#define __ASM_X86_HVM_VVMX_H__
+
+struct nestedvmx {
+    paddr_t    vmxon_region_pa;
+    void       *iobitmap[2];		/* map (va) of L1 guest I/O bitmap */
+    /* deferred nested interrupt */
+    struct {
+        unsigned long intr_info;
+        u32           error_code;
+    } intr;
+};
+
+#define vcpu_2_nvmx(v)	(vcpu_nestedhvm(v).u.nvmx)
+#endif /* __ASM_X86_HVM_VVMX_H__ */
+
author
#4 lore raw

PATCH 1/1 Add APIs for nestedhvm_ops

In reply to Eddie Dong

# HG changeset patch
# User Eddie Dong <[email protected]>
# Date 1307003600 -28800
# Node ID 4e094881883f10f94575a6f69194a2393e16b7d1 # Parent 4bbf0eaec85c764c7872d1cfc1c59c419dfabe0a Add APIs for nestedhvm_ops.

xen/arch/x86/hvm/hvm.c +1 -1
diff -r 4bbf0eaec85c -r 4e094881883f xen/arch/x86/hvm/hvm.c
@@ -3502,7 +3502,7 @@ long do_hvm_op(unsigned long op, XEN_GUE
                 /* Remove the check below once we have
                  * shadow-on-shadow.
                  */
-                if ( !paging_mode_hap(d) && a.value )
+                if ( cpu_has_svm && !paging_mode_hap(d) && a.value )
                     rc = -EINVAL;
                 /* Set up NHVM state for any vcpus that are already up */
                 if ( !d->arch.hvm_domain.params[HVM_PARAM_NESTEDHVM] )
xen/arch/x86/hvm/vmx/Makefile +1 -0
diff -r 4bbf0eaec85c -r 4e094881883f xen/arch/x86/hvm/vmx/Makefile
@@ -4,3 +4,4 @@ obj-y += realmode.o
 obj-y += vmcs.o
 obj-y += vmx.o
 obj-y += vpmu_core2.o
+obj-y += vvmx.o
xen/arch/x86/hvm/vmx/vmx.c +7 -1
diff -r 4bbf0eaec85c -r 4e094881883f xen/arch/x86/hvm/vmx/vmx.c
@@ -1407,7 +1407,13 @@ static struct hvm_function_table __read_
     .invlpg_intercept     = vmx_invlpg_intercept,
     .set_uc_mode          = vmx_set_uc_mode,
     .set_info_guest       = vmx_set_info_guest,
-    .set_rdtsc_exiting    = vmx_set_rdtsc_exiting
+    .set_rdtsc_exiting    = vmx_set_rdtsc_exiting,
+    .nhvm_vcpu_initialise = nvmx_vcpu_initialise,
+    .nhvm_vcpu_destroy    = nvmx_vcpu_destroy,
+    .nhvm_vcpu_reset      = nvmx_vcpu_reset,
+    .nhvm_vcpu_guestcr3   = nvmx_vcpu_guestcr3,
+    .nhvm_vcpu_hostcr3    = nvmx_vcpu_hostcr3,
+    .nhvm_vcpu_asid       = nvmx_vcpu_asid
 };
 
 struct hvm_function_table * __init start_vmx(void)
xen/arch/x86/hvm/vmx/vvmx.c new file +93 -0

93 lines not on this page · raw message

xen/include/asm-x86/hvm/vmx/vvmx.h +8 -0
diff -r 4bbf0eaec85c -r 4e094881883f xen/include/asm-x86/hvm/vmx/vvmx.h
@@ -34,5 +34,13 @@ struct nestedvmx {
 };
 
 #define vcpu_2_nvmx(v)	(vcpu_nestedhvm(v).u.nvmx)
+
+int nvmx_vcpu_initialise(struct vcpu *v);
+void nvmx_vcpu_destroy(struct vcpu *v);
+int nvmx_vcpu_reset(struct vcpu *v);
+uint64_t nvmx_vcpu_guestcr3(struct vcpu *v);
+uint64_t nvmx_vcpu_hostcr3(struct vcpu *v);
+uint32_t nvmx_vcpu_asid(struct vcpu *v);
+
 #endif /* __ASM_X86_HVM_VVMX_H__ */
author
#5 lore raw

PATCH 1/1 Emulation of guest VMXON/OFF instruction

In reply to Eddie Dong

# HG changeset patch
# User Eddie Dong <[email protected]>
# Date 1307003600 -28800
# Node ID c8812151acfd6d9468f3407bc6a1a278cd764567 # Parent 4e094881883f10f94575a6f69194a2393e16b7d1 Emulation of guest VMXON/OFF instruction.

xen/arch/x86/hvm/vmx/Makefile +1 -0
diff -r 4e094881883f -r c8812151acfd xen/arch/x86/hvm/vmx/Makefile
@@ -5,3 +5,4 @@ obj-y += vmcs.o
 obj-y += vmx.o
 obj-y += vpmu_core2.o
 obj-y += vvmx.o
+obj-y += vvmx.o
xen/arch/x86/hvm/vmx/vmx.c +10 -2
diff -r 4e094881883f -r c8812151acfd xen/arch/x86/hvm/vmx/vmx.c
@@ -2434,6 +2434,16 @@ asmlinkage void vmx_vmexit_handler(struc
         break;
     }
 
+    case EXIT_REASON_VMXOFF:
+        if ( nvmx_handle_vmxoff(regs) == X86EMUL_OKAY )
+            update_guest_eip();
+        break;
+
+    case EXIT_REASON_VMXON:
+        if ( nvmx_handle_vmxon(regs) == X86EMUL_OKAY )
+            update_guest_eip();
+        break;
+
     case EXIT_REASON_MWAIT_INSTRUCTION:
     case EXIT_REASON_MONITOR_INSTRUCTION:
     case EXIT_REASON_VMCLEAR:
@@ -2443,8 +2453,6 @@ asmlinkage void vmx_vmexit_handler(struc
     case EXIT_REASON_VMREAD:
     case EXIT_REASON_VMRESUME:
     case EXIT_REASON_VMWRITE:
-    case EXIT_REASON_VMXOFF:
-    case EXIT_REASON_VMXON:
     case EXIT_REASON_GETSEC:
     case EXIT_REASON_INVEPT:
     case EXIT_REASON_INVVPID:
xen/arch/x86/hvm/vmx/vvmx.c +225 -0

228 lines not on this page · raw message

xen/include/asm-x86/hvm/vmx/vvmx.h +54 -0

64 lines not on this page · raw message

#6 lore raw

Re: [PATCH 05 of 20] Emulation of guest VMXON/OFF instruction

xen/arch/x86/hvm/vmx/Makefile obj-y += vmcs.o · line 8

Quoted 8 lines · Eddie Dong

diff -r 4e094881883f -r c8812151acfd xen/arch/x86/hvm/vmx/Makefile

xen/arch/x86/hvm/vmx/Makefile +1 -0
@@ -5,3 +5,4 @@ obj-y += vmcs.o
 obj-y += vmx.o
 obj-y += vpmu_core2.o
 obj-y += vvmx.o
+obj-y += vvmx.o

Harmless, but wrong. :)

Tim.

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Xen Platform Team
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)
#7 lore raw

RE: [PATCH 05 of 20] Emulation of guest VMXON/OFF instruction

Quoted 6 lines
Quoted 3 lines

obj-y += vpmu_core2.o
obj-y += vvmx.o
+obj-y += vvmx.o

Harmless, but wrong. :)

Thanks, a patch merge introduced error :)
Fixed.
Eddie

author
#8 lore raw

PATCH 1/1 Define structure and access APIs for virtual VMCS

In reply to Eddie Dong

# HG changeset patch
# User Eddie Dong <[email protected]>
# Date 1307003600 -28800
# Node ID 8264b01b476b1b695727f78d92ab0ce553aa7516 # Parent c8812151acfd6d9468f3407bc6a1a278cd764567 Define structure and access APIs for virtual VMCS.

xen/arch/x86/hvm/vmx/vvmx.c +78 -0
diff -r c8812151acfd -r 8264b01b476b xen/arch/x86/hvm/vmx/vvmx.c
@@ -124,6 +124,84 @@ enum vmx_ops_result {
 #define CASE_GET_REG(REG, reg)      \
     case VMX_REG_ ## REG: value = regs->reg; break
 
+static int vvmcs_offset(u32 width, u32 type, u32 index)
+{
+    int offset;
+
+    offset = (index & 0x1f) | type << 5 | width << 7;
+
+    if ( offset == 0 )    /* vpid */
+        offset = 0x3f;
+
+    return offset;
+}
+
+u64 __get_vvmcs(void *vvmcs, u32 vmcs_encoding)
+{
+    union vmcs_encoding enc;
+    u64 *content = (u64 *) vvmcs;
+    int offset;
+    u64 res;
+
+    enc.word = vmcs_encoding;
+    offset = vvmcs_offset(enc.width, enc.type, enc.index);
+    res = content[offset];
+
+    switch ( enc.width ) {
+    case VVMCS_WIDTH_16:
+        res &= 0xffff;
+        break;
+   case VVMCS_WIDTH_64:
+        if ( enc.access_type )
+            res >>= 32;
+        break;
+    case VVMCS_WIDTH_32:
+        res &= 0xffffffff;
+        break;
+    case VVMCS_WIDTH_NATURAL:
+    default:
+        break;
+    }
+
+    return res;
+}
+
+void __set_vvmcs(void *vvmcs, u32 vmcs_encoding, u64 val)
+{
+    union vmcs_encoding enc;
+    u64 *content = (u64 *) vvmcs;
+    int offset;
+    u64 res;
+
+    enc.word = vmcs_encoding;
+    offset = vvmcs_offset(enc.width, enc.type, enc.index);
+    res = content[offset];
+
+    switch ( enc.width ) {
+    case VVMCS_WIDTH_16:
+        res = val & 0xffff;
+        break;
+    case VVMCS_WIDTH_64:
+        if ( enc.access_type )
+        {
+            res &= 0xffffffff;
+            res |= val << 32;
+        }
+        else
+            res = val;
+        break;
+    case VVMCS_WIDTH_32:
+        res = val & 0xffffffff;
+        break;
+    case VVMCS_WIDTH_NATURAL:
+    default:
+        res = val;
+        break;
+    }
+
+    content[offset] = res;
+}
+
 static unsigned long reg_read(struct cpu_user_regs *regs,
                               enum vmx_regs_enc index)
 {
xen/include/asm-x86/hvm/vmx/vvmx.h +56 -0

60 lines not on this page · raw message

author
#9 lore raw

PATCH 1/1 Emulation of guest vmptrld

In reply to Eddie Dong

# HG changeset patch
# User Eddie Dong <[email protected]>
# Date 1307003600 -28800
# Node ID 4dad232d7fc3bd62979a1b442d989fe0ca4baafe # Parent 8264b01b476b1b695727f78d92ab0ce553aa7516 Emulation of guest vmptrld

xen/arch/x86/hvm/vmx/vmx.c +5 -1
diff -r 8264b01b476b -r 4dad232d7fc3 xen/arch/x86/hvm/vmx/vmx.c
@@ -2444,11 +2444,15 @@ asmlinkage void vmx_vmexit_handler(struc
             update_guest_eip();
         break;
 
+    case EXIT_REASON_VMPTRLD:
+        if ( nvmx_handle_vmptrld(regs) == X86EMUL_OKAY )
+            update_guest_eip();
+        break;
+
     case EXIT_REASON_MWAIT_INSTRUCTION:
     case EXIT_REASON_MONITOR_INSTRUCTION:
     case EXIT_REASON_VMCLEAR:
     case EXIT_REASON_VMLAUNCH:
-    case EXIT_REASON_VMPTRLD:
     case EXIT_REASON_VMPTRST:
     case EXIT_REASON_VMREAD:
     case EXIT_REASON_VMRESUME:
xen/arch/x86/hvm/vmx/vvmx.c +86 -0

108 lines not on this page · raw message

xen/include/asm-x86/hvm/vmx/vvmx.h +3 -0
diff -r 8264b01b476b -r 4dad232d7fc3 xen/include/asm-x86/hvm/vmx/vvmx.h
@@ -152,5 +152,8 @@ enum vvmcs_encoding_type {
 u64 __get_vvmcs(void *vvmcs, u32 vmcs_encoding);
 void __set_vvmcs(void *vvmcs, u32 vmcs_encoding, u64 val);
 
+void nvmx_destroy_vmcs(struct vcpu *v);
+int nvmx_handle_vmptrld(struct cpu_user_regs *regs);
+
 #endif /* __ASM_X86_HVM_VVMX_H__ */
#10 lore raw

Re: [PATCH 07 of 20] Emulation of guest vmptrld

Quoted 13 lines · Eddie Dong

diff -r 8264b01b476b -r 4dad232d7fc3 xen/arch/x86/hvm/vmx/vvmx.c

xen/arch/x86/hvm/vmx/vvmx.c +6 -0
@@ -356,6 +356,41 @@ static void vmreturn(struct cpu_user_reg
     regs->eflags = eflags;
 }
 
+static void __map_io_bitmap(struct vcpu *v, u64 vmcs_reg)
+{
+    struct nestedvmx *nvmx = &vcpu_2_nvmx(v);
+    unsigned long gpa;
+    unsigned long mfn;
+    p2m_type_t p2mt;

xen/arch/x86/hvm/vmx/vvmx.c static void vmreturn(struct cpu_user_reg · line 374

Quoted 10 lines
xen/arch/x86/hvm/vmx/vvmx.c +10 -0
+
+    if ( vmcs_reg == IO_BITMAP_A )
+    {
+        if (nvmx->iobitmap[0]) {
+            unmap_domain_page_global(nvmx->iobitmap[0]);
+        }
+        gpa = __get_vvmcs(vcpu_nestedhvm(v).nv_vvmcx, IO_BITMAP_A);
+        mfn = mfn_x(gfn_to_mfn(p2m_get_hostp2m(v->domain),
+                              gpa >> PAGE_SHIFT, &p2mt));
+        nvmx->iobitmap[0] = map_domain_page_global(mfn);

Why are these maps _global? It might be OK to use 2 more global mappings per VCPU but the reason should probably go in a comment beside the call.

Also, I don't see where these mappings get torn down on domain destruction.

(While I'm looking at this code, this function is quite ugly. Why have a single function if you're going to duplicate its contents anyway?)

Quoted 72 lines
xen/arch/x86/hvm/vmx/vvmx.c +50 -0
+    }
+    else if ( vmcs_reg == IO_BITMAP_B )
+    {
+        if (nvmx->iobitmap[1]) {
+            unmap_domain_page_global(nvmx->iobitmap[1]);
+        }
+        gpa = __get_vvmcs(vcpu_nestedhvm(v).nv_vvmcx, IO_BITMAP_B);
+        mfn = mfn_x(gfn_to_mfn(p2m_get_hostp2m(v->domain),
+                               gpa >> PAGE_SHIFT, &p2mt));
+        nvmx->iobitmap[1] = map_domain_page_global(mfn);
+    }
+}
+
+static inline void map_io_bitmap_all(struct vcpu *v)
+{
+   __map_io_bitmap (v, IO_BITMAP_A);
+   __map_io_bitmap (v, IO_BITMAP_B);
+}
+
 /*
  * VMX instructions handling
  */
@@ -364,6 +399,7 @@ int nvmx_handle_vmxon(struct cpu_user_re
 {
     struct vcpu *v=current;
     struct nestedvmx *nvmx = &vcpu_2_nvmx(v);
+    struct nestedvcpu *nvcpu = &vcpu_nestedhvm(v);
     struct vmx_inst_decoded decode;
     unsigned long gpa = 0;
     int rc;
@@ -372,7 +408,22 @@ int nvmx_handle_vmxon(struct cpu_user_re
     if ( rc != X86EMUL_OKAY )
         return rc;
 
+    if ( nvmx->vmxon_region_pa )
+        gdprintk(XENLOG_WARNING, 
+                 "vmxon again: orig %lx new %lx\n",
+                 nvmx->vmxon_region_pa, gpa);
+
     nvmx->vmxon_region_pa = gpa;
+
+    /*
+     * `fork' the host vmcs to shadow_vmcs
+     * vmcs_lock is not needed since we are on current
+     */
+    nvcpu->nv_n1vmcx = v->arch.hvm_vmx.vmcs;
+    __vmpclear(virt_to_maddr(v->arch.hvm_vmx.vmcs));
+    memcpy(nvcpu->nv_n2vmcx, v->arch.hvm_vmx.vmcs, PAGE_SIZE);
+    __vmptrld(virt_to_maddr(v->arch.hvm_vmx.vmcs));
+    v->arch.hvm_vmx.launched = 0;
     vmreturn(regs, VMSUCCEED);
 
     return X86EMUL_OKAY;
@@ -394,3 +445,38 @@ int nvmx_handle_vmxoff(struct cpu_user_r
     return X86EMUL_OKAY;
 }
 
+int nvmx_handle_vmptrld(struct cpu_user_regs *regs)
+{
+    struct vcpu *v = current;
+    struct vmx_inst_decoded decode;
+    struct nestedvcpu *nvcpu = &vcpu_nestedhvm(v);
+    unsigned long gpa = 0;
+    unsigned long mfn;
+    p2m_type_t p2mt;
+    int rc;
+
+    rc = decode_vmx_inst(regs, &decode, &gpa, 0);
+    if ( rc != X86EMUL_OKAY )
+        return rc;
+
+    if ( gpa == vcpu_2_nvmx(v).vmxon_region_pa || gpa & 0xfff )

xen/arch/x86/hvm/vmx/vvmx.c int nvmx_handle_vmxoff(struct cpu_user_r · line 472

Quoted 10 lines
xen/arch/x86/hvm/vmx/vvmx.c +10 -0
+    {
+        vmreturn(regs, VMFAIL_INVALID);
+        goto out;
+    }
+
+    if ( nvcpu->nv_vvmcxaddr == VMCX_EADDR )
+    {
+        mfn = mfn_x(gfn_to_mfn(p2m_get_hostp2m(v->domain),
+                               gpa >> PAGE_SHIFT, &p2mt));
+        nvcpu->nv_vvmcx = map_domain_page_global(mfn);

Again, why _global?

Tim.

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Xen Platform Team
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)
#11 lore raw

RE: [PATCH 07 of 20] Emulation of guest vmptrld

Quoted 6 lines

xen/arch/x86/hvm/vmx/vvmx.c static void vmreturn(struct cpu_user_reg

Quoted 6 lines
xen/arch/x86/hvm/vmx/vvmx.c +6 -0
+    if ( vmcs_reg == IO_BITMAP_A )
+    {
+        if (nvmx->iobitmap[0]) {
+            unmap_domain_page_global(nvmx->iobitmap[0]);
+        }
+        gpa = __get_vvmcs(vcpu_nestedhvm(v).nv_vvmcx,
Quoted 8 lines

IO_BITMAP_A);

xen/arch/x86/hvm/vmx/vvmx.c static void vmreturn(struct cpu_user_reg · line 374

Quoted 3 lines
xen/arch/x86/hvm/vmx/vvmx.c +3 -0
+        mfn = mfn_x(gfn_to_mfn(p2m_get_hostp2m(v->domain),
+                              gpa >> PAGE_SHIFT, &p2mt));
+        nvmx->iobitmap[0] = map_domain_page_global(mfn);

Why are these maps _global? It might be OK to use 2 more global mappings per VCPU but the reason should probably go in a comment beside the call.

Do you mean to use hvm_map_guest_frame_ro? Fine to me.

Quoted 4 lines

Also, I don't see where these mappings get torn down on domain destruction.

Yes. Fixed in nvmx_vcpu_destroy.

Quoted 2 lines

(While I'm looking at this code, this function is quite ugly. Why have a single function if you're going to duplicate its contents anyway?)

??? We don't know fi guest changed the bitmap, so we have to check each time.

Quoted 9 lines

+

xen/arch/x86/hvm/vmx/vvmx.c int nvmx_handle_vmxoff(struct cpu_user_r · line 472

Quoted 5 lines
xen/arch/x86/hvm/vmx/vvmx.c +5 -0
+    if ( nvcpu->nv_vvmcxaddr == VMCX_EADDR )
+    {
+        mfn = mfn_x(gfn_to_mfn(p2m_get_hostp2m(v->domain),
+                               gpa >> PAGE_SHIFT, &p2mt));
+        nvcpu->nv_vvmcx = map_domain_page_global(mfn);

Again, why _global?

Will fix with hvm_map_guest_frame.

Thx, Eddie

#12 lore raw

Re: [PATCH 07 of 20] Emulation of guest vmptrld

Quoted 11 lines · Eddie
Quoted 11 lines

xen/arch/x86/hvm/vmx/vvmx.c static void vmreturn(struct cpu_user_reg

Quoted 6 lines
xen/arch/x86/hvm/vmx/vvmx.c +6 -0
+    if ( vmcs_reg == IO_BITMAP_A )
+    {
+        if (nvmx->iobitmap[0]) {
+            unmap_domain_page_global(nvmx->iobitmap[0]);
+        }
+        gpa = __get_vvmcs(vcpu_nestedhvm(v).nv_vvmcx,

IO_BITMAP_A);

Quoted 3 lines
xen/arch/x86/hvm/vmx/vvmx.c +3 -0
+        mfn = mfn_x(gfn_to_mfn(p2m_get_hostp2m(v->domain),
+                              gpa >> PAGE_SHIFT, &p2mt));
+        nvmx->iobitmap[0] = map_domain_page_global(mfn);
Quoted 5 lines
Quoted 3 lines

Why are these maps _global? It might be OK to use 2 more global mappings per VCPU but the reason should probably go in a comment beside the call.

Do you mean to use hvm_map_guest_frame_ro? Fine to me.

Yes, I think that would be better unless you know there's a point where the bitmaps are accessed on a vcpu other than current. (On 64-bit it makes no difference but on 32-bit map_domain_page_global() uses up a global shared resource).

Quoted 10 lines
Quoted 4 lines

Also, I don't see where these mappings get torn down on domain destruction.

Yes. Fixed in nvmx_vcpu_destroy.

Quoted 2 lines

(While I'm looking at this code, this function is quite ugly. Why have a single function if you're going to duplicate its contents anyway?)

??? We don't know fi guest changed the bitmap, so we have to check each time.

I think I wasn't clear. The logic is fine, I was just cavilling about coding style. You have some code that's basically

f1() { BUNCH_O_CODE(1) }

f2() { BUNCH_O_CODE(2) }

and places that need to call f1(), f2() or both. Merging those into a single function is a good idea, but the function should look like

f(x) {
int i = (x ? 1 : 2)
BUNCH_O_CODE(i)
}

and what you have is

f(x) {
if (x)

     BUNCH_O_CODE(1)
  else
     BUNCH_O_CODE(2)
}

which keeps the duplication.

Cheers,

Tim.

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Xen Platform Team
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)
#13 lore raw

RE: [PATCH 07 of 20] Emulation of guest vmptrld

Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

(While I'm looking at this code, this function is quite ugly. Why have a single function if you're going to duplicate its contents anyway?)

??? We don't know fi guest changed the bitmap, so we have to check each

time.

I think I wasn't clear. The logic is fine, I was just cavilling about coding style. You have some code that's basically

I see, yes it is better and fixed.

Thx, Eddie

author
#14 lore raw

PATCH 1/1 Emulation of guest VMPTRST

In reply to Eddie Dong

# HG changeset patch
# User Eddie Dong <[email protected]>
# Date 1307003600 -28800
# Node ID 54332433d873777e57e6ac47ee841a2a96c2f543 # Parent 4dad232d7fc3bd62979a1b442d989fe0ca4baafe Emulation of guest VMPTRST

xen/arch/x86/hvm/vmx/vmx.c +5 -1
diff -r 4dad232d7fc3 -r 54332433d873 xen/arch/x86/hvm/vmx/vmx.c
@@ -2449,11 +2449,15 @@ asmlinkage void vmx_vmexit_handler(struc
             update_guest_eip();
         break;
 
+    case EXIT_REASON_VMPTRST:
+        if ( nvmx_handle_vmptrst(regs) == X86EMUL_OKAY )
+            update_guest_eip();
+        break;
+
     case EXIT_REASON_MWAIT_INSTRUCTION:
     case EXIT_REASON_MONITOR_INSTRUCTION:
     case EXIT_REASON_VMCLEAR:
     case EXIT_REASON_VMLAUNCH:
-    case EXIT_REASON_VMPTRST:
     case EXIT_REASON_VMREAD:
     case EXIT_REASON_VMRESUME:
     case EXIT_REASON_VMWRITE:
xen/arch/x86/hvm/vmx/vvmx.c +22 -0
diff -r 4dad232d7fc3 -r 54332433d873 xen/arch/x86/hvm/vmx/vvmx.c
@@ -480,3 +480,25 @@ out:
     return X86EMUL_OKAY;
 }
 
+int nvmx_handle_vmptrst(struct cpu_user_regs *regs)
+{
+    struct vcpu *v = current;
+    struct vmx_inst_decoded decode;
+    struct nestedvcpu *nvcpu = &vcpu_nestedhvm(v);
+    unsigned long gpa = 0;
+    int rc;
+
+    rc = decode_vmx_inst(regs, &decode, &gpa, 0);
+    if ( rc != X86EMUL_OKAY )
+        return rc;
+
+    gpa = nvcpu->nv_vvmcxaddr;
+
+    rc = hvm_copy_to_guest_virt(decode.mem, &gpa, decode.len, 0);
+    if ( rc != HVMCOPY_okay )
+        return X86EMUL_EXCEPTION;
+
+    vmreturn(regs, VMSUCCEED);
+    return X86EMUL_OKAY;
+}
+
xen/include/asm-x86/hvm/vmx/vvmx.h +1 -0
diff -r 4dad232d7fc3 -r 54332433d873 xen/include/asm-x86/hvm/vmx/vvmx.h
@@ -154,6 +154,7 @@ void __set_vvmcs(void *vvmcs, u32 vmcs_e
 
 void nvmx_destroy_vmcs(struct vcpu *v);
 int nvmx_handle_vmptrld(struct cpu_user_regs *regs);
+int nvmx_handle_vmptrst(struct cpu_user_regs *regs);
 
 #endif /* __ASM_X86_HVM_VVMX_H__ */
author
#15 lore raw

PATCH 1/1 Emulation of guest VMCLEAR

In reply to Eddie Dong

# HG changeset patch
# User Eddie Dong <[email protected]>
# Date 1307003600 -28800
# Node ID 35cc736e8a75a0a349790871232f8761ceae41be # Parent 54332433d873777e57e6ac47ee841a2a96c2f543 Emulation of guest VMCLEAR

xen/arch/x86/hvm/vmx/vmx.c +5 -1
diff -r 54332433d873 -r 35cc736e8a75 xen/arch/x86/hvm/vmx/vmx.c
@@ -2444,6 +2444,11 @@ asmlinkage void vmx_vmexit_handler(struc
             update_guest_eip();
         break;
 
+    case EXIT_REASON_VMCLEAR:
+        if ( nvmx_handle_vmclear(regs) == X86EMUL_OKAY )
+            update_guest_eip();
+        break;
+ 
     case EXIT_REASON_VMPTRLD:
         if ( nvmx_handle_vmptrld(regs) == X86EMUL_OKAY )
             update_guest_eip();
@@ -2456,7 +2461,6 @@ asmlinkage void vmx_vmexit_handler(struc
 
     case EXIT_REASON_MWAIT_INSTRUCTION:
     case EXIT_REASON_MONITOR_INSTRUCTION:
-    case EXIT_REASON_VMCLEAR:
     case EXIT_REASON_VMLAUNCH:
     case EXIT_REASON_VMREAD:
     case EXIT_REASON_VMRESUME:
xen/arch/x86/hvm/vmx/vvmx.c +66 -0

93 lines not on this page · raw message

xen/include/asm-x86/hvm/vmx/vvmx.h +1 -0
diff -r 54332433d873 -r 35cc736e8a75 xen/include/asm-x86/hvm/vmx/vvmx.h
@@ -155,6 +155,7 @@ void __set_vvmcs(void *vvmcs, u32 vmcs_e
 void nvmx_destroy_vmcs(struct vcpu *v);
 int nvmx_handle_vmptrld(struct cpu_user_regs *regs);
 int nvmx_handle_vmptrst(struct cpu_user_regs *regs);
+int nvmx_handle_vmclear(struct cpu_user_regs *regs);
 
 #endif /* __ASM_X86_HVM_VVMX_H__ */
author
#16 lore raw

PATCH 1/1 Emulation of guest VMWRITE

In reply to Eddie Dong

# HG changeset patch
# User Eddie Dong <[email protected]>
# Date 1307003600 -28800
# Node ID 16e0e95f457e9b3f8ff0528c8f2b0f88b1c41109 # Parent 35cc736e8a75a0a349790871232f8761ceae41be Emulation of guest VMWRITE

xen/arch/x86/hvm/vmx/vmx.c +5 -1
diff -r 35cc736e8a75 -r 16e0e95f457e xen/arch/x86/hvm/vmx/vmx.c
@@ -2459,12 +2459,16 @@ asmlinkage void vmx_vmexit_handler(struc
             update_guest_eip();
         break;
 
+    case EXIT_REASON_VMWRITE:
+        if ( nvmx_handle_vmwrite(regs) == X86EMUL_OKAY )
+            update_guest_eip();
+        break;
+
     case EXIT_REASON_MWAIT_INSTRUCTION:
     case EXIT_REASON_MONITOR_INSTRUCTION:
     case EXIT_REASON_VMLAUNCH:
     case EXIT_REASON_VMREAD:
     case EXIT_REASON_VMRESUME:
-    case EXIT_REASON_VMWRITE:
     case EXIT_REASON_GETSEC:
     case EXIT_REASON_INVEPT:
     case EXIT_REASON_INVVPID:
xen/arch/x86/hvm/vmx/vvmx.c +24 -0
diff -r 35cc736e8a75 -r 16e0e95f457e xen/arch/x86/hvm/vmx/vvmx.c
@@ -568,3 +568,27 @@ out:
     return X86EMUL_OKAY;
 }
 
+int nvmx_handle_vmwrite(struct cpu_user_regs *regs)
+{
+    struct vcpu *v = current;
+    struct vmx_inst_decoded decode;
+    struct nestedvcpu *nvcpu = &vcpu_nestedhvm(v);
+    u64 operandS, vmcs_encoding;
+
+    if ( decode_vmx_inst(regs, &decode, &operandS, 0)
+             != X86EMUL_OKAY )
+        return X86EMUL_EXCEPTION;
+
+    vmcs_encoding = reg_read(regs, decode.reg2);
+    __set_vvmcs(nvcpu->nv_vvmcx, vmcs_encoding, operandS);
+
+    if ( vmcs_encoding == IO_BITMAP_A || vmcs_encoding == IO_BITMAP_A_HIGH )
+        __map_io_bitmap (v, IO_BITMAP_A);
+    else if ( vmcs_encoding == IO_BITMAP_B || 
+              vmcs_encoding == IO_BITMAP_B_HIGH )
+        __map_io_bitmap (v, IO_BITMAP_B);
+
+    vmreturn(regs, VMSUCCEED);
+    return X86EMUL_OKAY;
+}
+
xen/include/asm-x86/hvm/vmx/vvmx.h +1 -0
diff -r 35cc736e8a75 -r 16e0e95f457e xen/include/asm-x86/hvm/vmx/vvmx.h
@@ -156,6 +156,7 @@ void nvmx_destroy_vmcs(struct vcpu *v);
 int nvmx_handle_vmptrld(struct cpu_user_regs *regs);
 int nvmx_handle_vmptrst(struct cpu_user_regs *regs);
 int nvmx_handle_vmclear(struct cpu_user_regs *regs);
+int nvmx_handle_vmwrite(struct cpu_user_regs *regs);
 
 #endif /* __ASM_X86_HVM_VVMX_H__ */
author
#17 lore raw

PATCH 1/1 Emulation of guest VMREAD

In reply to Eddie Dong

# HG changeset patch
# User Eddie Dong <[email protected]>
# Date 1307003600 -28800
# Node ID 4631a951120093ade781c4f4542741266b615576 # Parent 16e0e95f457e9b3f8ff0528c8f2b0f88b1c41109 Emulation of guest VMREAD

xen/arch/x86/hvm/vmx/vmx.c +5 -1
diff -r 16e0e95f457e -r 4631a9511200 xen/arch/x86/hvm/vmx/vmx.c
@@ -2459,6 +2459,11 @@ asmlinkage void vmx_vmexit_handler(struc
             update_guest_eip();
         break;
 
+    case EXIT_REASON_VMREAD:
+        if ( nvmx_handle_vmread(regs) == X86EMUL_OKAY )
+            update_guest_eip();
+        break;
+ 
     case EXIT_REASON_VMWRITE:
         if ( nvmx_handle_vmwrite(regs) == X86EMUL_OKAY )
             update_guest_eip();
@@ -2467,7 +2472,6 @@ asmlinkage void vmx_vmexit_handler(struc
     case EXIT_REASON_MWAIT_INSTRUCTION:
     case EXIT_REASON_MONITOR_INSTRUCTION:
     case EXIT_REASON_VMLAUNCH:
-    case EXIT_REASON_VMREAD:
     case EXIT_REASON_VMRESUME:
     case EXIT_REASON_GETSEC:
     case EXIT_REASON_INVEPT:
xen/arch/x86/hvm/vmx/vvmx.c +57 -0

75 lines not on this page · raw message

xen/include/asm-x86/hvm/vmx/vvmx.h +1 -0
diff -r 16e0e95f457e -r 4631a9511200 xen/include/asm-x86/hvm/vmx/vvmx.h
@@ -156,6 +156,7 @@ void nvmx_destroy_vmcs(struct vcpu *v);
 int nvmx_handle_vmptrld(struct cpu_user_regs *regs);
 int nvmx_handle_vmptrst(struct cpu_user_regs *regs);
 int nvmx_handle_vmclear(struct cpu_user_regs *regs);
+int nvmx_handle_vmread(struct cpu_user_regs *regs);
 int nvmx_handle_vmwrite(struct cpu_user_regs *regs);
 
 #endif /* __ASM_X86_HVM_VVMX_H__ */
author
#18 lore raw

PATCH 1/1 Add APIs to switch n1/n2 VMCS

In reply to Eddie Dong

# HG changeset patch
# User Eddie Dong <[email protected]>
# Date 1307003601 -28800
# Node ID 62cc6c7516e010ef673c75bba83f901785b063d5 # Parent 4631a951120093ade781c4f4542741266b615576 Add APIs to switch n1/n2 VMCS.

xen/arch/x86/hvm/vmx/vmcs.c +39 -0
diff -r 4631a9511200 -r 62cc6c7516e0 xen/arch/x86/hvm/vmx/vmcs.c
@@ -669,6 +669,38 @@ void vmx_disable_intercept_for_msr(struc
     }
 }
 
+/*
+ * Switch VMCS between layer 1 & 2 guest
+ */
+void vmx_vmcs_switch(struct vcpu *v,
+                             struct vmcs_struct *from,
+                             struct vmcs_struct *to)
+{
+    /* no foreign access */
+    if ( unlikely(v != current) )
+        return;
+
+    if ( unlikely(current->arch.hvm_vmx.vmcs != from) )
+        return;
+
+    spin_lock(&v->arch.hvm_vmx.vmcs_lock);
+
+    __vmpclear(virt_to_maddr(from));
+    __vmptrld(virt_to_maddr(to));
+
+    v->arch.hvm_vmx.vmcs = to;
+    v->arch.hvm_vmx.launched = 0;
+    this_cpu(current_vmcs) = to;
+
+    if ( v->arch.hvm_vmx.hostenv_migrated )
+    {
+        v->arch.hvm_vmx.hostenv_migrated = 0;
+        vmx_set_host_env(v);
+    }
+
+    spin_unlock(&v->arch.hvm_vmx.vmcs_lock);
+}
+
 static int construct_vmcs(struct vcpu *v)
 {
     struct domain *d = v->domain;
@@ -1078,6 +1110,13 @@ void vmx_do_resume(struct vcpu *v)
         hvm_migrate_timers(v);
         hvm_migrate_pirqs(v);
         vmx_set_host_env(v);
+        /*
+         * Both n1 VMCS and n2 VMCS need to update the host environment after 
+         * VCPU migration. The environment of current VMCS is updated in place,
+         * but the action of another VMCS is deferred till it is switched in.
+         */
+        v->arch.hvm_vmx.hostenv_migrated = 1;
+
         hvm_asid_flush_vcpu(v);
     }
 
xen/include/asm-x86/hvm/vmx/vmcs.h +4 -0
diff -r 4631a9511200 -r 62cc6c7516e0 xen/include/asm-x86/hvm/vmx/vmcs.h
@@ -123,6 +123,7 @@ struct arch_vmx_struct {
     struct segment_register vm86_saved_seg[x86_seg_tr + 1];
     /* Remember EFLAGS while in virtual 8086 mode */
     uint32_t             vm86_saved_eflags;
+    int                  hostenv_migrated;
 };
 
 int vmx_create_vmcs(struct vcpu *v);
@@ -390,6 +391,9 @@ int vmx_read_guest_msr(u32 msr, u64 *val
 int vmx_write_guest_msr(u32 msr, u64 val);
 int vmx_add_guest_msr(u32 msr);
 int vmx_add_host_load_msr(u32 msr);
+void vmx_vmcs_switch(struct vcpu *v,
+                      struct vmcs_struct *from,
+                      struct vmcs_struct *to);
 
 #endif /* ASM_X86_HVM_VMX_VMCS_H__ */
#19 lore raw

Re: [PATCH 12 of 20] Add APIs to switch n1/n2 VMCS

Quoted 10 lines · Eddie Dong

diff -r 4631a9511200 -r 62cc6c7516e0 xen/arch/x86/hvm/vmx/vmcs.c

xen/arch/x86/hvm/vmx/vmcs.c +3 -0
@@ -669,6 +669,38 @@ void vmx_disable_intercept_for_msr(struc
     }
 }
 
+/*
+ * Switch VMCS between layer 1 & 2 guest
+ */

xen/arch/x86/hvm/vmx/vmcs.c void vmx_disable_intercept_for_msr(struc · line 684

Quoted 10 lines
xen/arch/x86/hvm/vmx/vmcs.c +10 -0
+void vmx_vmcs_switch(struct vcpu *v,
+                             struct vmcs_struct *from,
+                             struct vmcs_struct *to)
+{
+    /* no foreign access */
+    if ( unlikely(v != current) )
+        return;
+
+    if ( unlikely(current->arch.hvm_vmx.vmcs != from) )
+        return;

Do you really want this function to fail silently if called with v != current? Use ASSERT(), or, even better, remove the first argument entirely.

Cheers,

Tim.

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Xen Platform Team
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)
#20 lore raw

RE: [PATCH 12 of 20] Add APIs to switch n1/n2 VMCS

Quoted 11 lines

xen/arch/x86/hvm/vmx/vmcs.c void vmx_disable_intercept_for_msr(struc · line 684

Quoted 6 lines
xen/arch/x86/hvm/vmx/vmcs.c +6 -0
+    /* no foreign access */
+    if ( unlikely(v != current) )
+        return;
+
+    if ( unlikely(current->arch.hvm_vmx.vmcs != from) )
+        return;

Do you really want this function to fail silently if called with v != current? Use ASSERT(), or, even better, remove the first argument entirely.

Deleted.

Thx, Eddie

author
#21 lore raw

PATCH 1/1 Emulation of VMRESUME/VMLAUNCH

In reply to Eddie Dong

# HG changeset patch
# User Eddie Dong <[email protected]>
# Date 1307003601 -28800
# Node ID 279a27a3b1a90380c8fa579e87835cb58a8f4aac # Parent 62cc6c7516e010ef673c75bba83f901785b063d5 Emulation of VMRESUME/VMLAUNCH

xen/arch/x86/hvm/vmx/vmx.c +15 -2
diff -r 62cc6c7516e0 -r 279a27a3b1a9 xen/arch/x86/hvm/vmx/vmx.c
@@ -2175,6 +2175,11 @@ asmlinkage void vmx_vmexit_handler(struc
     /* Now enable interrupts so it's safe to take locks. */
     local_irq_enable();
 
+    /* XXX: This looks ugly, but we need a mechanism to ensure
+     * any pending vmresume has really happened
+     */
+    vcpu_nestedhvm(v).nv_vmswitch_in_progress = 0;
+
     if ( unlikely(exit_reason & VMX_EXIT_REASONS_FAILED_VMENTRY) )
         return vmx_failed_vmentry(exit_reason, regs);
 
@@ -2469,10 +2474,18 @@ asmlinkage void vmx_vmexit_handler(struc
             update_guest_eip();
         break;
 
+    case EXIT_REASON_VMLAUNCH:
+        if ( nvmx_handle_vmlaunch(regs) == X86EMUL_OKAY )
+            update_guest_eip();
+        break;
+
+    case EXIT_REASON_VMRESUME:
+        if ( nvmx_handle_vmresume(regs) == X86EMUL_OKAY )
+            update_guest_eip();
+        break;
+
     case EXIT_REASON_MWAIT_INSTRUCTION:
     case EXIT_REASON_MONITOR_INSTRUCTION:
-    case EXIT_REASON_VMLAUNCH:
-    case EXIT_REASON_VMRESUME:
     case EXIT_REASON_GETSEC:
     case EXIT_REASON_INVEPT:
     case EXIT_REASON_INVVPID:
xen/arch/x86/hvm/vmx/vvmx.c +35 -0
diff -r 62cc6c7516e0 -r 279a27a3b1a9 xen/arch/x86/hvm/vmx/vvmx.c
@@ -261,6 +261,13 @@ static void reg_write(struct cpu_user_re
     }
 }
 
+static inline u32 __n2_exec_control(struct vcpu *v)
+{
+    struct nestedvcpu *nvcpu = &vcpu_nestedhvm(v);
+
+    return __get_vvmcs(nvcpu->nv_vvmcx, CPU_BASED_VM_EXEC_CONTROL);
+}
+
 static int vmx_inst_check_privilege(struct cpu_user_regs *regs, int vmxop_check)
 {
     struct vcpu *v = current;
@@ -502,6 +509,34 @@ int nvmx_handle_vmxoff(struct cpu_user_r
     return X86EMUL_OKAY;
 }
 
+int nvmx_handle_vmresume(struct cpu_user_regs *regs)
+{
+    struct vcpu *v = current;
+    struct nestedvmx *nvmx = &vcpu_2_nvmx(v);
+    struct nestedvcpu *nvcpu = &vcpu_nestedhvm(v);
+    int rc;
+
+    rc = vmx_inst_check_privilege(regs, 0);
+    if ( rc != X86EMUL_OKAY )
+        return rc;
+
+    /* check VMCS is valid and IO BITMAP is set */
+    if ( (nvcpu->nv_vvmcxaddr != VMCX_EADDR) &&
+            ((nvmx->iobitmap[0] && nvmx->iobitmap[1]) ||
+            !(__n2_exec_control(v) & CPU_BASED_ACTIVATE_IO_BITMAP) ) )
+        nvcpu->nv_vmentry_pending = 1;
+    else
+        vmreturn(regs, VMFAIL_INVALID);
+
+    return X86EMUL_OKAY;
+}
+
+int nvmx_handle_vmlaunch(struct cpu_user_regs *regs)
+{
+    /* TODO: check for initial launch/resume */
+    return nvmx_handle_vmresume(regs);
+}
+
 int nvmx_handle_vmptrld(struct cpu_user_regs *regs)
 {
     struct vcpu *v = current;
xen/include/asm-x86/hvm/vmx/vvmx.h +2 -0
diff -r 62cc6c7516e0 -r 279a27a3b1a9 xen/include/asm-x86/hvm/vmx/vvmx.h
@@ -158,6 +158,8 @@ int nvmx_handle_vmptrst(struct cpu_user_
 int nvmx_handle_vmclear(struct cpu_user_regs *regs);
 int nvmx_handle_vmread(struct cpu_user_regs *regs);
 int nvmx_handle_vmwrite(struct cpu_user_regs *regs);
+int nvmx_handle_vmresume(struct cpu_user_regs *regs);
+int nvmx_handle_vmlaunch(struct cpu_user_regs *regs);
 
 #endif /* __ASM_X86_HVM_VVMX_H__ */
author
#22 lore raw

PATCH 1/1 Extend VMCS control fields for n2 guest

In reply to Eddie Dong

# HG changeset patch
# User Eddie Dong <[email protected]>
# Date 1307003601 -28800
# Node ID aacbe98da103be572c9f96d6c85788f74f574117 # Parent 279a27a3b1a90380c8fa579e87835cb58a8f4aac Extend VMCS control fields for n2 guest

xen/arch/x86/hvm/vmx/vmx.c +15 -4
diff -r 279a27a3b1a9 -r aacbe98da103 xen/arch/x86/hvm/vmx/vmx.c
@@ -54,6 +54,7 @@
 #include <asm/xenoprof.h>
 #include <asm/debugger.h>
 #include <asm/apic.h>
+#include <asm/hvm/nestedhvm.h>
 
 enum handler_return { HNDL_done, HNDL_unhandled, HNDL_exception_raised };
 
@@ -361,18 +362,28 @@ long_mode_do_msr_write(unsigned int msr,
 
 void vmx_update_cpu_exec_control(struct vcpu *v)
 {
-    __vmwrite(CPU_BASED_VM_EXEC_CONTROL, v->arch.hvm_vmx.exec_control);
+    if ( nestedhvm_vcpu_in_guestmode(v) )
+        nvmx_update_exec_control(v, v->arch.hvm_vmx.exec_control);
+    else
+        __vmwrite(CPU_BASED_VM_EXEC_CONTROL, v->arch.hvm_vmx.exec_control);
 }
 
 static void vmx_update_secondary_exec_control(struct vcpu *v)
 {
-    __vmwrite(SECONDARY_VM_EXEC_CONTROL,
-              v->arch.hvm_vmx.secondary_exec_control);
+    if ( nestedhvm_vcpu_in_guestmode(v) )
+        nvmx_update_secondary_exec_control(v,
+            v->arch.hvm_vmx.secondary_exec_control);
+    else
+        __vmwrite(SECONDARY_VM_EXEC_CONTROL,
+                  v->arch.hvm_vmx.secondary_exec_control);
 }
 
 void vmx_update_exception_bitmap(struct vcpu *v)
 {
-    __vmwrite(EXCEPTION_BITMAP, v->arch.hvm_vmx.exception_bitmap);
+    if ( nestedhvm_vcpu_in_guestmode(v) )
+        nvmx_update_exception_bitmap(v, v->arch.hvm_vmx.exception_bitmap);
+    else
+        __vmwrite(EXCEPTION_BITMAP, v->arch.hvm_vmx.exception_bitmap);
 }
 
 static int vmx_guest_x86_mode(struct vcpu *v)
xen/arch/x86/hvm/vmx/vvmx.c +88 -0

100 lines not on this page · raw message

xen/include/asm-x86/hvm/vmx/vvmx.h +5 -0
diff -r 279a27a3b1a9 -r aacbe98da103 xen/include/asm-x86/hvm/vmx/vvmx.h
@@ -161,5 +161,10 @@ int nvmx_handle_vmwrite(struct cpu_user_
 int nvmx_handle_vmresume(struct cpu_user_regs *regs);
 int nvmx_handle_vmlaunch(struct cpu_user_regs *regs);
 
+void nvmx_update_exec_control(struct vcpu *v, unsigned long value);
+void nvmx_update_secondary_exec_control(struct vcpu *v,
+                                        unsigned long value);
+void nvmx_update_exception_bitmap(struct vcpu *v, unsigned long value);
+
 #endif /* __ASM_X86_HVM_VVMX_H__ */
author
#23 lore raw

PATCH 1/1 Switch shadow/virtual VMCS between n1/n2 guests

In reply to Eddie Dong

# HG changeset patch
# User Eddie Dong <[email protected]>
# Date 1307003601 -28800
# Node ID bd15acfc9b822ccf27b5c7603e600e5e11733907 # Parent aacbe98da103be572c9f96d6c85788f74f574117 Switch shadow/virtual VMCS between n1/n2 guests.

xen/arch/x86/hvm/vmx/entry.S +1 -0
diff -r aacbe98da103 -r bd15acfc9b82 xen/arch/x86/hvm/vmx/entry.S
@@ -119,6 +119,7 @@ vmx_asm_vmexit_handler:
 .globl vmx_asm_do_vmentry
 vmx_asm_do_vmentry:
         call vmx_intr_assist
+        call nvmx_switch_guest
 
         get_current(bx)
         cli
xen/arch/x86/hvm/vmx/vvmx.c +397 -0

409 lines not on this page · raw message

xen/include/asm-x86/hvm/vmx/vvmx.h +1 -0
diff -r aacbe98da103 -r bd15acfc9b82 xen/include/asm-x86/hvm/vmx/vvmx.h
@@ -165,6 +165,7 @@ void nvmx_update_exec_control(struct vcp
 void nvmx_update_secondary_exec_control(struct vcpu *v,
                                         unsigned long value);
 void nvmx_update_exception_bitmap(struct vcpu *v, unsigned long value);
+asmlinkage void nvmx_switch_guest(void);
 
 #endif /* __ASM_X86_HVM_VVMX_H__ */
#24 lore raw

Re: [PATCH 15 of 20] Switch shadow/virtual VMCS between n1/n2 guests

xen/arch/x86/hvm/vmx/vvmx.c void nvmx_update_secondary_exec_control( · line 496

Quoted 7 lines · Eddie Dong
xen/arch/x86/hvm/vmx/vvmx.c +7 -0
+static void nvmx_update_exit_control(struct vcpu *v,
+					unsigned long host_cntrl)
+{
+    u32 shadow_cntrl;
+    struct nestedvcpu *nvcpu = &vcpu_nestedhvm(v);
+
+#define REMOVED_EXIT_CONTROL_BITS    ((1<<2) |           \

Define a macro for whatever 1<<2 means here, please.

Quoted 8 lines
xen/arch/x86/hvm/vmx/vvmx.c +8 -0
+                (VM_EXIT_SAVE_GUEST_PAT) |               \
+                (VM_EXIT_SAVE_GUEST_EFER) |              \
+                (VM_EXIT_SAVE_PREEMPT_TIMER))
+    shadow_cntrl = __get_vvmcs(nvcpu->nv_vvmcx, VM_EXIT_CONTROLS);
+    shadow_cntrl &= ~REMOVED_EXIT_CONTROL_BITS;
+    shadow_cntrl |= host_cntrl;
+    __vmwrite(VM_EXIT_CONTROLS, shadow_cntrl);
+}

[...]

Quoted 11 lines
xen/arch/x86/hvm/vmx/vvmx.c +11 -0
+static void sync_vvmcs_guest_state(struct vcpu *v, struct cpu_user_regs *regs)
+{
+    int i;
+    unsigned long mask;
+    unsigned long cr;
+    struct nestedvcpu *nvcpu = &vcpu_nestedhvm(v);
+    void *vvmcs = nvcpu->nv_vvmcx;
+
+    /* copy shadow vmcs.gstate back to vvmcs.gstate */
+    for ( i = 0; i < ARRAY_SIZE(vmcs_gstate_field); i++ )
+        shadow_to_vvmcs(vvmcs, vmcs_gstate_field[i]);

xen/arch/x86/hvm/vmx/vvmx.c static void nvmx_purge_vvmcs(struct vcpu · line 826

Quoted 10 lines
xen/arch/x86/hvm/vmx/vvmx.c +10 -0
+    /* RIP, RSP are in user regs */
+    __set_vvmcs(vvmcs, GUEST_RIP, regs->rip);
+    __set_vvmcs(vvmcs, GUEST_RSP, regs->rsp);
+
+    /* SDM 20.6.6: L2 guest execution may change GUEST CR0/CR4 */
+    mask = __get_vvmcs(vvmcs, CR0_GUEST_HOST_MASK);
+    if ( ~mask )
+    {
+        cr = __get_vvmcs(vvmcs, GUEST_CR0);
+        cr = (cr & mask) | (__vmread(GUEST_CR4) & ~mask);

Cut-n-paste error? ^^^^^^^^^

Tim.

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Xen Platform Team
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)
#25 lore raw

RE: [PATCH 15 of 20] Switch shadow/virtual VMCS between n1/n2 guests

Quoted 8 lines

xen/arch/x86/hvm/vmx/vvmx.c void nvmx_update_secondary_exec_control( · line 496

Quoted 5 lines
xen/arch/x86/hvm/vmx/vvmx.c +4 -0
+    u32 shadow_cntrl;
+    struct nestedvcpu *nvcpu = &vcpu_nestedhvm(v);
+
+#define REMOVED_EXIT_CONTROL_BITS    ((1<<2) |           \

Define a macro for whatever 1<<2 means here, please.

Done.

Quoted 12 lines

xen/arch/x86/hvm/vmx/vvmx.c void nvmx_update_secondary_exec_control(

Quoted 4 lines
xen/arch/x86/hvm/vmx/vvmx.c +4 -0
+                (VM_EXIT_SAVE_GUEST_PAT) |               \
+                (VM_EXIT_SAVE_GUEST_EFER) |              \
+                (VM_EXIT_SAVE_PREEMPT_TIMER))
+    shadow_cntrl = __get_vvmcs(nvcpu->nv_vvmcx,

VM_EXIT_CONTROLS);

Quoted 4 lines
xen/arch/x86/hvm/vmx/vvmx.c +4 -0
+    shadow_cntrl &= ~REMOVED_EXIT_CONTROL_BITS;
+    shadow_cntrl |= host_cntrl;
+    __vmwrite(VM_EXIT_CONTROLS, shadow_cntrl);
+}
Quoted 9 lines

xen/arch/x86/hvm/vmx/vvmx.c static void nvmx_purge_vvmcs(struct vcpu · line 826

Quoted 6 lines
xen/arch/x86/hvm/vmx/vvmx.c +6 -0
+    /* SDM 20.6.6: L2 guest execution may change GUEST CR0/CR4 */
+    mask = __get_vvmcs(vvmcs, CR0_GUEST_HOST_MASK);
+    if ( ~mask )
+    {
+        cr = __get_vvmcs(vvmcs, GUEST_CR0);
+        cr = (cr & mask) | (__vmread(GUEST_CR4) & ~mask);

Cut-n-paste error? ^^^^^^^^^

Oh, Yes, Thanks.
Eddie

#26 lore raw

Re: [PATCH 15 of 20] Switch shadow/virtual VMCS between n1/n2 guests

In reply to Eddie Dong

Hi,

Quoted 8 lines
xen/arch/x86/hvm/vmx/vvmx.c +8 -0
+asmlinkage void nvmx_switch_guest(void)
+{
+    struct vcpu *v = current;
+    struct nestedvcpu *nvcpu = &vcpu_nestedhvm(v);
+    struct cpu_user_regs *regs = guest_cpu_user_regs();
+
+    /*
+     * a softirq may interrupt us between a virtual vmentry is

xen/arch/x86/hvm/vmx/vvmx.c static void nvmx_purge_vvmcs(struct vcpu · line 932

Quoted 10 lines
xen/arch/x86/hvm/vmx/vvmx.c +10 -0
+     * just handled and the true vmentry. If during this window,
+     * a L1 virtual interrupt causes another virtual vmexit, we
+     * cannot let that happen or VM_ENTRY_INTR_INFO will be lost.
+     */
+    if ( unlikely(nvcpu->nv_vmswitch_in_progress) )
+        return;
+
+    if ( nestedhvm_vcpu_in_guestmode(v) && nvcpu->nv_vmexit_pending )
+    {
+        local_irq_enable();

Why? Is this function every called with interrupts disabled? And if so, will its caller deal with having them enabled when it exits?

xen/arch/x86/hvm/vmx/vvmx.c static void nvmx_purge_vvmcs(struct vcpu · line 937

Quoted 5 lines
xen/arch/x86/hvm/vmx/vvmx.c +5 -0
+        virtual_vmexit(regs);
+    }
+    else if ( !nestedhvm_vcpu_in_guestmode(v) && nvcpu->nv_vmentry_pending )
+    {
+        local_irq_enable();

ditto.

Tim.

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Xen Platform Team
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)
author
#27 lore raw

PATCH 1/1 interrupt/exception handling for n2 guest

In reply to Eddie Dong

# HG changeset patch
# User Eddie Dong <[email protected]>
# Date 1307003601 -28800
# Node ID f14f451a780e60e920c057e44fa1bc3ee40495a7 # Parent bd15acfc9b822ccf27b5c7603e600e5e11733907 interrupt/exception handling for n2 guest

xen/arch/x86/hvm/vmx/intr.c +100 -0
diff -r bd15acfc9b82 -r f14f451a780e xen/arch/x86/hvm/vmx/intr.c
@@ -35,6 +35,7 @@
 #include <asm/hvm/vmx/vmcs.h>
 #include <asm/hvm/vpic.h>
 #include <asm/hvm/vlapic.h>
+#include <asm/hvm/nestedhvm.h>
 #include <public/hvm/ioreq.h>
 #include <asm/hvm/trace.h>
 
@@ -109,6 +110,102 @@ static void enable_intr_window(struct vc
     }
 }
 
+/*
+ * Injecting interrupts for nested virtualization
+ *
+ *  When injecting virtual interrupts (originated from L0), there are
+ *  two major possibilities, within L1 context and within L2 context
+ *   1. L1 context (in_nesting == 0)
+ *     Everything is the same as without nested, check RFLAGS.IF to
+ *     see if the injection can be done, using VMCS to inject the
+ *     interrupt
+ *
+ *   2. L2 context (in_nesting == 1)
+ *     Causes a virtual VMExit, RFLAGS.IF is ignored, whether to ack
+ *     irq according to intr_ack_on_exit, shouldn't block normally,
+ *     except for:
+ *    a. context transition
+ *     interrupt needs to be blocked at virtual VMEntry time
+ *    b. L2 idtv reinjection
+ *     if L2 idtv is handled within L0 (e.g. L0 shadow page fault),
+ *     it needs to be reinjected without exiting to L1, interrupt
+ *     injection should be blocked as well at this point.
+ *
+ *  Unfortunately, interrupt blocking in L2 won't work with simple
+ *  intr_window_open (which depends on L2's IF). To solve this,
+ *  the following algorithm can be used:
+ *   v->arch.hvm_vmx.exec_control.VIRTUAL_INTR_PENDING now denotes
+ *   only L0 control, physical control may be different from it.
+ *       - if in L1, it behaves normally, intr window is written
+ *         to physical control as it is
+ *       - if in L2, replace it to MTF (or NMI window) if possible
+ *       - if MTF/NMI window is not used, intr window can still be
+ *         used but may have negative impact on interrupt performance.
+ */
+
+enum hvm_intblk nvmx_intr_blocked(struct vcpu *v)
+{
+    int r = hvm_intblk_none;
+    struct nestedvcpu *nvcpu = &vcpu_nestedhvm(v);
+
+    if ( nestedhvm_vcpu_in_guestmode(v) )
+    {
+        if ( nvcpu->nv_vmexit_pending ||
+             nvcpu->nv_vmswitch_in_progress ||
+             (__vmread(VM_ENTRY_INTR_INFO) & INTR_INFO_VALID_MASK) )
+            r = hvm_intblk_rflags_ie;
+    }
+    else if ( nvcpu->nv_vmentry_pending )
+        r = hvm_intblk_rflags_ie;
+
+    return r;
+}
+
+static int nvmx_intr_intercept(struct vcpu *v, struct hvm_intack intack)
+{
+    u32 exit_ctrl;
+
+    /*
+     * TODO:
+     *   - if L1 intr-window exiting == 0
+     *   - vNMI
+     */
+
+    if ( nvmx_intr_blocked(v) != hvm_intblk_none )
+    {
+        enable_intr_window(v, intack);
+        return 1;
+    }
+
+    if ( nestedhvm_vcpu_in_guestmode(v) )
+    {
+        if ( intack.source == hvm_intsrc_pic ||
+                 intack.source == hvm_intsrc_lapic )
+        {
+            vmx_inject_extint(intack.vector);
+
+            exit_ctrl = __get_vvmcs(vcpu_nestedhvm(v).nv_vvmcx,
+                            VM_EXIT_CONTROLS);
+            if ( exit_ctrl & VM_EXIT_ACK_INTR_ON_EXIT )
+            {
+                /* for now, duplicate the ack path in vmx_intr_assist */
+                hvm_vcpu_ack_pending_irq(v, intack);
+                pt_intr_post(v, intack);
+
+                intack = hvm_vcpu_has_pending_irq(v);
+                if ( unlikely(intack.source != hvm_intsrc_none) )
+                    enable_intr_window(v, intack);
+            }
+            else
+                enable_intr_window(v, intack);
+
+            return 1;
+        }
+    }
+
+    return 0;
+}
+
 asmlinkage void vmx_intr_assist(void)
 {
     struct hvm_intack intack;
@@ -132,6 +229,9 @@ asmlinkage void vmx_intr_assist(void)
         if ( likely(intack.source == hvm_intsrc_none) )
             goto out;
 
+        if ( unlikely(nvmx_intr_intercept(v, intack)) )
+            goto out;
+
         intblk = hvm_interrupt_blocked(v, intack);
         if ( intblk == hvm_intblk_tpr )
         {
xen/arch/x86/hvm/vmx/vmx.c +76 -4

132 lines not on this page · raw message

xen/arch/x86/hvm/vmx/vvmx.c +96 -0

123 lines not on this page · raw message

xen/include/asm-x86/hvm/vmx/vvmx.h +4 -0
diff -r bd15acfc9b82 -r f14f451a780e xen/include/asm-x86/hvm/vmx/vvmx.h
@@ -93,6 +93,9 @@ int nvmx_vcpu_reset(struct vcpu *v);
 uint64_t nvmx_vcpu_guestcr3(struct vcpu *v);
 uint64_t nvmx_vcpu_hostcr3(struct vcpu *v);
 uint32_t nvmx_vcpu_asid(struct vcpu *v);
+enum hvm_intblk nvmx_intr_blocked(struct vcpu *v);
+int nvmx_intercepts_exception(struct vcpu *v, 
+                              unsigned int trap, int error_code);
 
 int nvmx_handle_vmxon(struct cpu_user_regs *regs);
 int nvmx_handle_vmxoff(struct cpu_user_regs *regs);
@@ -166,6 +169,7 @@ void nvmx_update_secondary_exec_control(
                                         unsigned long value);
 void nvmx_update_exception_bitmap(struct vcpu *v, unsigned long value);
 asmlinkage void nvmx_switch_guest(void);
+void nvmx_idtv_handling(void);
 
 #endif /* __ASM_X86_HVM_VVMX_H__ */
author
#28 lore raw

PATCH 1/1 VM exit handler of n2-guest

In reply to Eddie Dong

# HG changeset patch
# User Eddie Dong <[email protected]>
# Date 1307003601 -28800
# Node ID 24d4d7d3e4c44c8dc61f464bca9aae57480dfe75 # Parent f14f451a780e60e920c057e44fa1bc3ee40495a7 VM exit handler of n2-guest

xen/arch/x86/hvm/vmx/vmx.c +10 -0
diff -r f14f451a780e -r 24d4d7d3e4c4 xen/arch/x86/hvm/vmx/vmx.c
@@ -943,6 +943,10 @@ static void vmx_set_segment_register(str
 static void vmx_set_tsc_offset(struct vcpu *v, u64 offset)
 {
     vmx_vmcs_enter(v);
+
+    if ( nestedhvm_vcpu_in_guestmode(v) )
+        offset += nvmx_get_tsc_offset(v);
+
     __vmwrite(TSC_OFFSET, offset);
 #if defined (__i386__)
     __vmwrite(TSC_OFFSET_HIGH, offset >> 32);
@@ -2258,6 +2262,11 @@ asmlinkage void vmx_vmexit_handler(struc
      * any pending vmresume has really happened
      */
     vcpu_nestedhvm(v).nv_vmswitch_in_progress = 0;
+    if ( nestedhvm_vcpu_in_guestmode(v) )
+    {
+        if ( nvmx_n2_vmexit_handler(regs, exit_reason) )
+            goto out;
+    }
 
     if ( unlikely(exit_reason & VMX_EXIT_REASONS_FAILED_VMENTRY) )
         return vmx_failed_vmentry(exit_reason, regs);
@@ -2655,6 +2664,7 @@ asmlinkage void vmx_vmexit_handler(struc
         break;
     }
 
+out:
     if ( nestedhvm_vcpu_in_guestmode(v) )
         nvmx_idtv_handling();
 }
xen/arch/x86/hvm/vmx/vvmx.c +272 -1

306 lines not on this page · raw message

xen/include/asm-x86/hvm/vmx/vvmx.h +3 -0
diff -r f14f451a780e -r 24d4d7d3e4c4 xen/include/asm-x86/hvm/vmx/vvmx.h
@@ -170,6 +170,9 @@ void nvmx_update_secondary_exec_control(
 void nvmx_update_exception_bitmap(struct vcpu *v, unsigned long value);
 asmlinkage void nvmx_switch_guest(void);
 void nvmx_idtv_handling(void);
+u64 nvmx_get_tsc_offset(struct vcpu *v);
+int nvmx_n2_vmexit_handler(struct cpu_user_regs *regs,
+                          unsigned int exit_reason);
 
 #endif /* __ASM_X86_HVM_VVMX_H__ */
#29 lore raw

Re: [PATCH 17 of 20] VM exit handler of n2-guest

xen/arch/x86/hvm/vmx/vvmx.c void nvmx_idtv_handling(void) · line 1344

Quoted 6 lines · Eddie Dong
xen/arch/x86/hvm/vmx/vvmx.c +6 -0
+    case EXIT_REASON_WBINVD:
+    case EXIT_REASON_EPT_VIOLATION:
+    case EXIT_REASON_EPT_MISCONFIG:
+    case EXIT_REASON_EXTERNAL_INTERRUPT:
+        /* pass to L0 handler */
+        break;

If the L1 guest asked to intercept WBINVD, will it ever get the VMEXIT? I didn't see any code in the L0 WBINVD handler to pass it on.

Cheers,

Tim.

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Xen Platform Team
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)
#30 lore raw

RE: [PATCH 17 of 20] VM exit handler of n2-guest

Quoted 11 lines

xen/arch/x86/hvm/vmx/vvmx.c void nvmx_idtv_handling(void) · line 1344

Quoted 6 lines · Eddie Dong
xen/arch/x86/hvm/vmx/vvmx.c +6 -0
+    case EXIT_REASON_WBINVD:
+    case EXIT_REASON_EPT_VIOLATION:
+    case EXIT_REASON_EPT_MISCONFIG:
+    case EXIT_REASON_EXTERNAL_INTERRUPT:
+        /* pass to L0 handler */
+        break;

If the L1 guest asked to intercept WBINVD, will it ever get the VMEXIT? I didn't see any code in the L0 WBINVD handler to pass it on.

Current patch doesn't expose Secondary Processor-Based VM-Execution Controls. So WBINVD exiting capability is removed in L1 guest.

Thx, Eddie

#31 lore raw

Re: [PATCH 17 of 20] VM exit handler of n2-guest

Quoted 8 lines · Eddie
Quoted 8 lines
Quoted 6 lines · Eddie Dong
xen/arch/x86/hvm/vmx/vvmx.c +6 -0
+    case EXIT_REASON_WBINVD:
+    case EXIT_REASON_EPT_VIOLATION:
+    case EXIT_REASON_EPT_MISCONFIG:
+    case EXIT_REASON_EXTERNAL_INTERRUPT:
+        /* pass to L0 handler */
+        break;
Quoted 6 lines
Quoted 3 lines

If the L1 guest asked to intercept WBINVD, will it ever get the VMEXIT? I didn't see any code in the L0 WBINVD handler to pass it on.

Current patch doesn't expose Secondary Processor-Based VM-Execution Controls. So WBINVD exiting capability is removed in L1 guest.

Ah, OK, thanks.

Tim.

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Xen Platform Team
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)
author
#32 lore raw

PATCH 1/1 Lazy FPU for n2 guest

In reply to Eddie Dong

# HG changeset patch
# User Eddie Dong <[email protected]>
# Date 1307003601 -28800
# Node ID 0cedbe9214c1632a0f1816d8b6d7442dc5f40065 # Parent 24d4d7d3e4c44c8dc61f464bca9aae57480dfe75 Lazy FPU for n2 guest

xen/arch/x86/hvm/vmx/vvmx.c +12 -1
diff -r 24d4d7d3e4c4 -r 0cedbe9214c1 xen/arch/x86/hvm/vmx/vvmx.c
@@ -842,6 +842,9 @@ static void virtual_vmentry(struct cpu_u
     regs->rsp = __get_vvmcs(vvmcs, GUEST_RSP);
     regs->rflags = __get_vvmcs(vvmcs, GUEST_RFLAGS);
 
+    /* updating host cr0 to sync TS bit */
+    __vmwrite(HOST_CR0, v->arch.hvm_vmx.host_cr0);
+
     /* TODO: EPT_POINTER */
 }
 
@@ -990,6 +993,9 @@ static void virtual_vmexit(struct cpu_us
     regs->rsp = __get_vvmcs(nvcpu->nv_vvmcx, HOST_RSP);
     regs->rflags = __vmread(GUEST_RFLAGS);
 
+    /* updating host cr0 to sync TS bit */
+    __vmwrite(HOST_CR0, v->arch.hvm_vmx.host_cr0);
+
     vmreturn(regs, VMSUCCEED);
 }
 
@@ -1319,13 +1325,18 @@ int nvmx_n2_vmexit_handler(struct cpu_us
 
         /*
          * decided by L0 and L1 exception bitmap, if the vetor is set by
-         * both, L0 has priority on #PF, L1 has priority on others
+         * both, L0 has priority on #PF and #NM, L1 has priority on others
          */
         if ( vector == TRAP_page_fault )
         {
             if ( paging_mode_hap(v->domain) )
                 nvcpu->nv_vmexit_pending = 1;
         }
+        else if ( vector == TRAP_no_device )
+        {
+            if ( v->fpu_dirtied )
+                nvcpu->nv_vmexit_pending = 1;
+        }
         else if ( (intr_info & valid_mask) == valid_mask )
         {
             exec_bitmap =__get_vvmcs(nvcpu->nv_vvmcx, EXCEPTION_BITMAP);
author
#33 lore raw

PATCH 1/1 Add VMXE bits in virtual CR4

In reply to Eddie Dong

# HG changeset patch
# User Eddie Dong <[email protected]>
# Date 1307003601 -28800
# Node ID c046b25135205ff58c0b729c0b94cd920cdbb7e2 # Parent 0cedbe9214c1632a0f1816d8b6d7442dc5f40065 Add VMXE bits in virtual CR4

xen/include/asm-x86/cpufeature.h +2 -0
diff -r 0cedbe9214c1 -r c046b2513520 xen/include/asm-x86/cpufeature.h
@@ -216,6 +216,8 @@
 
 #define cpu_has_svm		boot_cpu_has(X86_FEATURE_SVM)
 
+#define cpu_has_vmx		boot_cpu_has(X86_FEATURE_VMXE)
+
 #endif /* __ASM_I386_CPUFEATURE_H */
 
 /* 
xen/include/asm-x86/hvm/hvm.h +2 -0
diff -r 0cedbe9214c1 -r c046b2513520 xen/include/asm-x86/hvm/hvm.h
@@ -313,6 +313,8 @@ static inline int hvm_do_pmu_interrupt(s
         X86_CR4_DE  | X86_CR4_PSE | X86_CR4_PAE |       \
         X86_CR4_MCE | X86_CR4_PGE | X86_CR4_PCE |       \
         X86_CR4_OSFXSR | X86_CR4_OSXMMEXCPT |           \
+	((nestedhvm_enabled((_v)->domain) &&            \
+          cpu_has_vmx) ? X86_CR4_VMXE : 0)  |       	\
         (xsave_enabled(_v) ? X86_CR4_OSXSAVE : 0))))
 
 /* These exceptions must always be intercepted. */
#34 lore raw

Re: [PATCH 19 of 20] Add VMXE bits in virtual CR4

xen/include/asm-x86/hvm/hvm.h static inline int hvm_do_pmu_interrupt(s · line 317

Quoted 9 lines · Eddie Dong

diff -r 0cedbe9214c1 -r c046b2513520 xen/include/asm-x86/hvm/hvm.h

xen/include/asm-x86/hvm/hvm.h +2 -0
@@ -313,6 +313,8 @@ static inline int hvm_do_pmu_interrupt(s
         X86_CR4_DE  | X86_CR4_PSE | X86_CR4_PAE |       \
         X86_CR4_MCE | X86_CR4_PGE | X86_CR4_PCE |       \
         X86_CR4_OSFXSR | X86_CR4_OSXMMEXCPT |           \
+	((nestedhvm_enabled((_v)->domain) &&            \
+          cpu_has_vmx) ? X86_CR4_VMXE : 0)  |       	\

Should we also add VMXE to this mask even if !nestedhvm_enabled()?

Tim.

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Xen Platform Team
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)
#35 lore raw

RE: [PATCH 19 of 20] Add VMXE bits in virtual CR4

Quoted 12 lines

xen/include/asm-x86/hvm/hvm.h static inline int hvm_do_pmu_interrupt(s · line 317

Quoted 9 lines

diff -r 0cedbe9214c1 -r c046b2513520 xen/include/asm-x86/hvm/hvm.h

xen/include/asm-x86/hvm/hvm.h +2 -0
@@ -313,6 +313,8 @@ static inline int hvm_do_pmu_interrupt(s
         X86_CR4_DE  | X86_CR4_PSE | X86_CR4_PAE |       \
         X86_CR4_MCE | X86_CR4_PGE | X86_CR4_PCE |       \
         X86_CR4_OSFXSR | X86_CR4_OSXMMEXCPT |           \
+	((nestedhvm_enabled((_v)->domain) &&            \
+          cpu_has_vmx) ? X86_CR4_VMXE : 0)  |       	\

Should we also add VMXE to this mask even if !nestedhvm_enabled()?

Fine.
Eddie

author
#36 lore raw

PATCH 1/1 n2 MSR handling and capability exposure

In reply to Eddie Dong

# HG changeset patch
# User Eddie Dong <[email protected]>
# Date 1307003601 -28800
# Node ID ee55fa0471a6b72569b567286ae264bc1dcdbb4b # Parent c046b25135205ff58c0b729c0b94cd920cdbb7e2 n2 MSR handling and capability exposure

xen/arch/x86/hvm/vmx/vmx.c +10 -4
diff -r c046b2513520 -r ee55fa0471a6 xen/arch/x86/hvm/vmx/vmx.c
@@ -1778,8 +1778,11 @@ static int vmx_msr_read_intercept(unsign
         *msr_content |= (u64)__vmread(GUEST_IA32_DEBUGCTL_HIGH) << 32;
 #endif
         break;
-    case MSR_IA32_VMX_BASIC...MSR_IA32_VMX_PROCBASED_CTLS2:
-        goto gp_fault;
+    case IA32_FEATURE_CONTROL_MSR:
+    case MSR_IA32_VMX_BASIC...MSR_IA32_VMX_TRUE_ENTRY_CTLS:
+        if ( !nvmx_msr_read_intercept(msr, msr_content) )
+            goto gp_fault;
+        break;
     case MSR_IA32_MISC_ENABLE:
         rdmsrl(MSR_IA32_MISC_ENABLE, *msr_content);
         /* Debug Trace Store is not supported. */
@@ -1940,8 +1943,11 @@ static int vmx_msr_write_intercept(unsig
 
         break;
     }
-    case MSR_IA32_VMX_BASIC...MSR_IA32_VMX_PROCBASED_CTLS2:
-        goto gp_fault;
+    case IA32_FEATURE_CONTROL_MSR:
+    case MSR_IA32_VMX_BASIC...MSR_IA32_VMX_TRUE_ENTRY_CTLS:
+        if ( !nvmx_msr_write_intercept(msr, msr_content) )
+            goto gp_fault;
+        break;
     default:
         if ( vpmu_do_wrmsr(msr, msr_content) )
             return X86EMUL_OKAY;
xen/arch/x86/hvm/vmx/vvmx.c +88 -0

94 lines not on this page · raw message

xen/include/asm-x86/hvm/vmx/vvmx.h +4 -0
diff -r c046b2513520 -r ee55fa0471a6 xen/include/asm-x86/hvm/vmx/vvmx.h
@@ -163,6 +163,10 @@ int nvmx_handle_vmread(struct cpu_user_r
 int nvmx_handle_vmwrite(struct cpu_user_regs *regs);
 int nvmx_handle_vmresume(struct cpu_user_regs *regs);
 int nvmx_handle_vmlaunch(struct cpu_user_regs *regs);
+int nvmx_msr_read_intercept(unsigned int msr,
+                                u64 *msr_content);
+int nvmx_msr_write_intercept(unsigned int msr,
+                                 u64 msr_content);
 
 void nvmx_update_exec_control(struct vcpu *v, unsigned long value);
 void nvmx_update_secondary_exec_control(struct vcpu *v,
#37 lore raw

Re: [PATCH 20 of 20] n2 MSR handling and capability exposure

xen/arch/x86/hvm/vmx/vvmx.c int nvmx_handle_vmwrite(struct cpu_user_ · line 1285

Quoted 6 lines · Eddie Dong
xen/arch/x86/hvm/vmx/vvmx.c +6 -0
+    case MSR_IA32_VMX_PINBASED_CTLS:
+#define REMOVED_PIN_CONTROL_CAP (PIN_BASED_PREEMPT_TIMER)
+        rdmsr(msr, eax, edx);
+        data = edx;
+        data = (data << 32) | eax;
+        break;

You don't actually mask the value here.

BTW, I don't really like defining all these REMOVED_* macros, each of which is used only once a few lines from the definition (here and elsewhere in the series). It just adds clutter for no benefit.

Tim.

Quoted 33 lines
xen/arch/x86/hvm/vmx/vvmx.c +33 -0
+    case MSR_IA32_VMX_PROCBASED_CTLS:
+        rdmsr(msr, eax, edx);
+#define REMOVED_EXEC_CONTROL_CAP (CPU_BASED_TPR_SHADOW \
+            | CPU_BASED_ACTIVATE_MSR_BITMAP            \
+            | CPU_BASED_ACTIVATE_SECONDARY_CONTROLS)
+        data = edx & ~REMOVED_EXEC_CONTROL_CAP;
+        data = (data << 32) | eax;
+        break;
+    case MSR_IA32_VMX_EXIT_CTLS:
+        rdmsr(msr, eax, edx);
+#define REMOVED_EXIT_CONTROL_CAP (VM_EXIT_SAVE_GUEST_PAT \
+            | VM_EXIT_LOAD_HOST_PAT                      \
+            | VM_EXIT_SAVE_GUEST_EFER                    \
+            | VM_EXIT_LOAD_HOST_EFER                     \
+            | VM_EXIT_SAVE_PREEMPT_TIMER)
+        data = edx & ~REMOVED_EXIT_CONTROL_CAP;
+        data = (data << 32) | eax;
+        break;
+    case MSR_IA32_VMX_ENTRY_CTLS:
+        rdmsr(msr, eax, edx);
+#define REMOVED_ENTRY_CONTROL_CAP (VM_ENTRY_LOAD_GUEST_PAT \
+            | VM_ENTRY_LOAD_GUEST_EFER)
+        data = edx & ~REMOVED_ENTRY_CONTROL_CAP;
+        data = (data << 32) | eax;
+        break;
+    case MSR_IA32_VMX_PROCBASED_CTLS2:
+        mask = 0;
+
+        rdmsr(msr, eax, edx);
+        data = edx & mask;
+        data = (data << 32) | eax;
+        break;
+
Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Xen Platform Team
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)
#38 lore raw

Re: [PATCH 20 of 20] n2 MSR handling and capability exposure

Quoted 8 lines · Tim Deegan

xen/arch/x86/hvm/vmx/vvmx.c int nvmx_handle_vmwrite(struct cpu_user_ · line 1285

Quoted 6 lines · Eddie Dong
xen/arch/x86/hvm/vmx/vvmx.c +6 -0
+    case MSR_IA32_VMX_PINBASED_CTLS:
+#define REMOVED_PIN_CONTROL_CAP (PIN_BASED_PREEMPT_TIMER)
+        rdmsr(msr, eax, edx);
+        data = edx;
+        data = (data << 32) | eax;
+        break;
Quoted 6 lines

You don't actually mask the value here.

BTW, I don't really like defining all these REMOVED_* macros, each of which is used only once a few lines from the definition (here and elsewhere in the series). It just adds clutter for no benefit.

Oh, I forgot to say: will this feature-blacklisting work over live migration to a machine with a different CPU? There isn't an equivalnet of the CPUID masking feature to make all the machines in a cluster seem to have the same VMX features.

Elsewhere we use whitelisting for passsing hardware capability flags to HVM guests; I think we should use whitelists here too.

Cheers,

Tim.

Quoted 34 lines
Quoted 33 lines
xen/arch/x86/hvm/vmx/vvmx.c +33 -0
+    case MSR_IA32_VMX_PROCBASED_CTLS:
+        rdmsr(msr, eax, edx);
+#define REMOVED_EXEC_CONTROL_CAP (CPU_BASED_TPR_SHADOW \
+            | CPU_BASED_ACTIVATE_MSR_BITMAP            \
+            | CPU_BASED_ACTIVATE_SECONDARY_CONTROLS)
+        data = edx & ~REMOVED_EXEC_CONTROL_CAP;
+        data = (data << 32) | eax;
+        break;
+    case MSR_IA32_VMX_EXIT_CTLS:
+        rdmsr(msr, eax, edx);
+#define REMOVED_EXIT_CONTROL_CAP (VM_EXIT_SAVE_GUEST_PAT \
+            | VM_EXIT_LOAD_HOST_PAT                      \
+            | VM_EXIT_SAVE_GUEST_EFER                    \
+            | VM_EXIT_LOAD_HOST_EFER                     \
+            | VM_EXIT_SAVE_PREEMPT_TIMER)
+        data = edx & ~REMOVED_EXIT_CONTROL_CAP;
+        data = (data << 32) | eax;
+        break;
+    case MSR_IA32_VMX_ENTRY_CTLS:
+        rdmsr(msr, eax, edx);
+#define REMOVED_ENTRY_CONTROL_CAP (VM_ENTRY_LOAD_GUEST_PAT \
+            | VM_ENTRY_LOAD_GUEST_EFER)
+        data = edx & ~REMOVED_ENTRY_CONTROL_CAP;
+        data = (data << 32) | eax;
+        break;
+    case MSR_IA32_VMX_PROCBASED_CTLS2:
+        mask = 0;
+
+        rdmsr(msr, eax, edx);
+        data = edx & mask;
+        data = (data << 32) | eax;
+        break;
+
Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Xen Platform Team
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)
#39 lore raw

Re: [PATCH 20 of 20] n2 MSR handling and capability exposure

Quoted 5 lines · Tim Deegan
Quoted 4 lines

BTW, I don't really like defining all these REMOVED_* macros, each of which is used only once a few lines from the definition (here and elsewhere in the series). It just adds clutter for no benefit.

Quoted 7 lines

Oh, I forgot to say: will this feature-blacklisting work over live migration to a machine with a different CPU? There isn't an equivalnet of the CPUID masking feature to make all the machines in a cluster seem to have the same VMX features.

Elsewhere we use whitelisting for passsing hardware capability flags to HVM guests; I think we should use whitelists here too.

Blacklists create a total mess of doom. We should absolutely disallow the creation of any new ones. I think HVM guests are currently clean in this regard and should stay that way.

-- Keir

#40 lore raw

RE: [PATCH 20 of 20] n2 MSR handling and capability exposure

In reply to Tim Deegan
Quoted 5 lines

Oh, I forgot to say: will this feature-blacklisting work over live migration to a machine with a different CPU? There isn't an equivalnet of the CPUID masking feature to make all the machines in a cluster seem to have the same VMX features.

That seems to be an issue neutral to nested virtualization. We should be able to migrate among same processors. But it is difficult to migrate a L2 guest to other machine as L1 guest. It may be OK evnetually, but not addressed right now.

My understanding is that same CPUID doesn't mean exactly same capability.

Quoted 4 lines

Elsewhere we use whitelisting for passsing hardware capability flags to HVM guests; I think we should use whitelists here too.

Thx, Eddie

#41 lore raw

RE: [PATCH 20 of 20] n2 MSR handling and capability exposure

In reply to Tim Deegan
Quoted 10 lines

xen/arch/x86/hvm/vmx/vvmx.c int nvmx_handle_vmwrite(struct cpu_user_ · line 1285

Quoted 6 lines · Eddie Dong
xen/arch/x86/hvm/vmx/vvmx.c +6 -0
+    case MSR_IA32_VMX_PINBASED_CTLS:
+#define REMOVED_PIN_CONTROL_CAP (PIN_BASED_PREEMPT_TIMER)
+        rdmsr(msr, eax, edx);
+        data = edx;
+        data = (data << 32) | eax;
+        break;

You don't actually mask the value here.

Fixed.

Quoted 4 lines

BTW, I don't really like defining all these REMOVED_* macros, each of which is used only once a few lines from the definition (here and elsewhere in the series). It just adds clutter for no benefit.

OK, removed to be in code itself.

Thx, Eddie

#42 lore raw
In reply to Eddie Dong

Hi,

Thanks for these patches. They look pretty good; I have a few comments on the individual patches that I'll post separately.

Overall the only worry I have is the number of TODOs left at the end of the series. Some of them are obvioulsy ony important when you come to do the nested EPT work. I'd appreciate a comment on whether you think any of these is important:

+static int nvmx_intr_intercept(struct vcpu *v, struct hvm_intack intack)
+{
+ u32 exit_ctrl;
+
+ /*

+     * TODO:
+     *   - if L1 intr-window exiting == 0
+     *   - vNMI
+     */

+static int decode_vmx_inst(struct cpu_user_regs *regs,
+ struct vmx_inst_decoded *decode,
+ unsigned long *poperandS, int vmxon_check)
+{
[...]
+ /* TODO: segment type check */

This one, at least, I think does need to be fixed!

+static void load_shadow_control(struct vcpu *v)
+{
+ /* TODO: Make sure the shadow control doesn't set the bits
+ * L0 VMM doesn't handle.
+ */

+int nvmx_handle_vmlaunch(struct cpu_user_regs *regs) +{
+ /* TODO: check for initial launch/resume */
+ return nvmx_handle_vmresume(regs);
+}

+void nvmx_idtv_handling(void)
+{
[...]
+ /* TODO: NMI */
+}

+static void load_shadow_guest_state(struct vcpu *v) +{
[...]
+ /* XXX: should refer to GUEST_HOST_MASK of both L0 and L1 */

Cheers,

Tim.

Signature · 3 lines
Tim Deegan <[email protected]>
Principal Software Engineer, Xen Platform Team
Citrix Systems UK Ltd.  (Company #02937203, SL9 0BG)
#43 lore raw
Quoted 21 lines

-----Original Message-----
From: Tim Deegan [mailto:[email protected]]
Sent: Thursday, June 02, 2011 10:34 PM
To: Dong, Eddie
Cc: [email protected]
Subject: Re: [Xen-devel] [PATCH 00 of 20] NestedVMX support> Hi,

Thanks for these patches. They look pretty good; I have a few comments on the individual patches that I'll post separately.

Overall the only worry I have is the number of TODOs left at the end of the series. Some of them are obvioulsy ony important when you come to do the nested EPT work. I'd appreciate a comment on whether you think any of these is important:

+static int nvmx_intr_intercept(struct vcpu *v, struct hvm_intack intack)

Review

Quoted 8 lines
(quoted diff) +8 -0
+{
+    u32 exit_ctrl;
+
+    /*
+     * TODO:
+     *   - if L1 intr-window exiting == 0
+     *   - vNMI
+     */

Deleted.

Review

Quoted 9 lines
(quoted diff) +3 -0
+static int decode_vmx_inst(struct cpu_user_regs *regs,
+                           struct vmx_inst_decoded *decode,
+                           unsigned long *poperandS, int

vmxon_check)

(quoted diff) +2 -0
+{
[...]
+        /* TODO: segment type check */

Fixed.

Review

Quoted 9 lines

This one, at least, I think does need to be fixed!

(quoted diff) +5 -0
+static void load_shadow_control(struct vcpu *v)
+{
+    /* TODO: Make sure the shadow control doesn't set the bits
+     * L0 VMM doesn't handle.
+     */

deleted

Review

Quoted 7 lines
(quoted diff) +5 -0
+int nvmx_handle_vmlaunch(struct cpu_user_regs *regs)
+{
+    /* TODO: check for initial launch/resume */
+    return nvmx_handle_vmresume(regs);
+}

Handled w/ correct launch state.

Review

Quoted 7 lines
(quoted diff) +4 -0
+void nvmx_idtv_handling(void)
+{
[...]
+    /* TODO: NMI */
+}

deleted

Review

Quoted 6 lines
(quoted diff) +3 -0
+static void load_shadow_guest_state(struct vcpu *v)
+{
[...]
+    /* XXX: should refer to GUEST_HOST_MASK of both L0 and L1 */

Deleted and will revisit later.

Quoted 9 lines

Cheers,

Tim.

--
Tim Deegan <[email protected]>
Principal Software Engineer, Xen Platform Team Citrix Systems UK Ltd. (Company #02937203, SL9 0BG)