KVM: nVMX: Move "vmcs12 to shadow/evmcs sync" to helper function
authorSean Christopherson <sean.j.christopherson@intel.com>
Mon, 3 Dec 2018 21:53:14 +0000 (13:53 -0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 14 Dec 2018 16:18:00 +0000 (17:18 +0100)
...so that the function doesn't need to be created when moving the
nested code out of vmx.c.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/vmx/vmx.c

index e67ff71..7b3a539 100644 (file)
@@ -9113,6 +9113,30 @@ static void vmx_update_hv_timer(struct kvm_vcpu *vcpu)
        vmx->loaded_vmcs->hv_timer_armed = false;
 }
 
+static void nested_sync_from_vmcs12(struct kvm_vcpu *vcpu)
+{
+       struct vcpu_vmx *vmx = to_vmx(vcpu);
+
+       /*
+        * hv_evmcs may end up being not mapped after migration (when
+        * L2 was running), map it here to make sure vmcs12 changes are
+        * properly reflected.
+        */
+       if (vmx->nested.enlightened_vmcs_enabled && !vmx->nested.hv_evmcs)
+               nested_vmx_handle_enlightened_vmptrld(vcpu, false);
+
+       if (vmx->nested.hv_evmcs) {
+               copy_vmcs12_to_enlightened(vmx);
+               /* All fields are clean */
+               vmx->nested.hv_evmcs->hv_clean_fields |=
+                       HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL;
+       } else {
+               copy_vmcs12_to_shadow(vmx);
+       }
+
+       vmx->nested.need_vmcs12_sync = false;
+}
+
 static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
 {
        struct vcpu_vmx *vmx = to_vmx(vcpu);
@@ -9133,26 +9157,8 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
                vmcs_write32(PLE_WINDOW, vmx->ple_window);
        }
 
-       if (vmx->nested.need_vmcs12_sync) {
-               /*
-                * hv_evmcs may end up being not mapped after migration (when
-                * L2 was running), map it here to make sure vmcs12 changes are
-                * properly reflected.
-                */
-               if (vmx->nested.enlightened_vmcs_enabled &&
-                   !vmx->nested.hv_evmcs)
-                       nested_vmx_handle_enlightened_vmptrld(vcpu, false);
-
-               if (vmx->nested.hv_evmcs) {
-                       copy_vmcs12_to_enlightened(vmx);
-                       /* All fields are clean */
-                       vmx->nested.hv_evmcs->hv_clean_fields |=
-                               HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL;
-               } else {
-                       copy_vmcs12_to_shadow(vmx);
-               }
-               vmx->nested.need_vmcs12_sync = false;
-       }
+       if (vmx->nested.need_vmcs12_sync)
+               nested_sync_from_vmcs12(vcpu);
 
        if (test_bit(VCPU_REGS_RSP, (unsigned long *)&vcpu->arch.regs_dirty))
                vmcs_writel(GUEST_RSP, vcpu->arch.regs[VCPU_REGS_RSP]);