Skip to content

Commit 49e5d16

Browse files
ouptonMarc Zyngier
authored andcommitted
KVM: arm64: vgic: Don't acquire its_lock before config_lock
commit f003277 ("KVM: arm64: Use config_lock to protect vgic state") was meant to rectify a longstanding lock ordering issue in KVM where the kvm->lock is taken while holding vcpu->mutex. As it so happens, the aforementioned commit introduced yet another locking issue by acquiring the its_lock before acquiring the config lock. This is obviously wrong, especially considering that the lock ordering is well documented in vgic.c. Reshuffle the locks once more to take the config_lock before the its_lock. While at it, sprinkle in the lockdep hinting that has become popular as of late to keep lockdep apprised of our ordering. Cc: stable@vger.kernel.org Fixes: f003277 ("KVM: arm64: Use config_lock to protect vgic state") Signed-off-by: Oliver Upton <oliver.upton@linux.dev> Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20230412062733.988229-1-oliver.upton@linux.dev
1 parent f003277 commit 49e5d16

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,6 +1958,16 @@ static int vgic_its_create(struct kvm_device *dev, u32 type)
19581958
mutex_init(&its->its_lock);
19591959
mutex_init(&its->cmd_lock);
19601960

1961+
/* Yep, even more trickery for lock ordering... */
1962+
#ifdef CONFIG_LOCKDEP
1963+
mutex_lock(&dev->kvm->arch.config_lock);
1964+
mutex_lock(&its->cmd_lock);
1965+
mutex_lock(&its->its_lock);
1966+
mutex_unlock(&its->its_lock);
1967+
mutex_unlock(&its->cmd_lock);
1968+
mutex_unlock(&dev->kvm->arch.config_lock);
1969+
#endif
1970+
19611971
its->vgic_its_base = VGIC_ADDR_UNDEF;
19621972

19631973
INIT_LIST_HEAD(&its->device_list);
@@ -2752,15 +2762,14 @@ static int vgic_its_ctrl(struct kvm *kvm, struct vgic_its *its, u64 attr)
27522762
return 0;
27532763

27542764
mutex_lock(&kvm->lock);
2755-
mutex_lock(&its->its_lock);
27562765

27572766
if (!lock_all_vcpus(kvm)) {
2758-
mutex_unlock(&its->its_lock);
27592767
mutex_unlock(&kvm->lock);
27602768
return -EBUSY;
27612769
}
27622770

27632771
mutex_lock(&kvm->arch.config_lock);
2772+
mutex_lock(&its->its_lock);
27642773

27652774
switch (attr) {
27662775
case KVM_DEV_ARM_ITS_CTRL_RESET:
@@ -2774,9 +2783,9 @@ static int vgic_its_ctrl(struct kvm *kvm, struct vgic_its *its, u64 attr)
27742783
break;
27752784
}
27762785

2786+
mutex_unlock(&its->its_lock);
27772787
mutex_unlock(&kvm->arch.config_lock);
27782788
unlock_all_vcpus(kvm);
2779-
mutex_unlock(&its->its_lock);
27802789
mutex_unlock(&kvm->lock);
27812790
return ret;
27822791
}

0 commit comments

Comments
 (0)