Re: [PATCH v2] selftests/mm: handle implicit read permissions in madv_populate
From: David Hildenbrand (Arm)
Date: Tue Nov 17 2026 - 03:58:48 EST
On 11/17/26 08:06, Xionggui Chen wrote:
> From: Xionggui Chen <chenxionggui@xxxxxxxxxxxxxxxxxxx>
>
> 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.
Thanks, please don't send new revisions in reply to previous revisions next time.
>
> Link: https://lore.kernel.org/20261112031811.56500-1-evers_chen@xxxxxxx
> Fixes: e5bfac53e310 ("selftests/vm: add test for MADV_POPULATE_(READ|WRITE)")
> Signed-off-by: Xionggui Chen <chenxionggui@xxxxxxxxxxxxxxxxxxx>
> ---
> 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");
>
No that's a simple fix :)
Acked-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
--
Cheers,
David