Skip to content

Commit a788fbb

Browse files
committed
KVM: VMX: Skip VMCLEAR logic during emergency reboots if CR4.VMXE=0
Bail from vmx_emergency_disable() without processing the list of loaded VMCSes if CR4.VMXE=0, i.e. if the CPU can't be post-VMXON. It should be impossible for the list to have entries if VMX is already disabled, and even if that invariant doesn't hold, VMCLEAR will #UD anyways, i.e. processing the list is pointless even if it somehow isn't empty. Assuming no existing KVM bugs, this should be a glorified nop. The primary motivation for the change is to avoid having code that looks like it does VMCLEAR, but then skips VMXON, which is nonsensical. Suggested-by: Kai Huang <[email protected]> Reviewed-by: Kai Huang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 2e6b9bd commit a788fbb

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

arch/x86/kvm/vmx/vmx.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,12 +754,20 @@ static void vmx_emergency_disable(void)
754754

755755
kvm_rebooting = true;
756756

757+
/*
758+
* Note, CR4.VMXE can be _cleared_ in NMI context, but it can only be
759+
* set in task context. If this races with VMX is disabled by an NMI,
760+
* VMCLEAR and VMXOFF may #UD, but KVM will eat those faults due to
761+
* kvm_rebooting set.
762+
*/
763+
if (!(__read_cr4() & X86_CR4_VMXE))
764+
return;
765+
757766
list_for_each_entry(v, &per_cpu(loaded_vmcss_on_cpu, cpu),
758767
loaded_vmcss_on_cpu_link)
759768
vmcs_clear(v->vmcs);
760769

761-
if (__read_cr4() & X86_CR4_VMXE)
762-
kvm_cpu_vmxoff();
770+
kvm_cpu_vmxoff();
763771
}
764772

765773
static void __loaded_vmcs_clear(void *arg)

0 commit comments

Comments
 (0)