Skip to contentSkip to conversation

selftests: vm: add process_mrelease tests

PATCH Applied Suren Baghdasaryan 4 participants 4 messages May 18, 2022 – May 21, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 selftests: vm: add process_mrelease tests

Introduce process_mrelease syscall sanity tests which include tests which expect to fail:
- process_mrelease with invalid pidfd and flags inputs
- process_mrelease on a live process with no pending signals and valid process_mrelease usage which is expected to succeed. Because process_mrelease has to be used against a process with a pending SIGKILL, it's possible that the process exits before process_mrelease gets called. In such cases we retry the test with a victim that allocates twice more memory up to 1GB. This would require the victim process to spend more time during exit and process_mrelease has a better chance of catching the process before it exits and succeeding.

On success the test reports the amount of memory the child had to allocate for reaping to succeed. Sample output:

$ mrelease_test
Success reaping a child with 1MB of memory allocations

On failure the test reports the failure. Sample outputs:

$ mrelease_test
All process_mrelease attempts failed!
$ mrelease_test
process_mrelease: Invalid argument

---
Changes in v3:
- Applied on git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm mm-stable, per Andrew
- Fixed formatting for sample outputs in the description, per Shuah
- Removed pidfd_open, process_mrelease, write_fault_pages functions, per Shuah
- Moved child main routine into its own function, per Shuah
- Followed tools/testing/selftests/pidfd/pidfd.h as a model to deal with undefined syscall numbers, per Shuah

 tools/testing/selftests/vm/.gitignore      |   1 +
 tools/testing/selftests/vm/Makefile        |   1 +
 tools/testing/selftests/vm/mrelease_test.c | 200 +++++++++++++++++++++
 tools/testing/selftests/vm/run_vmtests.sh  |   2 +
 4 files changed, 204 insertions(+)
 create mode 100644 tools/testing/selftests/vm/mrelease_test.c
tools/testing/selftests/vm/.gitignore +1 -0
index 3cb4fa771ec2..6c2ac4208c27 100644
@@ -10,6 +10,7 @@ map_populate
 thuge-gen
 compaction_test
 mlock2-tests
+mrelease_test
 mremap_dontunmap
 mremap_test
 on-fault-limit
tools/testing/selftests/vm/Makefile +1 -0
index f1228370e99b..8111a33e4824 100644
@@ -44,6 +44,7 @@ TEST_GEN_FILES += memfd_secret
 TEST_GEN_FILES += migration
 TEST_GEN_FILES += mlock-random-test
 TEST_GEN_FILES += mlock2-tests
+TEST_GEN_FILES += mrelease_test
 TEST_GEN_FILES += mremap_dontunmap
 TEST_GEN_FILES += mremap_test
 TEST_GEN_FILES += on-fault-limit
tools/testing/selftests/vm/mrelease_test.c new file +200 -0

200 lines not on this page · raw message

tools/testing/selftests/vm/run_vmtests.sh +2 -0
index a2302b5faaf2..41fce8bea929 100755
@@ -141,6 +141,8 @@ run_test ./mlock-random-test
 
 run_test ./mlock2-tests
 
+run_test ./mrelease_test
+
 run_test ./mremap_test
 
 run_test ./thuge-gen
Signature · 1 line
2.36.1.124.g0e6072fb45-goog
maintainer Reviewed-by on v3 1/1
#1 lore raw
Quoted 27 lines · Suren Baghdasaryan

Introduce process_mrelease syscall sanity tests which include tests which expect to fail:
- process_mrelease with invalid pidfd and flags inputs
- process_mrelease on a live process with no pending signals and valid process_mrelease usage which is expected to succeed. Because process_mrelease has to be used against a process with a pending SIGKILL, it's possible that the process exits before process_mrelease gets called. In such cases we retry the test with a victim that allocates twice more memory up to 1GB. This would require the victim process to spend more time during exit and process_mrelease has a better chance of catching the process before it exits and succeeding.

On success the test reports the amount of memory the child had to allocate for reaping to succeed. Sample output:

$ mrelease_test
Success reaping a child with 1MB of memory allocations

On failure the test reports the failure. Sample outputs:

$ mrelease_test
All process_mrelease attempts failed!
$ mrelease_test
process_mrelease: Invalid argument
Quoted 10 lines

---
Changes in v3:
- Applied on git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm mm-stable, per Andrew
- Fixed formatting for sample outputs in the description, per Shuah
- Removed pidfd_open, process_mrelease, write_fault_pages functions, per Shuah
- Moved child main routine into its own function, per Shuah
- Followed tools/testing/selftests/pidfd/pidfd.h as a model to deal with undefined syscall numbers, per Shuah

Looks good to me Suren. Thank you.

thanks,
-- Shuah

Acked-by on v3 1/1
#2 lore raw
In reply to Suren Baghdasaryan
Quoted 20 lines · Suren Baghdasaryan

Introduce process_mrelease syscall sanity tests which include tests which expect to fail:
- process_mrelease with invalid pidfd and flags inputs
- process_mrelease on a live process with no pending signals and valid process_mrelease usage which is expected to succeed. Because process_mrelease has to be used against a process with a pending SIGKILL, it's possible that the process exits before process_mrelease gets called. In such cases we retry the test with a victim that allocates twice more memory up to 1GB. This would require the victim process to spend more time during exit and process_mrelease has a better chance of catching the process before it exits and succeeding.

On success the test reports the amount of memory the child had to allocate for reaping to succeed. Sample output:

$ mrelease_test
Success reaping a child with 1MB of memory allocations

On failure the test reports the failure. Sample outputs:

Quoted 8 lines
$ mrelease_test
All process_mrelease attempts failed!
$ mrelease_test
process_mrelease: Invalid argument

---

Thanks your adding selftests, Suren!

Reviewed-by on v3 1/1
#3 lore raw
In reply to Suren Baghdasaryan
Quoted 20 lines · Suren Baghdasaryan

Introduce process_mrelease syscall sanity tests which include tests which expect to fail:
- process_mrelease with invalid pidfd and flags inputs
- process_mrelease on a live process with no pending signals and valid process_mrelease usage which is expected to succeed. Because process_mrelease has to be used against a process with a pending SIGKILL, it's possible that the process exits before process_mrelease gets called. In such cases we retry the test with a victim that allocates twice more memory up to 1GB. This would require the victim process to spend more time during exit and process_mrelease has a better chance of catching the process before it exits and succeeding.

On success the test reports the amount of memory the child had to allocate for reaping to succeed. Sample output:

$ mrelease_test
Success reaping a child with 1MB of memory allocations

On failure the test reports the failure. Sample outputs:

Quoted 7 lines
$ mrelease_test
All process_mrelease attempts failed!
$ mrelease_test
process_mrelease: Invalid argument
Signature · 1 line
Muhammad Usama Anjum