KVM: nVMX: Move free_nested() below vmx_switch_vmcs()
authorSean Christopherson <sean.j.christopherson@intel.com>
Wed, 23 Sep 2020 18:44:49 +0000 (11:44 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 28 Sep 2020 11:57:45 +0000 (07:57 -0400)
Move free_nested() down below vmx_switch_vmcs() so that a future patch
can do an "emergency" invocation of vmx_switch_vmcs() if vmcs01 is not
the loaded VMCS when freeing nested resources.

No functional change intended.

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

index e004ab8..ac1e176 100644 (file)
@@ -233,6 +233,44 @@ static inline void nested_release_evmcs(struct kvm_vcpu *vcpu)
        vmx->nested.hv_evmcs = NULL;
 }
 
+static void vmx_sync_vmcs_host_state(struct vcpu_vmx *vmx,
+                                    struct loaded_vmcs *prev)
+{
+       struct vmcs_host_state *dest, *src;
+
+       if (unlikely(!vmx->guest_state_loaded))
+               return;
+
+       src = &prev->host_state;
+       dest = &vmx->loaded_vmcs->host_state;
+
+       vmx_set_host_fs_gs(dest, src->fs_sel, src->gs_sel, src->fs_base, src->gs_base);
+       dest->ldt_sel = src->ldt_sel;
+#ifdef CONFIG_X86_64
+       dest->ds_sel = src->ds_sel;
+       dest->es_sel = src->es_sel;
+#endif
+}
+
+static void vmx_switch_vmcs(struct kvm_vcpu *vcpu, struct loaded_vmcs *vmcs)
+{
+       struct vcpu_vmx *vmx = to_vmx(vcpu);
+       struct loaded_vmcs *prev;
+       int cpu;
+
+       if (vmx->loaded_vmcs == vmcs)
+               return;
+
+       cpu = get_cpu();
+       prev = vmx->loaded_vmcs;
+       vmx->loaded_vmcs = vmcs;
+       vmx_vcpu_load_vmcs(vcpu, cpu, prev);
+       vmx_sync_vmcs_host_state(vmx, prev);
+       put_cpu();
+
+       vmx_register_cache_reset(vcpu);
+}
+
 /*
  * Free whatever needs to be freed from vmx->nested when L1 goes down, or
  * just stops using VMX.
@@ -277,44 +315,6 @@ static void free_nested(struct kvm_vcpu *vcpu)
        free_loaded_vmcs(&vmx->nested.vmcs02);
 }
 
-static void vmx_sync_vmcs_host_state(struct vcpu_vmx *vmx,
-                                    struct loaded_vmcs *prev)
-{
-       struct vmcs_host_state *dest, *src;
-
-       if (unlikely(!vmx->guest_state_loaded))
-               return;
-
-       src = &prev->host_state;
-       dest = &vmx->loaded_vmcs->host_state;
-
-       vmx_set_host_fs_gs(dest, src->fs_sel, src->gs_sel, src->fs_base, src->gs_base);
-       dest->ldt_sel = src->ldt_sel;
-#ifdef CONFIG_X86_64
-       dest->ds_sel = src->ds_sel;
-       dest->es_sel = src->es_sel;
-#endif
-}
-
-static void vmx_switch_vmcs(struct kvm_vcpu *vcpu, struct loaded_vmcs *vmcs)
-{
-       struct vcpu_vmx *vmx = to_vmx(vcpu);
-       struct loaded_vmcs *prev;
-       int cpu;
-
-       if (vmx->loaded_vmcs == vmcs)
-               return;
-
-       cpu = get_cpu();
-       prev = vmx->loaded_vmcs;
-       vmx->loaded_vmcs = vmcs;
-       vmx_vcpu_load_vmcs(vcpu, cpu, prev);
-       vmx_sync_vmcs_host_state(vmx, prev);
-       put_cpu();
-
-       vmx_register_cache_reset(vcpu);
-}
-
 /*
  * Ensure that the current vmcs of the logical processor is the
  * vmcs01 of the vcpu before calling free_nested().