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

Dave Hansen
2025-12-19T18:48:40Z

On 12/19/25 10:35, Sean Christopherson wrote:
> I haven't tested yet, but I've got this:
>
> struct x86_virt_ops {
> int feature;
> int (*enable_virtualization_cpu)(void);
> int (*disable_virtualization_cpu)(void);
> void (*emergency_disable_virtualization_cpu)(void);
> };
> static struct x86_virt_ops virt_ops __ro_after_init;
>
> and then usage like:
>
> int x86_virt_get_ref(int feat)
> {
> int r;
>
> if (!virt_ops.feature || virt_ops.feature != feat)
> return -EOPNOTSUPP;
>
> if (this_cpu_inc_return(virtualization_nr_users) > 1)
> return 0;
>
> r = virt_ops.enable_virtualization_cpu();
> if (r)
> WARN_ON_ONCE(this_cpu_dec_return(virtualization_nr_users));
>
> return r;
> }
> EXPORT_SYMBOL_GPL(x86_virt_get_ref);

Yeah, that's much easier to follow, and fixes the naming collision thanks!