* [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-03 15:28 ` David Hildenbrand (Arm)
2026-12-01 19:16 ` [PATCH v5 2/3] selftests/mm: skip the mkdirty ptrace write tests without FOLL_FORCE Nikolai Dokutovich
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ 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] 8+ messages in thread* Re: [PATCH v5 1/3] selftests/mm: add a probe for FOLL_FORCE writes through /proc/self/mem
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-03 15:28 ` David Hildenbrand (Arm)
0 siblings, 0 replies; 8+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-03 15:28 UTC (permalink / raw)
To: Nikolai Dokutovich, Andrew Morton
Cc: Shuah Khan, Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Michal Hocko, Xu Xin, linux-mm, linux-kselftest, linux-kernel
On 12/1/26 20:16, Nikolai Dokutovich wrote:
> 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>
Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>
> 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.
I'll likely reduce that down to "Whether a write through /proc/self/mem into a
mapping that is not writable is currently permitted." when applying.
> + */
> +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
--
Cheers,
David
^ permalink raw reply [flat|nested] 8+ 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-03 15:28 ` David Hildenbrand (Arm)
2026-12-01 19:16 ` [PATCH v5 3/3] selftests/mm: skip the ksm PROT_NONE test " Nikolai Dokutovich
2026-12-03 15:31 ` [PATCH v5 0/3] selftests/mm: skip tests when FOLL_FORCE writes are not available David Hildenbrand
3 siblings, 1 reply; 8+ 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] 8+ messages in thread* Re: [PATCH v5 2/3] selftests/mm: skip the mkdirty ptrace write tests without FOLL_FORCE
2026-12-01 19:16 ` [PATCH v5 2/3] selftests/mm: skip the mkdirty ptrace write tests without FOLL_FORCE Nikolai Dokutovich
@ 2026-12-03 15:28 ` David Hildenbrand (Arm)
0 siblings, 0 replies; 8+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-03 15:28 UTC (permalink / raw)
To: Nikolai Dokutovich, Andrew Morton
Cc: Shuah Khan, Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Michal Hocko, Xu Xin, linux-mm, linux-kselftest, linux-kernel
On 12/1/26 20:16, Nikolai Dokutovich wrote:
> 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>
> ---
Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 8+ 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
2026-12-03 15:29 ` David Hildenbrand (Arm)
2026-12-03 15:31 ` [PATCH v5 0/3] selftests/mm: skip tests when FOLL_FORCE writes are not available David Hildenbrand
3 siblings, 1 reply; 8+ 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] 8+ messages in thread* Re: [PATCH v5 3/3] selftests/mm: skip the ksm PROT_NONE test without FOLL_FORCE
2026-12-01 19:16 ` [PATCH v5 3/3] selftests/mm: skip the ksm PROT_NONE test " Nikolai Dokutovich
@ 2026-12-03 15:29 ` David Hildenbrand (Arm)
0 siblings, 0 replies; 8+ messages in thread
From: David Hildenbrand (Arm) @ 2026-12-03 15:29 UTC (permalink / raw)
To: Nikolai Dokutovich, Andrew Morton
Cc: Shuah Khan, Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Michal Hocko, Xu Xin, linux-mm, linux-kselftest, linux-kernel
On 12/1/26 20:16, Nikolai Dokutovich wrote:
> 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>
Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v5 0/3] selftests/mm: skip tests when FOLL_FORCE writes are not available
2026-12-01 19:16 [PATCH v5 0/3] selftests/mm: skip tests when FOLL_FORCE writes are not available Nikolai Dokutovich
` (2 preceding siblings ...)
2026-12-01 19:16 ` [PATCH v5 3/3] selftests/mm: skip the ksm PROT_NONE test " Nikolai Dokutovich
@ 2026-12-03 15:31 ` David Hildenbrand
3 siblings, 0 replies; 8+ messages in thread
From: David Hildenbrand @ 2026-12-03 15:31 UTC (permalink / raw)
To: David Hildenbrand, Andrew Morton, Nikolai Dokutovich
Cc: Shuah Khan, Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
Michal Hocko, Xu Xin, linux-mm, linux-kselftest, linux-kernel
On Tue, 01 Dec 2026 22:16:40 +0300, Nikolai Dokutovich wrote:
> A write through /proc/self/mem into a mapping that is not writable needs
> FOLL_FORCE, which CONFIG_PROC_MEM_FORCE_PTRACE only grants to a caller that
> traces the target. mkdirty and the ksm PROT_NONE test then fail instead of
> skipping on a distribution kernel:
>
> not ok 1 write() failed
> not ok 5 ptrace write failed
>
> [...]
Applied, thanks!
tree: mm/core.git
branch: core-7.5.misc
Applied patches will appear soon in mm-next, followed by linux-next.
Please report any outstanding bugs that were missed during review, so we
can either drop the patch series or decide how to fix it up.
It is encouraged to provide Acked-bys, Reviewed-bys, and Tested-bys even
though the patches have already been applied. If possible, patch trailers
will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. Further, this is not a guarantee that the
patches will go upstream. If in doubt, please check the listed branch.
[1/3] selftests/mm: add a probe for FOLL_FORCE writes through /proc/self/mem
https://git.kernel.org/mm/core/c/39aeff5a
[2/3] selftests/mm: skip the mkdirty ptrace write tests without FOLL_FORCE
https://git.kernel.org/mm/core/c/cef3c46b
[3/3] selftests/mm: skip the ksm PROT_NONE test without FOLL_FORCE
https://git.kernel.org/mm/core/c/fd420b6f
--
Cheers,
David
^ permalink raw reply [flat|nested] 8+ messages in thread