]> git.ipfire.org Git - thirdparty/kernel/stable.git/blobdiff - arch/x86/kvm/vmx/nested.c
KVM: nVMX: do not use dangling shadow VMCS after guest reset
[thirdparty/kernel/stable.git] / arch / x86 / kvm / vmx / nested.c
index 4f23e34f628b6b6b49f3837cd59586af40f04da0..0f1378789bd0381e95c703ad658376efa3484d8d 100644 (file)
@@ -194,6 +194,7 @@ static void vmx_disable_shadow_vmcs(struct vcpu_vmx *vmx)
 {
        secondary_exec_controls_clearbit(vmx, SECONDARY_EXEC_SHADOW_VMCS);
        vmcs_write64(VMCS_LINK_POINTER, -1ull);
+       vmx->nested.need_vmcs12_to_shadow_sync = false;
 }
 
 static inline void nested_release_evmcs(struct kvm_vcpu *vcpu)
@@ -1341,6 +1342,9 @@ static void copy_shadow_to_vmcs12(struct vcpu_vmx *vmx)
        unsigned long val;
        int i;
 
+       if (WARN_ON(!shadow_vmcs))
+               return;
+
        preempt_disable();
 
        vmcs_load(shadow_vmcs);
@@ -1373,6 +1377,9 @@ static void copy_vmcs12_to_shadow(struct vcpu_vmx *vmx)
        unsigned long val;
        int i, q;
 
+       if (WARN_ON(!shadow_vmcs))
+               return;
+
        vmcs_load(shadow_vmcs);
 
        for (q = 0; q < ARRAY_SIZE(fields); q++) {
@@ -4436,7 +4443,6 @@ static inline void nested_release_vmcs12(struct kvm_vcpu *vcpu)
                /* copy to memory all shadowed fields in case
                   they were modified */
                copy_shadow_to_vmcs12(vmx);
-               vmx->nested.need_vmcs12_to_shadow_sync = false;
                vmx_disable_shadow_vmcs(vmx);
        }
        vmx->nested.posted_intr_nv = -1;