From: Xionggui Chen The madv_populate selftest assumes that mmap(PROT_WRITE) creates a VMA without VM_READ and expects MADV_POPULATE_READ to fail with EINVAL. On RISC-V, commit 6c7559f22b6f ("riscv/mm: ensure PROT_WRITE leads to VM_READ | VM_WRITE") makes the kernel set VM_READ for mappings requested with PROT_WRITE. MADV_POPULATE_READ checks this VMA permission, so it succeeds and the test fails incorrectly. Adjust the expected result for RISC-V using an architecture-specific conditional, while preserving the existing behavior on other architectures. On RISC-V with Linux 7.2.0, the original test fails 1 out of 16 tests, while the updated test passes all 16 tests. Link: https://lore.kernel.org/20261112031811.56500-1-evers_chen@163.com Fixes: e5bfac53e310 ("selftests/vm: add test for MADV_POPULATE_(READ|WRITE)") Signed-off-by: Xionggui Chen --- Changes in v2: - Use an architecture-specific conditional for RISC-V. - Remove /proc/self/maps parsing. - Remove the additional PROT_NONE test. tools/testing/selftests/mm/madv_populate.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/testing/selftests/mm/madv_populate.c b/tools/testing/selftests/mm/madv_populate.c index 7fce5d0b622b..fa26ca2d8cf6 100644 --- a/tools/testing/selftests/mm/madv_populate.c +++ b/tools/testing/selftests/mm/madv_populate.c @@ -81,8 +81,13 @@ static void test_prot_write(void) ksft_exit_fail_msg("mmap failed\n"); ret = madvise(addr, SIZE, MADV_POPULATE_READ); +#ifdef __riscv + ksft_test_result(ret == 0, + "MADV_POPULATE_READ with PROT_WRITE\n"); +#else ksft_test_result(ret == -1 && errno == EINVAL, "MADV_POPULATE_READ with PROT_WRITE\n"); +#endif ret = madvise(addr, SIZE, MADV_POPULATE_WRITE); ksft_test_result(!ret, "MADV_POPULATE_WRITE with PROT_WRITE\n");