Skip to contentSkip to conversation

drm/msm: Fix shrinker deadlock

PATCH In review Daniel J Blueman 4 participants 7 messages May 8 – May 15

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/msm: Fix shrinker deadlock

With PROVE_LOCKING on an Snapdragon X1 and VM reclaim pressure, we see:

"""
kswapd0/121 is trying to acquire lock:
ffff800080ed3800 (reservation_ww_class_acquire){+.+.}-{0:0}, at:
msm_gem_shrinker_scan (drivers/gpu/drm/msm/msm_gem_shrinker.c:189)

but task is already holding lock:
ffffbf4ddb44ca40 (fs_reclaim){+.+.}-{0:0}, at:
balance_pgdat (mm/vmscan.c:7236 (discriminator 2))

which lock already depends on the new lock.

the existing dependency chain (in reverse order) is:

-> #2 (fs_reclaim){+.+.}-{0:0}:

lock_acquire (kernel/locking/lockdep.c:5868 kernel/locking/lockdep.c:5825)
fs_reclaim_acquire (mm/page_alloc.c:4325 mm/page_alloc.c:4339)
dma_resv_lockdep (drivers/dma-buf/dma-resv.c:798)
do_one_initcall (init/main.c:1392)
kernel_init_freeable (init/main.c:1454 (discriminator 1) init/main.c:1470
  (discriminator 1) init/main.c:1490 (discriminator 1) init/main.c:1703
  (discriminator 1))

kernel_init (init/main.c:1593)
ret_from_fork (arch/arm64/kernel/entry.S:858)

-> #1 (reservation_ww_class_mutex){+.+.}-{4:4}:

lock_acquire (kernel/locking/lockdep.c:5868 kernel/locking/lockdep.c:5825)
dma_resv_lockdep (./include/linux/ww_mutex.h:164 (discriminator 1)
  drivers/dma-buf/dma-resv.c:791 (discriminator 1))
do_one_initcall (init/main.c:1392)
kernel_init_freeable (init/main.c:1454 (discriminator 1) init/main.c:1470
  (discriminator 1) init/main.c:1490 (discriminator 1) init/main.c:1703
  (discriminator 1))

kernel_init (init/main.c:1593)
ret_from_fork (arch/arm64/kernel/entry.S:858)

-> #0 (reservation_ww_class_acquire){+.+.}-{0:0}:
check_prev_add (kernel/locking/lockdep.c:3165)

__lock_acquire (kernel/locking/lockdep.c:3284
  kernel/locking/lockdep.c:3908 kernel/locking/lockdep.c:5237)
lock_acquire (kernel/locking/lockdep.c:5868 kernel/locking/lockdep.c:5825)
drm_gem_lru_scan (./include/linux/ww_mutex.h:163 (discriminator 1)
  drivers/gpu/drm/drm_gem.c:1681 (discriminator 1))

msm_gem_shrinker_scan (drivers/gpu/drm/msm/msm_gem_shrinker.c:189) do_shrink_slab (mm/shrinker.c:436)
shrink_slab (mm/shrinker.c:667)
shrink_one (mm/vmscan.c:5071)

shrink_node (mm/vmscan.c:5132 mm/vmscan.c:5210 mm/vmscan.c:6198)
balance_pgdat (mm/vmscan.c:7052 mm/vmscan.c:7228)

kswapd (mm/vmscan.c:7501)
kthread (kernel/kthread.c:436)
ret_from_fork (arch/arm64/kernel/entry.S:858)

other info that might help us debug this:

Chain exists of:

reservation_ww_class_acquire --> reservation_ww_class_mutex --> fs_reclaim """

kswapd0 holding fs_reclaim calls the MSM shrinker, which calls dma_resv_lock. This in turn acquires fs_reclaim.

Fix this deadlock by using dma_resv_trylock() instead, dropping the subsequently unused passed wait-wound lock 'ticket'.

Fixes fe4952b5f27c ("drm/msm: Convert vm locking")
---
 drivers/gpu/drm/msm/msm_gem_shrinker.c | 34 ++++++++++----------------
 1 file changed, 13 insertions(+), 21 deletions(-)
drivers/gpu/drm/msm/msm_gem_shrinker.c +13 -21
index 31fa51a44f86..5320ef57dd90 100644
@@ -43,8 +43,7 @@ msm_gem_shrinker_count(struct shrinker *shrinker, struct shrink_control *sc)
 }
 
 static bool
-with_vm_locks(struct ww_acquire_ctx *ticket,
-	      void (*fn)(struct drm_gem_object *obj),
+with_vm_locks(void (*fn)(struct drm_gem_object *obj),
 	      struct drm_gem_object *obj)
 {
 	/*
@@ -52,7 +51,7 @@ with_vm_locks(struct ww_acquire_ctx *ticket,
 	 * success paths
 	 */
 	struct drm_gpuvm_bo *vm_bo, *last_locked = NULL;
-	int ret = 0;
+	bool locked = true;
 
 	drm_gem_for_each_gpuvm_bo (vm_bo, obj) {
 		struct dma_resv *resv = drm_gpuvm_resv(vm_bo->vm);
@@ -60,23 +59,14 @@ with_vm_locks(struct ww_acquire_ctx *ticket,
 		if (resv == obj->resv)
 			continue;
 
-		ret = dma_resv_lock(resv, ticket);
-
 		/*
-		 * Since we already skip the case when the VM and obj
-		 * share a resv (ie. _NO_SHARE objs), we don't expect
-		 * to hit a double-locking scenario... which the lock
-		 * unwinding cannot really cope with.
+		 * dma_resv_lock can't be used due to acquiring 'ticket' before the
+		 * fs_reclaim lock, which is held in shrinker context
 		 */
-		WARN_ON(ret == -EALREADY);
-
-		/*
-		 * Don't bother with slow-lock / backoff / retry sequence,
-		 * if we can't get the lock just give up and move on to
-		 * the next object.
-		 */
-		if (ret)
+		if (!dma_resv_trylock(resv)) {
+			locked = false;
 			goto out_unlock;
+		}
 
 		/*
 		 * Hold a ref to prevent the vm_bo from being freed
@@ -108,7 +98,7 @@ with_vm_locks(struct ww_acquire_ctx *ticket,
 		}
 	}
 
-	return ret == 0;
+	return locked;
 }
 
 static bool
@@ -120,7 +110,7 @@ purge(struct drm_gem_object *obj, struct ww_acquire_ctx *ticket)
 	if (msm_gem_active(obj))
 		return false;
 
-	return with_vm_locks(ticket, msm_gem_purge, obj);
+	return with_vm_locks(msm_gem_purge, obj);
 }
 
 static bool
@@ -164,7 +154,6 @@ static unsigned long
 msm_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc)
 {
 	struct msm_drm_private *priv = shrinker->private_data;
-	struct ww_acquire_ctx ticket;
 	struct {
 		struct drm_gem_lru *lru;
 		bool (*shrink)(struct drm_gem_object *obj, struct ww_acquire_ctx *ticket);
@@ -185,11 +174,14 @@ msm_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc)
 	for (unsigned i = 0; (nr > 0) && (i < ARRAY_SIZE(stages)); i++) {
 		if (!stages[i].cond)
 			continue;
+		/*
+		 * 'ticket' not needed on trylock paths
+		 */
 		stages[i].freed =
 			drm_gem_lru_scan(stages[i].lru, nr,
 					 &stages[i].remaining,
 					 stages[i].shrink,
-					 &ticket);
+					 NULL);
 		nr -= stages[i].freed;
 		freed += stages[i].freed;
 		remaining += stages[i].remaining;
Signature · 1 line
2.53.0
#1 lore raw
Quoted 38 lines · Daniel J Blueman

With PROVE_LOCKING on an Snapdragon X1 and VM reclaim pressure, we see:

"""
kswapd0/121 is trying to acquire lock:
ffff800080ed3800 (reservation_ww_class_acquire){+.+.}-{0:0}, at:
msm_gem_shrinker_scan (drivers/gpu/drm/msm/msm_gem_shrinker.c:189)

but task is already holding lock:
ffffbf4ddb44ca40 (fs_reclaim){+.+.}-{0:0}, at:
balance_pgdat (mm/vmscan.c:7236 (discriminator 2))

which lock already depends on the new lock.

the existing dependency chain (in reverse order) is:

-> #2 (fs_reclaim){+.+.}-{0:0}:

lock_acquire (kernel/locking/lockdep.c:5868 kernel/locking/lockdep.c:5825)
fs_reclaim_acquire (mm/page_alloc.c:4325 mm/page_alloc.c:4339)
dma_resv_lockdep (drivers/dma-buf/dma-resv.c:798)
do_one_initcall (init/main.c:1392)
kernel_init_freeable (init/main.c:1454 (discriminator 1) init/main.c:1470
  (discriminator 1) init/main.c:1490 (discriminator 1) init/main.c:1703
  (discriminator 1))

kernel_init (init/main.c:1593)
ret_from_fork (arch/arm64/kernel/entry.S:858)

-> #1 (reservation_ww_class_mutex){+.+.}-{4:4}:

lock_acquire (kernel/locking/lockdep.c:5868 kernel/locking/lockdep.c:5825)
dma_resv_lockdep (./include/linux/ww_mutex.h:164 (discriminator 1)
  drivers/dma-buf/dma-resv.c:791 (discriminator 1))
do_one_initcall (init/main.c:1392)
kernel_init_freeable (init/main.c:1454 (discriminator 1) init/main.c:1470
  (discriminator 1) init/main.c:1490 (discriminator 1) init/main.c:1703
  (discriminator 1))

kernel_init (init/main.c:1593)
ret_from_fork (arch/arm64/kernel/entry.S:858)

Quoted 7 lines

-> #0 (reservation_ww_class_acquire){+.+.}-{0:0}:
check_prev_add (kernel/locking/lockdep.c:3165)

__lock_acquire (kernel/locking/lockdep.c:3284
  kernel/locking/lockdep.c:3908 kernel/locking/lockdep.c:5237)
lock_acquire (kernel/locking/lockdep.c:5868 kernel/locking/lockdep.c:5825)
drm_gem_lru_scan (./include/linux/ww_mutex.h:163 (discriminator 1)
  drivers/gpu/drm/drm_gem.c:1681 (discriminator 1))

Your line #s don't quite match mine, but AFAICT this is from the ww_acquire_init()

What I'm unsure about is if this could cause live-lock against another operation which requires obtaining both obj and vm locks in a potentially different order (which would also be using a ww_acquire_ctx ticket to backoff in case of conflicting locking order). It wouldn't deadlock because we don't sleep forever if we do sleep, but...

Possibly we should also be using trylock to also acquire the vm lock, but lockdep would still complain as it doesn't know the ticket will be only used w/ trylock (unless we did something hacky by using a different ww_class?)

BR,
-R

Quoted 126 lines

msm_gem_shrinker_scan (drivers/gpu/drm/msm/msm_gem_shrinker.c:189) do_shrink_slab (mm/shrinker.c:436)
shrink_slab (mm/shrinker.c:667)
shrink_one (mm/vmscan.c:5071)

shrink_node (mm/vmscan.c:5132 mm/vmscan.c:5210 mm/vmscan.c:6198)
balance_pgdat (mm/vmscan.c:7052 mm/vmscan.c:7228)

kswapd (mm/vmscan.c:7501)
kthread (kernel/kthread.c:436)
ret_from_fork (arch/arm64/kernel/entry.S:858)

other info that might help us debug this:

Chain exists of:

reservation_ww_class_acquire --> reservation_ww_class_mutex --> fs_reclaim """

kswapd0 holding fs_reclaim calls the MSM shrinker, which calls dma_resv_lock. This in turn acquires fs_reclaim.

Fix this deadlock by using dma_resv_trylock() instead, dropping the subsequently unused passed wait-wound lock 'ticket'.

Fixes fe4952b5f27c ("drm/msm: Convert vm locking")
---
 drivers/gpu/drm/msm/msm_gem_shrinker.c | 34 ++++++++++----------------
 1 file changed, 13 insertions(+), 21 deletions(-)
drivers/gpu/drm/msm/msm_gem_shrinker.c +13 -22
index 31fa51a44f86..5320ef57dd90 100644
@@ -43,8 +43,7 @@ msm_gem_shrinker_count(struct shrinker *shrinker, struct shrink_control *sc)
 }
 
 static bool
-with_vm_locks(struct ww_acquire_ctx *ticket,
-             void (*fn)(struct drm_gem_object *obj),
+with_vm_locks(void (*fn)(struct drm_gem_object *obj),
              struct drm_gem_object *obj)
 {
        /*
@@ -52,7 +51,7 @@ with_vm_locks(struct ww_acquire_ctx *ticket,
         * success paths
         */
        struct drm_gpuvm_bo *vm_bo, *last_locked = NULL;
-       int ret = 0;
+       bool locked = true;
 
        drm_gem_for_each_gpuvm_bo (vm_bo, obj) {
                struct dma_resv *resv = drm_gpuvm_resv(vm_bo->vm);
@@ -60,23 +59,14 @@ with_vm_locks(struct ww_acquire_ctx *ticket,
                if (resv == obj->resv)
                        continue;
 
-               ret = dma_resv_lock(resv, ticket);
-
                /*
-                * Since we already skip the case when the VM and obj
-                * share a resv (ie. _NO_SHARE objs), we don't expect
-                * to hit a double-locking scenario... which the lock
-                * unwinding cannot really cope with.
+                * dma_resv_lock can't be used due to acquiring 'ticket' before the
+                * fs_reclaim lock, which is held in shrinker context
                 */
-               WARN_ON(ret == -EALREADY);
-
-               /*
-                * Don't bother with slow-lock / backoff / retry sequence,
-                * if we can't get the lock just give up and move on to
-                * the next object.
-                */
-               if (ret)
+               if (!dma_resv_trylock(resv)) {
+                       locked = false;
                        goto out_unlock;
+               }
 
                /*
                 * Hold a ref to prevent the vm_bo from being freed
@@ -108,7 +98,7 @@ with_vm_locks(struct ww_acquire_ctx *ticket,
                }
        }
 
-       return ret == 0;
+       return locked;
 }
 
 static bool
@@ -120,7 +110,7 @@ purge(struct drm_gem_object *obj, struct ww_acquire_ctx *ticket)
        if (msm_gem_active(obj))
                return false;
 
-       return with_vm_locks(ticket, msm_gem_purge, obj);
+       return with_vm_locks(msm_gem_purge, obj);
 }
 
 static bool
@@ -164,7 +154,6 @@ static unsigned long
 msm_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc)
 {
        struct msm_drm_private *priv = shrinker->private_data;
-       struct ww_acquire_ctx ticket;
        struct {
                struct drm_gem_lru *lru;
                bool (*shrink)(struct drm_gem_object *obj, struct ww_acquire_ctx *ticket);
@@ -185,11 +174,14 @@ msm_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc)
        for (unsigned i = 0; (nr > 0) && (i < ARRAY_SIZE(stages)); i++) {
                if (!stages[i].cond)
                        continue;
+               /*
+                * 'ticket' not needed on trylock paths
+                */
                stages[i].freed =
                        drm_gem_lru_scan(stages[i].lru, nr,
                                         &stages[i].remaining,
                                         stages[i].shrink,
-                                        &ticket);
+                                        NULL);
                nr -= stages[i].freed;
                freed += stages[i].freed;
                remaining += stages[i].remaining;
--

2.53.0

#5 lore raw
In reply to Daniel J Blueman
kernel test robot noticed the following build errors:

Hi Daniel,

kernel test robot noticed the following build errors:

[auto build test ERROR on drm-misc/drm-misc-next]
[also build test ERROR on linus/master v7.1-rc2 next-20260508] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Daniel-J-Blueman/drm-msm-Fix-shrinker-deadlock/20260510-132942
base:   https://gitlab.freedesktop.org/drm/misc/kernel.git drm-misc-next
patch link:    https://lore.kernel.org/r/20260508065722.18785-1-daniel%40quora.org
patch subject: [PATCH] drm/msm: Fix shrinker deadlock
config: um-allmodconfig (https://download.01.org/0day-ci/archive/20260510/[email protected]/config)
compiler: clang version 19.1.7 (https://github.com/llvm/llvm-project cd708029e0b2869e80abe31ddb175f7c35361f90)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260510/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

In file included from drivers/gpu/drm/msm/msm_gem_shrinker.c:10:
In file included from drivers/gpu/drm/msm/msm_drv.h:22:
In file included from include/linux/iommu.h:10:
In file included from include/linux/scatterlist.h:9:
In file included from arch/um/include/asm/io.h:24:
include/asm-generic/io.h:1209:55: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
1209 | return (port > MMIO_UPPER_LIMIT) ? NULL : PCI_IOBASE + port;
| ~~~~~~~~~~ ^

>> drivers/gpu/drm/msm/msm_gem_shrinker.c:125:46: error: too many arguments to function call, expected 2, have 3
     125 |         return with_vm_locks(ticket, msm_gem_evict, obj);
         |                ~~~~~~~~~~~~~                        ^~~
   drivers/gpu/drm/msm/msm_gem_shrinker.c:46:1: note: 'with_vm_locks' declared here
      46 | with_vm_locks(void (*fn)(struct drm_gem_object *obj),
         | ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      47 |               struct drm_gem_object *obj)
         |               ~~~~~~~~~~~~~~~~~~~~~~~~~~

1 warning and 1 error generated.

vim +125 drivers/gpu/drm/msm/msm_gem_shrinker.c

6afb0750dba05c Rob Clark 2021-04-05  115  
63f17ef834284d Rob Clark 2021-04-05  116  static bool
02070f04987524 Rob Clark 2025-06-29  117  evict(struct drm_gem_object *obj, struct ww_acquire_ctx *ticket)
63f17ef834284d Rob Clark 2021-04-05  118  {
b352ba54a82072 Rob Clark 2022-08-02  119  	if (is_unevictable(to_msm_bo(obj)))
63f17ef834284d Rob Clark 2021-04-05  120  		return false;
63f17ef834284d Rob Clark 2021-04-05  121  
b352ba54a82072 Rob Clark 2022-08-02  122  	if (msm_gem_active(obj))
01780d02634a3a Rob Clark 2022-08-02  123  		return false;
01780d02634a3a Rob Clark 2022-08-02  124  

fe4952b5f27cca Rob Clark 2025-06-29 @125 return with_vm_locks(ticket, msm_gem_evict, obj);
63f17ef834284d Rob Clark 2021-04-05 126 }
63f17ef834284d Rob Clark 2021-04-05 127

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#6 lore raw
In reply to Daniel J Blueman
kernel test robot noticed the following build errors:

Hi Daniel,

kernel test robot noticed the following build errors:

[auto build test ERROR on drm-misc/drm-misc-next]
[also build test ERROR on linus/master v7.1-rc2 next-20260508] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Daniel-J-Blueman/drm-msm-Fix-shrinker-deadlock/20260510-132942
base:   https://gitlab.freedesktop.org/drm/misc/kernel.git drm-misc-next
patch link:    https://lore.kernel.org/r/20260508065722.18785-1-daniel%40quora.org
patch subject: [PATCH] drm/msm: Fix shrinker deadlock
config: um-allyesconfig (https://download.01.org/0day-ci/archive/20260511/[email protected]/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260511/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

drivers/gpu/drm/msm/msm_gem_shrinker.c: In function 'evict':

>> drivers/gpu/drm/msm/msm_gem_shrinker.c:125:30: error: passing argument 1 of 'with_vm_locks' from incompatible pointer type [-Wincompatible-pointer-types]
     125 |         return with_vm_locks(ticket, msm_gem_evict, obj);
         |                              ^~~~~~
         |                              |
         |                              struct ww_acquire_ctx *
   drivers/gpu/drm/msm/msm_gem_shrinker.c:46:22: note: expected 'void (*)(struct drm_gem_object *)' but argument is of type 'struct ww_acquire_ctx *'
      46 | with_vm_locks(void (*fn)(struct drm_gem_object *obj),
         |               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/gpu/drm/msm/msm_gem_shrinker.c:125:38: error: passing argument 2 of 'with_vm_locks' from incompatible pointer type [-Wincompatible-pointer-types]
     125 |         return with_vm_locks(ticket, msm_gem_evict, obj);
         |                                      ^~~~~~~~~~~~~
         |                                      |
         |                                      void (*)(struct drm_gem_object *)
   drivers/gpu/drm/msm/msm_gem_shrinker.c:47:38: note: expected 'struct drm_gem_object *' but argument is of type 'void (*)(struct drm_gem_object *)'
      47 |               struct drm_gem_object *obj)
         |               ~~~~~~~~~~~~~~~~~~~~~~~^~~
>> drivers/gpu/drm/msm/msm_gem_shrinker.c:125:16: error: too many arguments to function 'with_vm_locks'
     125 |         return with_vm_locks(ticket, msm_gem_evict, obj);
         |                ^~~~~~~~~~~~~
   drivers/gpu/drm/msm/msm_gem_shrinker.c:46:1: note: declared here
      46 | with_vm_locks(void (*fn)(struct drm_gem_object *obj),
         | ^~~~~~~~~~~~~

vim +/with_vm_locks +125 drivers/gpu/drm/msm/msm_gem_shrinker.c

6afb0750dba05c Rob Clark 2021-04-05  115  
63f17ef834284d Rob Clark 2021-04-05  116  static bool
02070f04987524 Rob Clark 2025-06-29  117  evict(struct drm_gem_object *obj, struct ww_acquire_ctx *ticket)
63f17ef834284d Rob Clark 2021-04-05  118  {
b352ba54a82072 Rob Clark 2022-08-02  119  	if (is_unevictable(to_msm_bo(obj)))
63f17ef834284d Rob Clark 2021-04-05  120  		return false;
63f17ef834284d Rob Clark 2021-04-05  121  
b352ba54a82072 Rob Clark 2022-08-02  122  	if (msm_gem_active(obj))
01780d02634a3a Rob Clark 2022-08-02  123  		return false;
01780d02634a3a Rob Clark 2022-08-02  124  

fe4952b5f27cca Rob Clark 2025-06-29 @125 return with_vm_locks(ticket, msm_gem_evict, obj);
63f17ef834284d Rob Clark 2021-04-05 126 }
63f17ef834284d Rob Clark 2021-04-05 127

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#2 lore raw
In reply to Rob Clark

Hi,

Quoted 57 lines · On Sat, 9 May 2026 08:34:15 -0700 Rob Clark <[email protected]> wrote:
Quoted 38 lines · Daniel J Blueman

With PROVE_LOCKING on an Snapdragon X1 and VM reclaim pressure, we see:

"""
kswapd0/121 is trying to acquire lock:
ffff800080ed3800 (reservation_ww_class_acquire){+.+.}-{0:0}, at:
msm_gem_shrinker_scan (drivers/gpu/drm/msm/msm_gem_shrinker.c:189)

but task is already holding lock:
ffffbf4ddb44ca40 (fs_reclaim){+.+.}-{0:0}, at:
balance_pgdat (mm/vmscan.c:7236 (discriminator 2))

which lock already depends on the new lock.

the existing dependency chain (in reverse order) is:

-> #2 (fs_reclaim){+.+.}-{0:0}:

lock_acquire (kernel/locking/lockdep.c:5868 kernel/locking/lockdep.c:5825)
fs_reclaim_acquire (mm/page_alloc.c:4325 mm/page_alloc.c:4339)
dma_resv_lockdep (drivers/dma-buf/dma-resv.c:798)
do_one_initcall (init/main.c:1392)
kernel_init_freeable (init/main.c:1454 (discriminator 1) init/main.c:1470
  (discriminator 1) init/main.c:1490 (discriminator 1) init/main.c:1703
  (discriminator 1))

kernel_init (init/main.c:1593)
ret_from_fork (arch/arm64/kernel/entry.S:858)

-> #1 (reservation_ww_class_mutex){+.+.}-{4:4}:

lock_acquire (kernel/locking/lockdep.c:5868 kernel/locking/lockdep.c:5825)
dma_resv_lockdep (./include/linux/ww_mutex.h:164 (discriminator 1)
  drivers/dma-buf/dma-resv.c:791 (discriminator 1))
do_one_initcall (init/main.c:1392)
kernel_init_freeable (init/main.c:1454 (discriminator 1) init/main.c:1470
  (discriminator 1) init/main.c:1490 (discriminator 1) init/main.c:1703
  (discriminator 1))

kernel_init (init/main.c:1593)
ret_from_fork (arch/arm64/kernel/entry.S:858)

Quoted 7 lines

-> #0 (reservation_ww_class_acquire){+.+.}-{0:0}:
check_prev_add (kernel/locking/lockdep.c:3165)

__lock_acquire (kernel/locking/lockdep.c:3284
  kernel/locking/lockdep.c:3908 kernel/locking/lockdep.c:5237)
lock_acquire (kernel/locking/lockdep.c:5868 kernel/locking/lockdep.c:5825)
drm_gem_lru_scan (./include/linux/ww_mutex.h:163 (discriminator 1)
  drivers/gpu/drm/drm_gem.c:1681 (discriminator 1))  

Your line #s don't quite match mine, but AFAICT this is from the ww_acquire_init()

What I'm unsure about is if this could cause live-lock against another operation which requires obtaining both obj and vm locks in a potentially different order (which would also be using a ww_acquire_ctx ticket to backoff in case of conflicting locking order). It wouldn't deadlock because we don't sleep forever if we do sleep, but...

Quoted 4 lines

Possibly we should also be using trylock to also acquire the vm lock, but lockdep would still complain as it doesn't know the ticket will be only used w/ trylock (unless we did something hacky by using a different ww_class?)

FWIW, we started using a ticket in the initial version of the Panthor shrinker, and ditched it at some point because of these unsolvable lock ordering issues. It also seems to me that trylock-all-the-way is the right solution, and if we trylock and back off + immediately move to the next BO if any lock is already held, the ticket approach is not as useful, because we're not going to use the retry mechanism provided by ww_mutex anyway.

It's true that it does the bookkeeping, which simplifies the rollback procedure, but if you look at the other locks taken in the shrinker path, they are static (one per-component involved in reclaim) for most of them, meaning the rollback is pretty straightforward. The only exception is the VM lock (one per vm_bo in case of shared BOs). In panthor, we just decided to open-code this rollback logic (see panthor_gem_try_evict_no_resv_wait() [1]) instead of teaching ww_mutex about non-blocking locks when a ticket is provided. Not saying this is the best option, but it works...

Regards,

Boris

[1]https://gitlab.freedesktop.org/drm/misc/kernel/-/blob/drm-misc-next/drivers/gpu/drm/panthor/panthor_gem.c?ref_type=heads#L1425

#3 lore raw
Quoted 76 lines · Boris Brezillon

Hi,

Quoted 57 lines · On Sat, 9 May 2026 08:34:15 -0700 Rob Clark <[email protected]> wrote:
Quoted 38 lines · Daniel J Blueman

With PROVE_LOCKING on an Snapdragon X1 and VM reclaim pressure, we see:

"""
kswapd0/121 is trying to acquire lock:
ffff800080ed3800 (reservation_ww_class_acquire){+.+.}-{0:0}, at:
msm_gem_shrinker_scan (drivers/gpu/drm/msm/msm_gem_shrinker.c:189)

but task is already holding lock:
ffffbf4ddb44ca40 (fs_reclaim){+.+.}-{0:0}, at:
balance_pgdat (mm/vmscan.c:7236 (discriminator 2))

which lock already depends on the new lock.

the existing dependency chain (in reverse order) is:

-> #2 (fs_reclaim){+.+.}-{0:0}:

lock_acquire (kernel/locking/lockdep.c:5868 kernel/locking/lockdep.c:5825)
fs_reclaim_acquire (mm/page_alloc.c:4325 mm/page_alloc.c:4339)
dma_resv_lockdep (drivers/dma-buf/dma-resv.c:798)
do_one_initcall (init/main.c:1392)
kernel_init_freeable (init/main.c:1454 (discriminator 1) init/main.c:1470
  (discriminator 1) init/main.c:1490 (discriminator 1) init/main.c:1703
  (discriminator 1))

kernel_init (init/main.c:1593)
ret_from_fork (arch/arm64/kernel/entry.S:858)

-> #1 (reservation_ww_class_mutex){+.+.}-{4:4}:

lock_acquire (kernel/locking/lockdep.c:5868 kernel/locking/lockdep.c:5825)
dma_resv_lockdep (./include/linux/ww_mutex.h:164 (discriminator 1)
  drivers/dma-buf/dma-resv.c:791 (discriminator 1))
do_one_initcall (init/main.c:1392)
kernel_init_freeable (init/main.c:1454 (discriminator 1) init/main.c:1470
  (discriminator 1) init/main.c:1490 (discriminator 1) init/main.c:1703
  (discriminator 1))

kernel_init (init/main.c:1593)
ret_from_fork (arch/arm64/kernel/entry.S:858)

Quoted 7 lines

-> #0 (reservation_ww_class_acquire){+.+.}-{0:0}:
check_prev_add (kernel/locking/lockdep.c:3165)

__lock_acquire (kernel/locking/lockdep.c:3284
  kernel/locking/lockdep.c:3908 kernel/locking/lockdep.c:5237)
lock_acquire (kernel/locking/lockdep.c:5868 kernel/locking/lockdep.c:5825)
drm_gem_lru_scan (./include/linux/ww_mutex.h:163 (discriminator 1)
  drivers/gpu/drm/drm_gem.c:1681 (discriminator 1))

Your line #s don't quite match mine, but AFAICT this is from the ww_acquire_init()

What I'm unsure about is if this could cause live-lock against another operation which requires obtaining both obj and vm locks in a potentially different order (which would also be using a ww_acquire_ctx ticket to backoff in case of conflicting locking order). It wouldn't deadlock because we don't sleep forever if we do sleep, but...

Quoted 4 lines

Possibly we should also be using trylock to also acquire the vm lock, but lockdep would still complain as it doesn't know the ticket will be only used w/ trylock (unless we did something hacky by using a different ww_class?)

FWIW, we started using a ticket in the initial version of the Panthor shrinker, and ditched it at some point because of these unsolvable lock ordering issues. It also seems to me that trylock-all-the-way is the right solution, and if we trylock and back off + immediately move to the next BO if any lock is already held, the ticket approach is not as useful, because we're not going to use the retry mechanism provided by ww_mutex anyway.

Quoted 9 lines

It's true that it does the bookkeeping, which simplifies the rollback procedure, but if you look at the other locks taken in the shrinker path, they are static (one per-component involved in reclaim) for most of them, meaning the rollback is pretty straightforward. The only exception is the VM lock (one per vm_bo in case of shared BOs). In panthor, we just decided to open-code this rollback logic (see panthor_gem_try_evict_no_resv_wait() [1]) instead of teaching ww_mutex about non-blocking locks when a ticket is provided. Not saying this is the best option, but it works...

hmm, ok.. and if we block waiting for BO that is before grabbing the vm locks so no live-lock concern (sry, been a while since I've looked at this).. So I guess trylock is maybe the better approach. In this case we should drop the ticket arg (basically revert commit 02070f049875 ("drm/gem: Add ww_acquire_ctx support to drm_gem_lru_scan()"))

BR,
-R

Quoted 5 lines

Regards,

Boris

[1]https://gitlab.freedesktop.org/drm/misc/kernel/-/blob/drm-misc-next/drivers/gpu/drm/panthor/panthor_gem.c?ref_type=heads#L1425

#4 lore raw
Quoted 89 lines · Rob Clark
Quoted 76 lines · Boris Brezillon

Hi,

Quoted 57 lines · On Sat, 9 May 2026 08:34:15 -0700 Rob Clark <[email protected]> wrote:
Quoted 38 lines · Daniel J Blueman

With PROVE_LOCKING on an Snapdragon X1 and VM reclaim pressure, we see:

"""
kswapd0/121 is trying to acquire lock:
ffff800080ed3800 (reservation_ww_class_acquire){+.+.}-{0:0}, at:
msm_gem_shrinker_scan (drivers/gpu/drm/msm/msm_gem_shrinker.c:189)

but task is already holding lock:
ffffbf4ddb44ca40 (fs_reclaim){+.+.}-{0:0}, at:
balance_pgdat (mm/vmscan.c:7236 (discriminator 2))

which lock already depends on the new lock.

the existing dependency chain (in reverse order) is:

-> #2 (fs_reclaim){+.+.}-{0:0}:

lock_acquire (kernel/locking/lockdep.c:5868 kernel/locking/lockdep.c:5825)
fs_reclaim_acquire (mm/page_alloc.c:4325 mm/page_alloc.c:4339)
dma_resv_lockdep (drivers/dma-buf/dma-resv.c:798)
do_one_initcall (init/main.c:1392)
kernel_init_freeable (init/main.c:1454 (discriminator 1) init/main.c:1470
  (discriminator 1) init/main.c:1490 (discriminator 1) init/main.c:1703
  (discriminator 1))

kernel_init (init/main.c:1593)
ret_from_fork (arch/arm64/kernel/entry.S:858)

-> #1 (reservation_ww_class_mutex){+.+.}-{4:4}:

lock_acquire (kernel/locking/lockdep.c:5868 kernel/locking/lockdep.c:5825)
dma_resv_lockdep (./include/linux/ww_mutex.h:164 (discriminator 1)
  drivers/dma-buf/dma-resv.c:791 (discriminator 1))
do_one_initcall (init/main.c:1392)
kernel_init_freeable (init/main.c:1454 (discriminator 1) init/main.c:1470
  (discriminator 1) init/main.c:1490 (discriminator 1) init/main.c:1703
  (discriminator 1))

kernel_init (init/main.c:1593)
ret_from_fork (arch/arm64/kernel/entry.S:858)

Quoted 7 lines

-> #0 (reservation_ww_class_acquire){+.+.}-{0:0}:
check_prev_add (kernel/locking/lockdep.c:3165)

__lock_acquire (kernel/locking/lockdep.c:3284
  kernel/locking/lockdep.c:3908 kernel/locking/lockdep.c:5237)
lock_acquire (kernel/locking/lockdep.c:5868 kernel/locking/lockdep.c:5825)
drm_gem_lru_scan (./include/linux/ww_mutex.h:163 (discriminator 1)
  drivers/gpu/drm/drm_gem.c:1681 (discriminator 1))

Your line #s don't quite match mine, but AFAICT this is from the ww_acquire_init()

What I'm unsure about is if this could cause live-lock against another operation which requires obtaining both obj and vm locks in a potentially different order (which would also be using a ww_acquire_ctx ticket to backoff in case of conflicting locking order). It wouldn't deadlock because we don't sleep forever if we do sleep, but...

Quoted 4 lines

Possibly we should also be using trylock to also acquire the vm lock, but lockdep would still complain as it doesn't know the ticket will be only used w/ trylock (unless we did something hacky by using a different ww_class?)

FWIW, we started using a ticket in the initial version of the Panthor shrinker, and ditched it at some point because of these unsolvable lock ordering issues. It also seems to me that trylock-all-the-way is the right solution, and if we trylock and back off + immediately move to the next BO if any lock is already held, the ticket approach is not as useful, because we're not going to use the retry mechanism provided by ww_mutex anyway.

Quoted 9 lines

It's true that it does the bookkeeping, which simplifies the rollback procedure, but if you look at the other locks taken in the shrinker path, they are static (one per-component involved in reclaim) for most of them, meaning the rollback is pretty straightforward. The only exception is the VM lock (one per vm_bo in case of shared BOs). In panthor, we just decided to open-code this rollback logic (see panthor_gem_try_evict_no_resv_wait() [1]) instead of teaching ww_mutex about non-blocking locks when a ticket is provided. Not saying this is the best option, but it works...

Quoted 6 lines

hmm, ok.. and if we block waiting for BO that is before grabbing the vm locks so no live-lock concern (sry, been a while since I've looked at this).. So I guess trylock is maybe the better approach. In this case we should drop the ticket arg (basically revert commit 02070f049875 ("drm/gem: Add ww_acquire_ctx support to drm_gem_lru_scan()"))

I'll pull this into msm-fixes. I've fixed a compile error with the original patch (and replaced the lockdep splat with something legible... somehow whitespace was swallowed with the original).

For next cycle I'll send a cleanup to drop the now unused ticket arg for drm_gem_lru_scan()

BR,
-R

Quoted 8 lines

BR,
-R

Quoted 5 lines

Regards,

Boris

[1]https://gitlab.freedesktop.org/drm/misc/kernel/-/blob/drm-misc-next/drivers/gpu/drm/panthor/panthor_gem.c?ref_type=heads#L1425