[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <16a9cc439f2826ee99ff1cfc42c9006a7a544dd4.camel@intel.com>
Date: Wed, 10 Sep 2025 11:35:35 +0000
From: "Huang, Kai" <kai.huang@...el.com>
To: "Gao, Chao" <chao.gao@...el.com>
CC: "kvm@...r.kernel.org" <kvm@...r.kernel.org>, "brgerst@...il.com"
<brgerst@...il.com>, "andrew.cooper3@...rix.com" <andrew.cooper3@...rix.com>,
"arjan@...ux.intel.com" <arjan@...ux.intel.com>, "x86@...nel.org"
<x86@...nel.org>, "rafael@...nel.org" <rafael@...nel.org>,
"dave.hansen@...ux.intel.com" <dave.hansen@...ux.intel.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"seanjc@...gle.com" <seanjc@...gle.com>, "xin@...or.com" <xin@...or.com>,
"pbonzini@...hat.com" <pbonzini@...hat.com>, "mingo@...hat.com"
<mingo@...hat.com>, "tglx@...utronix.de" <tglx@...utronix.de>,
"hpa@...or.com" <hpa@...or.com>, "peterz@...radead.org"
<peterz@...radead.org>, "Edgecombe, Rick P" <rick.p.edgecombe@...el.com>,
"linux-pm@...r.kernel.org" <linux-pm@...r.kernel.org>,
"kprateek.nayak@....com" <kprateek.nayak@....com>, "pavel@...nel.org"
<pavel@...nel.org>, "david.kaplan@....com" <david.kaplan@....com>, "Williams,
Dan J" <dan.j.williams@...el.com>, "bp@...en8.de" <bp@...en8.de>
Subject: Re: [RFC PATCH v1 1/5] x86/boot: Shift VMXON from KVM init to CPU
startup phase
On Wed, 2025-09-10 at 19:10 +0800, Chao Gao wrote:
> > > @@ -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.
>
This is when 'enable_virt_at_load' is off, right? The default value is
true.
> 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?
Since I think doing VMXON when bringing up CPU unconditionally is a
dramatic move at this stage, I was actually thinking we don't do VMXON in
CPUHP callback, but only do prepare things like sanity check and VMXON
region setup etc. If anything fails, we refuse to online CPU, or mark CPU
as VMX not supported, whatever.
The core kernel then provides two APIs to do VMXON/VMXOFF respectively,
and KVM can use them. The APIs needs to handle concurrent requests from
multiple users, though. VMCLEAR could still be in KVM since this is kinda
KVM's internal on how to manage vCPUs.
Does this make sense?
Powered by blists - more mailing lists