Skip to content

Commit f616506

Browse files
Marc Zyngieroupton
Marc Zyngier
authored andcommitted
KVM: arm64: vgic: Don't hold config_lock while unregistering redistributors
We recently moved the teardown of the vgic part of a vcpu inside a critical section guarded by the config_lock. This teardown phase involves calling into kvm_io_bus_unregister_dev(), which takes the kvm->srcu lock. However, this violates the established order where kvm->srcu is taken on a memory fault (such as an MMIO access), possibly followed by taking the config_lock if the GIC emulation requires mutual exclusion from the other vcpus. It therefore results in a bad lockdep splat, as reported by Zenghui. Fix this by moving the call to kvm_io_bus_unregister_dev() outside of the config_lock critical section. At this stage, there shouln't be any need to hold the config_lock. As an additional bonus, document the ordering between kvm->slots_lock, kvm->srcu and kvm->arch.config_lock so that I cannot pretend I didn't know about those anymore. Fixes: 9eb1813 ("KVM: arm64: vgic: Hold config_lock while tearing down a CPU interface") Reported-by: Zenghui Yu <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Reviewed-by: Zenghui Yu <[email protected]> Tested-by: Zenghui Yu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent 2240a50 commit f616506

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,8 @@ static void __kvm_vgic_vcpu_destroy(struct kvm_vcpu *vcpu)
417417
kfree(vgic_cpu->private_irqs);
418418
vgic_cpu->private_irqs = NULL;
419419

420-
if (vcpu->kvm->arch.vgic.vgic_model == KVM_DEV_TYPE_ARM_VGIC_V3) {
421-
vgic_unregister_redist_iodev(vcpu);
420+
if (vcpu->kvm->arch.vgic.vgic_model == KVM_DEV_TYPE_ARM_VGIC_V3)
422421
vgic_cpu->rd_iodev.base_addr = VGIC_ADDR_UNDEF;
423-
}
424422
}
425423

426424
void kvm_vgic_vcpu_destroy(struct kvm_vcpu *vcpu)
@@ -448,6 +446,11 @@ void kvm_vgic_destroy(struct kvm *kvm)
448446
kvm_vgic_dist_destroy(kvm);
449447

450448
mutex_unlock(&kvm->arch.config_lock);
449+
450+
if (kvm->arch.vgic.vgic_model == KVM_DEV_TYPE_ARM_VGIC_V3)
451+
kvm_for_each_vcpu(i, vcpu, kvm)
452+
vgic_unregister_redist_iodev(vcpu);
453+
451454
mutex_unlock(&kvm->slots_lock);
452455
}
453456

arch/arm64/kvm/vgic/vgic.c

+5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ struct vgic_global kvm_vgic_global_state __ro_after_init = {
3636
* we have to disable IRQs before taking this lock and everything lower
3737
* than it.
3838
*
39+
* The config_lock has additional ordering requirements:
40+
* kvm->slots_lock
41+
* kvm->srcu
42+
* kvm->arch.config_lock
43+
*
3944
* If you need to take multiple locks, always take the upper lock first,
4045
* then the lower ones, e.g. first take the its_lock, then the irq_lock.
4146
* If you are already holding a lock and need to take a higher one, you

0 commit comments

Comments
 (0)