Re: [PATCH 0/2] introduce __next_thread(), change next_thread()

From: Oleg Nesterov
Date: Fri Aug 25 2023 - 09:40:22 EST


On 08/25, Eric W. Biederman wrote:
>
> Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> writes:
>
> > One of the main users is while_each_thread(), which certainly wants
> > that NULL case, both for an easier loop condition, but also because
> > the only user that uses the 't' pointer after the loop is
> > fs/proc/base.c, which wants it to be NULL.
>
> Sort of.
>
> I have found 3 loops that want to loop through all of the threads of
> a process starting with the current thread.
>
> The loop in do_wait.
> The loop finding the thread to signal in complete_signal.
> The loop in retarget_shared_pending finding which threads
> to wake up.

Yes, plus check_unsafe_exec() and zap_other_threads() which want to
skip the initial thread.

> > And kernel/bpf/task_iter.c seems to *expect* NULL at the end?

Yes. I'll (try to) send the patches today. This code needs cleanups
first.

> > End result: if you're changing next_thread() anyway, please just
> > change it to be a completely new thing that returns NULL at the end,
> > which is what everybody really seems to want, and don't add a new
> > __next_thread() helper. Ok?
>
> So I would say Oleg please build the helper that do_wait wants
> and use it in do_wait, complete_signal, and retarget_shared_pending.

Later. But so far I am not 100% sure this makes sense... I guess we
will need to discuss this again.

> Change the rest of the loops can use for_each_thread (skipping
> the current task if needed) or for_each_process_thread.

Yes, I was going to do this.

> Change next_thread to be your __next_thread, and update the 2 callers
> appropriately.

But I can't do this until I change the current users of next_thread()
and while_each_thread().

Oleg.