From mboxrd@z Thu Jan 1 00:00:00 1970 From: Qing He Subject: [PATCH 07/16] vmx: nest: switch current vmcs Date: Wed, 8 Sep 2010 23:22:15 +0800 Message-ID: <1283959344-3837-8-git-send-email-qing.he@intel.com> References: <1283959344-3837-1-git-send-email-qing.he@intel.com> Return-path: In-Reply-To: <1283959344-3837-1-git-send-email-qing.he@intel.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com Cc: Qing He List-Id: xen-devel@lists.xenproject.org facility to switch between host vmcs and shadow vmcs Signed-off-by: Qing He Signed-off-by: Eddie Dong --- 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__ */