public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] Introduce ioctl_pidfd_get_info_supported() function
@ 2025-09-22 20:39 Avinesh Kumar
  2025-09-22 21:07 ` Petr Vorel
  0 siblings, 1 reply; 19+ messages in thread
From: Avinesh Kumar @ 2025-09-22 20:39 UTC (permalink / raw)
  To: ltp

- use new routine in ioctl_pidfd05 test
- refactor ioctl_pidfd_info_exit_supported() routine

Suggested-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Avinesh Kumar <akumar@suse.de>
---
 testcases/kernel/syscalls/ioctl/ioctl_pidfd.h | 45 +++++++++++--------
 .../kernel/syscalls/ioctl/ioctl_pidfd05.c     |  9 +++-
 2 files changed, 34 insertions(+), 20 deletions(-)

diff --git a/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h b/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
index 811f969cd..6ee6c6db5 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
+++ b/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
@@ -9,19 +9,16 @@
 #include "tst_test.h"
 #include "lapi/pidfd.h"
 
-static inline int ioctl_pidfd_info_exit_supported(void)
+static inline long ioctl_pidfd_get_info_supported(void)
 {
-	int ret;
 	pid_t pid;
-	int pidfd;
-	int supported = 0;
+	int pidfd, ret;
 	struct pidfd_info info;
 
-	if (tst_kvercmp(6, 15, 0) >= 0)
+	if (tst_kvercmp(6, 12, 0) >= 0)
 		return 1;
 
 	memset(&info, 0, sizeof(struct pidfd_info));
-	info.mask = PIDFD_INFO_EXIT;
 
 	pid = SAFE_FORK();
 	if (!pid)
@@ -31,23 +28,33 @@ static inline int ioctl_pidfd_info_exit_supported(void)
 	SAFE_WAITPID(pid, NULL, 0);
 
 	ret = ioctl(pidfd, PIDFD_GET_INFO, &info);
+	SAFE_CLOSE(pidfd);
+
 	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 (errno == ENOTTY)
+			return -1;
+
+		if (errno == EINVAL || errno == ESRCH)
+			return 0;
+
+		tst_brk(TBROK | TERRNO, "unexpected ioctl(PIDFD_GET_INFO) error");
 	}
 
-	SAFE_CLOSE(pidfd);
+	return info.mask;
+}
+
+static inline int ioctl_pidfd_info_exit_supported(void)
+{
+	long mask;
+
+	if (tst_kvercmp(6, 15, 0) >= 0)
+		return 1;
+
+	mask = ioctl_pidfd_get_info_supported();
+	if (mask == -1)
+		return 0;
 
-	return supported;
+	return !!(mask & PIDFD_INFO_EXIT);
 }
 
 #endif
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c b/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c
index c379717b3..871f2fe5e 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c
@@ -14,7 +14,7 @@
 #include "tst_test.h"
 #include "lapi/pidfd.h"
 #include "lapi/sched.h"
-#include "lapi/ioctl.h"
+#include "ioctl_pidfd.h"
 
 struct pidfd_info_invalid {
 	uint32_t dummy;
@@ -48,8 +48,15 @@ static void run(void)
 	SAFE_CLOSE(pidfd);
 }
 
+static void setup(void)
+{
+	if (ioctl_pidfd_get_info_supported() == -1)
+		tst_brk(TCONF, "ioctl(PIDFD_GET_INFO) is not implemented");
+}
+
 static struct tst_test test = {
 	.test_all = run,
+	.setup = setup,
 	.forks_child = 1,
 	.bufs = (struct tst_buffers []) {
 		{&args, .size = sizeof(*args)},
-- 
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [LTP] [PATCH] Introduce ioctl_pidfd_get_info_supported() function
  2025-09-22 20:39 [LTP] [PATCH] Introduce ioctl_pidfd_get_info_supported() function Avinesh Kumar
@ 2025-09-22 21:07 ` Petr Vorel
  2025-09-23  7:51   ` [LTP] [PATCH v2] " Avinesh Kumar
  0 siblings, 1 reply; 19+ messages in thread
From: Petr Vorel @ 2025-09-22 21:07 UTC (permalink / raw)
  To: Avinesh Kumar; +Cc: ltp

Hi Avinesh,

thanks for fixing this!
...
>  	if (ret == -1) {
> +		if (errno == ENOTTY)
> +			return -1;
> +
> +		if (errno == EINVAL || errno == ESRCH)
> +			return 0;
> +
> +		tst_brk(TBROK | TERRNO, "unexpected ioctl(PIDFD_GET_INFO) error");
>  	}

> -	SAFE_CLOSE(pidfd);
> +	return info.mask;

Because ioctl_pidfd_get_info_supported() returns 3 different states
(-1 (not supported), 0 (supported) and >= 0 (mask) it wouldn't harm to document
return type.

All the more so because ioctl_pidfd_info_exit_supported() uses reversed
conditions for supported (1) / not supported (0).

I understand chosen values, but because names suggest the same functionality doc
would help.

> +}
> +
> +static inline int ioctl_pidfd_info_exit_supported(void)
This could be bool, that's itself a documentation (just 2 possible values, not
more).

Kind regards,
Petr

> +{
> +	long mask;
> +
> +	if (tst_kvercmp(6, 15, 0) >= 0)
> +		return 1;
> +
> +	mask = ioctl_pidfd_get_info_supported();
> +	if (mask == -1)
> +		return 0;

> -	return supported;
> +	return !!(mask & PIDFD_INFO_EXIT);
>  }

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [LTP] [PATCH v2] Introduce ioctl_pidfd_get_info_supported() function
  2025-09-22 21:07 ` Petr Vorel
@ 2025-09-23  7:51   ` Avinesh Kumar
  2025-09-23  9:43     ` Petr Vorel
  2025-09-23 11:17     ` Cyril Hrubis
  0 siblings, 2 replies; 19+ messages in thread
From: Avinesh Kumar @ 2025-09-23  7:51 UTC (permalink / raw)
  To: ltp

- use new routine in ioctl_pidfd05 test
- refactor ioctl_pidfd_info_exit_supported() routine

Suggested-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Avinesh Kumar <akumar@suse.de>
---
 testcases/kernel/syscalls/ioctl/ioctl_pidfd.h | 49 ++++++++++++-------
 .../kernel/syscalls/ioctl/ioctl_pidfd05.c     |  9 +++-
 2 files changed, 39 insertions(+), 19 deletions(-)

diff --git a/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h b/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
index 811f969cd..067ef18ba 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
+++ b/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
@@ -9,19 +9,16 @@
 #include "tst_test.h"
 #include "lapi/pidfd.h"
 
-static inline int ioctl_pidfd_info_exit_supported(void)
+static inline long ioctl_pidfd_get_info_supported(void)
 {
-	int ret;
 	pid_t pid;
-	int pidfd;
-	int supported = 0;
+	int pidfd, ret;
 	struct pidfd_info info;
 
-	if (tst_kvercmp(6, 15, 0) >= 0)
+	if (tst_kvercmp(6, 12, 0) >= 0)
 		return 1;
 
 	memset(&info, 0, sizeof(struct pidfd_info));
-	info.mask = PIDFD_INFO_EXIT;
 
 	pid = SAFE_FORK();
 	if (!pid)
@@ -31,23 +28,39 @@ static inline int ioctl_pidfd_info_exit_supported(void)
 	SAFE_WAITPID(pid, NULL, 0);
 
 	ret = ioctl(pidfd, PIDFD_GET_INFO, &info);
+	SAFE_CLOSE(pidfd);
+
 	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
+		/* - ENOTTY: kernel too old, ioctl(PIDFD_GET_INFO) not implemented; return -1 */
+		if (errno == ENOTTY)
+			return -1;
+
+		/* - EINVAL: ioctl(PIDFD_GET_INFO) exists but invalid args
+		 * - ESRCH: ioctl(PIDFD_GET_INFO) exists but task already exited
+		 * both mean supported, but info.mask is not set; return 0
 		 */
-		if (errno != ENOTTY &&
-			errno != EINVAL &&
-			errno != ESRCH)
-			tst_brk(TBROK | TERRNO, "ioctl error");
-	} else {
-		if (info.mask & PIDFD_INFO_EXIT)
-			supported = 1;
+		if (errno == EINVAL || errno == ESRCH)
+			return 0;
+
+		tst_brk(TBROK | TERRNO, "unexpected ioctl(PIDFD_GET_INFO) error");
 	}
 
-	SAFE_CLOSE(pidfd);
+	/* ioctl(PIDFD_GET_INFO) successful; return mask */
+	return info.mask;
+}
+
+static inline bool ioctl_pidfd_info_exit_supported(void)
+{
+	long mask;
+
+	if (tst_kvercmp(6, 15, 0) >= 0)
+		return 1;
+
+	mask = ioctl_pidfd_get_info_supported();
+	if (mask == -1)
+		return 0;
 
-	return supported;
+	return !!(mask & PIDFD_INFO_EXIT);
 }
 
 #endif
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c b/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c
index c379717b3..871f2fe5e 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c
@@ -14,7 +14,7 @@
 #include "tst_test.h"
 #include "lapi/pidfd.h"
 #include "lapi/sched.h"
-#include "lapi/ioctl.h"
+#include "ioctl_pidfd.h"
 
 struct pidfd_info_invalid {
 	uint32_t dummy;
@@ -48,8 +48,15 @@ static void run(void)
 	SAFE_CLOSE(pidfd);
 }
 
+static void setup(void)
+{
+	if (ioctl_pidfd_get_info_supported() == -1)
+		tst_brk(TCONF, "ioctl(PIDFD_GET_INFO) is not implemented");
+}
+
 static struct tst_test test = {
 	.test_all = run,
+	.setup = setup,
 	.forks_child = 1,
 	.bufs = (struct tst_buffers []) {
 		{&args, .size = sizeof(*args)},
-- 
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [LTP] [PATCH v2] Introduce ioctl_pidfd_get_info_supported() function
  2025-09-23  7:51   ` [LTP] [PATCH v2] " Avinesh Kumar
@ 2025-09-23  9:43     ` Petr Vorel
  2025-09-23 11:17     ` Cyril Hrubis
  1 sibling, 0 replies; 19+ messages in thread
From: Petr Vorel @ 2025-09-23  9:43 UTC (permalink / raw)
  To: Avinesh Kumar; +Cc: ltp

Hi Avinesh,

...
>  	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
> +		/* - ENOTTY: kernel too old, ioctl(PIDFD_GET_INFO) not implemented; return -1 */
> +		if (errno == ENOTTY)
> +			return -1;
> +
> +		/* - EINVAL: ioctl(PIDFD_GET_INFO) exists but invalid args
> +		 * - ESRCH: ioctl(PIDFD_GET_INFO) exists but task already exited
> +		 * both mean supported, but info.mask is not set; return 0
>  		 */
I originally mean to move the docs above function signature (to the top)
and add it for both, but I suppose this is perfectly ok (it was here before).

Thanks for improving it.

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

> -		if (errno != ENOTTY &&
> -			errno != EINVAL &&
> -			errno != ESRCH)
> -			tst_brk(TBROK | TERRNO, "ioctl error");
> -	} else {
> -		if (info.mask & PIDFD_INFO_EXIT)
> -			supported = 1;
> +		if (errno == EINVAL || errno == ESRCH)
> +			return 0;
> +
> +		tst_brk(TBROK | TERRNO, "unexpected ioctl(PIDFD_GET_INFO) error");
>  	}

> -	SAFE_CLOSE(pidfd);
> +	/* ioctl(PIDFD_GET_INFO) successful; return mask */
> +	return info.mask;
> +}
> +
> +static inline bool ioctl_pidfd_info_exit_supported(void)
> +{
...

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [LTP] [PATCH v2] Introduce ioctl_pidfd_get_info_supported() function
  2025-09-23  7:51   ` [LTP] [PATCH v2] " Avinesh Kumar
  2025-09-23  9:43     ` Petr Vorel
@ 2025-09-23 11:17     ` Cyril Hrubis
  2025-09-23 11:39       ` Petr Vorel
  1 sibling, 1 reply; 19+ messages in thread
From: Cyril Hrubis @ 2025-09-23 11:17 UTC (permalink / raw)
  To: Avinesh Kumar; +Cc: ltp

Hi!
> - use new routine in ioctl_pidfd05 test
> - refactor ioctl_pidfd_info_exit_supported() routine
> 
> Suggested-by: Petr Vorel <pvorel@suse.cz>
> Signed-off-by: Avinesh Kumar <akumar@suse.de>
> ---
>  testcases/kernel/syscalls/ioctl/ioctl_pidfd.h | 49 ++++++++++++-------
>  .../kernel/syscalls/ioctl/ioctl_pidfd05.c     |  9 +++-
>  2 files changed, 39 insertions(+), 19 deletions(-)
> 
> diff --git a/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h b/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
> index 811f969cd..067ef18ba 100644
> --- a/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
> +++ b/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
> @@ -9,19 +9,16 @@
>  #include "tst_test.h"
>  #include "lapi/pidfd.h"
>  
> -static inline int ioctl_pidfd_info_exit_supported(void)
> +static inline long ioctl_pidfd_get_info_supported(void)
>  {
> -	int ret;
>  	pid_t pid;
> -	int pidfd;
> -	int supported = 0;
> +	int pidfd, ret;
>  	struct pidfd_info info;
>  
> -	if (tst_kvercmp(6, 15, 0) >= 0)
> +	if (tst_kvercmp(6, 12, 0) >= 0)
>  		return 1;
>  
>  	memset(&info, 0, sizeof(struct pidfd_info));
> -	info.mask = PIDFD_INFO_EXIT;

We have to keep the PIDFD_INFO_EXIT in the mask, otherwise it will never
be set back by the kernel.

>  	pid = SAFE_FORK();
>  	if (!pid)
> @@ -31,23 +28,39 @@ static inline int ioctl_pidfd_info_exit_supported(void)
>  	SAFE_WAITPID(pid, NULL, 0);
>  
>  	ret = ioctl(pidfd, PIDFD_GET_INFO, &info);
> +	SAFE_CLOSE(pidfd);
> +
>  	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
> +		/* - ENOTTY: kernel too old, ioctl(PIDFD_GET_INFO) not implemented; return -1 */
> +		if (errno == ENOTTY)
> +			return -1;
> +
> +		/* - EINVAL: ioctl(PIDFD_GET_INFO) exists but invalid args
> +		 * - ESRCH: ioctl(PIDFD_GET_INFO) exists but task already exited
> +		 * both mean supported, but info.mask is not set; return 0
>  		 */
> -		if (errno != ENOTTY &&
> -			errno != EINVAL &&
> -			errno != ESRCH)
> -			tst_brk(TBROK | TERRNO, "ioctl error");
> -	} else {
> -		if (info.mask & PIDFD_INFO_EXIT)
> -			supported = 1;
> +		if (errno == EINVAL || errno == ESRCH)
> +			return 0;

If we do not pass the PIDFD_INFO_EXIT above we will end up with ESRCH
here all the time.

Generally I do not like this code that much, since we depend on the fact
that we get ESCHR from the syscall if PIDFD_INFO_EXIT is not
implemented. Without the PIDFD_INFO_EXIT flag the pidfd_info() syscall
is supposed to work on a process before it's waited for and
PIDFD_INFO_EXIT does not work before the process is waited for, mixing
these two checks is a bit ugly.

> +		tst_brk(TBROK | TERRNO, "unexpected ioctl(PIDFD_GET_INFO) error");
>  	}
>  
> -	SAFE_CLOSE(pidfd);
> +	/* ioctl(PIDFD_GET_INFO) successful; return mask */
> +	return info.mask;
> +}
> +
> +static inline bool ioctl_pidfd_info_exit_supported(void)
> +{
> +	long mask;
> +
> +	if (tst_kvercmp(6, 15, 0) >= 0)
> +		return 1;
> +
> +	mask = ioctl_pidfd_get_info_supported();
> +	if (mask == -1)
> +		return 0;
>  
> -	return supported;
> +	return !!(mask & PIDFD_INFO_EXIT);
>  }
>  
>  #endif
> diff --git a/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c b/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c
> index c379717b3..871f2fe5e 100644
> --- a/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c
> +++ b/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c
> @@ -14,7 +14,7 @@
>  #include "tst_test.h"
>  #include "lapi/pidfd.h"
>  #include "lapi/sched.h"
> -#include "lapi/ioctl.h"
> +#include "ioctl_pidfd.h"
>  
>  struct pidfd_info_invalid {
>  	uint32_t dummy;
> @@ -48,8 +48,15 @@ static void run(void)
>  	SAFE_CLOSE(pidfd);
>  }
>  
> +static void setup(void)
> +{
> +	if (ioctl_pidfd_get_info_supported() == -1)
> +		tst_brk(TCONF, "ioctl(PIDFD_GET_INFO) is not implemented");
> +}
> +
>  static struct tst_test test = {
>  	.test_all = run,
> +	.setup = setup,
>  	.forks_child = 1,
>  	.bufs = (struct tst_buffers []) {
>  		{&args, .size = sizeof(*args)},
> -- 
> 2.51.0
> 

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [LTP] [PATCH v2] Introduce ioctl_pidfd_get_info_supported() function
  2025-09-23 11:17     ` Cyril Hrubis
@ 2025-09-23 11:39       ` Petr Vorel
  2025-09-23 11:49         ` Cyril Hrubis
  0 siblings, 1 reply; 19+ messages in thread
From: Petr Vorel @ 2025-09-23 11:39 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi Avinesh, Cyril,

...
> >  	memset(&info, 0, sizeof(struct pidfd_info));
> > -	info.mask = PIDFD_INFO_EXIT;

> We have to keep the PIDFD_INFO_EXIT in the mask, otherwise it will never
> be set back by the kernel.

+1, I'm sorry to overlook this change.

> >  	pid = SAFE_FORK();
> >  	if (!pid)
> > @@ -31,23 +28,39 @@ static inline int ioctl_pidfd_info_exit_supported(void)
> >  	SAFE_WAITPID(pid, NULL, 0);

> >  	ret = ioctl(pidfd, PIDFD_GET_INFO, &info);
> > +	SAFE_CLOSE(pidfd);
> > +
> >  	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
> > +		/* - ENOTTY: kernel too old, ioctl(PIDFD_GET_INFO) not implemented; return -1 */
> > +		if (errno == ENOTTY)
> > +			return -1;
> > +
> > +		/* - EINVAL: ioctl(PIDFD_GET_INFO) exists but invalid args
> > +		 * - ESRCH: ioctl(PIDFD_GET_INFO) exists but task already exited
> > +		 * both mean supported, but info.mask is not set; return 0
> >  		 */
> > -		if (errno != ENOTTY &&
> > -			errno != EINVAL &&
> > -			errno != ESRCH)
> > -			tst_brk(TBROK | TERRNO, "ioctl error");
> > -	} else {
> > -		if (info.mask & PIDFD_INFO_EXIT)
> > -			supported = 1;
> > +		if (errno == EINVAL || errno == ESRCH)
> > +			return 0;

> If we do not pass the PIDFD_INFO_EXIT above we will end up with ESRCH
> here all the time.

+1 (again, I'm sorry to overlook it).

> Generally I do not like this code that much, since we depend on the fact
> that we get ESCHR from the syscall if PIDFD_INFO_EXIT is not
> implemented. Without the PIDFD_INFO_EXIT flag the pidfd_info() syscall
> is supposed to work on a process before it's waited for and
> PIDFD_INFO_EXIT does not work before the process is waited for, mixing
> these two checks is a bit ugly.

Avinesh, I'm sorry, I see my suggestion to reuse code to detect PIDFD_INFO_EXIT
for checking PIDFD_GET_INFO was not a good idea. It'll be clearer to have them
separated.

BTW although ioctl_pidfd_info_exit_supported() should be kept as is, it does not
harm to use bool for it. But that's not related to this fix.

Kind regards,
Petr

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [LTP] [PATCH v2] Introduce ioctl_pidfd_get_info_supported() function
  2025-09-23 11:39       ` Petr Vorel
@ 2025-09-23 11:49         ` Cyril Hrubis
  2025-09-23 15:03           ` [LTP] [PATCH v3] " Avinesh Kumar
  0 siblings, 1 reply; 19+ messages in thread
From: Cyril Hrubis @ 2025-09-23 11:49 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

Hi!
> > Generally I do not like this code that much, since we depend on the fact
> > that we get ESCHR from the syscall if PIDFD_INFO_EXIT is not
> > implemented. Without the PIDFD_INFO_EXIT flag the pidfd_info() syscall
> > is supposed to work on a process before it's waited for and
> > PIDFD_INFO_EXIT does not work before the process is waited for, mixing
> > these two checks is a bit ugly.
> 
> Avinesh, I'm sorry, I see my suggestion to reuse code to detect PIDFD_INFO_EXIT
> for checking PIDFD_GET_INFO was not a good idea. It'll be clearer to have them
> separated.

We went through a few iteration of the check with Andrea before we
arrived at a working version. Sometimes detecting features gets
complex...

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [LTP] [PATCH v3] Introduce ioctl_pidfd_get_info_supported() function
  2025-09-23 11:49         ` Cyril Hrubis
@ 2025-09-23 15:03           ` Avinesh Kumar
  2025-09-23 18:44             ` Petr Vorel
  2025-09-24  8:34             ` [LTP] [PATCH v3] " Cyril Hrubis
  0 siblings, 2 replies; 19+ messages in thread
From: Avinesh Kumar @ 2025-09-23 15:03 UTC (permalink / raw)
  To: ltp

use this routine in ioctl_pidfd05 before proceeding with the test

Suggested-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Avinesh Kumar <akumar@suse.de>
---
 testcases/kernel/syscalls/ioctl/ioctl_pidfd.h | 42 +++++++++++++++++++
 .../kernel/syscalls/ioctl/ioctl_pidfd05.c     |  9 +++-
 2 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h b/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
index 811f969cd..29bc60cfb 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
+++ b/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
@@ -9,6 +9,48 @@
 #include "tst_test.h"
 #include "lapi/pidfd.h"
 
+static inline bool ioctl_pidfd_get_info_supported(void)
+{
+	pid_t pid;
+	int pidfd, ret;
+	int supported = 0;
+	struct pidfd_info info;
+
+	if (tst_kvercmp(6, 12, 0) >= 0)
+		return 1;
+
+	memset(&info, 0, sizeof(struct pidfd_info));
+
+	pid = SAFE_FORK();
+	if (!pid)
+		exit(100);
+
+	pidfd = SAFE_PIDFD_OPEN(pid, 0);
+	SAFE_WAITPID(pid, NULL, 0);
+
+	ret = ioctl(pidfd, PIDFD_GET_INFO, &info);
+	SAFE_CLOSE(pidfd);
+
+	if (ret == -1) {
+		/* - ENOTTY: kernel too old, ioctl(PIDFD_GET_INFO) not implemented */
+		if (errno == ENOTTY)
+			supported = 0;
+
+		/* - EINVAL: ioctl(PIDFD_GET_INFO) exists but args invalid
+		 * - ESRCH: ioctl(PIDFD_GET_INFO) exists but task already exited
+		 * supported in both cases, but info.mask not set
+		 */
+		else if (errno == EINVAL || errno == ESRCH)
+			supported = 1;
+		else
+			tst_brk(TBROK | TERRNO, "unexpected ioctl(PIDFD_GET_INFO) error");
+	} else {
+		supported = 1;
+	}
+
+	return supported;
+}
+
 static inline int ioctl_pidfd_info_exit_supported(void)
 {
 	int ret;
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c b/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c
index c379717b3..d20c6f074 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c
@@ -14,7 +14,7 @@
 #include "tst_test.h"
 #include "lapi/pidfd.h"
 #include "lapi/sched.h"
-#include "lapi/ioctl.h"
+#include "ioctl_pidfd.h"
 
 struct pidfd_info_invalid {
 	uint32_t dummy;
@@ -48,8 +48,15 @@ static void run(void)
 	SAFE_CLOSE(pidfd);
 }
 
+static void setup(void)
+{
+	if (!ioctl_pidfd_get_info_supported())
+		tst_brk(TCONF, "ioctl(PIDFD_GET_INFO) is not implemented");
+}
+
 static struct tst_test test = {
 	.test_all = run,
+	.setup = setup,
 	.forks_child = 1,
 	.bufs = (struct tst_buffers []) {
 		{&args, .size = sizeof(*args)},
-- 
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [LTP] [PATCH v3] Introduce ioctl_pidfd_get_info_supported() function
  2025-09-23 15:03           ` [LTP] [PATCH v3] " Avinesh Kumar
@ 2025-09-23 18:44             ` Petr Vorel
  2025-09-24  8:40               ` Cyril Hrubis
  2025-09-24  8:34             ` [LTP] [PATCH v3] " Cyril Hrubis
  1 sibling, 1 reply; 19+ messages in thread
From: Petr Vorel @ 2025-09-23 18:44 UTC (permalink / raw)
  To: Avinesh Kumar; +Cc: ltp

Hi Avinesh,

> use this routine in ioctl_pidfd05 before proceeding with the test

Reviewed-by: Petr Vorel <pvorel@suse.cz>

BTW, when testing on 6.11, I got:
ioctl_pidfd05.c:45: TFAIL: ioctl(pidfd, PIDFD_GET_INFO, NULL) expected EINVAL: ENOTTY (25)

Which is error unrelated to this patch, it's from original.
196988f7d1 ("Add ioctl_pidfd05 test")

Doc in ioctl_pidfd_info_exit_supported() is clear about it:
		/* - ENOTTY: old kernels not implementing fs/pidfs.c:pidfd_ioctl
		 * - EINVAL: until v6.13 kernel
		 * - ESRCH: all kernels between v6.13 and v6.15
		 */

But test happily ignores the fact :).

@Cyril do we want to fix it? Do we want to check for kernel versions or we just
take any of these values?

Kind regards,
Petr

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [LTP] [PATCH v3] Introduce ioctl_pidfd_get_info_supported() function
  2025-09-23 15:03           ` [LTP] [PATCH v3] " Avinesh Kumar
  2025-09-23 18:44             ` Petr Vorel
@ 2025-09-24  8:34             ` Cyril Hrubis
  2025-09-24 20:30               ` Avinesh Kumar
  1 sibling, 1 reply; 19+ messages in thread
From: Cyril Hrubis @ 2025-09-24  8:34 UTC (permalink / raw)
  To: Avinesh Kumar; +Cc: ltp

Hi!
> +static inline bool ioctl_pidfd_get_info_supported(void)
> +{
> +	pid_t pid;
> +	int pidfd, ret;
> +	int supported = 0;
> +	struct pidfd_info info;
> +
> +	if (tst_kvercmp(6, 12, 0) >= 0)
> +		return 1;
> +
> +	memset(&info, 0, sizeof(struct pidfd_info));
> +
> +	pid = SAFE_FORK();
> +	if (!pid)
> +		exit(100);
> +
> +	pidfd = SAFE_PIDFD_OPEN(pid, 0);
> +	SAFE_WAITPID(pid, NULL, 0);

Again, please do not waitpid before the PIDFD_GET_INFO ioctl(). If you
do that it has no chance of succeeding.

From fs/pidfd.c:

...
        task = get_pid_task(pid, PIDTYPE_PID);
        if (!task) {
                /*
                 * If the task has already been reaped, only exit
                 * information is available
                 */
                if (!(mask & PIDFD_INFO_EXIT))
                        return -ESRCH;

                goto copy_out;
        }
...

We have to do the ioctl() first and the waitpid() second for this case.

And if we do so we don't have to check the errno at all, the call will
just succeed in case that it's supported.

> +	ret = ioctl(pidfd, PIDFD_GET_INFO, &info);
> +	SAFE_CLOSE(pidfd);
> +
> +	if (ret == -1) {
> +		/* - ENOTTY: kernel too old, ioctl(PIDFD_GET_INFO) not implemented */
> +		if (errno == ENOTTY)
> +			supported = 0;
> +
> +		/* - EINVAL: ioctl(PIDFD_GET_INFO) exists but args invalid
> +		 * - ESRCH: ioctl(PIDFD_GET_INFO) exists but task already exited
> +		 * supported in both cases, but info.mask not set
> +		 */
> +		else if (errno == EINVAL || errno == ESRCH)
> +			supported = 1;
> +		else
> +			tst_brk(TBROK | TERRNO, "unexpected ioctl(PIDFD_GET_INFO) error");
> +	} else {
> +		supported = 1;
> +	}
> +
> +	return supported;
> +}
> +
>  static inline int ioctl_pidfd_info_exit_supported(void)
>  {
>  	int ret;
> diff --git a/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c b/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c
> index c379717b3..d20c6f074 100644
> --- a/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c
> +++ b/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c
> @@ -14,7 +14,7 @@
>  #include "tst_test.h"
>  #include "lapi/pidfd.h"
>  #include "lapi/sched.h"
> -#include "lapi/ioctl.h"
> +#include "ioctl_pidfd.h"
>  
>  struct pidfd_info_invalid {
>  	uint32_t dummy;
> @@ -48,8 +48,15 @@ static void run(void)
>  	SAFE_CLOSE(pidfd);
>  }
>  
> +static void setup(void)
> +{
> +	if (!ioctl_pidfd_get_info_supported())
> +		tst_brk(TCONF, "ioctl(PIDFD_GET_INFO) is not implemented");
> +}
> +
>  static struct tst_test test = {
>  	.test_all = run,
> +	.setup = setup,
>  	.forks_child = 1,
>  	.bufs = (struct tst_buffers []) {
>  		{&args, .size = sizeof(*args)},
> -- 
> 2.51.0
> 

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [LTP] [PATCH v3] Introduce ioctl_pidfd_get_info_supported() function
  2025-09-23 18:44             ` Petr Vorel
@ 2025-09-24  8:40               ` Cyril Hrubis
  2025-09-24 20:29                 ` [LTP] [PATCH v4] " Avinesh Kumar
  0 siblings, 1 reply; 19+ messages in thread
From: Cyril Hrubis @ 2025-09-24  8:40 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

Hi!
> > use this routine in ioctl_pidfd05 before proceeding with the test
> 
> Reviewed-by: Petr Vorel <pvorel@suse.cz>
> 
> BTW, when testing on 6.11, I got:
> ioctl_pidfd05.c:45: TFAIL: ioctl(pidfd, PIDFD_GET_INFO, NULL) expected EINVAL: ENOTTY (25)

This is exactly what this patch is trying to address. Not sure what went
wrong there.

> Which is error unrelated to this patch, it's from original.
> 196988f7d1 ("Add ioctl_pidfd05 test")
> 
> Doc in ioctl_pidfd_info_exit_supported() is clear about it:
> 		/* - ENOTTY: old kernels not implementing fs/pidfs.c:pidfd_ioctl
> 		 * - EINVAL: until v6.13 kernel
> 		 * - ESRCH: all kernels between v6.13 and v6.15
> 		 */

And the pidfd_info_supported() tries to address that by returning zero
on ENOTTY.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [LTP] [PATCH v4] Introduce ioctl_pidfd_get_info_supported() function
  2025-09-24  8:40               ` Cyril Hrubis
@ 2025-09-24 20:29                 ` Avinesh Kumar
  2025-09-25  2:05                   ` Li Wang via ltp
                                     ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Avinesh Kumar @ 2025-09-24 20:29 UTC (permalink / raw)
  To: ltp

Check if ioctl(PIDFD_GET_INFO) is implemented or not
before proceeding in ioctl_pidfd05 test

Suggested-by: Cyril Hrubis <chrubis@suse.cz>
Suggested-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Avinesh Kumar <akumar@suse.de>
---
 testcases/kernel/syscalls/ioctl/ioctl_pidfd.h | 28 +++++++++++++++++++
 .../kernel/syscalls/ioctl/ioctl_pidfd05.c     |  9 +++++-
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h b/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
index 811f969cd..b785d8043 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
+++ b/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
@@ -9,6 +9,34 @@
 #include "tst_test.h"
 #include "lapi/pidfd.h"
 
+static inline bool ioctl_pidfd_get_info_supported(void)
+{
+	pid_t pid;
+	int pidfd, ret;
+	int supported = 0;
+	struct pidfd_info info;
+
+	if (tst_kvercmp(6, 13, 0) >= 0)
+		return 1;
+
+	memset(&info, 0, sizeof(struct pidfd_info));
+
+	pid = SAFE_FORK();
+	if (!pid)
+		exit(100);
+
+	pidfd = SAFE_PIDFD_OPEN(pid, 0);
+
+	ret = ioctl(pidfd, PIDFD_GET_INFO, &info);
+	SAFE_WAITPID(pid, NULL, 0);
+
+	if (ret != -1)
+		supported = 1;
+
+	SAFE_CLOSE(pidfd);
+	return supported;
+}
+
 static inline int ioctl_pidfd_info_exit_supported(void)
 {
 	int ret;
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c b/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c
index c379717b3..d20c6f074 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c
@@ -14,7 +14,7 @@
 #include "tst_test.h"
 #include "lapi/pidfd.h"
 #include "lapi/sched.h"
-#include "lapi/ioctl.h"
+#include "ioctl_pidfd.h"
 
 struct pidfd_info_invalid {
 	uint32_t dummy;
@@ -48,8 +48,15 @@ static void run(void)
 	SAFE_CLOSE(pidfd);
 }
 
+static void setup(void)
+{
+	if (!ioctl_pidfd_get_info_supported())
+		tst_brk(TCONF, "ioctl(PIDFD_GET_INFO) is not implemented");
+}
+
 static struct tst_test test = {
 	.test_all = run,
+	.setup = setup,
 	.forks_child = 1,
 	.bufs = (struct tst_buffers []) {
 		{&args, .size = sizeof(*args)},
-- 
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [LTP] [PATCH v3] Introduce ioctl_pidfd_get_info_supported() function
  2025-09-24  8:34             ` [LTP] [PATCH v3] " Cyril Hrubis
@ 2025-09-24 20:30               ` Avinesh Kumar
  0 siblings, 0 replies; 19+ messages in thread
From: Avinesh Kumar @ 2025-09-24 20:30 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi Cyril,

On Wednesday, September 24, 2025 10:34:43 AM CEST Cyril Hrubis wrote:
> Hi!
> > +static inline bool ioctl_pidfd_get_info_supported(void)
> > +{
> > +	pid_t pid;
> > +	int pidfd, ret;
> > +	int supported = 0;
> > +	struct pidfd_info info;
> > +
> > +	if (tst_kvercmp(6, 12, 0) >= 0)
> > +		return 1;
> > +
> > +	memset(&info, 0, sizeof(struct pidfd_info));
> > +
> > +	pid = SAFE_FORK();
> > +	if (!pid)
> > +		exit(100);
> > +
> > +	pidfd = SAFE_PIDFD_OPEN(pid, 0);
> > +	SAFE_WAITPID(pid, NULL, 0);
> 
> Again, please do not waitpid before the PIDFD_GET_INFO ioctl(). If you
> do that it has no chance of succeeding.
> 
> From fs/pidfd.c:
> 
> ...
>         task = get_pid_task(pid, PIDTYPE_PID);
>         if (!task) {
>                 /*
>                  * If the task has already been reaped, only exit
>                  * information is available
>                  */
>                 if (!(mask & PIDFD_INFO_EXIT))
>                         return -ESRCH;
> 
>                 goto copy_out;
>         }
> ...
> 
> We have to do the ioctl() first and the waitpid() second for this case.
> 
> And if we do so we don't have to check the errno at all, the call will
> just succeed in case that it's supported.
> 
Thank you for your patience explaining this one repeatedly. I read through
the iterations of these new tests in ML to get better understanding of
checking the feature detection. I have sent another revision.
I have also changed the kernel version check from 6.12 to 6.13 as that's
where I see pidfd_info() implementation.


Regards,
Avinesh




-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [LTP] [PATCH v4] Introduce ioctl_pidfd_get_info_supported() function
  2025-09-24 20:29                 ` [LTP] [PATCH v4] " Avinesh Kumar
@ 2025-09-25  2:05                   ` Li Wang via ltp
  2025-09-25  2:44                   ` Li Wang via ltp
  2025-09-25  6:54                   ` [LTP] [PATCH v4] " Cyril Hrubis
  2 siblings, 0 replies; 19+ messages in thread
From: Li Wang via ltp @ 2025-09-25  2:05 UTC (permalink / raw)
  To: Avinesh Kumar; +Cc: ltp

On Thu, Sep 25, 2025 at 4:29 AM Avinesh Kumar <akumar@suse.de> wrote:

> Check if ioctl(PIDFD_GET_INFO) is implemented or not
> before proceeding in ioctl_pidfd05 test
>
> Suggested-by: Cyril Hrubis <chrubis@suse.cz>
> Suggested-by: Petr Vorel <pvorel@suse.cz>
> Signed-off-by: Avinesh Kumar <akumar@suse.de>
>

This version looks much more elegant.

Reviewed-by: Li Wang <liwang@redhat.com>

---
>  testcases/kernel/syscalls/ioctl/ioctl_pidfd.h | 28 +++++++++++++++++++
>  .../kernel/syscalls/ioctl/ioctl_pidfd05.c     |  9 +++++-
>  2 files changed, 36 insertions(+), 1 deletion(-)
>
> diff --git a/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
> b/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
> index 811f969cd..b785d8043 100644
> --- a/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
> +++ b/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
> @@ -9,6 +9,34 @@
>  #include "tst_test.h"
>  #include "lapi/pidfd.h"
>
> +static inline bool ioctl_pidfd_get_info_supported(void)
> +{
> +       pid_t pid;
> +       int pidfd, ret;
> +       int supported = 0;
> +       struct pidfd_info info;
> +
> +       if (tst_kvercmp(6, 13, 0) >= 0)
> +               return 1;
> +
> +       memset(&info, 0, sizeof(struct pidfd_info));
> +
> +       pid = SAFE_FORK();
> +       if (!pid)
> +               exit(100);
> +
> +       pidfd = SAFE_PIDFD_OPEN(pid, 0);
> +
> +       ret = ioctl(pidfd, PIDFD_GET_INFO, &info);
> +       SAFE_WAITPID(pid, NULL, 0);
> +
> +       if (ret != -1)
> +               supported = 1;
> +
> +       SAFE_CLOSE(pidfd);
> +       return supported;
> +}
> +
>  static inline int ioctl_pidfd_info_exit_supported(void)
>  {
>         int ret;
> diff --git a/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c
> b/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c
> index c379717b3..d20c6f074 100644
> --- a/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c
> +++ b/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c
> @@ -14,7 +14,7 @@
>  #include "tst_test.h"
>  #include "lapi/pidfd.h"
>  #include "lapi/sched.h"
> -#include "lapi/ioctl.h"
> +#include "ioctl_pidfd.h"
>
>  struct pidfd_info_invalid {
>         uint32_t dummy;
> @@ -48,8 +48,15 @@ static void run(void)
>         SAFE_CLOSE(pidfd);
>  }
>
> +static void setup(void)
> +{
> +       if (!ioctl_pidfd_get_info_supported())
> +               tst_brk(TCONF, "ioctl(PIDFD_GET_INFO) is not implemented");
> +}
> +
>  static struct tst_test test = {
>         .test_all = run,
> +       .setup = setup,
>         .forks_child = 1,
>         .bufs = (struct tst_buffers []) {
>                 {&args, .size = sizeof(*args)},
> --
> 2.51.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>
>

-- 
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [LTP] [PATCH v4] Introduce ioctl_pidfd_get_info_supported() function
  2025-09-24 20:29                 ` [LTP] [PATCH v4] " Avinesh Kumar
  2025-09-25  2:05                   ` Li Wang via ltp
@ 2025-09-25  2:44                   ` Li Wang via ltp
  2025-09-25  8:19                     ` [LTP] [PATCH v5] " Avinesh Kumar
  2025-09-25  6:54                   ` [LTP] [PATCH v4] " Cyril Hrubis
  2 siblings, 1 reply; 19+ messages in thread
From: Li Wang via ltp @ 2025-09-25  2:44 UTC (permalink / raw)
  To: Avinesh Kumar; +Cc: ltp

On Thu, Sep 25, 2025 at 4:29 AM Avinesh Kumar <akumar@suse.de> wrote:

> Check if ioctl(PIDFD_GET_INFO) is implemented or not
> before proceeding in ioctl_pidfd05 test
>
> Suggested-by: Cyril Hrubis <chrubis@suse.cz>
> Suggested-by: Petr Vorel <pvorel@suse.cz>
> Signed-off-by: Avinesh Kumar <akumar@suse.de>
> ---
>  testcases/kernel/syscalls/ioctl/ioctl_pidfd.h | 28 +++++++++++++++++++
>  .../kernel/syscalls/ioctl/ioctl_pidfd05.c     |  9 +++++-
>  2 files changed, 36 insertions(+), 1 deletion(-)
>
> diff --git a/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
> b/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
> index 811f969cd..b785d8043 100644
> --- a/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
> +++ b/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
> @@ -9,6 +9,34 @@
>  #include "tst_test.h"
>  #include "lapi/pidfd.h"
>
> +static inline bool ioctl_pidfd_get_info_supported(void)
>

The return type should be int, but not bool.



> +{
> +       pid_t pid;
> +       int pidfd, ret;
> +       int supported = 0;
> +       struct pidfd_info info;
> +
> +       if (tst_kvercmp(6, 13, 0) >= 0)
> +               return 1;
> +
> +       memset(&info, 0, sizeof(struct pidfd_info));
> +
> +       pid = SAFE_FORK();
> +       if (!pid)
> +               exit(100);
> +
> +       pidfd = SAFE_PIDFD_OPEN(pid, 0);
> +
> +       ret = ioctl(pidfd, PIDFD_GET_INFO, &info);
> +       SAFE_WAITPID(pid, NULL, 0);
> +
> +       if (ret != -1)
> +               supported = 1;
> +
> +       SAFE_CLOSE(pidfd);
> +       return supported;
> +}
> +
>  static inline int ioctl_pidfd_info_exit_supported(void)
>  {
>         int ret;
> diff --git a/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c
> b/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c
> index c379717b3..d20c6f074 100644
> --- a/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c
> +++ b/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c
> @@ -14,7 +14,7 @@
>  #include "tst_test.h"
>  #include "lapi/pidfd.h"
>  #include "lapi/sched.h"
> -#include "lapi/ioctl.h"
> +#include "ioctl_pidfd.h"
>
>  struct pidfd_info_invalid {
>         uint32_t dummy;
> @@ -48,8 +48,15 @@ static void run(void)
>         SAFE_CLOSE(pidfd);
>  }
>
> +static void setup(void)
> +{
> +       if (!ioctl_pidfd_get_info_supported())
> +               tst_brk(TCONF, "ioctl(PIDFD_GET_INFO) is not implemented");
> +}
> +
>  static struct tst_test test = {
>         .test_all = run,
> +       .setup = setup,
>         .forks_child = 1,
>         .bufs = (struct tst_buffers []) {
>                 {&args, .size = sizeof(*args)},
> --
> 2.51.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>
>

-- 
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [LTP] [PATCH v4] Introduce ioctl_pidfd_get_info_supported() function
  2025-09-24 20:29                 ` [LTP] [PATCH v4] " Avinesh Kumar
  2025-09-25  2:05                   ` Li Wang via ltp
  2025-09-25  2:44                   ` Li Wang via ltp
@ 2025-09-25  6:54                   ` Cyril Hrubis
  2 siblings, 0 replies; 19+ messages in thread
From: Cyril Hrubis @ 2025-09-25  6:54 UTC (permalink / raw)
  To: Avinesh Kumar; +Cc: ltp

Hi!
Looks good now:

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [LTP] [PATCH v5] Introduce ioctl_pidfd_get_info_supported() function
  2025-09-25  2:44                   ` Li Wang via ltp
@ 2025-09-25  8:19                     ` Avinesh Kumar
  2025-09-25 11:45                       ` Petr Vorel
  2025-09-25 12:15                       ` Petr Vorel
  0 siblings, 2 replies; 19+ messages in thread
From: Avinesh Kumar @ 2025-09-25  8:19 UTC (permalink / raw)
  To: ltp

Check if ioctl(PIDFD_GET_INFO) is implemented or not
before proceeding in ioctl_pidfd05 test

Reviewed-by: Li Wang <liwang@redhat.com>
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Suggested-by: Cyril Hrubis <chrubis@suse.cz>
Suggested-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Avinesh Kumar <akumar@suse.de>
---
 testcases/kernel/syscalls/ioctl/ioctl_pidfd.h | 28 +++++++++++++++++++
 .../kernel/syscalls/ioctl/ioctl_pidfd05.c     |  9 +++++-
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h b/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
index 811f969cd..2740284f7 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
+++ b/testcases/kernel/syscalls/ioctl/ioctl_pidfd.h
@@ -9,6 +9,34 @@
 #include "tst_test.h"
 #include "lapi/pidfd.h"
 
+static inline int ioctl_pidfd_get_info_supported(void)
+{
+	pid_t pid;
+	int pidfd, ret;
+	int supported = 0;
+	struct pidfd_info info;
+
+	if (tst_kvercmp(6, 13, 0) >= 0)
+		return 1;
+
+	memset(&info, 0, sizeof(struct pidfd_info));
+
+	pid = SAFE_FORK();
+	if (!pid)
+		exit(100);
+
+	pidfd = SAFE_PIDFD_OPEN(pid, 0);
+
+	ret = ioctl(pidfd, PIDFD_GET_INFO, &info);
+	SAFE_WAITPID(pid, NULL, 0);
+
+	if (ret != -1)
+		supported = 1;
+
+	SAFE_CLOSE(pidfd);
+	return supported;
+}
+
 static inline int ioctl_pidfd_info_exit_supported(void)
 {
 	int ret;
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c b/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c
index c379717b3..d20c6f074 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c
@@ -14,7 +14,7 @@
 #include "tst_test.h"
 #include "lapi/pidfd.h"
 #include "lapi/sched.h"
-#include "lapi/ioctl.h"
+#include "ioctl_pidfd.h"
 
 struct pidfd_info_invalid {
 	uint32_t dummy;
@@ -48,8 +48,15 @@ static void run(void)
 	SAFE_CLOSE(pidfd);
 }
 
+static void setup(void)
+{
+	if (!ioctl_pidfd_get_info_supported())
+		tst_brk(TCONF, "ioctl(PIDFD_GET_INFO) is not implemented");
+}
+
 static struct tst_test test = {
 	.test_all = run,
+	.setup = setup,
 	.forks_child = 1,
 	.bufs = (struct tst_buffers []) {
 		{&args, .size = sizeof(*args)},
-- 
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [LTP] [PATCH v5] Introduce ioctl_pidfd_get_info_supported() function
  2025-09-25  8:19                     ` [LTP] [PATCH v5] " Avinesh Kumar
@ 2025-09-25 11:45                       ` Petr Vorel
  2025-09-25 12:15                       ` Petr Vorel
  1 sibling, 0 replies; 19+ messages in thread
From: Petr Vorel @ 2025-09-25 11:45 UTC (permalink / raw)
  To: Avinesh Kumar; +Cc: ltp

Hi Avinesh,

...
> +static inline int ioctl_pidfd_get_info_supported(void)

nit: I liked more the previous version v4, where 'bool' was used.
Actually both functions could use 'bool', but I'm perfectly ok with 'int'.

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

> +{
> +	pid_t pid;
> +	int pidfd, ret;
> +	int supported = 0;
> +	struct pidfd_info info;
> +
> +	if (tst_kvercmp(6, 13, 0) >= 0)
> +		return 1;
> +
> +	memset(&info, 0, sizeof(struct pidfd_info));
> +
> +	pid = SAFE_FORK();
> +	if (!pid)
> +		exit(100);
> +
> +	pidfd = SAFE_PIDFD_OPEN(pid, 0);
> +
> +	ret = ioctl(pidfd, PIDFD_GET_INFO, &info);
> +	SAFE_WAITPID(pid, NULL, 0);
> +
> +	if (ret != -1)
> +		supported = 1;
> +
> +	SAFE_CLOSE(pidfd);
> +	return supported;
> +}

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [LTP] [PATCH v5] Introduce ioctl_pidfd_get_info_supported() function
  2025-09-25  8:19                     ` [LTP] [PATCH v5] " Avinesh Kumar
  2025-09-25 11:45                       ` Petr Vorel
@ 2025-09-25 12:15                       ` Petr Vorel
  1 sibling, 0 replies; 19+ messages in thread
From: Petr Vorel @ 2025-09-25 12:15 UTC (permalink / raw)
  To: Avinesh Kumar; +Cc: ltp

Hi all,

Fix merged, thank you!

Kind regards,
Petr

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2025-09-25 12:15 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-22 20:39 [LTP] [PATCH] Introduce ioctl_pidfd_get_info_supported() function Avinesh Kumar
2025-09-22 21:07 ` Petr Vorel
2025-09-23  7:51   ` [LTP] [PATCH v2] " Avinesh Kumar
2025-09-23  9:43     ` Petr Vorel
2025-09-23 11:17     ` Cyril Hrubis
2025-09-23 11:39       ` Petr Vorel
2025-09-23 11:49         ` Cyril Hrubis
2025-09-23 15:03           ` [LTP] [PATCH v3] " Avinesh Kumar
2025-09-23 18:44             ` Petr Vorel
2025-09-24  8:40               ` Cyril Hrubis
2025-09-24 20:29                 ` [LTP] [PATCH v4] " Avinesh Kumar
2025-09-25  2:05                   ` Li Wang via ltp
2025-09-25  2:44                   ` Li Wang via ltp
2025-09-25  8:19                     ` [LTP] [PATCH v5] " Avinesh Kumar
2025-09-25 11:45                       ` Petr Vorel
2025-09-25 12:15                       ` Petr Vorel
2025-09-25  6:54                   ` [LTP] [PATCH v4] " Cyril Hrubis
2025-09-24  8:34             ` [LTP] [PATCH v3] " Cyril Hrubis
2025-09-24 20:30               ` Avinesh Kumar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox