Skip to content

Commit 5d85c63

Browse files
hoshinolinajannau
authored andcommitted
drm/asahi: mmu: Fix lockdep issues with GpuVm
Signed-off-by: Asahi Lina <lina@asahilina.net>
1 parent f78063c commit 5d85c63

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

drivers/gpu/drm/asahi/mmu.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use core::sync::atomic::{fence, AtomicU32, AtomicU64, AtomicU8, Ordering};
1818
use core::time::Duration;
1919

2020
use kernel::{
21-
bindings, c_str, delay, device,
22-
drm::{gpuvm, mm},
21+
bindings, c_str, delay, device, drm,
22+
drm::{gem::BaseObject, gpuvm, mm},
2323
error::{to_result, Result},
2424
io_pgtable,
2525
io_pgtable::{prot, AppleUAT, IoPageTable},
@@ -579,11 +579,16 @@ impl Clone for VmBind {
579579

580580
/// Inner data required for an object mapping into a [`Vm`].
581581
pub(crate) struct KernelMappingInner {
582+
// Drop order matters:
583+
// - Drop the GpuVmBo first, which resv locks its BO and drops a GpuVm reference
584+
// - Drop the GEM BO next, since BO free can take the resv lock itself
585+
// - Drop the owner GpuVm last, since that again can take resv locks when the refcount drops to 0
586+
bo: Option<ARef<gpuvm::GpuVmBo<VmInner>>>,
587+
_gem: Option<drm::gem::ObjectRef<gem::Object>>,
582588
owner: ARef<gpuvm::GpuVm<VmInner>>,
583589
uat_inner: Arc<UatInner>,
584590
prot: u32,
585591
mapped_size: usize,
586-
bo: Option<ARef<gpuvm::GpuVmBo<VmInner>>>,
587592
}
588593

589594
/// An object mapping into a [`Vm`], which reserves the address range from use by other mappings.
@@ -1093,6 +1098,7 @@ impl Vm {
10931098
uat_inner,
10941099
prot,
10951100
bo: Some(vm_bo),
1101+
_gem: Some(gem.reference()),
10961102
mapped_size: size,
10971103
},
10981104
(size + if guard { UAT_PGSZ } else { 0 }) as u64, // Add guard page
@@ -1135,6 +1141,7 @@ impl Vm {
11351141
uat_inner,
11361142
prot,
11371143
bo: Some(vm_bo),
1144+
_gem: Some(gem.reference()),
11381145
mapped_size: size,
11391146
},
11401147
addr,
@@ -1235,6 +1242,7 @@ impl Vm {
12351242
uat_inner,
12361243
prot,
12371244
bo: None,
1245+
_gem: None,
12381246
mapped_size: size,
12391247
},
12401248
iova,
@@ -1274,6 +1282,9 @@ impl Vm {
12741282
mod_dev_dbg!(inner.dev, "MMU: bo_unmap\n");
12751283
inner.bo_unmap(&mut ctx, &bo)?;
12761284
mod_dev_dbg!(inner.dev, "MMU: bo_unmap done\n");
1285+
// We need to drop the exec_lock first, then the GpuVmBo since that will take the lock itself.
1286+
core::mem::drop(inner);
1287+
core::mem::drop(bo);
12771288
}
12781289

12791290
Ok(())

0 commit comments

Comments
 (0)