KVM: VMX: Fold loaded_vmcs_init() into alloc_loaded_vmcs()
authorSean Christopherson <sean.j.christopherson@intel.com>
Sat, 21 Mar 2020 19:37:50 +0000 (12:37 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 23 Mar 2020 19:44:26 +0000 (15:44 -0400)
Subsume loaded_vmcs_init() into alloc_loaded_vmcs(), its only remaining
caller, and drop the VMCLEAR on the shadow VMCS, which is guaranteed to
be NULL.  loaded_vmcs_init() was previously used by loaded_vmcs_clear(),
but loaded_vmcs_clear() also subsumed loaded_vmcs_init() to properly
handle smp_wmb() with respect to VMCLEAR.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Message-Id: <20200321193751.24985-3-sean.j.christopherson@intel.com>
Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/vmx/vmx.c
arch/x86/kvm/vmx/vmx.h

index efaca09455bfaf8c6f7fca1c92a5d402168e3cbc..07634caa560d3b3aacea41896eea63626a2f09ed 100644 (file)
@@ -653,15 +653,6 @@ static int vmx_set_guest_msr(struct vcpu_vmx *vmx, struct shared_msr_entry *msr,
        return ret;
 }
 
-void loaded_vmcs_init(struct loaded_vmcs *loaded_vmcs)
-{
-       vmcs_clear(loaded_vmcs->vmcs);
-       if (loaded_vmcs->shadow_vmcs && loaded_vmcs->launched)
-               vmcs_clear(loaded_vmcs->shadow_vmcs);
-       loaded_vmcs->cpu = -1;
-       loaded_vmcs->launched = 0;
-}
-
 #ifdef CONFIG_KEXEC_CORE
 static void crash_vmclear_local_loaded_vmcss(void)
 {
@@ -2555,9 +2546,12 @@ int alloc_loaded_vmcs(struct loaded_vmcs *loaded_vmcs)
        if (!loaded_vmcs->vmcs)
                return -ENOMEM;
 
+       vmcs_clear(loaded_vmcs->vmcs);
+
        loaded_vmcs->shadow_vmcs = NULL;
        loaded_vmcs->hv_timer_soft_disabled = false;
-       loaded_vmcs_init(loaded_vmcs);
+       loaded_vmcs->cpu = -1;
+       loaded_vmcs->launched = 0;
 
        if (cpu_has_vmx_msr_bitmap()) {
                loaded_vmcs->msr_bitmap = (unsigned long *)
index be93d597306cf691c4e0158c7bf09b98f7ec98ee..79d38f41ef7a191ac77a90f1880494c3943e6f79 100644 (file)
@@ -492,7 +492,6 @@ struct vmcs *alloc_vmcs_cpu(bool shadow, int cpu, gfp_t flags);
 void free_vmcs(struct vmcs *vmcs);
 int alloc_loaded_vmcs(struct loaded_vmcs *loaded_vmcs);
 void free_loaded_vmcs(struct loaded_vmcs *loaded_vmcs);
-void loaded_vmcs_init(struct loaded_vmcs *loaded_vmcs);
 void loaded_vmcs_clear(struct loaded_vmcs *loaded_vmcs);
 
 static inline struct vmcs *alloc_vmcs(bool shadow)