Re: [PATCH v4] selftests/pidfd: wait for POLLHUP before reading exit info
From: Oleg Nesterov
Date: Wed Oct 21 2026 - 03:36:32 EST
On 10/20, fujo wrote:
>
> The CLONE_AUTOREAP tests poll for POLLIN and then immediately call
> PIDFD_GET_INFO with PIDFD_INFO_EXIT. PIDFD_INFO_EXIT is only published
> from release_task() -> pidfs_exit(), which runs after the pidfd already
> reported POLLIN for the exited task. A poller woken by
> do_notify_pidfd() can therefore read a mask without PIDFD_INFO_EXIT;
> under KASAN the autoreap_multithreaded case fails this way.
>
> POLLHUP is returned once the task linkage has been removed from
> struct pid, which happens after pidfs_exit() has published the exit
> information. Wait for POLLHUP and check it in revents.
>
> The zero-timeout liveness check in autokill_pidfd_open_no_effect keeps
> POLLIN; it verifies that the child has not exited yet.
>
> With this change all tests pass ten consecutive runs on an unpatched
> kernel.
>
> Signed-off-by: fujo <hooyan2024@xxxxxxxxx>
> ---
> .../selftests/pidfd/pidfd_autoreap_test.c | 34 +++++++++----------
> 1 file changed, 17 insertions(+), 17 deletions(-)
Reviewed-by: Oleg Nesterov <oleg@xxxxxxxxxx>