Introduce ioctl_pidfd_get_info_supported() function
PATCH 1/1 Introduce ioctl_pidfd_get_info_supported() function
- use new routine in ioctl_pidfd05 test
- refactor ioctl_pidfd_info_exit_supported() routine
--- testcases/kernel/syscalls/ioctl/ioctl_pidfd.h | 45 +++++++++++-------- .../kernel/syscalls/ioctl/ioctl_pidfd05.c | 9 +++- 2 files changed, 34 insertions(+), 20 deletions(-)
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h +26 -19
@@ -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
testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c +8 -1
@@ -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)},
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Avinesh,
thanks for fixing this!
...
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h static inline int ioctl_pidfd_info_exit_supported(void) · line 43
Quoted 12 lines
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h +8
-1if (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.
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h static inline int ioctl_pidfd_info_exit_supported(void) · line 46
Quoted 3 lines
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h +3
-0+} + +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
Quoted 13 lines
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h +10
-1+{ +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 ); }
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/1 Introduce ioctl_pidfd_get_info_supported() function
- use new routine in ioctl_pidfd05 test
- refactor ioctl_pidfd_info_exit_supported() routine
--- testcases/kernel/syscalls/ioctl/ioctl_pidfd.h | 49 ++++++++++++------- .../kernel/syscalls/ioctl/ioctl_pidfd05.c | 9 +++- 2 files changed, 39 insertions(+), 19 deletions(-)
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h +31 -18
@@ -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
testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c +8 -1
@@ -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)},
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Avinesh,
...
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h static inline int ioctl_pidfd_info_exit_supported(void) · line 41
Quoted 12 lines
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h +7
-3if (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.
Kind regards,
Petr
Quoted 20 lines
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h +10
-8-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 ) +{
...
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 24 lines
- use new routine in
ioctl_pidfd05test
- refactorioctl_pidfd_info_exit_supported()routineSuggested-by Petr Vorel <[email protected]>Signed-off-by Avinesh Kumar <[email protected]>--- testcases/kernel/syscalls/ioctl/ioctl_pidfd.h | 49 ++++++++++++------- .../kernel/syscalls/ioctl/ioctl_pidfd05.c | 9 +++- 2 files changed, 39 insertions(+), 19 deletions(-)testcases/kernel/syscalls/ioctl/ioctl_pidfd.h +1
-3@@ -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;
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h line 24
Quoted 10 lines
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h +2
-3-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.
Quoted 19 lines
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h +9
-3pid =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
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h static inline int ioctl_pidfd_info_exit_supported(void) · line 43
Quoted 10 lines
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h +2
-7*/ -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.
Quoted 56 lines
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h +16
-2+ 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 testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c +8
-1@@ -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)},Signature · 1 line
2.51.0
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Avinesh, Cyril,
...
Quoted 5 lines
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h line 24
Quoted 2 lines
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h +0
-1memset (&info,0 ,sizeof (struct pidfd_info )); - info.mask =PIDFD_INFO_EXIT ;We have to keep the
PIDFD_INFO_EXITin the mask, otherwise it will never be set back by the kernel.
+1, I'm sorry to overlook this change.
Quoted 24 lines
Quoted 24 lines
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h +9
-7pid =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" );
Quoted 8 lines
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h static inline int ioctl_pidfd_info_exit_supported(void) · line 43
Quoted 5 lines
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h +2
-3- }else { -if (info.mask &PIDFD_INFO_EXIT ) - supported =1 ; +if (errno ==EINVAL || errno ==ESRCH ) +return 0 ;If we do not pass the
PIDFD_INFO_EXITabove we will end up with ESRCH here all the time.
+1 (again, I'm sorry to overlook it).
Quoted 6 lines
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_EXITis not implemented. Without thePIDFD_INFO_EXITflag thepidfd_info()syscall is supposed to work on a process before it's waited for andPIDFD_INFO_EXITdoes 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
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 10 lines
Quoted 6 lines
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_EXITis not implemented. Without thePIDFD_INFO_EXITflag thepidfd_info()syscall is supposed to work on a process before it's waited for andPIDFD_INFO_EXITdoes 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_EXITfor checkingPIDFD_GET_INFOwas 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...
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 1/1 Introduce ioctl_pidfd_get_info_supported() function
use this routine in ioctl_pidfd05 before proceeding with the test
--- testcases/kernel/syscalls/ioctl/ioctl_pidfd.h | 42 +++++++++++++++++++ .../kernel/syscalls/ioctl/ioctl_pidfd05.c | 9 +++- 2 files changed, 50 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h +42 -0
@@ -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;
testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c +8 -1
@@ -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)},
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Avinesh,
Quoted 1 line
use this routine in
ioctl_pidfd05before proceeding with the test
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
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 6 lines
Quoted 1 line
use this routine in
ioctl_pidfd05before proceeding with the testReviewed-by Petr Vorel <[email protected]>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.
Quoted 8 lines
Which is error unrelated to this patch, it's from original.
196988f7d1("Addioctl_pidfd05test")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.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 1/1 Introduce ioctl_pidfd_get_info_supported() function
Check if ioctl(PIDFD_GET_INFO) is implemented or not before proceeding in ioctl_pidfd05 test
--- testcases/kernel/syscalls/ioctl/ioctl_pidfd.h | 28 +++++++++++++++++++ .../kernel/syscalls/ioctl/ioctl_pidfd05.c | 9 +++++- 2 files changed, 36 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h +28 -0
@@ -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;
testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c +8 -1
@@ -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)},
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 7 lines · Avinesh Kumar
Check if
ioctl(PIDFD_GET_INFO)is implemented or not before proceeding inioctl_pidfd05testSuggested-by Cyril Hrubis <[email protected]>Suggested-by Petr Vorel <[email protected]>Signed-off-by Avinesh Kumar <[email protected]>
This version looks much more elegant.
---
Quoted 82 lines
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h | 28 +++++++++++++++++++ .../kernel/syscalls/ioctl/ioctl_pidfd05.c | 9 +++++- 2 files changed, 36 insertions(+), 1 deletion(-)testcases/kernel/syscalls/ioctl/ioctl_pidfd.h +28
-0@@ -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;testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c +8
-2@@ -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
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 17 lines · Avinesh Kumar
Check if
ioctl(PIDFD_GET_INFO)is implemented or not before proceeding inioctl_pidfd05testSuggested-by Cyril Hrubis <[email protected]>Suggested-by Petr Vorel <[email protected]>Signed-off-by Avinesh Kumar <[email protected]>--- testcases/kernel/syscalls/ioctl/ioctl_pidfd.h | 28 +++++++++++++++++++ .../kernel/syscalls/ioctl/ioctl_pidfd05.c | 9 +++++- 2 files changed, 36 insertions(+), 1 deletion(-)testcases/kernel/syscalls/ioctl/ioctl_pidfd.h +0
-0
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h line 13
Quoted 5 lines
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h +1
-0@@ -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.
Quoted 68 lines
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h +27
-0+{ +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;testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c +8
-2@@ -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
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v5 1/1 Introduce ioctl_pidfd_get_info_supported() function
Check if ioctl(PIDFD_GET_INFO) is implemented or not before proceeding in ioctl_pidfd05 test
--- testcases/kernel/syscalls/ioctl/ioctl_pidfd.h | 28 +++++++++++++++++++ .../kernel/syscalls/ioctl/ioctl_pidfd05.c | 9 +++++- 2 files changed, 36 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h +28 -0
@@ -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;
testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c +8 -1
@@ -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)},
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Avinesh,
...
Quoted 1 line
+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'.
Kind regards,
Petr
Quoted 26 lines
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h +26
-0+{ +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; +}
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi all,
Fix merged, thank you!
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Looks good now:
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 8 lines
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h +8
-0+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 )
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h line 29
Quoted 10 lines
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h +10
-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.
Quoted 58 lines
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h +23
-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;testcases/kernel/syscalls/ioctl/ioctl_pidfd05.c +8
-1@@ -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)},Signature · 1 line
2.51.0
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Cyril,
Quoted 37 lines · CEST Cyril Hrubis
Hi!
Quoted 8 lines
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h +8
-0+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 )testcases/kernel/syscalls/ioctl/ioctl_pidfd.h line 29
Quoted 10 lines
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h +10
-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_INFOioctl(). 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; }
Quoted 7 lines
...
We have to do the
ioctl()first and thewaitpid()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
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp