From: Yang Zhang Subject: [PATCH v2] VMX: Eliminate cr3 save/loading exiting when UG enabled Date: Wed, 18 Dec 2013 12:00:56 +0800 Message-ID: <1387339256-21840-1-git-send-email-yang.z.zhang@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: Yang Zhang , eddie.dong@intel.com, jun.nakajima@intel.com, JBeulich@suse.com List-Id: xen-devel@lists.xenproject.org From: Yang Zhang With the feature of unrestricted guest, there should no vmexit be triggered when guest accesses the cr3 in non-paging mode. Signed-off-by: Yang Zhang --- changes in v2: Fix the guest boot failure on non-UG platform. The previous patch doesn't consider the non-UG platform and will cause guest boot failure on non-ug platform. During developing this patch, i was thinking whether the reading of GUEST_CR3 is necessary on each vmexit. I thought the answer should be no. But current implemention relies the {hw,guest}_cr3 in many places and it hard to do a cleanup.(If anyone interesting, welcome :)) BTW: this patch will improve performance, especially for context switching intensive workload, we saw about 1% improvement. So please backport it to 4.3. --- xen/arch/x86/hvm/vmx/vmx.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index dfff628..f6409d6 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -1157,7 +1157,7 @@ static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr) uint32_t cr3_ctls = (CPU_BASED_CR3_LOAD_EXITING | CPU_BASED_CR3_STORE_EXITING); v->arch.hvm_vmx.exec_control &= ~cr3_ctls; - if ( !hvm_paging_enabled(v) ) + if ( !hvm_paging_enabled(v) && !vmx_unrestricted_guest(v) ) v->arch.hvm_vmx.exec_control |= cr3_ctls; /* Trap CR3 updates if CR3 memory events are enabled. */ @@ -1231,7 +1231,7 @@ static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr) case 3: if ( paging_mode_hap(v->domain) ) { - if ( !hvm_paging_enabled(v) ) + if ( !hvm_paging_enabled(v) && !vmx_unrestricted_guest(v) ) v->arch.hvm_vcpu.hw_cr[3] = v->domain->arch.hvm_domain.params[HVM_PARAM_IDENT_PT]; vmx_load_pdptrs(v); @@ -2487,10 +2487,11 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs) hvm_invalidate_regs_fields(regs); - if ( paging_mode_hap(v->domain) && hvm_paging_enabled(v) ) + if ( paging_mode_hap(v->domain) ) { __vmread(GUEST_CR3, &v->arch.hvm_vcpu.hw_cr[3]); - v->arch.hvm_vcpu.guest_cr[3] = v->arch.hvm_vcpu.hw_cr[3]; + if ( vmx_unrestricted_guest(v) || hvm_paging_enabled(v) ) + v->arch.hvm_vcpu.guest_cr[3] = v->arch.hvm_vcpu.hw_cr[3]; } __vmread(VM_EXIT_REASON, &exit_reason); -- 1.7.1