From 6522c1c222bce496172ed1058f8c57a5df251227 Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Mon, 28 May 2018 15:02:34 +0100 Subject: [PATCH] x86/vmx: Defer vmx_vmcs_exit() as long as possible in construct_vmcs() paging_update_paging_modes() and vmx_vlapic_msr_changed() both operate on the VMCS being constructed. Avoid dropping and re-acquiring the reference multiple times. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich Acked-by: Kevin Tian (cherry picked from commit f30e3cf34042846e391e3f8361fc6a76d181a7ee) --- xen/arch/x86/hvm/vmx/vmcs.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c index 8d66b0537d..b344bf476f 100644 --- a/xen/arch/x86/hvm/vmx/vmcs.c +++ b/xen/arch/x86/hvm/vmx/vmcs.c @@ -1017,6 +1017,7 @@ static int construct_vmcs(struct vcpu *v) unsigned long sysenter_eip; u32 vmexit_ctl = vmx_vmexit_control; u32 vmentry_ctl = vmx_vmentry_control; + int rc = 0; vmx_vmcs_enter(v); @@ -1104,8 +1105,8 @@ static int construct_vmcs(struct vcpu *v) if ( msr_bitmap == NULL ) { - vmx_vmcs_exit(v); - return -ENOMEM; + rc = -ENOMEM; + goto out; } memset(msr_bitmap, ~0, PAGE_SIZE); @@ -1289,8 +1290,6 @@ static int construct_vmcs(struct vcpu *v) if ( cpu_has_vmx_tsc_scaling ) __vmwrite(TSC_MULTIPLIER, d->arch.hvm_domain.tsc_scaling_ratio); - vmx_vmcs_exit(v); - /* PVH: paging mode is updated by arch_set_info_guest(). */ if ( is_hvm_domain(d) ) { @@ -1300,7 +1299,10 @@ static int construct_vmcs(struct vcpu *v) vmx_vlapic_msr_changed(v); } - return 0; + out: + vmx_vmcs_exit(v); + + return rc; } static int vmx_msr_entry_key_cmp(const void *key, const void *elt) -- 2.39.5