Re: [RFC PATCH 2/4] KVM: x86: Extract VMXON and EFER.SVME enablement to kernel
From: Chao Gao
Date: Mon Oct 13 2025 - 09:20:14 EST
>+static void x86_svm_emergency_disable_virtualization_cpu(void)
>+{
>+ virt_rebooting = true;
>+
>+ /*
>+ * Note, CR4.VMXE can be _cleared_ in NMI context, but it can only be
>+ * set in task context. If this races with VMX being disabled via NMI,
>+ * VMCLEAR and VMXOFF may #UD, but the kernel will eat those faults due
>+ * to virt_rebooting being set.
>+ */
>+ if (!(__read_cr4() & X86_CR4_VMXE))
>+ return;
copy-paste error.
>+void __init x86_virt_init(void)
>+{
>+ cpu_emergency_virt_cb *vmx_cb = NULL, *svm_cb = NULL;
>+
>+ if (x86_virt_is_vmx())
>+ vmx_cb = x86_vmx_init();
>+
>+ if (x86_virt_is_svm())
>+ svm_cb = x86_svm_init();
>+
>+ if (!vmx_cb && !svm_cb)
>+ return;
>+
>+ if (WARN_ON_ONCE(vmx_cb && svm_cb))
>+ return;
>+
>+ cpu_emergency_register_virt_callback(vmx_cb ? : svm_cb);
To be consistent with x86_virt_{get,put}_cpu(), perhaps we can have a common
emergency callback and let reboot.c call it directly, with the common callback
routing to svm/vmx code according to the hardware type.
>+ x86_virt_initialized = true;
>+}
>--
>2.51.0.740.g6adb054d12-goog
>