Skip to contentSkip to conversation

FAILED: patch "[PATCH] mm/shrinker: do not hold RCU lock in" failed to apply to 6.6-stable tree

PATCH New [email protected] 2 participants 3 messages Jul 13 – Jul 15

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x b902890c62d200b3509cb5e09cf1e0a66553c128
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026071317-sandfish-tulip-2010@gregkh' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'

Possible dependencies:

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From b902890c62d200b3509cb5e09cf1e0a66553c128 Mon Sep 17 00:00:00 2001
From: Shakeel Butt <[email protected]>
Date: Wed, 10 Jun 2026 16:20:48 -0700
Subject: [PATCH] mm/shrinker: do not hold RCU lock in
shrinker_debugfs_count_show()

Reading the debugfs "count" file of a memcg-aware shrinker can sleep inside an RCU read-side critical section:

  BUG: sleeping function called from invalid context at kernel/cgroup/rstat.c:421
  RCU nest depth: 1, expected: 0
   css_rstat_flush
   mem_cgroup_flush_stats
   zswap_shrinker_count
   shrinker_debugfs_count_show

shrinker_debugfs_count_show() invokes the ->count_objects() callback under rcu_read_lock(). The zswap callback flushes memcg stats via css_rstat_flush(), which may sleep, so it must not run under RCU.

The RCU lock is not needed here. mem_cgroup_iter() takes RCU internally and returns a memcg holding a css reference (dropped on the next iteration or by mem_cgroup_iter_break()), so the memcg stays alive without it. The shrinker is kept alive by the open debugfs file: shrinker_free() removes the debugfs entries via debugfs_remove_recursive(), which waits for in-flight readers to drain, before call_rcu(..., shrinker_free_rcu_cb). The sibling "scan" handler already invokes the sleeping ->scan_objects() callback with no RCU section.

Drop the rcu_read_lock()/rcu_read_unlock().

mm/shrinker_debug.c +0 -4
index affa64437302..cda4e86428c8 100644
@@ -57,8 +57,6 @@ static int shrinker_debugfs_count_show(struct seq_file *m, void *v)
 	if (!count_per_node)
 		return -ENOMEM;
 
-	rcu_read_lock();
-
 	memcg_aware = shrinker->flags & SHRINKER_MEMCG_AWARE;
 
 	memcg = mem_cgroup_iter(NULL, NULL, NULL);
@@ -88,8 +86,6 @@ static int shrinker_debugfs_count_show(struct seq_file *m, void *v)
 		}
 	} while ((memcg = mem_cgroup_iter(NULL, memcg, NULL)) != NULL);
 
-	rcu_read_unlock();
-
 	kfree(count_per_node);
 	return ret;
 }
maintainer
#1 lore raw

PATCH 1/2 mm: shrinker: remove redundant shrinker_rwsem in debugfs operations

From: Qi Zheng <[email protected]>

[ Upstream commit 1dd49e58f966b1eecd935dc28458a8369ae94ad1 ]

debugfs_remove_recursive() will wait for debugfs_file_put() to return, so the shrinker will not be freed when doing debugfs operations (such as shrinker_debugfs_count_show() and shrinker_debugfs_scan_write()), so there is no need to hold shrinker_rwsem during debugfs operations.

Cc Christian Brauner <[email protected]>
Cc Christian König <[email protected]>
Cc Chuck Lever <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Darrick J. Wong <[email protected]>
Cc Dave Chinner <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Joel Fernandes <[email protected]>
Cc Kirill Tkhai <[email protected]>
Cc Paul E. McKenney <[email protected]>
Cc Roman Gushchin <[email protected]>
Cc Sergey Senozhatsky <[email protected]>
Cc Steven Price <[email protected]>
Cc Theodore Ts'o <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Abhinav Kumar <[email protected]>
Cc Alasdair Kergon <[email protected]>
Cc Alexander Viro <[email protected]>
Cc Alyssa Rosenzweig <[email protected]>
Cc Andreas Dilger <[email protected]>
Cc Andreas Gruenbacher <[email protected]>
Cc Anna Schumaker <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Bob Peterson <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Carlos Llamas <[email protected]>
Cc Chandan Babu R <[email protected]>
Cc Chao Yu <[email protected]>
Cc Chris Mason <[email protected]>
Cc Coly Li <[email protected]>
Cc Dai Ngo <[email protected]>
Cc Dave Hansen <[email protected]>
Cc David Airlie <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc David Sterba <[email protected]>
Cc Dmitry Baryshkov <[email protected]>
Cc Gao Xiang <[email protected]>
Cc Huang Rui <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Jaegeuk Kim <[email protected]>
Cc Jani Nikula <[email protected]>
Cc Jan Kara <[email protected]>
Cc Jason Wang <[email protected]>
Cc Jeff Layton <[email protected]>
Cc Jeffle Xu <[email protected]>
Cc Joonas Lahtinen <[email protected]>
Cc Josef Bacik <[email protected]>
Cc Juergen Gross <[email protected]>
Cc Kent Overstreet <[email protected]>
Cc Marijn Suijten <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Cc Mike Snitzer <[email protected]>
Cc Minchan Kim <[email protected]>
Cc Muchun Song <[email protected]>
Cc Nadav Amit <[email protected]>
Cc Neil Brown <[email protected]>
Cc Oleksandr Tyshchenko <[email protected]>
Cc Olga Kornievskaia <[email protected]>
Cc Richard Weinberger <[email protected]>
Cc Rob Clark <[email protected]>
Cc Rob Herring <[email protected]>
Cc Rodrigo Vivi <[email protected]>
Cc Sean Paul <[email protected]>
Cc Song Liu <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Tomeu Vizoso <[email protected]>
Cc Tom Talpey <[email protected]>
Cc Trond Myklebust <[email protected]>
Cc Tvrtko Ursulin <[email protected]>
Cc Xuan Zhuo <[email protected]>
Cc Yue Hu <[email protected]>

Stable-dep-of: b902890c62d2 ("mm/shrinker: do not hold RCU lock in shrinker_debugfs_count_show()")

---
 mm/shrinker_debug.c | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)
mm/shrinker_debug.c +1 -15
index 3ab53fad8876ea..61702bdc1af48d 100644
@@ -49,17 +49,12 @@ static int shrinker_debugfs_count_show(struct seq_file *m, void *v)
 	struct mem_cgroup *memcg;
 	unsigned long total;
 	bool memcg_aware;
-	int ret, nid;
+	int ret = 0, nid;
 
 	count_per_node = kcalloc(nr_node_ids, sizeof(unsigned long), GFP_KERNEL);
 	if (!count_per_node)
 		return -ENOMEM;
 
-	ret = down_read_killable(&shrinker_rwsem);
-	if (ret) {
-		kfree(count_per_node);
-		return ret;
-	}
 	rcu_read_lock();
 
 	memcg_aware = shrinker->flags & SHRINKER_MEMCG_AWARE;
@@ -92,7 +87,6 @@ static int shrinker_debugfs_count_show(struct seq_file *m, void *v)
 	} while ((memcg = mem_cgroup_iter(NULL, memcg, NULL)) != NULL);
 
 	rcu_read_unlock();
-	up_read(&shrinker_rwsem);
 
 	kfree(count_per_node);
 	return ret;
@@ -117,7 +111,6 @@ static ssize_t shrinker_debugfs_scan_write(struct file *file,
 	struct mem_cgroup *memcg = NULL;
 	int nid;
 	char kbuf[72];
-	ssize_t ret;
 
 	read_len = size < (sizeof(kbuf) - 1) ? size : (sizeof(kbuf) - 1);
 	if (copy_from_user(kbuf, buf, read_len))
@@ -146,12 +139,6 @@ static ssize_t shrinker_debugfs_scan_write(struct file *file,
 		return -EINVAL;
 	}
 
-	ret = down_read_killable(&shrinker_rwsem);
-	if (ret) {
-		mem_cgroup_put(memcg);
-		return ret;
-	}
-
 	sc.nid = nid;
 	sc.memcg = memcg;
 	sc.nr_to_scan = nr_to_scan;
@@ -159,7 +146,6 @@ static ssize_t shrinker_debugfs_scan_write(struct file *file,
 
 	shrinker->scan_objects(shrinker, &sc);
 
-	up_read(&shrinker_rwsem);
 	mem_cgroup_put(memcg);
 
 	return size;
Signature · 1 line
2.53.0
maintainer
#2 lore raw

PATCH 2/2 mm/shrinker: do not hold RCU lock in shrinker_debugfs_count_show()

From: Shakeel Butt <[email protected]>

[ Upstream commit b902890c62d200b3509cb5e09cf1e0a66553c128 ]

Reading the debugfs "count" file of a memcg-aware shrinker can sleep inside an RCU read-side critical section:

  BUG: sleeping function called from invalid context at kernel/cgroup/rstat.c:421
  RCU nest depth: 1, expected: 0
   css_rstat_flush
   mem_cgroup_flush_stats
   zswap_shrinker_count
   shrinker_debugfs_count_show

shrinker_debugfs_count_show() invokes the ->count_objects() callback under rcu_read_lock(). The zswap callback flushes memcg stats via css_rstat_flush(), which may sleep, so it must not run under RCU.

The RCU lock is not needed here. mem_cgroup_iter() takes RCU internally and returns a memcg holding a css reference (dropped on the next iteration or by mem_cgroup_iter_break()), so the memcg stays alive without it. The shrinker is kept alive by the open debugfs file: shrinker_free() removes the debugfs entries via debugfs_remove_recursive(), which waits for in-flight readers to drain, before call_rcu(..., shrinker_free_rcu_cb). The sibling "scan" handler already invokes the sleeping ->scan_objects() callback with no RCU section.

Drop the rcu_read_lock()/rcu_read_unlock().

---
 mm/shrinker_debug.c | 4 ----
 1 file changed, 4 deletions(-)
mm/shrinker_debug.c +0 -4
index 61702bdc1af48d..56b1e3a5020dd5 100644
@@ -55,8 +55,6 @@ static int shrinker_debugfs_count_show(struct seq_file *m, void *v)
 	if (!count_per_node)
 		return -ENOMEM;
 
-	rcu_read_lock();
-
 	memcg_aware = shrinker->flags & SHRINKER_MEMCG_AWARE;
 
 	memcg = mem_cgroup_iter(NULL, NULL, NULL);
@@ -86,8 +84,6 @@ static int shrinker_debugfs_count_show(struct seq_file *m, void *v)
 		}
 	} while ((memcg = mem_cgroup_iter(NULL, memcg, NULL)) != NULL);
 
-	rcu_read_unlock();
-
 	kfree(count_per_node);
 	return ret;
 }
Signature · 1 line
2.53.0