Skip to content

Commit eb836f0

Browse files
aikgregkh
authored andcommitted
KVM: PPC: Book3S: Protect kvmppc_gpa_to_ua() with SRCU
commit 8f6a9f0 upstream. kvmppc_gpa_to_ua() accesses KVM memory slot array via srcu_dereference_check() and this produces warnings from RCU like below. This extends the existing srcu_read_lock/unlock to cover that kvmppc_gpa_to_ua() as well. We did not hit this before as this lock is not needed for the realmode handlers and hash guests would use the realmode path all the time; however the radix guests are always redirected to the virtual mode handlers and hence the warning. [ 68.253798] ./include/linux/kvm_host.h:575 suspicious rcu_dereference_check() usage! [ 68.253799] other info that might help us debug this: [ 68.253802] rcu_scheduler_active = 2, debug_locks = 1 [ 68.253804] 1 lock held by qemu-system-ppc/6413: [ 68.253806] #0: (&vcpu->mutex){+.+.}, at: [<c00800000e3c22f4>] vcpu_load+0x3c/0xc0 [kvm] [ 68.253826] stack backtrace: [ 68.253830] CPU: 92 PID: 6413 Comm: qemu-system-ppc Tainted: G W 4.14.0-rc3-00553-g432dcba58e9c-dirty #72 [ 68.253833] Call Trace: [ 68.253839] [c000000fd3d9f790] [c000000000b7fcc8] dump_stack+0xe8/0x160 (unreliable) [ 68.253845] [c000000fd3d9f7d0] [c0000000001924c0] lockdep_rcu_suspicious+0x110/0x180 [ 68.253851] [c000000fd3d9f850] [c0000000000e825c] kvmppc_gpa_to_ua+0x26c/0x2b0 [ 68.253858] [c000000fd3d9f8b0] [c00800000e3e1984] kvmppc_h_put_tce+0x12c/0x2a0 [kvm] Fixes: 121f80b ("KVM: PPC: VFIO: Add in-kernel acceleration for VFIO") Signed-off-by: Alexey Kardashevskiy <[email protected]> Signed-off-by: Paul Mackerras <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 39418e2 commit eb836f0

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

arch/powerpc/kvm/book3s_64_vio.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -479,36 +479,41 @@ long kvmppc_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn,
479479
return ret;
480480

481481
dir = iommu_tce_direction(tce);
482+
483+
idx = srcu_read_lock(&vcpu->kvm->srcu);
484+
482485
if ((dir != DMA_NONE) && kvmppc_gpa_to_ua(vcpu->kvm,
483-
tce & ~(TCE_PCI_READ | TCE_PCI_WRITE), &ua, NULL))
484-
return H_PARAMETER;
486+
tce & ~(TCE_PCI_READ | TCE_PCI_WRITE), &ua, NULL)) {
487+
ret = H_PARAMETER;
488+
goto unlock_exit;
489+
}
485490

486491
entry = ioba >> stt->page_shift;
487492

488493
list_for_each_entry_lockless(stit, &stt->iommu_tables, next) {
489-
if (dir == DMA_NONE) {
494+
if (dir == DMA_NONE)
490495
ret = kvmppc_tce_iommu_unmap(vcpu->kvm,
491496
stit->tbl, entry);
492-
} else {
493-
idx = srcu_read_lock(&vcpu->kvm->srcu);
497+
else
494498
ret = kvmppc_tce_iommu_map(vcpu->kvm, stit->tbl,
495499
entry, ua, dir);
496-
srcu_read_unlock(&vcpu->kvm->srcu, idx);
497-
}
498500

499501
if (ret == H_SUCCESS)
500502
continue;
501503

502504
if (ret == H_TOO_HARD)
503-
return ret;
505+
goto unlock_exit;
504506

505507
WARN_ON_ONCE(1);
506508
kvmppc_clear_tce(stit->tbl, entry);
507509
}
508510

509511
kvmppc_tce_put(stt, entry, tce);
510512

511-
return H_SUCCESS;
513+
unlock_exit:
514+
srcu_read_unlock(&vcpu->kvm->srcu, idx);
515+
516+
return ret;
512517
}
513518
EXPORT_SYMBOL_GPL(kvmppc_h_put_tce);
514519

0 commit comments

Comments
 (0)