Re: [RFC PATCH v1 1/5] x86/boot: Shift VMXON from KVM init to CPU startup phase

Chao Gao
2025-09-10T11:11:17Z

>> @@ -2551,6 +2636,12 @@ void __init arch_cpu_finalize_init(void)
>> *c = boot_cpu_data;
>> c->initialized = true;
>>
>> + /*
>> + * Enable BSP virtualization right after the BSP cpuinfo_x86 structure
>> + * is initialized to ensure this_cpu_has() works as expected.
>> + */
>> + cpu_enable_virtualization();
>> +
>>
>
>Any reason that you choose to do it in arch_cpu_finalize_init()? Perhaps
>just a arch_initcall() or similar?
>
>KVM has a specific CPUHP_AP_KVM_ONLINE to handle VMXON/OFF for CPU
>online/offline. And it's not in STARTUP section (which is not allowed to
>fail) so it can handle the failure of VMXON.
>
>How about adding a VMX specific CPUHP callback instead?
>
>In this way, not only we can put all VMX related code together (e.g.,
>arch/x86/virt/vmx/vmx.c) which is way easier to review/maintain, but also
>we can still handle the failure of VMXON just like in KVM.

KVM's policy is that a CPU can be online if there is no VM running. It is hard
to implement/move the same logic inside the core kernel because the core kernel
would need to refcount the running VMs. Any idea/suggestion on how to handle
VMXON failure in the core kernel?