[PATCH v3 07/15] hung_task: convert process/thread iterators to for_each_*_rculock

From: Ye Liu

Date: Fri Sep 11 2026 - 04:16:33 EST


From: Ye Liu <liuye@xxxxxxxxxx>

Replace the manual rcu_read_lock()/rcu_read_unlock() pair combined
with for_each_process_thread() loop in kernel/hung_task.c with
for_each_process_thread_rculock(), which scopes the RCU read lock
to the loop body via scoped_guard(rcu).

No functional change.

Signed-off-by: Ye Liu <liuye@xxxxxxxxxx>
Acked-by: Michal Hocko <mhocko@xxxxxxxx>
Reviewed-by: SJ Park <sj@xxxxxxxxxx>
Reviewed-by: Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx>
Reviewed-by: Oleg Nesterov <oleg@xxxxxxxxxx>
---
Changes in v3:
- Split from kernel/ patch in v2 (Peter Zijlstra, Steven Rostedt)

Changes in v2:
- Rename *_rcu to *_rculock
- Rename stale 'unlock:' label to 'out:' in hung_task.c (Günther Noack)
kernel/hung_task.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)

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;
if (time_after(jiffies, last_break + HUNG_TASK_LOCK_BREAK)) {
if (!rcu_lock_break(g, t))
- goto unlock;
+ goto out;
last_break = jiffies;
}

@@ -337,9 +336,7 @@ static void check_hung_uninterruptible_tasks(unsigned long timeout)
hung_task_info(t, timeout, this_round_count);
}
}
- unlock:
- rcu_read_unlock();
-
+out:
if (!this_round_count)
return;

--
2.25.1