exit: Factor thread_group_exited out of pidfd_poll
Create an independent helper thread_group_exited which returns true when all threads have passed exit_notify in do_exit. AKA all of the threads are at least zombies and might be dead or completely gone. Create this helper by taking the logic out of pidfd_poll where it is already tested, and adding a READ_ONCE on the read of task->exit_state. I will be changing the user mode driver code to use this same logic to know when a user mode driver needs to be restarted. Place the new helper thread_group_exited in kernel/exit.c and EXPORT it so it can be used by modules. Link: https://lkml.kernel.org/r/20200702164140.4468-13-ebiederm@xmission.com Acked-by: Christian Brauner <christian.brauner@ubuntu.com> Acked-by: Alexei Starovoitov <ast@kernel.org> Tested-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
This commit is contained in:
@@ -1713,6 +1713,30 @@ Efault:
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* thread_group_exited - check that a thread group has exited
|
||||
* @pid: tgid of thread group to be checked.
|
||||
*
|
||||
* Test if the thread group represented by tgid has exited (all
|
||||
* threads are zombies, dead or completely gone).
|
||||
*
|
||||
* Return: true if the thread group has exited. false otherwise.
|
||||
*/
|
||||
bool thread_group_exited(struct pid *pid)
|
||||
{
|
||||
struct task_struct *task;
|
||||
bool exited;
|
||||
|
||||
rcu_read_lock();
|
||||
task = pid_task(pid, PIDTYPE_PID);
|
||||
exited = !task ||
|
||||
(READ_ONCE(task->exit_state) && thread_group_empty(task));
|
||||
rcu_read_unlock();
|
||||
|
||||
return exited;
|
||||
}
|
||||
EXPORT_SYMBOL(thread_group_exited);
|
||||
|
||||
__weak void abort(void)
|
||||
{
|
||||
BUG();
|
||||
|
Reference in New Issue
Block a user