tst_fd.c: fix test_failures on loongarch's old
cover tst_fd.c: fix test_failures on loongarch's old
From: Gang Yan <[email protected]>
Patch1 fixes LTP tst_fd/accept03 test failures on LoongArch64 introduced after commit 209f0c6360da ("Update arch(s) syscalls files") removed memfd_secret syscall number from loongarch64 syscall table.
Patch 2-3 refactors LTP syscall helper to properly handle missing syscalls without unexpected TBROK/TFAIL errors.
Gang Yan (3):
loongarch.in: add memfd_secret syscall generate_syscall.sh: add a helper named tst_syscall_base tst_fd.c: replace syscall() with tst_syscall_base()
include/lapi/syscalls/generate_syscalls.sh | 27 +++++++++++++--------- include/lapi/syscalls/loongarch64.in | 1 + lib/tst_fd.c | 22 +++++++++--------- 3 files changed, 28 insertions(+), 22 deletions(-)
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 1/3 loongarch.in: add memfd_secret syscall
From: Gang Yan <[email protected]>
In 209f0c6360da('Update arch(s) syscalls files'), it only removes the 'memfd_secret' for loongarch, so that caused a error based on the old kernel:
'''
...
accept03.c:47: TFAIL: accept() on memfd secret expected ENOTSOCK: EBADF (9) tst_fd.c:307: TBROK: close(38) failed: EBADF(9)
'''
This patch put it back, and the output is attached below:
'''
...tst_fd.c: 262: TCONF: Skipping memfd secret : ENOSYS(38) '''
--- include/lapi/syscalls/loongarch64.in | 1 + 1 file changed, 1 insertion(+)
include/lapi/syscalls/loongarch64.in +1 -0
@@ -296,6 +296,7 @@ mount_setattr 442 quotactl_fd 443 landlock_create_ruleset 444 landlock_add_rule 445 +memfd_secret 447 landlock_restrict_self 446 process_mrelease 448 futex_waitv 449
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 3/3 tst_fd.c: replace syscall() with tst_syscall_base()
In reply to Gang YanFrom: Gang Yan <[email protected]>
If some feature is not supported by some arch, like _NR__memfd_secret, it will become -1. And the syscall can continue with '-1' and the output would be:
'''
accept03.c:47: TFAIL: accept() on memfd secret expected ENOTSOCK: EBADF (9) tst_fd.c:307: TBROK: close(38) failed: EBADF(9)
'''
This patch use tst_syscall to give a more specific fail reason:
'''
tst_fd.c:262: TCONF: Skipping memfd secret: ENOSYS(38) '''
--- lib/tst_fd.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
lib/tst_fd.c +11 -11
@@ -139,14 +139,14 @@ static void open_timerfd(struct tst_fd *fd)static void open_pidfd (struct tst_fd *fd) { - fd->fd =syscall (__NR_pidfd_open,getpid (),0 ); + fd->fd =tst_syscall_base (__NR_pidfd_open,getpid (),0 );if (fd->fd <0 )tst_res (TCONF |TERRNO ,"pidfd_open()" ); }static void open_fanotify (struct tst_fd *fd) { - fd->fd =syscall (__NR_fanotify_init,FAN_CLASS_NOTIF ,O_RDONLY ); + fd->fd =tst_syscall_base (__NR_fanotify_init,FAN_CLASS_NOTIF ,O_RDONLY );if (fd->fd <0 ) {tst_res (TCONF |TERRNO ,"Skipping %s" ,tst_fd_desc (fd));
@@ -164,7 +164,7 @@ static void open_inotify(struct tst_fd *fd)static void open_userfaultfd (struct tst_fd *fd) { - fd->fd =syscall (__NR_userfaultfd,0 ); + fd->fd =tst_syscall_base (__NR_userfaultfd,0 );if (fd->fd <0 ) { tst_res(TCONF | TERRNO,
@@ -183,7 +183,7 @@ static void open_perf_event(struct tst_fd *fd) .exclude_hv = 1, }; - fd->fd =syscall (__NR_perf_event_open, &pe_attr,0 ,-1 ,-1 ,0 ); + fd->fd =tst_syscall_base (__NR_perf_event_open, &pe_attr,0 ,-1 ,-1 ,0 );if (fd->fd <0 ) {tst_res (TCONF |TERRNO ,"Skipping %s" ,tst_fd_desc (fd));
@@ -194,7 +194,7 @@ static void open_io_uring(struct tst_fd *fd) {struct io_uring_params uring_params = {}; - fd->fd =syscall (__NR_io_uring_setup,1 , &uring_params); + fd->fd =tst_syscall_base (__NR_io_uring_setup,1 , &uring_params);if (fd->fd <0 ) {tst_res (TCONF |TERRNO ,"Skipping %s" ,tst_fd_desc (fd));
@@ -210,7 +210,7 @@ static void open_bpf_map(struct tst_fd *fd) .max_entries = 1, }; - fd->fd =syscall (__NR_bpf,BPF_MAP_CREATE , &array_attr,sizeof (array_attr)); + fd->fd =tst_syscall_base (__NR_bpf,BPF_MAP_CREATE , &array_attr,sizeof (array_attr));if (fd->fd <0 ) {tst_res (TCONF |TERRNO ,"Skipping %s" ,tst_fd_desc (fd));
@@ -219,7 +219,7 @@ static void open_bpf_map(struct tst_fd *fd)static void open_fsopen (struct tst_fd *fd) { - fd->fd =syscall (__NR_fsopen,"ext2" ,0 ); + fd->fd =tst_syscall_base (__NR_fsopen,"ext2" ,0 );if (fd->fd <0 ) {tst_res (TCONF |TERRNO ,"Skipping %s" ,tst_fd_desc (fd));
@@ -228,7 +228,7 @@ static void open_fsopen(struct tst_fd *fd)static void open_fspick (struct tst_fd *fd) { - fd->fd =syscall (__NR_fspick,AT_FDCWD ,"/" ,0 ); + fd->fd =tst_syscall_base (__NR_fspick,AT_FDCWD ,"/" ,0 );if (fd->fd <0 ) {tst_res (TCONF |TERRNO ,"Skipping %s" ,tst_fd_desc (fd));
@@ -237,7 +237,7 @@ static void open_fspick(struct tst_fd *fd)static void open_open_tree (struct tst_fd *fd) { - fd->fd =syscall (__NR_open_tree,AT_FDCWD ,"/" ,0 ); + fd->fd =tst_syscall_base (__NR_open_tree,AT_FDCWD ,"/" ,0 );if (fd->fd <0 ) {tst_res (TCONF |TERRNO ,"Skipping %s" ,tst_fd_desc (fd));
@@ -246,7 +246,7 @@ static void open_open_tree(struct tst_fd *fd)static void open_memfd (struct tst_fd *fd) { - fd->fd =syscall (__NR_memfd_create,"ltp_memfd" ,0 ); + fd->fd =tst_syscall_base (__NR_memfd_create,"ltp_memfd" ,0 );if (fd->fd <0 ) {tst_res (TCONF |TERRNO ,"Skipping %s" ,tst_fd_desc (fd));
@@ -255,7 +255,7 @@ static void open_memfd(struct tst_fd *fd)static void open_memfd_secret (struct tst_fd *fd) { - fd->fd =syscall (__NR_memfd_secret,0 ); + fd->fd =tst_syscall_base (__NR_memfd_secret,0 );if (fd->fd <0 ) {tst_res (TCONF |TERRNO ,"Skipping %s" ,tst_fd_desc (fd));
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 2/3 generate_syscall.sh: add a helper named tst_syscall_base
In reply to Gang YanFrom: Gang Yan <[email protected]>
This patch adds a helper named tst_syscall_base, it can check the syscall on older distros without tst_brk.
--- include/lapi/syscalls/generate_syscalls.sh | 27 +++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-)
include/lapi/syscalls/generate_syscalls.sh +16 -11
@@ -49,18 +49,23 @@ tst_brkm(TCONF, dummy_cleanup, \ }) #endif +#define tst_syscall_base(NR, ...) ({ \ + intptr_t tst_ret; \ + if (NR == __LTP__NR_INVALID_SYSCALL) { \ + errno = ENOSYS; \ + tst_ret = -1; \ + } else { \ + tst_ret = syscall(NR, ##__VA_ARGS__); \ + } \ + tst_ret; \ +}) + #define tst_syscall(NR, ...) ({ \ -intptr_t tst_ret; \ -if (NR == __LTP__NR_INVALID_SYSCALL) { \ - errno = ENOSYS; \ - tst_ret = -1; \ -} else { \ - tst_ret = syscall(NR, ##__VA_ARGS__); \ -} \ -if (tst_ret == -1 && errno == ENOSYS) { \ - TST_SYSCALL_BRK__(NR, #NR); \ -} \ -tst_ret; \ + intptr_t tst_ret = tst_syscall_base(NR, ##__VA_ARGS__); \ + if (tst_ret == -1 && errno == ENOSYS) { \ + TST_SYSCALL_BRK__(NR, #NR); \ + } \ + tst_ret; \ }) #define __LTP__NR_INVALID_SYSCALL -1' >${SYSCALLS_FILE}
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] loongarch.in: add memfd_secret syscall
In reply to Gang YanHi Gang,
Quoted 1 line · Gang Yan
loongarch.in: add
memfd_secretsyscall
--- [PATCH 1/3] ---
The subject names the wrong file. The changed file is "loongarch64.in", not "loongarch.in".
Quoted 3 lines
In 209f0c6360da('Update arch(s) syscalls files'), it only removes the '
memfd_secret' for loongarch, so that caused a error based on the old kernel:
"a error" -> "an error". Also, "based on the old kernel" is unclear: the EBADF failure occurs because __NR_memfd_secret defaults to -1 when absent from the syscall table, not because of any particular kernel version.
Quoted 2 lines
+memfd_secret 447
landlock_restrict_self446
memfd_secret (447) is inserted before landlock_restrict_self (446), breaking the ascending numerical order of the file. Should the insertion point be after landlock_restrict_self?
landlock_add_rule 445 landlock_restrict_self 446 + memfd_secret 447 process_mrelease 448
--- [PATCH 2/3] ---
The subject names the wrong file. The script is "generate_syscalls.sh" (plural), not "generate_syscall.sh".
Review
Quoted 10 lines
(quoted diff) +10
-0+#define tst_syscall_base(NR, ...) ({ \ + intptr_t tst_ret; \ + if (NR == __LTP__NR_INVALID_SYSCALL) { \ + errno = ENOSYS; \ + tst_ret = -1; \ + } else { \ + tst_ret = syscall(NR, ##__VA_ARGS__); \ + } \ + tst_ret; \ +})
The macro body uses spaces for indentation. LTP follows Linux kernel coding style which requires tabs. The same applies to the refactored tst_syscall body below.
Review
Quoted 7 lines
(quoted diff) +7
-0+#define tst_syscall(NR, ...) ({ \ + intptr_t tst_ret = tst_syscall_base(NR, ##__VA_ARGS__); \ + if (tst_ret == -1 && errno == ENOSYS) { \ + TST_SYSCALL_BRK__(NR, #NR); \ + } \ + tst_ret; \ +})
Same indentation issue -- tabs required.
--- [PATCH 3/3] ---
Quoted 1 line
If some feature is not supported by some arch, like
_NR__memfd_secret,
Typo: "_NR__memfd_secret" should be "__NR_memfd_secret".
Quoted 1 line
This patch use
tst_syscallto give a more specific fail reason:
The macro used throughout this patch is tst_syscall_base(), not tst_syscall(). "use" -> "uses".
Verdict - Needs revision
---
Note:
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 2/3] generate_syscall.sh: add a helper named tst_syscall_base
In reply to Gang YanHi Gang,
Quoted 18 lines
From: Gang Yan <[email protected]>
This patch adds a helper named
tst_syscall_base, it can check the syscall on older distros withouttst_brk.Signed-off-by Gang Yan <[email protected]>--- include/lapi/syscalls/generate_syscalls.sh | 27 +++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-)include/lapi/syscalls/generate_syscalls.sh +0
-0@@ -49,18 +49,23 @@ tst_brkm(TCONF, dummy_cleanup, \ }) #endif
include/lapi/syscalls/generate_syscalls.sh tst_brkm(TCONF, dummy_cleanup, \ · line 61
Quoted 10 lines
include/lapi/syscalls/generate_syscalls.sh +10
-0+#define tst_syscall_base(NR, ...) ({ \ + intptr_t tst_ret; \ + if (NR == __LTP__NR_INVALID_SYSCALL) { \ + errno = ENOSYS; \ + tst_ret = -1; \ + } else { \ + tst_ret = syscall(NR, ##__VA_ARGS__); \ + } \ + tst_ret; \ +})
Do we really need this? If we don't define memfd_secret, we really want to get a TCONF. And the function is used in a weird way.
If you need to add the support for memfd_secret, please just update the syscalls files via:
./include/lapi/syscalls/generate_arch.sh <path to linux sources>
We don't update .in files manually since it's error prone.
Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 2/3] generate_syscall.sh: add a helper named tst_syscall_base
Quoted 33 lines · Andrea Cervesato
Hi Gang,
Quoted 30 lines
From: Gang Yan <[email protected]>
This patch adds a helper named
tst_syscall_base, it can check the syscall on older distros withouttst_brk.Signed-off-by Gang Yan <[email protected]>---
include/lapi/syscalls/generate_syscalls.sh | 27 +++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-)diff --git
a/include/lapi/syscalls/generate_syscalls.shb/include/lapi/syscalls/generate_syscalls.shindex19f280dfb..95c2c9aeb100755
---a/include/lapi/syscalls/generate_syscalls.sh
+++b/include/lapi/syscalls/generate_syscalls.sh
@@ -49,18 +49,23 @@ tst_brkm(TCONF,dummy_cleanup, \
})
#endif+#define
tst_syscall_base(NR, ...)({ \
+intptr_ttst_ret; \
+ if (NR ==__LTP__NR_INVALID_SYSCALL) { \
+ errno = ENOSYS; \
+tst_ret= -1; \
+ } else { \
+tst_ret=syscall(NR, ##__VA_ARGS__); \
+ } \
+tst_ret; \
+})
Hi Andrea,
Thanks for your review.
Quoted 2 lines
Do we really need this? If we don't define
memfd_secret, we really want to get a TCONF. And the function is used in a weird way.
You are right. I've confirmed that syscall(-1) returning a positive value is a glibc or kernel bug on loongarch64, syscall(-1) should return -1, but return 38 (ENONSYS) in my enviroment. It is not something LTP should work around.
Quoted 8 lines
If you need to add the support for
memfd_secret, please just update the syscalls files via:
./include/lapi/syscalls/generate_arch.sh<path to linux sources>We don't update .in files manually since it's error prone.
Thanks again
Cherrs
Gang
Quoted 6 lines
Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux [email protected] mailto:[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp