Now that KVM's APIs for locking all vCPUs return -EBUSY if vCPU creation is
in-progress, drop the manual check for the same from vGIC creation, and
update the comments accordingly.

Note, while KVM arm64 guards many vGIC operations with its arch-specific
config_lock, holding kvm->lock is sufficient to guarantee a stable result
for "is vCPU creation in-progress".  So, no functional change intended.

Note #2, the open coded check in vgic_init() is racy when called without
kvm->lock held, e.g. via vgic_lazy_init().  I.e. that check needs to stay
open coded to avoid triggering a lockdep assert.  Whether or not the race
is "fine" is a problem for a different day.

Signed-off-by: Sean Christopherson <[email protected]>
---
 arch/arm64/kvm/vgic/vgic-init.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/arch/arm64/kvm/vgic/vgic-init.c b/arch/arm64/kvm/vgic/vgic-init.c
index 4012df6002ea..a58575df36e9 100644
--- a/arch/arm64/kvm/vgic/vgic-init.c
+++ b/arch/arm64/kvm/vgic/vgic-init.c
@@ -97,6 +97,9 @@ int kvm_vgic_create(struct kvm *kvm, u32 type)
        /*
         *  - Acquiring the vCPU mutex for every *online* vCPU to prevent
         *    concurrent vCPU ioctls for vCPUs already visible to userspace.
+        *    This also ensures KVM isn't in the middle of creating a vCPU,
+        *    i.e. that there are no vCPUs that have been created but aren't
+        *    yet fully online.
         */
        ret = -EBUSY;
        if (kvm_trylock_all_vcpus(kvm))
@@ -105,18 +108,11 @@ int kvm_vgic_create(struct kvm *kvm, u32 type)
        /*
         *  - Taking the config_lock which protects VGIC data structures such
         *    as the per-vCPU arrays of private IRQs (SGIs, PPIs).
-        */
-       mutex_lock(&kvm->arch.config_lock);
-
-       /*
-        * - Bailing on the entire thing if a vCPU is in the middle of creation,
-        *   dropped the kvm->lock, but hasn't reached kvm_arch_vcpu_create().
         *
         * The whole combination of this guarantees that no vCPU can get into
         * KVM with a VGIC configuration inconsistent with the VM's VGIC.
         */
-       if (kvm->created_vcpus != atomic_read(&kvm->online_vcpus))
-               goto out_unlock;
+       mutex_lock(&kvm->arch.config_lock);
 
        if (irqchip_in_kernel(kvm)) {
                ret = -EEXIST;
-- 
2.55.0.1082.g2b9226bbc0-goog


Reply via email to