Re: [RFC PATCH 2/4] KVM: x86: Extract VMXON and EFER.SVME enablement to kernel

From: Sean Christopherson

Date: Mon Oct 13 2025 - 13:49:21 EST


On Mon, Oct 13, 2025, Chao Gao wrote:
> >+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.

Oh, yeah, that's a much better idea, especially if x86_virt_init() runs
unconditionally during boot (as proposed). cpu_emergency_disable_virtualization()
can be dropped entirely (it'd just be a one-line wrapper).