Merge patch series "pidfs: provide information after task has been reaped"
Christian Brauner <brauner@kernel.org> says: Various tools need access to information about a process/task even after it has already been reaped. For example, systemd's journal logs and uses such information as the cgroup id and exit status to deal with processes that have been sent via SCM_PIDFD or SCM_PEERPIDFD. By the time the pidfd is received the process might have already been reaped. This series aims to provide information by extending the PIDFD_GET_INFO ioctl to retrieve the exit code and cgroup id. There might be other stuff that we would want in the future. Pidfd polling allows waiting on either task exit or for a task to have been reaped. The contract for PIDFD_INFO_EXIT is simply that EPOLLHUP must be observed before exit information can be retrieved, i.e., exit information is only provided once the task has been reaped. Note, that if a thread-group leader exits before other threads in the thread-group then exit information will only be available once the thread-group is empty. This aligns with wait() as well, where reaping of a thread-group leader that exited before the thread-group was empty is delayed until the thread-group is empty. With PIDFD_INFO_EXIT autoreaping might actually become usable because it means a parent can ignore SIGCHLD or set SA_NOCLDWAIT and simply use pidfd polling and PIDFD_INFO_EXIT to get get status information for its children. The kernel will autocleanup right away instead of delaying. This includes expansive selftests including for thread-group behior and multi-threaded exec by a non-thread-group leader thread. * patches from https://lore.kernel.org/r/20250305-work-pidfs-kill_on_last_close-v3-0-c8c3d8361705@kernel.org: selftests/pidfd: add seventh PIDFD_INFO_EXIT selftest selftests/pidfd: add sixth PIDFD_INFO_EXIT selftest selftests/pidfd: add fifth PIDFD_INFO_EXIT selftest selftests/pidfd: add fourth PIDFD_INFO_EXIT selftest selftests/pidfd: add third PIDFD_INFO_EXIT selftest selftests/pidfd: add second PIDFD_INFO_EXIT selftest selftests/pidfd: add first PIDFD_INFO_EXIT selftest selftests/pidfd: expand common pidfd header pidfs/selftests: ensure correct headers for ioctl handling selftests/pidfd: fix header inclusion pidfs: allow to retrieve exit information pidfs: record exit code and cgroupid at exit pidfs: use private inode slab cache pidfs: move setting flags into pidfs_alloc_file() pidfd: rely on automatic cleanup in __pidfd_prepare() pidfs: switch to copy_struct_to_user() Link: https://lore.kernel.org/r/20250305-work-pidfs-kill_on_last_close-v3-0-c8c3d8361705@kernel.org Signed-off-by:Christian Brauner <brauner@kernel.org>
Showing
- fs/internal.h 1 addition, 0 deletionsfs/internal.h
- fs/libfs.c 2 additions, 2 deletionsfs/libfs.c
- fs/pidfs.c 163 additions, 19 deletionsfs/pidfs.c
- include/linux/pidfs.h 1 addition, 0 deletionsinclude/linux/pidfs.h
- include/uapi/linux/pidfd.h 2 additions, 1 deletioninclude/uapi/linux/pidfd.h
- kernel/exit.c 2 additions, 0 deletionskernel/exit.c
- kernel/fork.c 4 additions, 11 deletionskernel/fork.c
- tools/testing/selftests/pidfd/.gitignore 2 additions, 0 deletionstools/testing/selftests/pidfd/.gitignore
- tools/testing/selftests/pidfd/Makefile 3 additions, 1 deletiontools/testing/selftests/pidfd/Makefile
- tools/testing/selftests/pidfd/pidfd.h 93 additions, 0 deletionstools/testing/selftests/pidfd/pidfd.h
- tools/testing/selftests/pidfd/pidfd_exec_helper.c 12 additions, 0 deletionstools/testing/selftests/pidfd/pidfd_exec_helper.c
- tools/testing/selftests/pidfd/pidfd_fdinfo_test.c 1 addition, 0 deletionstools/testing/selftests/pidfd/pidfd_fdinfo_test.c
- tools/testing/selftests/pidfd/pidfd_info_test.c 497 additions, 0 deletionstools/testing/selftests/pidfd/pidfd_info_test.c
- tools/testing/selftests/pidfd/pidfd_open_test.c 0 additions, 26 deletionstools/testing/selftests/pidfd/pidfd_open_test.c
- tools/testing/selftests/pidfd/pidfd_setns_test.c 0 additions, 45 deletionstools/testing/selftests/pidfd/pidfd_setns_test.c
Loading
Please register or sign in to comment