Skip to content

Commit 6a2c148

Browse files
Maxim Levitskyafranjir
authored andcommitted
KVM: arm64: switch to using kvm_lock/unlock_all_vcpus
Switch to kvm_lock/unlock_all_vcpus instead of arm's own version. This fixes lockdep warning about reaching maximum lock depth: [ 328.171264] BUG: MAX_LOCK_DEPTH too low! [ 328.175227] turning off the locking correctness validator. [ 328.180726] Please attach the output of /proc/lock_stat to the bug report [ 328.187531] depth: 48 max: 48! [ 328.190678] 48 locks held by qemu-kvm/11664: [ 328.194957] #0: ffff800086de5ba0 (&kvm->lock){+.+.}-{3:3}, at: kvm_ioctl_create_device+0x174/0x5b0 [ 328.204048] #1: ffff0800e78800b8 (&vcpu->mutex){+.+.}-{3:3}, at: lock_all_vcpus+0x16c/0x2a0 [ 328.212521] #2: ffff07ffeee51e98 (&vcpu->mutex){+.+.}-{3:3}, at: lock_all_vcpus+0x16c/0x2a0 [ 328.220991] #3: ffff0800dc7d80b8 (&vcpu->mutex){+.+.}-{3:3}, at: lock_all_vcpus+0x16c/0x2a0 [ 328.229463] #4: ffff07ffe0c980b8 (&vcpu->mutex){+.+.}-{3:3}, at: lock_all_vcpus+0x16c/0x2a0 [ 328.237934] #5: ffff0800a3883c78 (&vcpu->mutex){+.+.}-{3:3}, at: lock_all_vcpus+0x16c/0x2a0 [ 328.246405] #6: ffff07fffbe480b8 (&vcpu->mutex){+.+.}-{3:3}, at: lock_all_vcpus+0x16c/0x2a0 Suggested-by: Paolo Bonzini <[email protected]> Signed-off-by: Maxim Levitsky <[email protected]>
1 parent faf35ce commit 6a2c148

File tree

6 files changed

+14
-60
lines changed

6 files changed

+14
-60
lines changed

arch/arm64/include/asm/kvm_host.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,9 +1263,6 @@ int __init populate_sysreg_config(const struct sys_reg_desc *sr,
12631263
unsigned int idx);
12641264
int __init populate_nv_trap_config(void);
12651265

1266-
bool lock_all_vcpus(struct kvm *kvm);
1267-
void unlock_all_vcpus(struct kvm *kvm);
1268-
12691266
void kvm_calculate_traps(struct kvm_vcpu *vcpu);
12701267

12711268
/* MMIO helpers */

arch/arm64/kvm/arch_timer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,7 @@ int kvm_vm_ioctl_set_counter_offset(struct kvm *kvm,
17661766

17671767
mutex_lock(&kvm->lock);
17681768

1769-
if (lock_all_vcpus(kvm)) {
1769+
if (!kvm_lock_all_vcpus(kvm, true)) {
17701770
set_bit(KVM_ARCH_FLAG_VM_COUNTER_OFFSET, &kvm->arch.flags);
17711771

17721772
/*
@@ -1778,7 +1778,7 @@ int kvm_vm_ioctl_set_counter_offset(struct kvm *kvm,
17781778
kvm->arch.timer_data.voffset = offset->counter_offset;
17791779
kvm->arch.timer_data.poffset = offset->counter_offset;
17801780

1781-
unlock_all_vcpus(kvm);
1781+
kvm_unlock_all_vcpus(kvm);
17821782
} else {
17831783
ret = -EBUSY;
17841784
}

arch/arm64/kvm/arm.c

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,49 +1914,6 @@ int kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
19141914
}
19151915
}
19161916

1917-
/* unlocks vcpus from @vcpu_lock_idx and smaller */
1918-
static void unlock_vcpus(struct kvm *kvm, int vcpu_lock_idx)
1919-
{
1920-
struct kvm_vcpu *tmp_vcpu;
1921-
1922-
for (; vcpu_lock_idx >= 0; vcpu_lock_idx--) {
1923-
tmp_vcpu = kvm_get_vcpu(kvm, vcpu_lock_idx);
1924-
mutex_unlock(&tmp_vcpu->mutex);
1925-
}
1926-
}
1927-
1928-
void unlock_all_vcpus(struct kvm *kvm)
1929-
{
1930-
lockdep_assert_held(&kvm->lock);
1931-
1932-
unlock_vcpus(kvm, atomic_read(&kvm->online_vcpus) - 1);
1933-
}
1934-
1935-
/* Returns true if all vcpus were locked, false otherwise */
1936-
bool lock_all_vcpus(struct kvm *kvm)
1937-
{
1938-
struct kvm_vcpu *tmp_vcpu;
1939-
unsigned long c;
1940-
1941-
lockdep_assert_held(&kvm->lock);
1942-
1943-
/*
1944-
* Any time a vcpu is in an ioctl (including running), the
1945-
* core KVM code tries to grab the vcpu->mutex.
1946-
*
1947-
* By grabbing the vcpu->mutex of all VCPUs we ensure that no
1948-
* other VCPUs can fiddle with the state while we access it.
1949-
*/
1950-
kvm_for_each_vcpu(c, tmp_vcpu, kvm) {
1951-
if (!mutex_trylock(&tmp_vcpu->mutex)) {
1952-
unlock_vcpus(kvm, c - 1);
1953-
return false;
1954-
}
1955-
}
1956-
1957-
return true;
1958-
}
1959-
19601917
static unsigned long nvhe_percpu_size(void)
19611918
{
19621919
return (unsigned long)CHOOSE_NVHE_SYM(__per_cpu_end) -

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ int kvm_vgic_create(struct kvm *kvm, u32 type)
8888
lockdep_assert_held(&kvm->lock);
8989

9090
ret = -EBUSY;
91-
if (!lock_all_vcpus(kvm))
91+
if (kvm_lock_all_vcpus(kvm, true))
9292
return ret;
9393

9494
mutex_lock(&kvm->arch.config_lock);
@@ -142,7 +142,7 @@ int kvm_vgic_create(struct kvm *kvm, u32 type)
142142

143143
out_unlock:
144144
mutex_unlock(&kvm->arch.config_lock);
145-
unlock_all_vcpus(kvm);
145+
kvm_unlock_all_vcpus(kvm);
146146
return ret;
147147
}
148148

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1999,7 +1999,7 @@ static int vgic_its_attr_regs_access(struct kvm_device *dev,
19991999

20002000
mutex_lock(&dev->kvm->lock);
20012001

2002-
if (!lock_all_vcpus(dev->kvm)) {
2002+
if (kvm_lock_all_vcpus(dev->kvm, true)) {
20032003
mutex_unlock(&dev->kvm->lock);
20042004
return -EBUSY;
20052005
}
@@ -2034,7 +2034,7 @@ static int vgic_its_attr_regs_access(struct kvm_device *dev,
20342034
}
20352035
out:
20362036
mutex_unlock(&dev->kvm->arch.config_lock);
2037-
unlock_all_vcpus(dev->kvm);
2037+
kvm_unlock_all_vcpus(dev->kvm);
20382038
mutex_unlock(&dev->kvm->lock);
20392039
return ret;
20402040
}
@@ -2704,7 +2704,7 @@ static int vgic_its_ctrl(struct kvm *kvm, struct vgic_its *its, u64 attr)
27042704

27052705
mutex_lock(&kvm->lock);
27062706

2707-
if (!lock_all_vcpus(kvm)) {
2707+
if (kvm_lock_all_vcpus(kvm, true)) {
27082708
mutex_unlock(&kvm->lock);
27092709
return -EBUSY;
27102710
}
@@ -2726,7 +2726,7 @@ static int vgic_its_ctrl(struct kvm *kvm, struct vgic_its *its, u64 attr)
27262726

27272727
mutex_unlock(&its->its_lock);
27282728
mutex_unlock(&kvm->arch.config_lock);
2729-
unlock_all_vcpus(kvm);
2729+
kvm_unlock_all_vcpus(kvm);
27302730
mutex_unlock(&kvm->lock);
27312731
return ret;
27322732
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,15 @@ static int vgic_set_common_attr(struct kvm_device *dev,
268268
return -ENXIO;
269269
mutex_lock(&dev->kvm->lock);
270270

271-
if (!lock_all_vcpus(dev->kvm)) {
271+
if (kvm_lock_all_vcpus(dev->kvm, true)) {
272272
mutex_unlock(&dev->kvm->lock);
273273
return -EBUSY;
274274
}
275275

276276
mutex_lock(&dev->kvm->arch.config_lock);
277277
r = vgic_v3_save_pending_tables(dev->kvm);
278278
mutex_unlock(&dev->kvm->arch.config_lock);
279-
unlock_all_vcpus(dev->kvm);
279+
kvm_unlock_all_vcpus(dev->kvm);
280280
mutex_unlock(&dev->kvm->lock);
281281
return r;
282282
}
@@ -390,7 +390,7 @@ static int vgic_v2_attr_regs_access(struct kvm_device *dev,
390390

391391
mutex_lock(&dev->kvm->lock);
392392

393-
if (!lock_all_vcpus(dev->kvm)) {
393+
if (kvm_lock_all_vcpus(dev->kvm, true)) {
394394
mutex_unlock(&dev->kvm->lock);
395395
return -EBUSY;
396396
}
@@ -415,7 +415,7 @@ static int vgic_v2_attr_regs_access(struct kvm_device *dev,
415415

416416
out:
417417
mutex_unlock(&dev->kvm->arch.config_lock);
418-
unlock_all_vcpus(dev->kvm);
418+
kvm_unlock_all_vcpus(dev->kvm);
419419
mutex_unlock(&dev->kvm->lock);
420420

421421
if (!ret && !is_write)
@@ -554,7 +554,7 @@ static int vgic_v3_attr_regs_access(struct kvm_device *dev,
554554

555555
mutex_lock(&dev->kvm->lock);
556556

557-
if (!lock_all_vcpus(dev->kvm)) {
557+
if (kvm_lock_all_vcpus(dev->kvm, true)) {
558558
mutex_unlock(&dev->kvm->lock);
559559
return -EBUSY;
560560
}
@@ -611,7 +611,7 @@ static int vgic_v3_attr_regs_access(struct kvm_device *dev,
611611

612612
out:
613613
mutex_unlock(&dev->kvm->arch.config_lock);
614-
unlock_all_vcpus(dev->kvm);
614+
kvm_unlock_all_vcpus(dev->kvm);
615615
mutex_unlock(&dev->kvm->lock);
616616

617617
if (!ret && uaccess && !is_write) {

0 commit comments

Comments
 (0)