Skip to content

Commit f96b874

Browse files
committed
drm/asahi: alloc: Fix lockdep cyclic locking between drm::mm and dma_resv
[ 1.324612] WARNING: possible circular locking dependency detected [ 1.328915] 6.16.8-asahi+ #asahi-dev Not tainted [ 1.329844] ------------------------------------------------------ [ 1.330990] systemd-udevd/129 is trying to acquire lock: [ 1.331990] ffff800026c5cdb0 (reservation_ww_class_mutex){+.+.}-{4:4}, at: rust_helper_dma_resv_lock+0x18/0x30 [ 1.333611] [ 1.333611] but task is already holding lock: [ 1.335051] ffff80002b939a78 (../rust/kernel/drm/mm.rs:172){+.+.}-{4:4}, at: rust_helper_mutex_lock+0x1c/0x38 [ 1.336689] [ 1.336689] which lock already depends on the new lock. [ 1.336689] [ 1.338743] [ 1.338743] the existing dependency chain (in reverse order) is: [ 1.340344] [ 1.340344] -> #1 (../rust/kernel/drm/mm.rs:172){+.+.}-{4:4}: [ 1.341844] lock_acquire+0x234/0x380 [ 1.342685] __mutex_lock+0xcc/0x5f8 [ 1.343490] mutex_lock_nested+0x2c/0x40 [ 1.344364] rust_helper_mutex_lock+0x1c/0x38 [ 1.345235] _RNvMs5_NtNtCshQQYMpKpVoA_6kernel3drm2mmINtB5_9AllocatoruNtNtCsfX8uYfFxWaG_5asahi3mmu18KernelMappingInnerE12reserve_nodeBW_+0xb0/0x150 [asahi] [ 1.347737] _RNvMs0_NtCsfX8uYfFxWaG_5asahi3gemNtB5_9ObjectRef6map_at+0x184/0x298 [asahi] [ 1.349168] _RNvMsc_NtCsfX8uYfFxWaG_5asahi5allocNtB5_13HeapAllocator9add_block+0x27c/0x8f4 [asahi] [ 1.350693] _RNvXsd_NtCsfX8uYfFxWaG_5asahi5allocNtB5_13HeapAllocatorNtB5_9Allocator5alloc+0x42c/0x8b0 [asahi] [ 1.352372] _RNvMs4_NtCsfX8uYfFxWaG_5asahi5eventNtB5_12EventManager3new+0xf4/0xacc [asahi] [ 1.353803] _RNvMs8_NtCsfX8uYfFxWaG_5asahi3gpuNtB5_18GpuManagerG13V12_318make_event_manager+0x20/0x70 [asahi] [ 1.355488] _RNvMsb_NtCsfX8uYfFxWaG_5asahi3gpuNtB5_18GpuManagerG14V13_53new+0x514/0xb14 [asahi] [ 1.356994] _RNvXs2_NtCsfX8uYfFxWaG_5asahi6driverNtB5_11AsahiDriverNtNtCshQQYMpKpVoA_6kernel8platform6Driver5probe+0x710/0x7fc [asahi] [ 1.358954] _RNvMs_NtCshQQYMpKpVoA_6kernel8platformINtB4_7AdapterNtNtCsfX8uYfFxWaG_5asahi6driver11AsahiDriverE14probe_callbackBS_+0x58/0xa0 [asahi] [ 1.361018] platform_probe+0x70/0xe8 [ 1.361889] really_probe+0xc8/0x3a0 [ 1.362756] __driver_probe_device+0x84/0x160 [ 1.363657] driver_probe_device+0x48/0x138 [ 1.364553] __driver_attach+0xd8/0x200 [ 1.365402] bus_for_each_dev+0x90/0x100 [ 1.366250] driver_attach+0x2c/0x40 [ 1.367058] bus_add_driver+0x118/0x240 [ 1.367923] driver_register+0x70/0x138 [ 1.368789] __platform_driver_register+0x28/0x40 [ 1.369749] init_module+0x70/0x4000 [asahi] [ 1.370630] do_one_initcall+0x88/0x378 [ 1.371478] do_init_module+0x5c/0x268 [ 1.372306] load_module+0x1ad0/0x20f8 [ 1.373115] init_module_from_file+0x90/0xd8 [ 1.374006] idempotent_init_module+0x1fc/0x2f0 [ 1.374925] __arm64_sys_finit_module+0x6c/0xe0 [ 1.375864] invoke_syscall.constprop.0+0x50/0xe0 [ 1.376796] do_el0_svc+0x44/0xe0 [ 1.377553] el0_svc+0x50/0x1e0 [ 1.378288] el0t_64_sync_handler+0x10c/0x140 [ 1.379167] el0t_64_sync+0x198/0x1a0 [ 1.379939] [ 1.379939] -> #0 (reservation_ww_class_mutex){+.+.}-{4:4}: [ 1.381310] check_prev_add+0x110/0xdc0 [ 1.382127] __lock_acquire+0x1248/0x1520 [ 1.382934] lock_acquire+0x234/0x380 [ 1.383713] __ww_mutex_lock.constprop.0+0xe4/0xc40 [ 1.384650] ww_mutex_lock+0x58/0xe0 [ 1.385407] rust_helper_dma_resv_lock+0x18/0x30 [ 1.386298] _RNvMs0_NtCsfX8uYfFxWaG_5asahi3gemNtB5_9ObjectRef4vmap+0x44/0x174 [asahi] [ 1.387622] _RNvXsd_NtCsfX8uYfFxWaG_5asahi5allocNtB5_13HeapAllocatorNtB5_9Allocator5alloc+0x63c/0x8b0 [asahi] [ 1.389219] _RNvMs4_NtCsfX8uYfFxWaG_5asahi5eventNtB5_12EventManager3new+0xf4/0xacc [asahi] [ 1.390619] _RNvMs8_NtCsfX8uYfFxWaG_5asahi3gpuNtB5_18GpuManagerG13V12_318make_event_manager+0x20/0x70 [asahi] [ 1.392227] _RNvMsb_NtCsfX8uYfFxWaG_5asahi3gpuNtB5_18GpuManagerG14V13_53new+0x514/0xb14 [asahi] [ 1.393670] _RNvXs2_NtCsfX8uYfFxWaG_5asahi6driverNtB5_11AsahiDriverNtNtCshQQYMpKpVoA_6kernel8platform6Driver5probe+0x710/0x7fc [asahi] [ 1.395526] _RNvMs_NtCshQQYMpKpVoA_6kernel8platformINtB4_7AdapterNtNtCsfX8uYfFxWaG_5asahi6driver11AsahiDriverE14probe_callbackBS_+0x58/0xa0 [asahi] [ 1.397590] platform_probe+0x70/0xe8 [ 1.398408] really_probe+0xc8/0x3a0 [ 1.399234] __driver_probe_device+0x84/0x160 [ 1.400109] driver_probe_device+0x48/0x138 [ 1.400956] __driver_attach+0xd8/0x200 [ 1.401779] bus_for_each_dev+0x90/0x100 [ 1.402577] driver_attach+0x2c/0x40 [ 1.403325] bus_add_driver+0x118/0x240 [ 1.404141] driver_register+0x70/0x138 [ 1.404921] __platform_driver_register+0x28/0x40 [ 1.405795] init_module+0x70/0x4000 [asahi] [ 1.406620] do_one_initcall+0x88/0x378 [ 1.407389] do_init_module+0x5c/0x268 [ 1.408144] load_module+0x1ad0/0x20f8 [ 1.408895] init_module_from_file+0x90/0xd8 [ 1.409706] idempotent_init_module+0x1fc/0x2f0 [ 1.410572] __arm64_sys_finit_module+0x6c/0xe0 [ 1.411425] invoke_syscall.constprop.0+0x50/0xe0 [ 1.412318] do_el0_svc+0x44/0xe0 [ 1.413036] el0_svc+0x50/0x1e0 [ 1.413697] el0t_64_sync_handler+0x10c/0x140 [ 1.414529] el0t_64_sync+0x198/0x1a0 [ 1.415261] [ 1.415261] other info that might help us debug this: [ 1.415261] [ 1.416937] Possible unsafe locking scenario: [ 1.416937] [ 1.418111] CPU0 CPU1 [ 1.418900] ---- ---- [ 1.419667] lock(../rust/kernel/drm/mm.rs:172); [ 1.420462] lock(reservation_ww_class_mutex); [ 1.421571] lock(../rust/kernel/drm/mm.rs:172); [ 1.422721] lock(reservation_ww_class_mutex); [ 1.423540] [ 1.423540] *** DEADLOCK *** [ 1.423540] [ 1.424924] 2 locks held by systemd-udevd/129: [ 1.425695] #0: ffff8000269e1900 (&dev->mutex){....}-{4:4}, at: __driver_attach+0xcc/0x200 [ 1.426968] #1: ffff80002b939a78 (../rust/kernel/drm/mm.rs:172){+.+.}-{4:4}, at: rust_helper_mutex_lock+0x1c/0x38 [ 1.428495] [ 1.428495] stack backtrace: [ 1.429565] CPU: 4 UID: 0 PID: 129 Comm: systemd-udevd Not tainted 6.16.8-asahi+ #asahi-dev PREEMPT(full) [ 1.429568] Hardware name: Apple MacBook Pro (13-inch, M2, 2022) (DT) [ 1.429568] Call trace: [ 1.429569] show_stack+0x30/0x90 (C) [ 1.429571] dump_stack_lvl+0x70/0x98 [ 1.429572] dump_stack+0x18/0x24 [ 1.429573] print_circular_bug+0x25c/0x2a8 [ 1.429574] check_noncircular+0x184/0x1a8 [ 1.429575] check_prev_add+0x110/0xdc0 [ 1.429576] __lock_acquire+0x1248/0x1520 [ 1.429578] lock_acquire+0x234/0x380 [ 1.429579] __ww_mutex_lock.constprop.0+0xe4/0xc40 [ 1.429580] ww_mutex_lock+0x58/0xe0 [ 1.429580] rust_helper_dma_resv_lock+0x18/0x30 [ 1.429581] _RNvMs0_NtCsfX8uYfFxWaG_5asahi3gemNtB5_9ObjectRef4vmap+0x44/0x174 [asahi] [ 1.429591] _RNvXsd_NtCsfX8uYfFxWaG_5asahi5allocNtB5_13HeapAllocatorNtB5_9Allocator5alloc+0x63c/0x8b0 [asahi] [ 1.429598] _RNvMs4_NtCsfX8uYfFxWaG_5asahi5eventNtB5_12EventManager3new+0xf4/0xacc [asahi] [ 1.429605] _RNvMs8_NtCsfX8uYfFxWaG_5asahi3gpuNtB5_18GpuManagerG13V12_318make_event_manager+0x20/0x70 [asahi] [ 1.429612] _RNvMsb_NtCsfX8uYfFxWaG_5asahi3gpuNtB5_18GpuManagerG14V13_53new+0x514/0xb14 [asahi] [ 1.429619] _RNvXs2_NtCsfX8uYfFxWaG_5asahi6driverNtB5_11AsahiDriverNtNtCshQQYMpKpVoA_6kernel8platform6Driver5probe+0x710/0x7fc [asahi] [ 1.429626] _RNvMs_NtCshQQYMpKpVoA_6kernel8platformINtB4_7AdapterNtNtCsfX8uYfFxWaG_5asahi6driver11AsahiDriverE14probe_callbackBS_+0x58/0xa0 [asahi] [ 1.429633] platform_probe+0x70/0xe8 [ 1.429634] really_probe+0xc8/0x3a0 [ 1.429635] __driver_probe_device+0x84/0x160 [ 1.429637] driver_probe_device+0x48/0x138 [ 1.429638] __driver_attach+0xd8/0x200 [ 1.429639] bus_for_each_dev+0x90/0x100 [ 1.429640] driver_attach+0x2c/0x40 [ 1.429641] bus_add_driver+0x118/0x240 [ 1.429642] driver_register+0x70/0x138 [ 1.429643] __platform_driver_register+0x28/0x40 [ 1.429644] init_module+0x70/0x4000 [asahi] [ 1.429651] do_one_initcall+0x88/0x378 [ 1.429652] do_init_module+0x5c/0x268 [ 1.429654] load_module+0x1ad0/0x20f8 [ 1.429655] init_module_from_file+0x90/0xd8 [ 1.429656] idempotent_init_module+0x1fc/0x2f0 [ 1.429658] __arm64_sys_finit_module+0x6c/0xe0 [ 1.429659] invoke_syscall.constprop.0+0x50/0xe0 [ 1.429661] do_el0_svc+0x44/0xe0 [ 1.429662] el0_svc+0x50/0x1e0 [ 1.429664] el0t_64_sync_handler+0x10c/0x140 [ 1.429665] el0t_64_sync+0x198/0x1a0 [ 1.432242] ------------[ cut here ]------------ Signed-off-by: Janne Grunau <j@jannau.net>
1 parent 3ecfa22 commit f96b874

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

drivers/gpu/drm/asahi/alloc.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,13 @@ impl HeapAllocator {
780780
);
781781
})?;
782782

783+
if self.cpu_maps {
784+
// Create virtual mapping here ahead of time so that the vmap() in
785+
// alloc_inner() does not take the the object's dma_resv lock while
786+
// the mm lock is locked. mmu::Vm requires the opposite lock order.
787+
obj.vmap()?;
788+
}
789+
783790
self.mm
784791
.with_inner(|inner| inner.backing_objects.reserve(1, GFP_KERNEL))?;
785792

0 commit comments

Comments
 (0)