mkdirty writes through /proc/self/mem into read-only PTEs and expects the kernel to force the write. That is only allowed when the writing task is tracing the target task, which is not the case here, so on a kernel with the default CONFIG_PROC_MEM_FORCE_PTRACE the setup write fails and the test reports a failure instead of skipping: not ok 1 write() failed Check the permission once in main() and skip the two ptrace write tests at their entry when it is denied. A kernel built with CONFIG_PROC_MEM_ALWAYS_FORCE or booted with proc_mem.force_override=always still runs them for real, so a genuine failure is still reported. Commit a3907a3169d0 ("selftests/mm: specify requirement for PROC_MEM_ALWAYS_FORCE=y") asks for CONFIG_PROC_MEM_ALWAYS_FORCE=y in mm/config, which applies once that fragment is merged into the kernel configuration; this skip additionally keeps an installed binary from failing on a kernel that was not built that way. The remaining subtests do not depend on the forced write and keep running. Signed-off-by: Nikolai Dokutovich --- tools/testing/selftests/mm/mkdirty.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tools/testing/selftests/mm/mkdirty.c b/tools/testing/selftests/mm/mkdirty.c index 68dd447a5454..427436330d9e 100644 --- a/tools/testing/selftests/mm/mkdirty.c +++ b/tools/testing/selftests/mm/mkdirty.c @@ -29,6 +29,7 @@ static size_t pagesize; static size_t thpsize; static int mem_fd; static int pagemap_fd; +static enum proc_mem_force_write foll_force; static sigjmp_buf env; static void signal_handler(int sig) @@ -91,6 +92,11 @@ static void test_ptrace_write(void) ksft_print_msg("[INFO] PTRACE write access\n"); + if (foll_force == PROC_MEM_FORCE_WRITE_DENIED) { + ksft_test_result_skip("FOLL_FORCE write into a read-only mapping returned EIO\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 +134,11 @@ static void test_ptrace_write_thp(void) ksft_print_msg("[INFO] PTRACE write access to THP\n"); + if (foll_force == PROC_MEM_FORCE_WRITE_DENIED) { + ksft_test_result_skip("FOLL_FORCE write into a read-only mapping returned EIO\n"); + return; + } + mem = mmap_thp_range(PROT_READ, &mmap_mem, &mmap_size); if (mem == MAP_FAILED) return; @@ -350,6 +361,8 @@ int main(void) if (pagemap_fd < 0) ksft_exit_fail_msg("opening /proc/self/pagemap failed\n"); + foll_force = proc_mem_force_write_probe(PROT_READ); + /* * On some ptrace(FOLL_FORCE) write access via /proc/self/mem in * read-only VMAs, the kernel may set the PTE/PMD dirty. -- 2.43.0