Re: [PATCH v2 0/8] sched: introduce for_each_process_rculock and for_each_thread_rculock
From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
Date: 2026-09-07 08:26:20
Also in:
linux-fsdevel, linux-mm, linux-pm, linux-trace-kernel, lkml, rcu
On Mon, Sep 07, 2026 at 04:13:26PM +0800, Ye Liu wrote:
From: Ye Liu <liuye@kylinos.cn> Introduce for_each_process_rculock(), for_each_thread_rculock() and for_each_process_thread_rculock() macros that combine the existing iteration macros with scoped_guard(rcu), so that the RCU read lock is automatically acquired before iteration and released when the loop exits — including via break, goto, or return. The rest of the series converts manual rcu_read_lock()/ rcu_read_unlock() and guard(rcu)() pairs across mm/, kernel/, fs/, lib/ and security/ to use the new macros.
Andrew - just a note (assuming Ye Liu is in agreement) I think all of the below should be excluded from the cover letter that goes into the commit message, including the checkpatch thing.
Changes since v1 [1]:
- Rename macros from *_rcu to *_rculock, as suggested by Steven
Rostedt and acked by Thomas Gleixner, to avoid confusion with
existing *_rcu() list iterators that expect the caller to hold
the RCU read lock.
- Improve the comment on for_each_process_thread_rculock() to
document that 'break' only exits the inner loop and 'goto' is
needed to exit both loops (Thomas Gleixner).
- Rename the stale 'unlock:' label to 'out:' in hung_task.c, as
noted by Günther Noack.
- Clarify in patch 4 that page_pgoff() is safe outside the RCU
read-side critical section (SJ Park).
- CC all relevant maintainers on every patch (Lorenzo Stoakes).
- Drop the mm: prefix from patch 1, as the macros are in
include/linux/sched/signal.h (Michal Hocko).
Patch 1 may trigger checkpatch "Macros with complex values should be
enclosed in parentheses" errors. These are false positives — the
scoped_guard() pattern is a control-flow construct, not a multi-
statement macro, and the same idiom is used elsewhere in the kernel.While it's useful as a note to reviewers, in general checkpatch is taken with a pinch of salt - it's a master of false positives so usually no need to say this :)
Suggested by Michal Hocko for the oom_kill path [2]. [1] https://lore.kernel.org/all/20260904083001.553587-1-ye.liu@linux.dev/ (local) [2] https://lore.kernel.org/all/20260813092933.562028-1-ye.liu@linux.dev/ (local) Ye Liu (8): sched: introduce for_each_process_rculock and for_each_thread_rculock mm/oom_kill: convert process/thread iterators to for_each_*_rculock mm/ksm: convert process iterator to for_each_process_rculock mm/memory-failure: convert process iterator to for_each_process_rculock kernel: convert process/thread iterators to for_each_*_rculock fs: convert process/thread iterators to for_each_*_rculock lib: convert process iterator to for_each_process_rculock security/landlock: convert thread iterator to for_each_thread_rculock fs/proc/base.c | 4 +--- fs/resctrl/rdtgroup.c | 8 ++------ include/linux/sched/signal.h | 25 +++++++++++++++++++++++++ kernel/cpu.c | 4 +--- kernel/freezer.c | 4 +--- kernel/hung_task.c | 11 ++++------- kernel/locking/lockdep.c | 4 +--- kernel/rcu/update.c | 4 +--- kernel/sched/core.c | 3 +-- kernel/sched/debug.c | 4 +--- kernel/trace/fgraph.c | 8 ++------ kernel/unwind/deferred.c | 3 +-- lib/is_single_threaded.c | 5 +---- mm/ksm.c | 4 +--- mm/memory-failure.c | 16 ++++------------ mm/oom_kill.c | 20 +++++--------------- security/landlock/tsync.c | 8 ++------ 17 files changed, 54 insertions(+), 81 deletions(-) Signed-off-by: Ye Liu <liuye@kylinos.cn> -- 2.25.1
-- Cheers, Lorenzo