Skip to content

RFC pidfd: improve uapi when task isn't found

Christian Brauner linux-fsdevel lkml 1 version In review

Get series with b4
b4 am [email protected] change-id 20250403-work-pidfd-fixes-54c5b13ee0ee

Versions newest first

  1. v1 RFC Latest4 patches 4 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4selftests/pidfd: adapt to recent changestools/testing/selftests/pidfd/pidfd_info_test.c+6 -60 replies
2/4pidfd: remove unneeded NULL check from pidfd_prepare()kernel/fork.c+1 -10 replies
3/4pidfd: improve uapi when task isn't foundkernel/fork.c+28 -314 replies
4/4selftest/pidfd: add test for thread-group leader pidfd open for threadtools/testing/selftests/pidfd/pidfd_info_test.c+1 -00 replies

Reviews trailers per patch

1 of 4 patches has a Reviewed-by or Acked-by.

PatchOleg Nesterov
1/4
2/4
3/4R-b A-b
4/4

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH RFC 0/4] pidfd: improve uapi when task isn't found

Oleg,

We currently report EINVAL whenever a struct pid has no tasked attached anymore thereby conflating two concepts:

(1) The task has already been reaped.
(2) The caller requested a pidfd for a thread-group leader but the pid actually references a struct pid that isn't used as a thread-group leader.

This is causing issues for non-threaded workloads as in [1] where they expect ESRCH to be reported, not EINVAL. I think that's a very resonable assumption.

This patch tries to allow userspace to distinguish between (1) and (2). This is racy of course but that shouldn't matter.

Christian

---
Christian Brauner (4):
selftests/pidfd: adapt to recent changes
pidfd: remove unneeded NULL check from pidfd_prepare()
pidfd: improve uapi when task isn't found
selftest/pidfd: add test for thread-group leader pidfd open for thread

 kernel/fork.c                                   | 31 ++++++++++++++++++++++---
 tools/testing/selftests/pidfd/pidfd_info_test.c | 13 ++++++-----
 2 files changed, 35 insertions(+), 9 deletions(-)

---
base-commit: a2cc6ff5ec8f91bc463fd3b0c26b61166a07eb11
change-id: 20250403-work-pidfd-fixes-54c5b13ee0ee