[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aO2RQu-xuSC0GGnn@google.com>
Date: Mon, 13 Oct 2025 16:54:42 -0700
From: Sean Christopherson <seanjc@...gle.com>
To: Rick P Edgecombe <rick.p.edgecombe@...el.com>
Cc: "x86@...nel.org" <x86@...nel.org>, "kas@...nel.org" <kas@...nel.org>,
"dave.hansen@...ux.intel.com" <dave.hansen@...ux.intel.com>, "mingo@...hat.com" <mingo@...hat.com>,
"tglx@...utronix.de" <tglx@...utronix.de>, "bp@...en8.de" <bp@...en8.de>,
"pbonzini@...hat.com" <pbonzini@...hat.com>, Chao Gao <chao.gao@...el.com>,
Kai Huang <kai.huang@...el.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>, Dan J Williams <dan.j.williams@...el.com>,
Adrian Hunter <adrian.hunter@...el.com>, "kvm@...r.kernel.org" <kvm@...r.kernel.org>,
"linux-coco@...ts.linux.dev" <linux-coco@...ts.linux.dev>, "xin@...or.com" <xin@...or.com>
Subject: Re: [RFC PATCH 2/4] KVM: x86: Extract VMXON and EFER.SVME enablement
to kernel
On Mon, Oct 13, 2025, Rick P Edgecombe wrote:
> 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?
I want to avoid potential problems due to kvm-amd.ko doing x86_virt_get_cpu() and
succeeding on an Intel CPU, and vice versa. The obvious alternative would be to
have wrappers for VMX and SVM and then do whatever internally, but we'd need some
form of tracking internally no matter what, and I prefer X86_FEATURE_{SVM,VMX}
over one or more booleans.
FWIW, after Chao's feedback, this is what I have locally (a little less foo),
where x86_virt_feature is set during x86_virt_init().
int x86_virt_get_cpu(int feat)
{
int r;
if (!x86_virt_feature || x86_virt_feature != feat)
return -EOPNOTSUPP;
if (this_cpu_inc_return(virtualization_nr_users) > 1)
return 0;
r = x86_virt_call(get_cpu);
if (r)
WARN_ON_ONCE(this_cpu_dec_return(virtualization_nr_users));
return r;
}
EXPORT_SYMBOL_GPL(x86_virt_get_cpu);
Powered by blists - more mailing lists