On 9/26/26 14:41, Donggeun Yoo wrote:
> Move a swapped-out page out of a write-protected or RWP-protected area into
> a destination registered for missing faults only, and read pagemap bit 57
> at the destination. The destination was never protected, so the bit must
> be clear.
>
> Assisted-by: LLM
> Signed-off-by: Donggeun Yoo <[email protected]>
> ---
> tools/testing/selftests/mm/uffd-unit-tests.c | 84 ++++++++++++++++++++
> 1 file changed, 84 insertions(+)
>
> diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c
> b/tools/testing/selftests/mm/uffd-unit-tests.c
> index ef9b3956bdcfd..580178630eded 100644
> --- a/tools/testing/selftests/mm/uffd-unit-tests.c
> +++ b/tools/testing/selftests/mm/uffd-unit-tests.c
> @@ -2037,6 +2037,75 @@ static void
> uffd_move_pmd_split_test(uffd_global_test_opts_t *gopts, uffd_test_a
> uffd_move_pmd_handle_fault);
> }
>
> +/*
> + * Moving a swapped-out page out of a write-protected or RWP-protected area
> + * must not carry the uffd bit into a destination registered for missing
> + * faults only: such a bit is never cleared afterwards, so pagemap keeps
> + * reporting the page as uffd-tracked.
> + *
> + * Needs a swap device; skipped if MADV_PAGEOUT cannot evict the page.
> + */
> +static void uffd_move_swap_test_common(uffd_global_test_opts_t *gopts,
> + bool rwp)
> +{
> + unsigned long page_size = gopts->page_size;
> + struct uffdio_move move = { };
> + int pagemap_fd;
> +
> + if (rwp) {
> + if (uffd_register_rwp(gopts->uffd, gopts->area_src, page_size))
> + err("register src failure");
> + } else if (uffd_register(gopts->uffd, gopts->area_src, page_size,
> + false, true, false)) {
> + err("register src failure");
> + }
Why not combine it with the protection?
if (rwp) {
if (uffd_register_rwp(gopts->uffd, gopts->area_src, page_size))
err("register src failure");
rwprotect_range(gopts->uffd, (unsigned long)gopts->area_src,
page_size, true);
} else {
if (uffd_register(gopts->uffd, gopts->area_src, page_size,
false, true, false))
err("register src failure");
wp_range(gopts->uffd, (unsigned long)gopts->area_src,
page_size, true);
}
> + if (uffd_register(gopts->uffd, gopts->area_dst, page_size,
> + true, false, false))
> + err("register dst failure");
> +
> + if (rwp)
> + rwprotect_range(gopts->uffd, (unsigned long)gopts->area_src,
> + page_size, true);
> + else
> + wp_range(gopts->uffd, (unsigned long)gopts->area_src,
> + page_size, true);
> +
> + pagemap_fd = pagemap_open();
Why not do that at the very top?
int pagemap_fd = pagemap_open();
> + if (madvise(gopts->area_src, page_size, MADV_PAGEOUT))
> + err("MADV_PAGEOUT");
> + if (!pagemap_is_swapped(pagemap_fd, gopts->area_src)) {
> + uffd_test_skip("MADV_PAGEOUT did not swap the page; is swap
> enabled?");
> + goto out;
> + }
> +
> + move.dst = (unsigned long)gopts->area_dst;
> + move.src = (unsigned long)gopts->area_src;
> + move.len = page_size;
You can set that all already when initializing aboce
struct uffdio_move move = {
.dst = (unsigned long)gopts->area_dst,
[...]
};
> + if (ioctl(gopts->uffd, UFFDIO_MOVE, &move))
> + err("UFFDIO_MOVE");
BTW, why do we fail the entire test here instead of only this test case?
--
Cheers,
David