Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

change next_thread() to use __next_thread() ?: group_leader

This relies on fact that group leader is always the 1st entry in the
signal->thread_head list.

With or without this change, if the lockless next_thread(last_thread)
races with exec it can return the old or the new leader.

We are almost ready to kill task->thread_group, after this change its
only user is thread_group_empty().

Link: https://lkml.kernel.org/r/20230824143201.GB31222@redhat.com
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Oleg Nesterov and committed by
Andrew Morton
d639cf4a 33a98138

+2 -3
+2 -3
include/linux/sched/signal.h
··· 726 726 thread_node); 727 727 } 728 728 729 - static inline struct task_struct *next_thread(const struct task_struct *p) 729 + static inline struct task_struct *next_thread(struct task_struct *p) 730 730 { 731 - return list_entry_rcu(p->thread_group.next, 732 - struct task_struct, thread_group); 731 + return __next_thread(p) ?: p->group_leader; 733 732 } 734 733 735 734 static inline int thread_group_empty(struct task_struct *p)