Re: [PATCH v8 7/9] KVM: Move kvm_arch_vcpu_precreate() under kvm->lock

From: Sean Christopherson
Date: Fri Apr 15 2022 - 11:11:19 EST


On Fri, Apr 15, 2022, Sean Christopherson wrote:
> > It's safe to invoke kvm_arch_vcpu_precreate() within the protection of
> > kvm->lock directly rather than take into account in the implementation for
> > each architecture.
>
> This absolutely needs to explain _why_ it's safe, e.g. only arm64, x86, and s390
> have non-nop implementations and they're all simple and short with no tendrils
> into other code that might take kvm->lock.
>
> And as before, I suspect arm64 needs this protection, the vgic_initialized()
> check looks racy. Though it's hard to tell if doing the check under kvm->lock
> actually fixes anything.

Ah, I bet this code in vgic_init() provides the necessary protection.

/* Are we also in the middle of creating a VCPU? */
if (kvm->created_vcpus != atomic_read(&kvm->online_vcpus))
return -EBUSY;