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

From: Edgecombe, Rick P

Date: Mon Oct 13 2025 - 18:08:40 EST


On Fri, 2025-10-10 at 15:04 -0700, Sean Christopherson wrote:

> +
> +int x86_virt_get_cpu(int feat)
> +{
> + int r;
> +
> + if (!x86_virt_initialized)
> + return -EOPNOTSUPP;
> +
> + if (this_cpu_inc_return(virtualization_nr_users) > 1)
> + return 0;
> +
> + if (x86_virt_is_vmx() && feat == X86_FEATURE_VMX)
> + r = x86_vmx_get_cpu();
> + else if (x86_virt_is_svm() && feat == X86_FEATURE_SVM)
> + r = x86_svm_get_cpu();
> + else
> + r = -EOPNOTSUPP;
> +
> + if (r)
> + WARN_ON_ONCE(this_cpu_dec_return(virtualization_nr_users));
> +
> + return r;
> +}
> +EXPORT_SYMBOL_GPL(x86_virt_get_cpu);

Not sure if I missed some previous discussion or future plans, but doing this
via X86_FEATURE_FOO seems excessive. We could just have x86_virt_get_cpu(void)
afaict? Curious if there is a plan for other things to go here?