[PATCH 02/13] Update PIDFD_* constants for Linux 6.17
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Thu Nov 6 15:30:15 GMT 2025
On 06/11/25 15:59, Yury Khrustalev wrote:
> On Fri, Oct 03, 2025 at 04:38:53PM -0300, Adhemerval Zanella wrote:
>> The pidfd interface was extended with:
>>
>> * PIDFD_GET_INFO and pidfd_info (along with related extra flags) to
>> allow get information about the process without the need to parse
>> /proc (commit cdda1f26e74ba, Linux 6.13).
>>
>> * PIDFD_SELF_{THREAD,THREAD_GROUP,SELF,SELF_PROCESS} to allow
>> pidfd_send_signal refer to the own process or thread lead groups
>> without the need of allocating a file descriptor (commit f08d0c3a71114,
>> Linux 6.15).
>>
>> * PIDFD_INFO_COREDUMP that extends PIDFD_GET_INFO to obtain coredump
>> information.
>>
>> Linux uAPI header defines both PIDFD_SELF_THREAD and
>> PIDFD_SELF_THREAD_GROUP on linux/fcntl.h (since they reserve part of the
>> AT_* values), however for glibc I do not see any good reason to add pidfd
>> definitions on fcntl-linux.h.
>>
>> The tst-pidfd.c is extended with some PIDFD_SELF_* tests and a new
>> ‘tst-pidfd_getinfo.c’ test is added to check PIDFD_GET_INFO. The
>> PIDFD_INFO_COREDUMP tests would require very large and complex tests
>> that are already covered by kernel tests.
>>
>> Checked on aarch64-linux-gnu and x86_64-linux-gnu on kernels 6.8 and
>> 6.17.
>> ---
>> sysdeps/unix/sysv/linux/Makefile | 1 +
>> sysdeps/unix/sysv/linux/sys/pidfd.h | 58 +++++++++++++++++
>> sysdeps/unix/sysv/linux/tst-pidfd-consts.py | 2 +-
>> sysdeps/unix/sysv/linux/tst-pidfd.c | 44 ++++++++++++-
>> sysdeps/unix/sysv/linux/tst-pidfd_getinfo.c | 71 +++++++++++++++++++++
>> 5 files changed, 172 insertions(+), 4 deletions(-)
>> create mode 100644 sysdeps/unix/sysv/linux/tst-pidfd_getinfo.c
>
> The misc/tst-pidfd_getinfo test fails with
>
> error: ../sysdeps/unix/sysv/linux/tst-pidfd_getinfo.c:52: ioctl (PIDFD_GET_INFO) failed: Invalid argument
>
> on aarch64 with kernel 6.12 and passes on a system with kernel 6.17 and 6.18.
I had the impression ENOTTY was the error code in this case, on 6.1.0:
$ strace -f misc/tst-pidfd_getinfo --direct
[...]
ioctl(3, _IOC(_IOC_READ|_IOC_WRITE, 0xff, 0xb, 0x48), 0x7ffe475d4670) = -1 ENOTTY (Inappropriate ioctl for device)
[...]
If EINVAL is also a possible error we might need to also handle it.
>
> It also fails the misc/tst-pidfd-consts test when done via the
> build-many-glibc.py script for some targets:
>
> First source:
> #include <sys/pidfd.h>
>
>
> Second source:
> #include <asm/fcntl.h>
> #include <linux/pidfd.h>
>
>
> Different values for PIDFD_SELF_PROCESS: -10001 != -20000
> Different values for PIDFD_SELF_THREAD_GROUP: -10001 != -20000
It was initially added on Linux 6.15 and later redefined on 6.17
by 67fcec2919e4ed31ab845eb456ad7d6f1e85505c:
fcntl/pidfd: redefine PIDFD_SELF_THREAD_GROUP
Don't jump somewhere into the middle of the reserved range. We're still
able to change that value it won't be that widely used yet. If not, we
can revert.
((HEAD detached at v6.15))$ git grep PIDFD_SELF_THREAD_GROUP | grep \#define | head -n1
include/uapi/linux/pidfd.h:#define PIDFD_SELF_THREAD_GROUP -20000 /* Current thread group leader. */
((HEAD detached at v6.17))$ git grep PIDFD_SELF_THREAD_GROUP | grep \#define | head -n1
include/uapi/linux/fcntl.h:#define PIDFD_SELF_THREAD_GROUP -10001 /* Current thread group leader. */
I used the latest definition. I am ccing Christian Brauner to check
if this characterize a userland issue and which value we should
assume.
>
>> ...
>> + int pidfd = pidfd_open (getpid(), 0);
>> + TEST_VERIFY (pidfd >= 0);
>> +
>> + int pid = pidfd_getpid (pidfd);
>> + TEST_VERIFY (pid >= 0);
>> +
>> + struct pidfd_info info = {
>> + .mask = PIDFD_INFO_CGROUPID,
>> + };
>> + if (ioctl (pidfd, PIDFD_GET_INFO, &info) != 0)
>> + {
>> + if (errno == ENOTTY)
>
> Did you mean EINVAL here?
>
>> + FAIL_UNSUPPORTED ("kernel does not support PIDFD_GET_INFO");
>> + else
>> + FAIL_EXIT1 ("ioctl (PIDFD_GET_INFO) failed: %m");
>> + }
>> +
>
> Thanks,
> Yury
>
More information about the Libc-alpha
mailing list