* [PATCH 0/8] mm: introduce for_each_process_rcu and for_each_thread_rcu
@ 2026-09-04 8:29 Ye Liu
2026-09-04 8:30 ` [PATCH 8/8] security/landlock: convert thread iterator to for_each_thread_rcu Ye Liu
0 siblings, 1 reply; 4+ messages in thread
From: Ye Liu @ 2026-09-04 8:29 UTC (permalink / raw)
To: Andrew Morton, Michal Hocko, Peter Zijlstra, Paul E. McKenney,
Ingo Molnar, Steven Rostedt, Josh Poimboeuf,
Mickaël Salaün
Cc: Ye Liu, David Hildenbrand, Miaohe Lin, Naoya Horiguchi,
Rafael J. Wysocki, linux-mm, linux-kernel, linux-pm, rcu,
linux-trace-kernel, linux-fsdevel, linux-security-module,
Günther Noack
From: Ye Liu <liuye@kylinos.cn>
Introduce for_each_process_rcu(), for_each_thread_rcu() and
for_each_process_thread_rcu() 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.
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.
Suggested by Michal Hocko for the oom_kill path [1].
[1] https://lore.kernel.org/all/20260813092933.562028-1-ye.liu@linux.dev/
Ye Liu (8):
mm: introduce for_each_process_rcu and for_each_thread_rcu
mm/oom_kill: convert process/thread iterators to for_each_*_rcu
mm/ksm: convert process iterator to for_each_process_rcu
mm/memory-failure: convert process iterator to for_each_process_rcu
kernel: convert process/thread iterators to for_each_*_rcu
fs: convert process/thread iterators to for_each_*_rcu
lib: convert process iterator to for_each_process_rcu
security/landlock: convert thread iterator to for_each_thread_rcu
fs/proc/base.c | 4 +---
fs/resctrl/rdtgroup.c | 8 ++------
include/linux/sched/signal.h | 19 +++++++++++++++++++
kernel/cpu.c | 4 +---
kernel/freezer.c | 4 +---
kernel/hung_task.c | 7 ++-----
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, 46 insertions(+), 79 deletions(-)
Signed-off-by: Ye Liu <liuye@kylinos.cn>
--
2.25.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 8/8] security/landlock: convert thread iterator to for_each_thread_rcu
2026-09-04 8:29 [PATCH 0/8] mm: introduce for_each_process_rcu and for_each_thread_rcu Ye Liu
@ 2026-09-04 8:30 ` Ye Liu
2026-09-04 12:21 ` Justin Suess
2026-09-04 14:17 ` Günther Noack
0 siblings, 2 replies; 4+ messages in thread
From: Ye Liu @ 2026-09-04 8:30 UTC (permalink / raw)
To: Mickaël Salaün, Paul Moore, James Morris,
Serge E. Hallyn
Cc: Ye Liu, Günther Noack, linux-security-module, linux-kernel
From: Ye Liu <liuye@kylinos.cn>
Replace guard(rcu)() + for_each_thread() with for_each_thread_rcu(),
so that the RCU read-side critical section is scoped to the loop body.
No functional change.
Signed-off-by: Ye Liu <liuye@kylinos.cn>
---
security/landlock/tsync.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/security/landlock/tsync.c b/security/landlock/tsync.c
index 0b71e158c3f5..f1c08aae179b 100644
--- a/security/landlock/tsync.c
+++ b/security/landlock/tsync.c
@@ -335,9 +335,7 @@ static size_t count_additional_threads(const struct tsync_works *works)
caller = current;
- guard(rcu)();
-
- for_each_thread(caller, thread) {
+ for_each_thread_rcu(caller, thread) {
/* Skip current, since it is initiating the sync. */
if (thread == caller)
continue;
@@ -376,9 +374,7 @@ static bool schedule_task_work(struct tsync_works *works,
caller = current;
- guard(rcu)();
-
- for_each_thread(caller, thread) {
+ for_each_thread_rcu(caller, thread) {
/* Skip current, since it is initiating the sync. */
if (thread == caller)
continue;
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 8/8] security/landlock: convert thread iterator to for_each_thread_rcu
2026-09-04 8:30 ` [PATCH 8/8] security/landlock: convert thread iterator to for_each_thread_rcu Ye Liu
@ 2026-09-04 12:21 ` Justin Suess
2026-09-04 14:17 ` Günther Noack
1 sibling, 0 replies; 4+ messages in thread
From: Justin Suess @ 2026-09-04 12:21 UTC (permalink / raw)
To: Ye Liu
Cc: Mickaël Salaün, Paul Moore, James Morris,
Serge E. Hallyn, Ye Liu, Günther Noack,
linux-security-module, linux-kernel
On Fri, Sep 04, 2026 at 04:30:00PM +0800, Ye Liu wrote:
> From: Ye Liu <liuye@kylinos.cn>
>
> Replace guard(rcu)() + for_each_thread() with for_each_thread_rcu(),
> so that the RCU read-side critical section is scoped to the loop body.
>
> No functional change.
>
> Signed-off-by: Ye Liu <liuye@kylinos.cn>
> ---
> security/landlock/tsync.c | 8 ++------
> 1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/security/landlock/tsync.c b/security/landlock/tsync.c
> index 0b71e158c3f5..f1c08aae179b 100644
> --- a/security/landlock/tsync.c
> +++ b/security/landlock/tsync.c
> @@ -335,9 +335,7 @@ static size_t count_additional_threads(const struct tsync_works *works)
>
> caller = current;
>
> - guard(rcu)();
> -
> - for_each_thread(caller, thread) {
> + for_each_thread_rcu(caller, thread) {
> /* Skip current, since it is initiating the sync. */
> if (thread == caller)
> continue;
> @@ -376,9 +374,7 @@ static bool schedule_task_work(struct tsync_works *works,
>
> caller = current;
>
> - guard(rcu)();
> -
> - for_each_thread(caller, thread) {
> + for_each_thread_rcu(caller, thread) {
> /* Skip current, since it is initiating the sync. */
> if (thread == caller)
> continue;
Reviewed-by: Justin Suess <utilityemal77@gmail.com>
> --
> 2.25.1
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 8/8] security/landlock: convert thread iterator to for_each_thread_rcu
2026-09-04 8:30 ` [PATCH 8/8] security/landlock: convert thread iterator to for_each_thread_rcu Ye Liu
2026-09-04 12:21 ` Justin Suess
@ 2026-09-04 14:17 ` Günther Noack
1 sibling, 0 replies; 4+ messages in thread
From: Günther Noack @ 2026-09-04 14:17 UTC (permalink / raw)
To: Ye Liu
Cc: Mickaël Salaün, Paul Moore, James Morris,
Serge E. Hallyn, Ye Liu, Günther Noack,
linux-security-module, linux-kernel
On Fri, Sep 04, 2026 at 04:30:00PM +0800, Ye Liu wrote:
> From: Ye Liu <liuye@kylinos.cn>
>
> Replace guard(rcu)() + for_each_thread() with for_each_thread_rcu(),
> so that the RCU read-side critical section is scoped to the loop body.
>
> No functional change.
>
> Signed-off-by: Ye Liu <liuye@kylinos.cn>
> ---
> security/landlock/tsync.c | 8 ++------
> 1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/security/landlock/tsync.c b/security/landlock/tsync.c
> index 0b71e158c3f5..f1c08aae179b 100644
> --- a/security/landlock/tsync.c
> +++ b/security/landlock/tsync.c
> @@ -335,9 +335,7 @@ static size_t count_additional_threads(const struct tsync_works *works)
>
> caller = current;
>
> - guard(rcu)();
> -
> - for_each_thread(caller, thread) {
> + for_each_thread_rcu(caller, thread) {
> /* Skip current, since it is initiating the sync. */
> if (thread == caller)
> continue;
> @@ -376,9 +374,7 @@ static bool schedule_task_work(struct tsync_works *works,
>
> caller = current;
>
> - guard(rcu)();
> -
> - for_each_thread(caller, thread) {
> + for_each_thread_rcu(caller, thread) {
> /* Skip current, since it is initiating the sync. */
> if (thread == caller)
> continue;
> --
> 2.25.1
>
Reviewed-by: Günther Noack <gnoack3000@gmail.com>
Looks good, provided that the for_each_thread_rcu() macro gets
accepted.
Although, I find that in the Landlock case, it does not provide a very
strong advantage over the explicit "guard(rcu)();", and I find it
normally preferrable to use orthogonal APIs.
–Günther
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-09-04 14:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-04 8:29 [PATCH 0/8] mm: introduce for_each_process_rcu and for_each_thread_rcu Ye Liu
2026-09-04 8:30 ` [PATCH 8/8] security/landlock: convert thread iterator to for_each_thread_rcu Ye Liu
2026-09-04 12:21 ` Justin Suess
2026-09-04 14:17 ` Günther Noack
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox