Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 37459195 authored by Sean Christopherson's avatar Sean Christopherson Committed by Greg Kroah-Hartman
Browse files

x86/reboot: Disable virtualization in an emergency if SVM is supported



commit d81f952aa657b76cea381384bef1fea35c5fd266 upstream.

Disable SVM on all CPUs via NMI shootdown during an emergency reboot.
Like VMX, SVM can block INIT, e.g. if the emergency reboot is triggered
between CLGI and STGI, and thus can prevent bringing up other CPUs via
INIT-SIPI-SIPI.

Cc: stable@vger.kernel.org
Reviewed-by: default avatarThomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20221130233650.1404148-4-seanjc@google.com


Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 87459b9f
Loading
Loading
Loading
Loading
+11 −12
Original line number Original line Diff line number Diff line
@@ -530,27 +530,26 @@ static inline void kb_wait(void)


static inline void nmi_shootdown_cpus_on_restart(void);
static inline void nmi_shootdown_cpus_on_restart(void);


/* Use NMIs as IPIs to tell all CPUs to disable virtualization */
static void emergency_reboot_disable_virtualization(void)
static void emergency_vmx_disable_all(void)
{
{
	/* Just make sure we won't change CPUs while doing this */
	/* Just make sure we won't change CPUs while doing this */
	local_irq_disable();
	local_irq_disable();


	/*
	/*
	 * Disable VMX on all CPUs before rebooting, otherwise we risk hanging
	 * Disable virtualization on all CPUs before rebooting to avoid hanging
	 * the machine, because the CPU blocks INIT when it's in VMX root.
	 * the system, as VMX and SVM block INIT when running in the host.
	 *
	 *
	 * We can't take any locks and we may be on an inconsistent state, so
	 * We can't take any locks and we may be on an inconsistent state, so
	 * use NMIs as IPIs to tell the other CPUs to exit VMX root and halt.
	 * use NMIs as IPIs to tell the other CPUs to disable VMX/SVM and halt.
	 *
	 *
	 * Do the NMI shootdown even if VMX if off on _this_ CPU, as that
	 * Do the NMI shootdown even if virtualization is off on _this_ CPU, as
	 * doesn't prevent a different CPU from being in VMX root operation.
	 * other CPUs may have virtualization enabled.
	 */
	 */
	if (cpu_has_vmx()) {
	if (cpu_has_vmx() || cpu_has_svm(NULL)) {
		/* Safely force _this_ CPU out of VMX root operation. */
		/* Safely force _this_ CPU out of VMX/SVM operation. */
		__cpu_emergency_vmxoff();
		cpu_emergency_disable_virtualization();


		/* Halt and exit VMX root operation on the other CPUs. */
		/* Disable VMX/SVM and halt on other CPUs. */
		nmi_shootdown_cpus_on_restart();
		nmi_shootdown_cpus_on_restart();


	}
	}
@@ -588,7 +587,7 @@ static void native_machine_emergency_restart(void)
	unsigned short mode;
	unsigned short mode;


	if (reboot_emergency)
	if (reboot_emergency)
		emergency_vmx_disable_all();
		emergency_reboot_disable_virtualization();


	tboot_shutdown(TB_SHUTDOWN_REBOOT);
	tboot_shutdown(TB_SHUTDOWN_REBOOT);