* [LTP] [PATCH v4] Correctly check if PIDFD_INFO_EXIT is available
@ 2025-07-30 12:20 Andrea Cervesato
2025-07-30 14:28 ` Cyril Hrubis
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Andrea Cervesato @ 2025-07-30 12:20 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
When systems are not having the PIDFD_INFO_EXIT implementation,
ioctl_pidfd testing suite might fail with:
ioctl_pidfd.h:32: TBROK: ioctl(...) failed: ENOTTY (25)
Fix the ioctl_pidfd_info_exit_supported() behavior, considering ENOTTY,
EINVAL and ESRCH errors like a sign for not having PIDFD_INFO_EXIT
implemented in the system.
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Reviewed-by: Avinesh Kumar <akumar@suse.de>
Tested-by: Avinesh Kumar <akumar@suse.de>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
Changes in v4:
- use the right AND logic...
- Link to v3: https://lore.kernel.org/r/20250730-ioctl_pidfd_supported-v3-1-f40c047b29de@suse.com
Changes in v3:
- take in consideration also EINVAL and ESRCH errors
- Link to v2: https://lore.kernel.org/r/20250729-ioctl_pidfd_supported-v2-1-f9ef90134138@suse.com
Changes in v2:
- close pidfd when PIDFD_INFO_EXIT is supported
- Link to v1: https://lore.kernel.org/r/20250729-ioctl_pidfd_supported-v1-1-985626a0c46b@suse.com
---
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h b/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
index 8249ac753cf7fb8a3b749d55c7f0c3b30482c114..811f969cdee8147dfa43bc2ab1124dfd9fd21e41 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
+++ b/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
@@ -11,9 +11,10 @@
static inline int ioctl_pidfd_info_exit_supported(void)
{
- int ret = 0;
+ int ret;
pid_t pid;
int pidfd;
+ int supported = 0;
struct pidfd_info info;
if (tst_kvercmp(6, 15, 0) >= 0)
@@ -29,13 +30,24 @@ static inline int ioctl_pidfd_info_exit_supported(void)
pidfd = SAFE_PIDFD_OPEN(pid, 0);
SAFE_WAITPID(pid, NULL, 0);
- SAFE_IOCTL(pidfd, PIDFD_GET_INFO, &info);
- SAFE_CLOSE(pidfd);
+ ret = ioctl(pidfd, PIDFD_GET_INFO, &info);
+ if (ret == -1) {
+ /* - ENOTTY: old kernels not implementing fs/pidfs.c:pidfd_ioctl
+ * - EINVAL: until v6.13 kernel
+ * - ESRCH: all kernels between v6.13 and v6.15
+ */
+ if (errno != ENOTTY &&
+ errno != EINVAL &&
+ errno != ESRCH)
+ tst_brk(TBROK | TERRNO, "ioctl error");
+ } else {
+ if (info.mask & PIDFD_INFO_EXIT)
+ supported = 1;
+ }
- if (info.mask & PIDFD_INFO_EXIT)
- ret = 1;
+ SAFE_CLOSE(pidfd);
- return ret;
+ return supported;
}
#endif
---
base-commit: 890d6d64a235548cec559ffaf2e9208b80e6902b
change-id: 20250729-ioctl_pidfd_supported-437d25a4c382
Best regards,
--
Andrea Cervesato <andrea.cervesato@suse.com>
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [LTP] [PATCH v4] Correctly check if PIDFD_INFO_EXIT is available
2025-07-30 12:20 [LTP] [PATCH v4] Correctly check if PIDFD_INFO_EXIT is available Andrea Cervesato
@ 2025-07-30 14:28 ` Cyril Hrubis
2025-07-30 14:57 ` Andrea Cervesato via ltp
2025-07-30 16:36 ` Petr Vorel
2 siblings, 0 replies; 4+ messages in thread
From: Cyril Hrubis @ 2025-07-30 14:28 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi!
> When systems are not having the PIDFD_INFO_EXIT implementation,
> ioctl_pidfd testing suite might fail with:
>
> ioctl_pidfd.h:32: TBROK: ioctl(...) failed: ENOTTY (25)
>
> Fix the ioctl_pidfd_info_exit_supported() behavior, considering ENOTTY,
> EINVAL and ESRCH errors like a sign for not having PIDFD_INFO_EXIT
> implemented in the system.
> if (tst_kvercmp(6, 15, 0) >= 0)
> @@ -29,13 +30,24 @@ static inline int ioctl_pidfd_info_exit_supported(void)
> pidfd = SAFE_PIDFD_OPEN(pid, 0);
> SAFE_WAITPID(pid, NULL, 0);
>
> - SAFE_IOCTL(pidfd, PIDFD_GET_INFO, &info);
> - SAFE_CLOSE(pidfd);
> + ret = ioctl(pidfd, PIDFD_GET_INFO, &info);
> + if (ret == -1) {
> + /* - ENOTTY: old kernels not implementing fs/pidfs.c:pidfd_ioctl
Okay that's what we get if there is no ioctl() handler for the pidfs.
> + * - EINVAL: until v6.13 kernel
And this is supposedly before PIDFD_GET_INFO was added.
> + * - ESRCH: all kernels between v6.13 and v6.15
I suppose what happens between 6.13 and 6.15 is that PIDFD_GET_INFO is
acutally implemented but all the data about the process are gone once it
has been waited for. I was thinking that we could eliminate this branch
if we waited for the process after the ioctl() but we need the actual
process to exit since otherwise the PIFD_INFO_EXIT flag woudln't be set
in the result even if it's supported. Sigh.
So I guess that we cannot make this any simpler.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [LTP] [PATCH v4] Correctly check if PIDFD_INFO_EXIT is available
2025-07-30 12:20 [LTP] [PATCH v4] Correctly check if PIDFD_INFO_EXIT is available Andrea Cervesato
2025-07-30 14:28 ` Cyril Hrubis
@ 2025-07-30 14:57 ` Andrea Cervesato via ltp
2025-07-30 16:36 ` Petr Vorel
2 siblings, 0 replies; 4+ messages in thread
From: Andrea Cervesato via ltp @ 2025-07-30 14:57 UTC (permalink / raw)
To: Andrea Cervesato, ltp
Merged! Thanks.
- Andrea
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [LTP] [PATCH v4] Correctly check if PIDFD_INFO_EXIT is available
2025-07-30 12:20 [LTP] [PATCH v4] Correctly check if PIDFD_INFO_EXIT is available Andrea Cervesato
2025-07-30 14:28 ` Cyril Hrubis
2025-07-30 14:57 ` Andrea Cervesato via ltp
@ 2025-07-30 16:36 ` Petr Vorel
2 siblings, 0 replies; 4+ messages in thread
From: Petr Vorel @ 2025-07-30 16:36 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi Andrea, all,
> When systems are not having the PIDFD_INFO_EXIT implementation,
> ioctl_pidfd testing suite might fail with:
> ioctl_pidfd.h:32: TBROK: ioctl(...) failed: ENOTTY (25)
> Fix the ioctl_pidfd_info_exit_supported() behavior, considering ENOTTY,
> EINVAL and ESRCH errors like a sign for not having PIDFD_INFO_EXIT
> implemented in the system.
Thanks for doing the investigation and fixing this!
...
> - SAFE_IOCTL(pidfd, PIDFD_GET_INFO, &info);
> - SAFE_CLOSE(pidfd);
> + ret = ioctl(pidfd, PIDFD_GET_INFO, &info);
> + if (ret == -1) {
> + /* - ENOTTY: old kernels not implementing fs/pidfs.c:pidfd_ioctl
> + * - EINVAL: until v6.13 kernel
> + * - ESRCH: all kernels between v6.13 and v6.15
> + */
> + if (errno != ENOTTY &&
> + errno != EINVAL &&
> + errno != ESRCH)
> + tst_brk(TBROK | TERRNO, "ioctl error");
> + } else {
> + if (info.mask & PIDFD_INFO_EXIT)
nit: this could have been:
} else if (info.mask & PIDFD_INFO_EXIT) {
Kind regards,
Petr
> + supported = 1;
> + }
> - if (info.mask & PIDFD_INFO_EXIT)
> - ret = 1;
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-07-30 16:37 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-30 12:20 [LTP] [PATCH v4] Correctly check if PIDFD_INFO_EXIT is available Andrea Cervesato
2025-07-30 14:28 ` Cyril Hrubis
2025-07-30 14:57 ` Andrea Cervesato via ltp
2025-07-30 16:36 ` Petr Vorel
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.