Skip to content

sched: introduce for_each_process_rculock and for_each_thread_rculock

Ye Liu linux-fsdevel linux-mm linux-pm linux-security-module linux-trace-kernel lkml rcu 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest15 patches 5 repliesIn review
  2. v315 patches 5 repliesSuperseded
  3. v28 patches 38 repliesSuperseded

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/15sched: introduce for_each_process_rculock and for_each_thread_rculockinclude/linux/sched/signal.h+26 -00 replies
2/15mm/oom_kill: convert process/thread iterators to for_each_*_rculockmm/oom_kill.c+5 -151 reply
3/15mm/ksm: convert process iterator to for_each_process_rculockmm/ksm.c+1 -31 reply
4/15mm/memory-failure: convert process iterator to for_each_process_rculockmm/memory-failure.c+4 -120 replies
5/15cpu/hotplug: convert process iterator to for_each_process_rculockkernel/cpu.c+1 -30 replies
6/15freezer: convert thread iterator to for_each_thread_rculockkernel/freezer.c+1 -30 replies
7/15hung_task: convert process/thread iterators to for_each_*_rculockkernel/hung_task.c+4 -70 replies
8/15locking/lockdep: convert process/thread iterators to for_each_*_rculockkernel/locking/lockdep.c+1 -30 replies
9/15rcu: convert process/thread iterator to for_each_process_thread_rculockkernel/rcu/update.c+1 -31 reply
10/15sched: convert process/thread iterators to for_each_*_rculockkernel/sched/core.c kernel/sched/debug.c+2 -50 replies
11/15tracing/fgraph: convert process/thread iterator to for_each_process_thread_rculockkernel/trace/fgraph.c+2 -60 replies
12/15unwind: convert process/thread iterator to for_each_process_thread_rculockkernel/unwind/deferred.c+1 -20 replies
13/15fs: convert process/thread iterators to for_each_*_rculockfs/proc/base.c fs/resctrl/rdtgroup.c+3 -90 replies
14/15lib: convert process iterator to for_each_process_rculocklib/is_single_threaded.c+1 -41 reply
15/15security/landlock: convert thread iterator to for_each_thread_rculocksecurity/landlock/tsync.c+2 -60 replies

Reviews trailers per patch

All 15 patches have a Reviewed-by or Acked-by.

PatchMichal HockoSJ ParkGregory Price (Meta)Oleg NesterovLorenzo Stoakes (ARM)David Hildenbrand (Arm)Miaohe LinSteven RostedtJustin SuessGünther NoackPaul E. McKenney
1/15A-b R-b R-b R-b R-b
2/15A-b R-b R-b R-b R-b
3/15A-b R-b R-b R-b R-b A-b
4/15A-b R-b R-b R-b A-b
5/15A-b R-b R-b R-b
6/15A-b R-b R-b R-b
7/15A-b R-b R-b R-b
8/15A-b R-b R-b R-b
9/15A-b R-b R-b R-b R-b
10/15A-b R-b R-b R-b
11/15A-b R-b R-b R-b A-b
12/15A-b R-b R-b R-b A-b
13/15A-b R-b R-b R-b
14/15A-b R-b R-b R-b R-b
15/15R-b R-b R-b R-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 11 reviewers.

Read the v4 thread

Cover letter [PATCH v4 00/15] sched: introduce for_each_process_rculock and for_each_thread_rculock

From: Ye Liu <[email protected]>

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.

Suggested by Michal Hocko for the oom_kill path [2].

---
Changes since v3 [4]:
- Fix patch 5 (cpu/hotplug): title and commit message incorrectly said "thread iterator" and "for_each_thread_rculock" while the code converts for_each_process() to for_each_process_rculock().

Note: Patches 4, 11, and 13 received automated reviews from sashiko-bot in the v3 thread [4] that were verified as false positives:

- Patch 4: claimed the folio lock is dropped before collect_procs(),

    leading to a NULL deref on folio->mapping; the lock is held in all
    call paths.

- Patch 11: claimed mixing goto/scope-based cleanup in alloc_retstack_tasklist(); the goto free label handles memory cleanup, not lock management.
- Patch 13: claimed mixing goto/scope-based cleanup in __set_oom_adj(); goto err_unlock manages oom_adj_mutex while scoped_guard(rcu) manages the RCU read lock — different resources.

Changes since v2 [3]:
- Split the kernel/ patch into per-subsystem patches, as the combined patch could not be applied (Peter Zijlstra, Steven Rostedt).
- Move changelog below the --- separator so it is excluded from the commit message (Lorenzo Stoakes).
- Indent loop body in macro definitions to show scoped_guard scope (Lorenzo Stoakes).

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).

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/
[4] https://lore.kernel.org/all/[email protected]/

Ye Liu (15):
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
cpu/hotplug: convert process iterator to for_each_process_rculock
freezer: convert thread iterator to for_each_thread_rculock
hung_task: convert process/thread iterators to for_each_*_rculock locking/lockdep: convert process/thread iterators to
for_each_*_rculock
rcu: convert process/thread iterator to
for_each_process_thread_rculock
sched: convert process/thread iterators to for_each_*_rculock tracing/fgraph: convert process/thread iterator to
for_each_process_thread_rculock
unwind: convert process/thread iterator to
for_each_process_thread_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 | 26 ++++++++++++++++++++++++++
 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, 55 insertions(+), 81 deletions(-)

--
2.25.1