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

[Xen-devel] [PATCH 07/16] vmx: nest: switch current vmcs



facility to switch between host vmcs and shadow vmcs

Signed-off-by: Qing He <qing.he@xxxxxxxxx>
Signed-off-by: Eddie Dong <eddie.dong@xxxxxxxxx>

---

diff -r e638812d8f46 xen/arch/x86/hvm/vmx/vmcs.c
--- a/xen/arch/x86/hvm/vmx/vmcs.c       Wed Sep 08 21:30:02 2010 +0800
+++ b/xen/arch/x86/hvm/vmx/vmcs.c       Wed Sep 08 21:42:10 2010 +0800
@@ -642,6 +642,35 @@
               (unsigned long)&get_cpu_info()->guest_cpu_user_regs.error_code);
 }
 
+void vmx_vmcs_switch_current(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.vmcs_host_updated )
+    {
+        v->arch.hvm_vmx.vmcs_host_updated = 0;
+        vmx_set_host_env(v);
+    }
+
+    spin_unlock(&v->arch.hvm_vmx.vmcs_lock);
+}
+
 void vmx_disable_intercept_for_msr(struct vcpu *v, u32 msr)
 {
     unsigned long *msr_bitmap = v->arch.hvm_vmx.msr_bitmap;
@@ -1080,6 +1109,12 @@
         hvm_migrate_pirqs(v);
         vmx_set_host_env(v);
         hvm_asid_flush_vcpu(v);
+
+        /*
+         * nesting: we need to do additional host env sync if we have other
+         * VMCS's. Currently this only works with only one active sVMCS.
+         */
+        v->arch.hvm_vmx.vmcs_host_updated = 1;
     }
 
     debug_state = v->domain->debugger_attached;
diff -r e638812d8f46 xen/include/asm-x86/hvm/vmx/vmcs.h
--- a/xen/include/asm-x86/hvm/vmx/vmcs.h        Wed Sep 08 21:30:02 2010 +0800
+++ b/xen/include/asm-x86/hvm/vmx/vmcs.h        Wed Sep 08 21:42:10 2010 +0800
@@ -102,6 +102,7 @@
 
     /* nested virtualization */
     struct vmx_nest_struct nest;
+    int                  vmcs_host_updated;
 
 #ifdef __x86_64__
     struct vmx_msr_state msr_state;
@@ -389,6 +390,9 @@
 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_current(struct vcpu *v,
+                             struct vmcs_struct *from,
+                             struct vmcs_struct *to);
 
 #endif /* ASM_X86_HVM_VMX_VMCS_H__ */
 

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.