Reapply "pidfd_poll: report POLLHUP when pid_task() == NULL"

This reverts commit d3ec16ca12.

Reason of revert: Fix has been applied to lmkd to handle EPOLLHUP - aosp/3268491

Change-Id: I24e17e778ff013adcbf1a6ad43470adc8d9f19cb
Signed-off-by: Terence Tritton <ttritton@google.com>
Bug: 352286227
This commit is contained in:
Terence Tritton (xWF)
2024-10-14 12:25:32 +00:00
committed by Greg Kroah-Hartman
parent 6c15bc3c5b
commit 7ab18c2db0
2 changed files with 12 additions and 19 deletions
+7 -19
View File
@@ -89,23 +89,6 @@ static void pidfd_show_fdinfo(struct seq_file *m, struct file *f)
}
#endif
static bool pidfd_task_exited(struct pid *pid, bool thread)
{
struct task_struct *task;
bool exited;
rcu_read_lock();
task = pid_task(pid, PIDTYPE_PID);
exited = !task ||
(READ_ONCE(task->exit_state) && (thread || thread_group_empty(task)));
rcu_read_unlock();
return exited;
}
/*
* Poll support for process exit notification.
*/
@@ -113,6 +96,7 @@ static __poll_t pidfd_poll(struct file *file, struct poll_table_struct *pts)
{
struct pid *pid = pidfd_pid(file);
bool thread = file->f_flags & PIDFD_THREAD;
struct task_struct *task;
__poll_t poll_flags = 0;
poll_wait(file, &pid->wait_pidfd, pts);
@@ -120,8 +104,12 @@ static __poll_t pidfd_poll(struct file *file, struct poll_table_struct *pts)
* Depending on PIDFD_THREAD, inform pollers when the thread
* or the whole thread-group exits.
*/
if(pidfd_task_exited(pid, thread))
poll_flags = EPOLLIN | EPOLLRDNORM;
guard(rcu)();
task = pid_task(pid, PIDTYPE_PID);
if (!task)
poll_flags = EPOLLIN | EPOLLRDNORM | EPOLLHUP;
else if (task->exit_state && (thread || thread_group_empty(task)))
poll_flags = EPOLLIN | EPOLLRDNORM;
return poll_flags;
}
+5
View File
@@ -355,6 +355,11 @@ static void __change_pid(struct task_struct *task, enum pid_type type,
hlist_del_rcu(&task->pid_links[type]);
*pid_ptr = new;
if (type == PIDTYPE_PID) {
WARN_ON_ONCE(pid_has_task(pid, PIDTYPE_PID));
wake_up_all(&pid->wait_pidfd);
}
for (tmp = PIDTYPE_MAX; --tmp >= 0; )
if (pid_has_task(pid, tmp))
return;