Re: [PATCH v3 2/8] KVM: Register cpuhp and syscore callbacks when enabling hardware

From: Huang, Kai
Date: Sun Jun 09 2024 - 20:55:41 EST


On Fri, 2024-06-07 at 17:06 -0700, Sean Christopherson wrote:
> Register KVM's cpuhp and syscore callback when enabling virtualization
> in hardware instead of registering the callbacks during initialization,
> and let the CPU up/down framework invoke the inner enable/disable
> functions. Registering the callbacks during initialization makes things
> more complex than they need to be, as KVM needs to be very careful about
> handling races between enabling CPUs being onlined/offlined and hardware
> being enabled/disabled.
>
> Intel TDX support will require KVM to enable virtualization during KVM
> initialization, i.e. will add another wrinkle to things, at which point
> sorting out the potential races with kvm_usage_count would become even
> more complex.
>
> Note, using the cpuhp framework has a subtle behavioral change: enabling
> will be done serially across all CPUs, whereas KVM currently sends an IPI
> to all CPUs in parallel. While serializing virtualization enabling could
> create undesirable latency, the issue is limited to creation of KVM's
> first VM, and even that can be mitigated, e.g. by letting userspace force
> virtualization to be enabled when KVM is initialized.
>
> Cc: Chao Gao <chao.gao@xxxxxxxxx>
> Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
> ---
>

Reviewed-by: Kai Huang <kai.huang@xxxxxxxxx>