Skip to content

Commit 01ad29d

Browse files
Marc Zyngieroupton
authored andcommitted
KVM: arm64: vgic: Simplify kvm_vgic_destroy()
When destroying a vgic, we have rather cumbersome rules about when slots_lock and config_lock are held, resulting in fun buglets. The first port of call is to simplify kvm_vgic_map_resources() so that there is only one call to kvm_vgic_destroy() instead of two, with the second only holding half of the locks. For that, we kill the non-locking primitive and move the call outside of the locking altogether. This doesn't change anything (we re-acquire the locks and teardown the whole vgic), and simplifies the code significantly. Cc: [email protected] Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent 33cc938 commit 01ad29d

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

arch/arm64/kvm/vgic/vgic-init.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -382,26 +382,24 @@ void kvm_vgic_vcpu_destroy(struct kvm_vcpu *vcpu)
382382
vgic_cpu->rd_iodev.base_addr = VGIC_ADDR_UNDEF;
383383
}
384384

385-
static void __kvm_vgic_destroy(struct kvm *kvm)
385+
void kvm_vgic_destroy(struct kvm *kvm)
386386
{
387387
struct kvm_vcpu *vcpu;
388388
unsigned long i;
389389

390-
lockdep_assert_held(&kvm->arch.config_lock);
390+
mutex_lock(&kvm->slots_lock);
391391

392392
vgic_debug_destroy(kvm);
393393

394394
kvm_for_each_vcpu(i, vcpu, kvm)
395395
kvm_vgic_vcpu_destroy(vcpu);
396396

397+
mutex_lock(&kvm->arch.config_lock);
398+
397399
kvm_vgic_dist_destroy(kvm);
398-
}
399400

400-
void kvm_vgic_destroy(struct kvm *kvm)
401-
{
402-
mutex_lock(&kvm->arch.config_lock);
403-
__kvm_vgic_destroy(kvm);
404401
mutex_unlock(&kvm->arch.config_lock);
402+
mutex_unlock(&kvm->slots_lock);
405403
}
406404

407405
/**
@@ -469,25 +467,26 @@ int kvm_vgic_map_resources(struct kvm *kvm)
469467
type = VGIC_V3;
470468
}
471469

472-
if (ret) {
473-
__kvm_vgic_destroy(kvm);
470+
if (ret)
474471
goto out;
475-
}
472+
476473
dist->ready = true;
477474
dist_base = dist->vgic_dist_base;
478475
mutex_unlock(&kvm->arch.config_lock);
479476

480477
ret = vgic_register_dist_iodev(kvm, dist_base, type);
481-
if (ret) {
478+
if (ret)
482479
kvm_err("Unable to register VGIC dist MMIO regions\n");
483-
kvm_vgic_destroy(kvm);
484-
}
485-
mutex_unlock(&kvm->slots_lock);
486-
return ret;
487480

481+
goto out_slots;
488482
out:
489483
mutex_unlock(&kvm->arch.config_lock);
484+
out_slots:
490485
mutex_unlock(&kvm->slots_lock);
486+
487+
if (ret)
488+
kvm_vgic_destroy(kvm);
489+
491490
return ret;
492491
}
493492

0 commit comments

Comments
 (0)