Re: [PATCH 1/8] mm: introduce for_each_process_rcu and for_each_thread_rcu
From: Thomas Gleixner
Date: Fri Sep 04 2026 - 17:18:08 EST
On Fri, Sep 04 2026 at 12:25, Steven Rostedt wrote:
> On Fri, 4 Sep 2026 16:29:53 +0800
> Ye Liu <ye.liu@xxxxxxxxx> wrote:
>> +#define for_each_thread_rcu(p, t) \
>> + scoped_guard(rcu) \
>> + __for_each_thread((p)->signal, t)
>> +
>
> I would rename it to: *_rculock()
>
> as there are already *_rcu() list iterators that are used to be done within
> an rcu locked region. Using just *_rcu() would make it confusing to know if
> the rcu lock was taken or if the loop is expected to be locked within RCU.
Ack.
>> +/* Careful: this is a double loop, 'break' won't work as expected. */
>> +#define for_each_process_thread_rcu(p, t) \
>> + scoped_guard(rcu) \
>> + for_each_process(p) for_each_thread(p, t)
>
> I would not do this one. It is prone to bugs. As it is a double loop, the
> way to "break" is to do a goto. That will be bug to have a goto jump out of
> a scoped_guard().
No. Scopes can be left by any valid termination mechanism.
The only problematic case of leaving a scoped_guard() with goto is when
the goto is actually implemented as an ASM goto. See the comment above
arch_unsafe_get_user() in linux/uaccess.h.
But I agree that requiring a goto to break out of the nested loop is
nasty especially when it's not well documented. The copied original
comment is pretty useless.
Thanks,
tglx