Thread (47 messages) flat view 47 messages, 9 authors, 4d ago

Re: [PATCH v2 5/8] kernel: convert process/thread iterators to for_each_*_rculock

From: Peter Zijlstra <peterz@infradead.org>
Date: 2026-09-08 07:51:15
Also in: linux-fsdevel, linux-mm, linux-security-module, linux-trace-kernel, lkml, rcu

On Mon, Sep 07, 2026 at 11:53:51AM -0400, Gregory Price wrote:
On Mon, Sep 07, 2026 at 04:13:31PM +0800, Ye Liu wrote:
quoted
From: Ye Liu <liuye@kylinos.cn>

Replace the manual rcu_read_lock()/rcu_read_unlock() and guard(rcu)
pairs combined with for_each_process(), for_each_thread() and
for_each_process_thread() loops across kernel/ with the
for_each_*_rculock() macros, which scope the RCU read lock to the
loop body via scoped_guard(rcu).

No functional change.

Signed-off-by: Ye Liu <liuye@kylinos.cn>
Acked-by: Michal Hocko <mhocko@suse.com>
Question below
quoted
diff --git a/kernel/hung_task.c b/kernel/hung_task.c
index 6fcc94ce4ca9..73a5ad3be9a8 100644
--- a/kernel/hung_task.c
+++ b/kernel/hung_task.c
@@ -315,13 +315,12 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout)
 		return;
 
 	this_round_count = 0;
-	rcu_read_lock();
-	for_each_process_thread(g, t) {
+	for_each_process_thread_rculock(g, t) {
 		if (!max_count--)
-			goto unlock;
+			goto out;
... snip ...
quoted
- unlock:
-	rcu_read_unlock();
-
+out:
 	if (!this_round_count)
 		return;
 
The sunken rcu_read_lock()/unlock() + scoped_guard usage makes this goto
at a minimum very confusing, if not actually broken.
You can use goto to exit a scope, that's fine. Using goto to enter a
scope is not (clang will error on that).

Just don't use computed goto, that goes sideways real quick.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help