Add process_mrelease testing suite
PATCH v2 3/3 Add process_mrelease02 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
This test verifies that process_mrelease() syscall correctly raises the errors.
--- runtest/syscalls | 1 + .../kernel/syscalls/process_mrelease/.gitignore | 1 + .../syscalls/process_mrelease/process_mrelease02.c | 84 ++++++++++++++++++++++ 3 files changed, 86 insertions(+)
runtest/syscalls +1 -0
@@ -1074,6 +1074,7 @@ preadv203_64 preadv203_64 profil01 profil01 process_mrelease01 process_mrelease01 +process_mrelease02 process_mrelease02 process_vm_readv01 process_vm01 -r process_vm_readv02 process_vm_readv02
testcases/kernel/syscalls/process_mrelease/.gitignore +1 -0
@@ -1 +1,2 @@ /process_mrelease01 +/process_mrelease02
testcases/kernel/syscalls/process_mrelease/process_mrelease02.c new file +84 -0
84 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 2/3 Add process_mrelease01 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
This test verifies that process_mrelease() syscall is releasing memory from a killed process with memory allocation pending.
--- runtest/syscalls | 2 + .../kernel/syscalls/process_mrelease/.gitignore | 1 + .../kernel/syscalls/process_mrelease/Makefile | 7 + .../syscalls/process_mrelease/process_mrelease01.c | 168 +++++++++++++++++++++ 4 files changed, 178 insertions(+)
runtest/syscalls +2 -0
@@ -1073,6 +1073,8 @@ preadv203_64 preadv203_64 profil01 profil01 +process_mrelease01 process_mrelease01 + process_vm_readv01 process_vm01 -r process_vm_readv02 process_vm_readv02 process_vm_readv03 process_vm_readv03
testcases/kernel/syscalls/process_mrelease/.gitignore new file +1 -0
@@ -0,0 +1 @@ +/process_mrelease01
testcases/kernel/syscalls/process_mrelease/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]> + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/process_mrelease/process_mrelease01.c new file +168 -0
168 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
v2 cover Add process_mrelease testing suite
This testing suite is meant to add coverage for process_mrelease() syscall, introduced in the kernel 5.15.
The testing suite is providing following tests:
- process_mrelease01
- process_mrelease02
Since there's no man pages, please consider the following documentation instead:
https://lwn.net/Articles/864184/
https://lwn.net/Articles/865341/
---
Changes in v2:
- process_mrelease01: change the algorithm to ensure we released the
memory after process_mrelease() is called
- process_mrelease02: verify ESRCH error
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Andrea Cervesato (3):
Add process_mrelease syscalls definition
Add process_mrelease01 test
Add process_mrelease02 test
include/lapi/syscalls/aarch64.in | 1 + include/lapi/syscalls/arc.in | 1 + include/lapi/syscalls/arm.in | 1 + include/lapi/syscalls/hppa.in | 1 + include/lapi/syscalls/i386.in | 1 + include/lapi/syscalls/ia64.in | 1 + include/lapi/syscalls/mips_n32.in | 1 + include/lapi/syscalls/mips_n64.in | 1 + include/lapi/syscalls/mips_o32.in | 1 + include/lapi/syscalls/powerpc.in | 1 + include/lapi/syscalls/powerpc64.in | 1 + include/lapi/syscalls/s390.in | 1 + include/lapi/syscalls/s390x.in | 1 + include/lapi/syscalls/sh.in | 1 + include/lapi/syscalls/sparc.in | 1 + include/lapi/syscalls/sparc64.in | 1 + include/lapi/syscalls/x86_64.in | 1 + runtest/syscalls | 3 + .../kernel/syscalls/process_mrelease/.gitignore | 2 + .../kernel/syscalls/process_mrelease/Makefile | 7 + .../syscalls/process_mrelease/process_mrelease01.c | 168 +++++++++++++++++++++ .../syscalls/process_mrelease/process_mrelease02.c | 84 +++++++++++ 22 files changed, 281 insertions(+)
---
base-commit: e7ebc637d0d99295490adf57660a3b3a177d65d3
change-id: 20240522-process_mrelease-3f2632b432e6
Best regards,
Signature · 5 lines
Andrea Cervesato <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/3 Add process_mrelease syscalls definition
From: Andrea Cervesato <[email protected]>
--- include/lapi/syscalls/aarch64.in | 1 + include/lapi/syscalls/arc.in | 1 + include/lapi/syscalls/arm.in | 1 + include/lapi/syscalls/hppa.in | 1 + include/lapi/syscalls/i386.in | 1 + include/lapi/syscalls/ia64.in | 1 + include/lapi/syscalls/mips_n32.in | 1 + include/lapi/syscalls/mips_n64.in | 1 + include/lapi/syscalls/mips_o32.in | 1 + include/lapi/syscalls/powerpc.in | 1 + include/lapi/syscalls/powerpc64.in | 1 + include/lapi/syscalls/s390.in | 1 + include/lapi/syscalls/s390x.in | 1 + include/lapi/syscalls/sh.in | 1 + include/lapi/syscalls/sparc.in | 1 + include/lapi/syscalls/sparc64.in | 1 + include/lapi/syscalls/x86_64.in | 1 + 17 files changed, 17 insertions(+)
include/lapi/syscalls/aarch64.in +1 -0
@@ -299,6 +299,7 @@ quotactl_fd 443 landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 +process_mrelease 448 futex_waitv 449 cachestat 451 fchmodat2 452
include/lapi/syscalls/arc.in +1 -0
@@ -319,6 +319,7 @@ quotactl_fd 443 landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 +process_mrelease 448 futex_waitv 449 cachestat 451 fchmodat2 452
include/lapi/syscalls/arm.in +1 -0
@@ -398,6 +398,7 @@ landlock_create_ruleset (__NR_SYSCALL_BASE+444) landlock_add_rule (__NR_SYSCALL_BASE+445) landlock_restrict_self (__NR_SYSCALL_BASE+446) memfd_secret (__NR_SYSCALL_BASE+447) +process_mrelease (__NR_SYSCALL_BASE+448) futex_waitv (__NR_SYSCALL_BASE+449) cachestat (__NR_SYSCALL_BASE+451) fchmodat2 (__NR_SYSCALL_BASE+452)
include/lapi/syscalls/hppa.in +1 -0
@@ -46,6 +46,7 @@ quotactl_fd 443 landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 +process_mrelease 448 futex_waitv 449 cachestat 451 fchmodat2 452
include/lapi/syscalls/i386.in +1 -0
@@ -433,6 +433,7 @@ quotactl_fd 443 landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 +process_mrelease 448 futex_waitv 449 cachestat 451 fchmodat2 452
include/lapi/syscalls/ia64.in +1 -0
@@ -346,6 +346,7 @@ quotactl_fd 1467 landlock_create_ruleset 1468 landlock_add_rule 1469 landlock_restrict_self 1470 +process_mrelease 1472 futex_waitv 1473 cachestat 1475 fchmodat2 1476
include/lapi/syscalls/mips_n32.in +1 -0
@@ -373,6 +373,7 @@ quotactl_fd 6443 landlock_create_ruleset 6444 landlock_add_rule 6445 landlock_restrict_self 6446 +process_mrelease 6448 futex_waitv 6449 cachestat 6451 fchmodat2 6452
include/lapi/syscalls/mips_n64.in +1 -0
@@ -349,6 +349,7 @@ quotactl_fd 5443 landlock_create_ruleset 5444 landlock_add_rule 5445 landlock_restrict_self 5446 +process_mrelease 5448 futex_waitv 5449 cachestat 5451 fchmodat2 5452
include/lapi/syscalls/mips_o32.in +1 -0
@@ -419,6 +419,7 @@ quotactl_fd 4443 landlock_create_ruleset 4444 landlock_add_rule 4445 landlock_restrict_self 4446 +process_mrelease 4448 futex_waitv 4449 cachestat 4451 fchmodat2 4452
include/lapi/syscalls/powerpc.in +1 -0
@@ -426,6 +426,7 @@ quotactl_fd 443 landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 +process_mrelease 448 futex_waitv 449 cachestat 451 fchmodat2 452
include/lapi/syscalls/powerpc64.in +1 -0
@@ -426,6 +426,7 @@ quotactl_fd 443 landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 +process_mrelease 448 futex_waitv 449 cachestat 451 fchmodat2 452
include/lapi/syscalls/s390.in +1 -0
@@ -413,6 +413,7 @@ quotactl_fd 443 landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 +process_mrelease 448 futex_waitv 449 cachestat 451 fchmodat2 452
include/lapi/syscalls/s390x.in +1 -0
@@ -361,6 +361,7 @@ quotactl_fd 443 landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 +process_mrelease 448 futex_waitv 449 cachestat 451 fchmodat2 452
include/lapi/syscalls/sh.in +1 -0
@@ -407,6 +407,7 @@ quotactl_fd 443 landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 +process_mrelease 448 futex_waitv 449 cachestat 451 fchmodat2 452
include/lapi/syscalls/sparc.in +1 -0
@@ -412,6 +412,7 @@ quotactl_fd 443 landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 +process_mrelease 448 futex_waitv 449 cachestat 451 fchmodat2 452
include/lapi/syscalls/sparc64.in +1 -0
@@ -377,6 +377,7 @@ quotactl_fd 443 landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 +process_mrelease 448 futex_waitv 449 cachestat 451 fchmodat2 452
include/lapi/syscalls/x86_64.in +1 -0
@@ -354,6 +354,7 @@ quotactl_fd 443 landlock_create_ruleset 444 landlock_add_rule 445 landlock_restrict_self 446 +process_mrelease 448 futex_waitv 449 cachestat 451 fchmodat2 452
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 2/3] Add process_mrelease01 test
In reply to Andrea CervesatoHi!
Quoted 30 lines
testcases/kernel/syscalls/process_mrelease/process_mrelease01.c new file +30
-0+static void run (void ) +{ +int ret; +int pidfd; +int status; +pid_t pid; +int restart; + +for (mem_size =CHUNK ; mem_size <MAX_SIZE_MB ; mem_size +=CHUNK ) { + restart =0 ; + + pid =SAFE_FORK (); +if (!pid) { +do_child (mem_size); +exit (0 ); + } + +TST_CHECKPOINT_WAIT (0 ); + +tst_disable_oom_protection (pid); + +if (!memory_is_mapped (pid, *mem_addr, *mem_addr + mem_size)) { +tst_res (TFAIL ,"Memory is not mapped" ); +break ; + } + + pidfd =SAFE_PIDFD_OPEN (pid,0 ); + +tst_res (TINFO ,"Parent: killing child with PID=%d" , pid); +
testcases/kernel/syscalls/process_mrelease/process_mrelease01.c line 118
Quoted 10 lines
testcases/kernel/syscalls/process_mrelease/process_mrelease01.c new file +10
-0+SAFE_KILL (pid,SIGKILL ); + + ret =tst_syscall (__NR_process_mrelease, pidfd,0 ); +if (ret ==-1 ) { +if (errno ==ESRCH ) { +tst_res (TINFO ,"Parent: child terminated before " +"process_mrelease(). Increase memory size and " +"restart test" ); + + restart =1 ;
Does this even happen? I suppose that until the child has been waited for you shouldn't get ESRCH at all. The memory may be freed asynchronously but the pidfd is valid until we do waitpid, at least that's what the description says:
https://lore.kernel.org/linux-mm/20210902220029.bfau3YxNP%[email protected]/
But selftest seems to do the same loop on ESRCH so either the test or the documentation is wrong.
Michal any idea which is correct?
Quoted 6 lines
testcases/kernel/syscalls/process_mrelease/process_mrelease01.c new file +6
-0+ }else { +tst_res (TFAIL |TERRNO ,"process_mrelease(%d,0) error" , pidfd); + } + }else { +int timeout_ms =1000 ; +
testcases/kernel/syscalls/process_mrelease/process_mrelease01.c line 134
Quoted 10 lines
testcases/kernel/syscalls/process_mrelease/process_mrelease01.c new file +10
-0+tst_res (TPASS ,"process_mrelease(%d,0) passed" , pidfd); + +while (memory_is_mapped (pid, *mem_addr, *mem_addr + mem_size) && + timeout_ms--) +usleep (1000 ); + +if (memory_is_mapped (pid, *mem_addr, *mem_addr + mem_size)) +tst_res (TFAIL ,"Memory is still mapped inside child memory" ); +else +tst_res (TPASS ,"Memory has been released" );
As far as I understand this this will likely pass even without the process_mrelease() call since the process address space is being teared down anyways. But I do not have an idea how to make things better. I guess that if we wanted to know for sure we would have to run some complex statistics with and without the syscall and compare the timings...
Quoted 41 lines
testcases/kernel/syscalls/process_mrelease/process_mrelease01.c new file +34
-0+ } + +SAFE_WAITPID (-1 , &status,0 ); +SAFE_CLOSE (pidfd); + +if (!restart) +break ; + } +} + +static void setup (void ) +{ + mem_addr =SAFE_MMAP (NULL , +sizeof (unsigned long ), +PROT_READ |PROT_WRITE , +MAP_SHARED |MAP_ANON , +0 ,0 ); +} + +static void cleanup (void ) +{ +if (mem_addr) +SAFE_MUNMAP (mem_addr,sizeof (unsigned long )); +} + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .cleanup = cleanup, + .needs_root =1 , + .forks_child =1 , + .min_kver ="5.15" , + .needs_checkpoints =1 , +};Signature · 6 lines
-- 2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 3/3] Add process_mrelease02 test
In reply to Andrea CervesatoHi!
Quoted 48 lines
testcases/kernel/syscalls/process_mrelease/process_mrelease02.c new file +48
-0+/*\ +* [Description] +* +* This test verifies that process_mrelease() syscall is raising errors: +* * EBADF when a bad file descriptor is given +* * EINVAL when flags is not zero +* * EINVAL when memory of a task cannot be released because it's still running +* * ESRCH when child has been closed +*/ + +#include "tst_test.h" +#include "lapi/syscalls.h" + +static int badfd =-1 ; +static int pidfd; + +enum { +NO_CHILD , +EXIT_CHILD , +WAIT_CHILD , +}; + +static struct tcase { +int child_type; +int *fd; +int flags; +int exp_errno; +char *msg; +} tcases[] = { + {NO_CHILD , &badfd,0 ,EBADF ,"bad file descriptor" }, + {WAIT_CHILD , &pidfd,-1 ,EINVAL ,"flags is not 0" }, + {WAIT_CHILD , &pidfd,0 ,EINVAL ,"task memory cannot be released" }, + {EXIT_CHILD , &pidfd,0 ,ESRCH ,"child is not running" }, +}; + +static void run (unsigned int n) +{ +struct tcase *tc = &tcases[n]; +int status; + +if (tc->child_type !=NO_CHILD ) { +pid_t pid; + + pid =SAFE_FORK (); +if (!pid) { +if (tc->child_type ==WAIT_CHILD ) +TST_CHECKPOINT_WAIT (0 ); +
testcases/kernel/syscalls/process_mrelease/process_mrelease02.c line 63
Quoted 10 lines
testcases/kernel/syscalls/process_mrelease/process_mrelease02.c new file +10
-0+exit (0 ); + } + +tst_res (TINFO ,"Spawned waiting child with pid=%d" , pid); + + pidfd =SAFE_PIDFD_OPEN (pid,0 ); + +if (tc->child_type ==EXIT_CHILD ) +SAFE_WAITPID (pid, &status,0 ); + }
Why don't we instead fork two children in the setup, one of the waits and second exits and just set the pidfd once?
Quoted 27 lines
testcases/kernel/syscalls/process_mrelease/process_mrelease02.c new file +20
-0+TST_EXP_FAIL (tst_syscall (__NR_process_mrelease, *tc->fd, tc->flags), + tc->exp_errno, +"%s" , tc->msg); + +if (tc->child_type !=NO_CHILD ) { +if (tc->child_type ==WAIT_CHILD ) +TST_CHECKPOINT_WAKE (0 ); + +SAFE_CLOSE (pidfd); + } +} + +static struct tst_test test = { + .test = run, + .tcnt =ARRAY_SIZE (tcases), + .needs_root =1 , + .forks_child =1 , + .min_kver ="5.15" , + .needs_checkpoints =1 , +};Signature · 6 lines
-- 2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 3/3] Add process_mrelease02 test
Hi,
Quoted 53 lines · Cyril Hrubis
Hi!
Quoted 52 lines
testcases/kernel/syscalls/process_mrelease/process_mrelease02.c new file +52
-0+/*\ +* [Description] +* +* This test verifies that process_mrelease() syscall is raising errors: +* * EBADF when a bad file descriptor is given +* * EINVAL when flags is not zero +* * EINVAL when memory of a task cannot be released because it's still running +* * ESRCH when child has been closed +*/ + +#include "tst_test.h" +#include "lapi/syscalls.h" + +static int badfd =-1 ; +static int pidfd; + +enum { +NO_CHILD , +EXIT_CHILD , +WAIT_CHILD , +}; + +static struct tcase { +int child_type; +int *fd; +int flags; +int exp_errno; +char *msg; +} tcases[] = { + {NO_CHILD , &badfd,0 ,EBADF ,"bad file descriptor" }, + {WAIT_CHILD , &pidfd,-1 ,EINVAL ,"flags is not 0" }, + {WAIT_CHILD , &pidfd,0 ,EINVAL ,"task memory cannot be released" }, + {EXIT_CHILD , &pidfd,0 ,ESRCH ,"child is not running" }, +}; + +static void run (unsigned int n) +{ +struct tcase *tc = &tcases[n]; +int status; + +if (tc->child_type !=NO_CHILD ) { +pid_t pid; + + pid =SAFE_FORK (); +if (!pid) { +if (tc->child_type ==WAIT_CHILD ) +TST_CHECKPOINT_WAIT (0 ); + +exit (0 ); + } + +tst_res (TINFO ,"Spawned waiting child with pid=%d" , pid);
Quoted 8 lines
testcases/kernel/syscalls/process_mrelease/process_mrelease02.c line 63
Quoted 6 lines
testcases/kernel/syscalls/process_mrelease/process_mrelease02.c new file +6
-0+ + pidfd =SAFE_PIDFD_OPEN (pid,0 ); + +if (tc->child_type ==EXIT_CHILD ) +SAFE_WAITPID (pid, &status,0 ); + }Why don't we instead fork two children in the setup, one of the waits and second exits and just set the pidfd once?
At the end of each test() the library calls tst_reap_children() and the waiting child will fail with ETIMEDOUT, so we need to spawn a child for each new test.
Quoted 27 lines
Quoted 27 lines
testcases/kernel/syscalls/process_mrelease/process_mrelease02.c new file +20
-0+TST_EXP_FAIL (tst_syscall (__NR_process_mrelease, *tc->fd, tc->flags), + tc->exp_errno, +"%s" , tc->msg); + +if (tc->child_type !=NO_CHILD ) { +if (tc->child_type ==WAIT_CHILD ) +TST_CHECKPOINT_WAKE (0 ); + +SAFE_CLOSE (pidfd); + } +} + +static struct tst_test test = { + .test = run, + .tcnt =ARRAY_SIZE (tcases), + .needs_root =1 , + .forks_child =1 , + .min_kver ="5.15" , + .needs_checkpoints =1 , +};Signature · 6 lines
-- 2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 2/3] Add process_mrelease01 test
In reply to Cyril HrubisHi!
Quoted 67 lines · Cyril Hrubis
Hi!
Quoted 30 lines
testcases/kernel/syscalls/process_mrelease/process_mrelease01.c new file +30
-0+static void run (void ) +{ +int ret; +int pidfd; +int status; +pid_t pid; +int restart; + +for (mem_size =CHUNK ; mem_size <MAX_SIZE_MB ; mem_size +=CHUNK ) { + restart =0 ; + + pid =SAFE_FORK (); +if (!pid) { +do_child (mem_size); +exit (0 ); + } + +TST_CHECKPOINT_WAIT (0 ); + +tst_disable_oom_protection (pid); + +if (!memory_is_mapped (pid, *mem_addr, *mem_addr + mem_size)) { +tst_res (TFAIL ,"Memory is not mapped" ); +break ; + } + + pidfd =SAFE_PIDFD_OPEN (pid,0 ); + +tst_res (TINFO ,"Parent: killing child with PID=%d" , pid); +testcases/kernel/syscalls/process_mrelease/process_mrelease01.c line 118
Quoted 10 lines
testcases/kernel/syscalls/process_mrelease/process_mrelease01.c new file +10
-0+SAFE_KILL (pid,SIGKILL ); + + ret =tst_syscall (__NR_process_mrelease, pidfd,0 ); +if (ret ==-1 ) { +if (errno ==ESRCH ) { +tst_res (TINFO ,"Parent: child terminated before " +"process_mrelease(). Increase memory size and " +"restart test" ); + + restart =1 ;Does this even happen? I suppose that until the child has been waited for you shouldn't get ESRCH at all. The memory may be freed asynchronously but the pidfd is valid until we do waitpid, at least that's what the description says:
https://lore.kernel.org/linux-mm/20210902220029.bfau3YxNP%[email protected]/
But selftest seems to do the same loop on ESRCH so either the test or the documentation is wrong.
Michal any idea which is correct?
Quoted 14 lines
testcases/kernel/syscalls/process_mrelease/process_mrelease01.c new file +14
-0+ }else { +tst_res (TFAIL |TERRNO ,"process_mrelease(%d,0) error" , pidfd); + } + }else { +int timeout_ms =1000 ; + +tst_res (TPASS ,"process_mrelease(%d,0) passed" , pidfd); + +while (memory_is_mapped (pid, *mem_addr, *mem_addr + mem_size) && + timeout_ms--) +usleep (1000 ); + +if (memory_is_mapped (pid, *mem_addr, *mem_addr + mem_size)) +tst_res (TFAIL ,"Memory is still mapped inside child memory" );
Quoted 8 lines
testcases/kernel/syscalls/process_mrelease/process_mrelease01.c line 134
Quoted 2 lines
testcases/kernel/syscalls/process_mrelease/process_mrelease01.c new file +2
-0+else +tst_res (TPASS ,"Memory has been released" );As far as I understand this this will likely pass even without the
process_mrelease()call since the process address space is being teared down anyways. But I do not have an idea how to make things better. I guess that if we wanted to know for sure we would have to run some complex statistics with and without the syscall and compare the timings...
I don't know, I tried to port the kselftest that seemed to be reasonable. Let me know if this is still good, otherwise we need to change the whole algorithm. But honestly I don't see many other options than the current one.
Quoted 36 lines
Quoted 36 lines
testcases/kernel/syscalls/process_mrelease/process_mrelease01.c new file +34
-0+ } + +SAFE_WAITPID (-1 , &status,0 ); +SAFE_CLOSE (pidfd); + +if (!restart) +break ; + } +} + +static void setup (void ) +{ + mem_addr =SAFE_MMAP (NULL , +sizeof (unsigned long ), +PROT_READ |PROT_WRITE , +MAP_SHARED |MAP_ANON , +0 ,0 ); +} + +static void cleanup (void ) +{ +if (mem_addr) +SAFE_MUNMAP (mem_addr,sizeof (unsigned long )); +} + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .cleanup = cleanup, + .needs_root =1 , + .forks_child =1 , + .min_kver ="5.15" , + .needs_checkpoints =1 , +};
Quoted 6 lines
Quoted 6 lines
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Andrea
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 3/3] Add process_mrelease02 test
In reply to Andrea Cervesato via ltpHi!
Quoted 3 lines
At the end of each
test()the library callstst_reap_children()and the waiting child will fail with ETIMEDOUT, so we need to spawn a child for each new test.
Ah, right, we do not support run-away children like this.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 2/3] Add process_mrelease01 test
In reply to Andrea Cervesato via ltpPing @Cyril
Quoted 128 lines · Andrea Cervesato
Hi!
Quoted 73 lines · Cyril Hrubis
Hi!
Quoted 31 lines
testcases/kernel/syscalls/process_mrelease/process_mrelease01.c new file +9
-0+static void run(void) +{ + int ret; + int pidfd; + int status; + pid_t pid; + int restart; + + for (mem_size = CHUNK; mem_size < MAX_SIZE_MB; mem_size +=CHUNK) {
+ restart = 0;testcases/kernel/syscalls/process_mrelease/process_mrelease01.c new file +20
-0+ + pid = SAFE_FORK(); + if (!pid) { + do_child(mem_size); + exit(0); + } + + TST_CHECKPOINT_WAIT(0); + + tst_disable_oom_protection(pid); + + if (!memory_is_mapped(pid, *mem_addr, *mem_addr + mem_size)) { + tst_res(TFAIL, "Memory is not mapped"); + break; + } + + pidfd = SAFE_PIDFD_OPEN(pid, 0); + + tst_res(TINFO, "Parent: killing child with PID=%d", pid); +testcases/kernel/syscalls/process_mrelease/process_mrelease01.c line 118
Quoted 10 lines
testcases/kernel/syscalls/process_mrelease/process_mrelease01.c new file +10
-0+ SAFE_KILL(pid, SIGKILL); + + ret = tst_syscall(__NR_process_mrelease, pidfd, 0); + if (ret == -1) { + if (errno == ESRCH) { + tst_res(TINFO, "Parent: child terminated before " + "process_mrelease(). Increase memory size and " + "restart test"); + + restart = 1;Does this even happen? I suppose that until the child has been waited for you shouldn't get ESRCH at all. The memory may be freed asynchronously but the pidfd is valid until we do waitpid, at least that's what the description says:
https://lore.kernel.org/linux-mm/20210902220029.bfau3YxNP%[email protected]/
But selftest seems to do the same loop on ESRCH so either the test or the documentation is wrong.
Michal any idea which is correct?
Quoted 18 lines
+ } else {
+tst_res(TFAIL | TERRNO, "process_mrelease(%d,0) error", pidfd);
+ }
+ } else {
+ inttimeout_ms= 1000;testcases/kernel/syscalls/process_mrelease/process_mrelease01.c new file +4
-0+ + tst_res(TPASS, "process_mrelease(%d,0) passed", pidfd); + + while (memory_is_mapped(pid, *mem_addr, *mem_addr +
mem_size) &&
+ timeout_ms--)
+ usleep(1000);
+
+ if (memory_is_mapped(pid, *mem_addr, *mem_addr + mem_size))
+tst_res(TFAIL, "Memory is still mapped inside child memory");Quoted 8 lines
Quoted 2 lines
+ else
+tst_res(TPASS, "Memory has been released");As far as I understand this this will likely pass even without the
process_mrelease()call since the process address space is being teared down anyways. But I do not have an idea how to make things better. I guess that if we wanted to know for sure we would have to run some complex statistics with and without the syscall and compare the timings...I don't know, I tried to port the kselftest that seemed to be reasonable. Let me know if this is still good, otherwise we need to change the whole algorithm. But honestly I don't see many other options than the current one.
Quoted 36 lines
Quoted 36 lines
+ }
testcases/kernel/syscalls/process_mrelease/process_mrelease01.c new file +33
-0+ + SAFE_WAITPID(-1, &status, 0); + SAFE_CLOSE(pidfd); + + if (!restart) + break; + } +} + +static void setup (void ) +{ + mem_addr = SAFE_MMAP(NULL, + sizeof(unsigned long), + PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_ANON, + 0, 0); +} + +static void cleanup (void ) +{ + if (mem_addr) + SAFE_MUNMAP(mem_addr, sizeof(unsigned long)); +} + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .cleanup = cleanup, + .needs_root = 1, + .forks_child = 1, + .min_kver = "5.15", + .needs_checkpoints = 1, +};Quoted 6 lines
Quoted 6 lines
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltpAndrea
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 3/3] Add process_mrelease02 test
In reply to Andrea CervesatoQuoted 109 lines · Andrea Cervesato
From: Andrea Cervesato <[email protected]>
This test verifies that
process_mrelease()syscall correctly raises the errors.Signed-off-by Andrea Cervesato <[email protected]>--- runtest/syscalls | 1 + .../kernel/syscalls/process_mrelease/.gitignore | 1 + .../syscalls/process_mrelease/process_mrelease02.c | 84 ++++++++++++++++++++++ 3 files changed, 86 insertions(+)runtest/syscalls +1
-0@@ -1074,6 +1074,7 @@ preadv203_64 preadv203_64 profil01 profil01 process_mrelease01 process_mrelease01 +process_mrelease02 process_mrelease02 process_vm_readv01 process_vm01 -r process_vm_readv02 process_vm_readv02testcases/kernel/syscalls/process_mrelease/.gitignore +1
-0@@ -1 +1,2 @@ /process_mrelease01 +/process_mrelease02testcases/kernel/syscalls/process_mrelease/process_mrelease02.c new file +72
-0@@ -0,0 +1,84 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +/*\ +* [Description] +* +* This test verifies that process_mrelease() syscall is raising errors: +* * EBADF when a bad file descriptor is given +* * EINVAL when flags is not zero +* * EINVAL when memory of a task cannot be released because it's still running +* * ESRCH when child has been closed +*/ + +#include "tst_test.h" +#include "lapi/syscalls.h" + +static int badfd =-1 ; +static int pidfd; + +enum { +NO_CHILD , +EXIT_CHILD , +WAIT_CHILD , +}; + +static struct tcase { +int child_type; +int *fd; +int flags; +int exp_errno; +char *msg; +} tcases[] = { + {NO_CHILD , &badfd,0 ,EBADF ,"bad file descriptor" }, + {WAIT_CHILD , &pidfd,-1 ,EINVAL ,"flags is not 0" }, + {WAIT_CHILD , &pidfd,0 ,EINVAL ,"task memory cannot be released" }, + {EXIT_CHILD , &pidfd,0 ,ESRCH ,"child is not running" }, +}; + +static void run (unsigned int n) +{ +struct tcase *tc = &tcases[n]; +int status; + +if (tc->child_type !=NO_CHILD ) { +pid_t pid; + + pid =SAFE_FORK (); +if (!pid) { +if (tc->child_type ==WAIT_CHILD ) +TST_CHECKPOINT_WAIT (0 ); + +exit (0 ); + } + +tst_res (TINFO ,"Spawned waiting child with pid=%d" , pid); + + pidfd =SAFE_PIDFD_OPEN (pid,0 ); + +if (tc->child_type ==EXIT_CHILD ) +SAFE_WAITPID (pid, &status,0 ); + } + +TST_EXP_FAIL (tst_syscall (__NR_process_mrelease, *tc->fd, tc->flags), + tc->exp_errno, +"%s" , tc->msg); + +if (tc->child_type !=NO_CHILD ) { +if (tc->child_type ==WAIT_CHILD ) +TST_CHECKPOINT_WAKE (0 ); +
testcases/kernel/syscalls/process_mrelease/process_mrelease02.c line 82
Quoted 10 lines
testcases/kernel/syscalls/process_mrelease/process_mrelease02.c new file +10
-0+SAFE_CLOSE (pidfd); + } +} + +static struct tst_test test = { + .test = run, + .tcnt =ARRAY_SIZE (tcases), + .needs_root =1 , + .forks_child =1 , + .min_kver ="5.15" ,
I suggest also using syscall check process_mrelease support or not like kernel selftest. Such as:
if (!syscall(__NR_process_mrelease, -1, 0) || errno != EBADF) {
if (errno == ENOSYS) {
ksft_test_result_skip("process_mrelease not implemented\n");
ksft_finished();Quoted 9 lines
testcases/kernel/syscalls/process_mrelease/process_mrelease02.c new file +2
-0+ .needs_checkpoints = 1, +};Signature · 6 lines
-- 2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 2/3] Add process_mrelease01 test
In reply to Andrea Cervesato via ltpQuoted 53 lines · Andrea Cervesato via ltp
Hi!
Quoted 50 lines · Cyril Hrubis
Hi!
Quoted 30 lines
testcases/kernel/syscalls/process_mrelease/process_mrelease01.c new file +30
-0+static void run (void ) +{ +int ret; +int pidfd; +int status; +pid_t pid; +int restart; + +for (mem_size =CHUNK ; mem_size <MAX_SIZE_MB ; mem_size +=CHUNK ) { + restart =0 ; + + pid =SAFE_FORK (); +if (!pid) { +do_child (mem_size); +exit (0 ); + } + +TST_CHECKPOINT_WAIT (0 ); + +tst_disable_oom_protection (pid); + +if (!memory_is_mapped (pid, *mem_addr, *mem_addr + mem_size)) { +tst_res (TFAIL ,"Memory is not mapped" ); +break ; + } + + pidfd =SAFE_PIDFD_OPEN (pid,0 ); + +tst_res (TINFO ,"Parent: killing child with PID=%d" , pid); +testcases/kernel/syscalls/process_mrelease/process_mrelease01.c line 118
Quoted 10 lines
testcases/kernel/syscalls/process_mrelease/process_mrelease01.c new file +10
-0+SAFE_KILL (pid,SIGKILL ); + + ret =tst_syscall (__NR_process_mrelease, pidfd,0 ); +if (ret ==-1 ) { +if (errno ==ESRCH ) { +tst_res (TINFO ,"Parent: child terminated before " +"process_mrelease(). Increase memory size and " +"restart test" ); + + restart =1 ;Does this even happen? I suppose that until the child has been waited for you shouldn't get ESRCH at all. The memory may be freed asynchronously but the pidfd is valid until we do waitpid, at least that's what the description says:
https://lore.kernel.org/linux-mm/20210902220029.bfau3YxNP%[email protected]/
But selftest seems to do the same loop on ESRCH so either the test or the documentation is wrong.
If you add extra sleep between SAFE_KILL(pid, SIGKILL) and tst_syscall you will get ESRCH, so i guess child process has chance to be fully reaped before process_mrelease syscall.
Quoted 25 lines
Quoted 17 lines
Michal any idea which is correct?
Quoted 14 lines
testcases/kernel/syscalls/process_mrelease/process_mrelease01.c new file +14
-0+ }else { +tst_res (TFAIL |TERRNO ,"process_mrelease(%d,0) error" , pidfd); + } + }else { +int timeout_ms =1000 ; + +tst_res (TPASS ,"process_mrelease(%d,0) passed" , pidfd); + +while (memory_is_mapped (pid, *mem_addr, *mem_addr + mem_size) && + timeout_ms--) +usleep (1000 ); + +if (memory_is_mapped (pid, *mem_addr, *mem_addr + mem_size)) +tst_res (TFAIL ,"Memory is still mapped inside child memory" );Quoted 8 lines
testcases/kernel/syscalls/process_mrelease/process_mrelease01.c line 134
Quoted 2 lines
testcases/kernel/syscalls/process_mrelease/process_mrelease01.c new file +2
-0+else +tst_res (TPASS ,"Memory has been released" );As far as I understand this this will likely pass even without the
process_mrelease()call since the process address space is being teared down anyways. But I do not have an idea how to make things better. I guess that if we wanted to know for sure we would have to run some complex statistics with and without the syscall and compare the timings...
Quoted 3 lines
I don't know, I tried to port the kselftest that seemed to be reasonable. Let me know if this is still good, otherwise we need to change the whole algorithm. But honestly I don't see many other options than the current one.
kselftest does not has this memory check, i have done some test in my env, this memory check can pass even without the process_mrelease, so i think we do not need this check.
Quoted 46 lines
Quoted 36 lines
Quoted 36 lines
testcases/kernel/syscalls/process_mrelease/process_mrelease01.c new file +34
-0+ } + +SAFE_WAITPID (-1 , &status,0 ); +SAFE_CLOSE (pidfd); + +if (!restart) +break ; + } +} + +static void setup (void ) +{ + mem_addr =SAFE_MMAP (NULL , +sizeof (unsigned long ), +PROT_READ |PROT_WRITE , +MAP_SHARED |MAP_ANON , +0 ,0 ); +} + +static void cleanup (void ) +{ +if (mem_addr) +SAFE_MUNMAP (mem_addr,sizeof (unsigned long )); +} + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .cleanup = cleanup, + .needs_root =1 , + .forks_child =1 , + .min_kver ="5.15" , + .needs_checkpoints =1 , +};Quoted 6 lines
Quoted 6 lines
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltpAndrea
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp