FAILED: patch "[PATCH] mm/shrinker: do not hold RCU lock in" failed to apply to 6.1-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.1-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.1.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 '2026071318-kindling-retrial-f9b4@gregkh' --subject-prefix 'PATCH 6.1.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
@@ -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; }
Sasha Levin
maintainerPATCH 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.
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
@@ -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
Sasha Levin
maintainerPATCH 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
@@ -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