* [PATCH v5 1/3] selftests/mm: add a probe for FOLL_FORCE writes through /proc/self/mem
2026-12-01 19:16 [PATCH v5 0/3] selftests/mm: skip tests when FOLL_FORCE writes are not available Nikolai Dokutovich
@ 2026-12-01 19:16 ` Nikolai Dokutovich
2026-12-01 19:16 ` [PATCH v5 2/3] selftests/mm: skip the mkdirty ptrace write tests without FOLL_FORCE Nikolai Dokutovich
2026-12-01 19:16 ` [PATCH v5 3/3] selftests/mm: skip the ksm PROT_NONE test " Nikolai Dokutovich
2 siblings, 0 replies; 4+ messages in thread
From: Nikolai Dokutovich @ 2026-12-01 19:16 UTC (permalink / raw)
To: David Hildenbrand, Andrew Morton
Cc: Shuah Khan, Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Michal Hocko, Xu Xin, linux-mm, linux-kselftest, linux-kernel,
Nikolai Dokutovich
mkdirty and the ksm PROT_NONE test write through /proc/self/mem into a
mapping that is not writable. With CONFIG_PROC_MEM_FORCE_PTRACE such a
write is only allowed for a caller that traces the target, so both tests
fail instead of skipping on a distribution kernel.
Add a helper that performs that write on a scratch mapping and caches the
result.
Signed-off-by: Nikolai Dokutovich <ndokutovich@gmail.com>
---
tools/testing/selftests/mm/vm_util.c | 29 ++++++++++++++++++++++++++++
tools/testing/selftests/mm/vm_util.h | 8 ++++++++
2 files changed, 37 insertions(+)
diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c
index 515031b8283d..c933e6c575a4 100644
--- a/tools/testing/selftests/mm/vm_util.c
+++ b/tools/testing/selftests/mm/vm_util.c
@@ -1119,3 +1119,32 @@ void shm_limits_prepare(unsigned long length)
shmall = val;
}
}
+
+bool proc_mem_force_write_allowed(void)
+{
+ static int allowed = -1;
+ const size_t pagesize = getpagesize();
+ char data = 1;
+ char *mem;
+ int fd;
+
+ if (allowed >= 0)
+ return allowed;
+
+ mem = mmap(NULL, pagesize, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ if (mem == MAP_FAILED)
+ return false;
+
+ fd = open("/proc/self/mem", O_RDWR);
+ if (fd < 0) {
+ munmap(mem, pagesize);
+ return false;
+ }
+
+ allowed = lseek(fd, (off_t)(uintptr_t)mem, SEEK_SET) != (off_t)-1 &&
+ write(fd, &data, 1) == 1;
+
+ close(fd);
+ munmap(mem, pagesize);
+ return allowed;
+}
diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h
index b5d59729d432..52acf1a6b725 100644
--- a/tools/testing/selftests/mm/vm_util.h
+++ b/tools/testing/selftests/mm/vm_util.h
@@ -68,6 +68,14 @@ static inline void force_read_pages(char *addr, unsigned int nr_pages,
bool detect_huge_zeropage(void);
+/*
+ * Whether a write through /proc/self/mem into a mapping that is not writable
+ * is permitted. Probed once and cached; the permission depends on the kernel
+ * configuration and on whether the caller traces the target, not on the
+ * mapping.
+ */
+bool proc_mem_force_write_allowed(void);
+
/*
* Plan 9 FS has bugs (at least on QEMU) where certain operations fail with
* ENOENT on unlinked files. See
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH v5 2/3] selftests/mm: skip the mkdirty ptrace write tests without FOLL_FORCE
2026-12-01 19:16 [PATCH v5 0/3] selftests/mm: skip tests when FOLL_FORCE writes are not available Nikolai Dokutovich
2026-12-01 19:16 ` [PATCH v5 1/3] selftests/mm: add a probe for FOLL_FORCE writes through /proc/self/mem Nikolai Dokutovich
@ 2026-12-01 19:16 ` Nikolai Dokutovich
2026-12-01 19:16 ` [PATCH v5 3/3] selftests/mm: skip the ksm PROT_NONE test " Nikolai Dokutovich
2 siblings, 0 replies; 4+ messages in thread
From: Nikolai Dokutovich @ 2026-12-01 19:16 UTC (permalink / raw)
To: David Hildenbrand, Andrew Morton
Cc: Shuah Khan, Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Michal Hocko, Xu Xin, linux-mm, linux-kselftest, linux-kernel,
Nikolai Dokutovich
Both ptrace write tests fail when the kernel does not allow forced writes:
not ok 1 write() failed
Check the permission at their entry and skip instead. The other subtests
do not depend on it and keep running.
Signed-off-by: Nikolai Dokutovich <ndokutovich@gmail.com>
---
tools/testing/selftests/mm/mkdirty.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/tools/testing/selftests/mm/mkdirty.c b/tools/testing/selftests/mm/mkdirty.c
index 68dd447a5454..f6f50016cf5c 100644
--- a/tools/testing/selftests/mm/mkdirty.c
+++ b/tools/testing/selftests/mm/mkdirty.c
@@ -91,6 +91,11 @@ static void test_ptrace_write(void)
ksft_print_msg("[INFO] PTRACE write access\n");
+ if (!proc_mem_force_write_allowed()) {
+ ksft_test_result_skip("FOLL_FORCE write not available\n");
+ return;
+ }
+
mem = mmap(NULL, pagesize, PROT_READ, MAP_PRIVATE|MAP_ANON, -1, 0);
if (mem == MAP_FAILED) {
ksft_test_result_fail("mmap() failed\n");
@@ -128,6 +133,11 @@ static void test_ptrace_write_thp(void)
ksft_print_msg("[INFO] PTRACE write access to THP\n");
+ if (!proc_mem_force_write_allowed()) {
+ ksft_test_result_skip("FOLL_FORCE write not available\n");
+ return;
+ }
+
mem = mmap_thp_range(PROT_READ, &mmap_mem, &mmap_size);
if (mem == MAP_FAILED)
return;
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH v5 3/3] selftests/mm: skip the ksm PROT_NONE test without FOLL_FORCE
2026-12-01 19:16 [PATCH v5 0/3] selftests/mm: skip tests when FOLL_FORCE writes are not available Nikolai Dokutovich
2026-12-01 19:16 ` [PATCH v5 1/3] selftests/mm: add a probe for FOLL_FORCE writes through /proc/self/mem Nikolai Dokutovich
2026-12-01 19:16 ` [PATCH v5 2/3] selftests/mm: skip the mkdirty ptrace write tests without FOLL_FORCE Nikolai Dokutovich
@ 2026-12-01 19:16 ` Nikolai Dokutovich
2 siblings, 0 replies; 4+ messages in thread
From: Nikolai Dokutovich @ 2026-12-01 19:16 UTC (permalink / raw)
To: David Hildenbrand, Andrew Morton
Cc: Shuah Khan, Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Michal Hocko, Xu Xin, linux-mm, linux-kselftest, linux-kernel,
Nikolai Dokutovich
test_prot_none() fails when the kernel does not allow forced writes:
not ok 5 ptrace write failed
Check the permission at the start of the test and skip instead.
Signed-off-by: Nikolai Dokutovich <ndokutovich@gmail.com>
---
tools/testing/selftests/mm/ksm_functional_tests.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/tools/testing/selftests/mm/ksm_functional_tests.c b/tools/testing/selftests/mm/ksm_functional_tests.c
index 31c06c72203f..e21037c9bf24 100644
--- a/tools/testing/selftests/mm/ksm_functional_tests.c
+++ b/tools/testing/selftests/mm/ksm_functional_tests.c
@@ -629,6 +629,11 @@ static void test_prot_none(void)
ksft_print_msg("[RUN] %s\n", __func__);
+ if (!proc_mem_force_write_allowed()) {
+ ksft_test_result_skip("FOLL_FORCE write not available\n");
+ return;
+ }
+
map = mmap_and_merge_range(0x11, size, PROT_NONE, KSM_MERGE_MADVISE);
if (map == MAP_FAILED)
goto unmap;
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread