Skip to contentSkip to conversation

selftests/mm: add process_madvise() tests

PATCH Applied wang lian 1 participant 1 message Jul 29, 2025

Subsystems (3)
lore
Share & tools
lore

wang lian

author
#0 lore raw

PATCH v7 1/1 selftests/mm: add process_madvise() tests

Add tests for process_madvise(), focusing on verifying behavior under various conditions including valid usage and error cases.

---
Changelog v7:
- In the remote_collapse test, replace default_huge_page_size() with read_pmd_pagesize()
- Add a new test, invalid_vlen, to verify that process_madvise() correctly fails with EINVAL when the vlen argument exceeds UIO_MAXIOV.

Changelog v6: https://lore.kernel.org/lkml/[email protected]/
- Refactor child process and pidfd management to use the kselftest fixture's setup and teardown mechanism. This ensures that child processes are reliably terminated and file descriptors are closed, even when a test is aborted by an ASSERT or SKIP macro. This resolves the issue where a failed assertion could lead to a leaked child process.

Changelog v5: https://lore.kernel.org/lkml/[email protected]/
- Refactor the remote_collapse test to concentrate on its primary goal confirming the successful remote invocation of process_madvise() on a child process.
- Split the validation logic for invalid pidfds out of the remote test and into two new (exited_process_pidfd and bad_pidfd).
- Based mm-new branch, can ensure clean application

Changelog v4: https://lore.kernel.org/lkml/[email protected]/
- Refine resource cleanup logic in test teardown to be more robust.
- Improve remote_collapse test to correctly handle different THP (Transparent Huge Page) policies ('always', 'madvise', 'never'), including handling race conditions with khugepaged.
- Resolve build errors

Changelog v3: https://lore.kernel.org/lkml/[email protected]/
- Rebased onto the latest mm-stable branch to ensure clean application.
- Refactor common signal handling logic into vm_util to reduce code duplication.
- Improve test robustness and diagnostics based on community feedback.
- Address minor code style and script corrections.

Changelog v2: https://lore.kernel.org/lkml/[email protected]/
- Drop MADV_DONTNEED tests based on feedback.
- Focus solely on process_madvise() syscall.
- Improve error handling and structure.
- Add future-proof flag test.
- Style and comment cleanups.

-V1: https://lore.kernel.org/lkml/[email protected]/

 tools/testing/selftests/mm/.gitignore     |   1 +
 tools/testing/selftests/mm/Makefile       |   1 +
 tools/testing/selftests/mm/process_madv.c | 344 ++++++++++++++++++++++
 tools/testing/selftests/mm/run_vmtests.sh |   5 +
 4 files changed, 351 insertions(+)
 create mode 100644 tools/testing/selftests/mm/process_madv.c
tools/testing/selftests/mm/.gitignore +1 -0
index f2dafa0b700b..e7b23a8a05fe 100644
@@ -21,6 +21,7 @@ on-fault-limit
 transhuge-stress
 pagemap_ioctl
 pfnmap
+process_madv
 *.tmp*
 protection_keys
 protection_keys_32
tools/testing/selftests/mm/Makefile +1 -0
index ae6f994d3add..d13b3cef2a2b 100644
@@ -85,6 +85,7 @@ TEST_GEN_FILES += mseal_test
 TEST_GEN_FILES += on-fault-limit
 TEST_GEN_FILES += pagemap_ioctl
 TEST_GEN_FILES += pfnmap
+TEST_GEN_FILES += process_madv
 TEST_GEN_FILES += thuge-gen
 TEST_GEN_FILES += transhuge-stress
 TEST_GEN_FILES += uffd-stress
tools/testing/selftests/mm/process_madv.c new file +344 -0

344 lines not on this page · raw message

tools/testing/selftests/mm/run_vmtests.sh +5 -0
index a38c984103ce..471e539d82b8 100755
@@ -65,6 +65,8 @@ separated by spaces:
 	test pagemap_scan IOCTL
 - pfnmap
 	tests for VM_PFNMAP handling
+- process_madv
+	test for process_madv
 - cow
 	test copy-on-write semantics
 - thp
@@ -425,6 +427,9 @@ CATEGORY="madv_guard" run_test ./guard-regions
 # MADV_POPULATE_READ and MADV_POPULATE_WRITE tests
 CATEGORY="madv_populate" run_test ./madv_populate
 
+# PROCESS_MADV test
+CATEGORY="process_madv" run_test ./process_madv
+
 CATEGORY="vma_merge" run_test ./merge
 
 if [ -x ./memfd_secret ]
Signature · 1 line
2.43.0