From: Donggeun Yoo <donggeunyoo.kernel@gmail.com>
To: akpm@linux-foundation.org, rppt@kernel.org
Cc: peterx@redhat.com, surenb@google.com, aarcange@redhat.com,
david@kernel.org, ljs@kernel.org, liam@infradead.org,
vbabka@kernel.org, mhocko@suse.com, shuah@kernel.org,
kas@kernel.org, linux-mm@kvack.org,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
donggeunyoo.kernel@gmail.com
Subject: [PATCH v4 2/2] selftests/mm: add tests for UFFDIO_MOVE of a uffd-protected swap entry
Date: Sat, 3 Oct 2026 19:30:30 +0900 [thread overview]
Message-ID: <20261003103030.63380-3-donggeunyoo.kernel@gmail.com> (raw)
In-Reply-To: <20261003103030.63380-1-donggeunyoo.kernel@gmail.com>
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 <donggeunyoo.kernel@gmail.com>
---
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..97484c82f24e1 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 = {
+ .dst = (unsigned long)gopts->area_dst,
+ .src = (unsigned long)gopts->area_src,
+ .len = page_size,
+ };
+ int pagemap_fd = pagemap_open();
+
+ 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 (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;
+ }
+
+ if (ioctl(gopts->uffd, UFFDIO_MOVE, &move)) {
+ uffd_test_fail("UFFDIO_MOVE failed: %s", strerror(errno));
+ goto out;
+ }
+
+ if (pagemap_get_entry(pagemap_fd, gopts->area_dst) & PM_UFFD_WP)
+ uffd_test_fail("uffd bit moved into an area registered for missing faults only");
+ else
+ uffd_test_pass();
+out:
+ close(pagemap_fd);
+ uffd_unregister(gopts->uffd, gopts->area_src, page_size);
+ uffd_unregister(gopts->uffd, gopts->area_dst, page_size);
+}
+
+static void uffd_move_swap_wp_test(uffd_global_test_opts_t *gopts,
+ uffd_test_args_t *targs)
+{
+ uffd_move_swap_test_common(gopts, false);
+}
+
+static void uffd_move_swap_rwp_test(uffd_global_test_opts_t *gopts,
+ uffd_test_args_t *targs)
+{
+ uffd_move_swap_test_common(gopts, true);
+}
+
static bool
uffdio_verify_results(const char *name, int ret, int error, long result)
{
@@ -2359,6 +2428,21 @@ uffd_test_case_t uffd_tests[] = {
.uffd_feature_required = UFFD_FEATURE_MOVE,
.test_case_ops = &uffd_move_test_pmd_case_ops,
},
+ {
+ .name = "move-swap-wp",
+ .uffd_fn = uffd_move_swap_wp_test,
+ .mem_targets = MEM_ANON,
+ .uffd_feature_required = UFFD_FEATURE_MOVE |
+ UFFD_FEATURE_PAGEFAULT_FLAG_WP,
+ .test_case_ops = &uffd_move_test_case_ops,
+ },
+ {
+ .name = "move-swap-rwp",
+ .uffd_fn = uffd_move_swap_rwp_test,
+ .mem_targets = MEM_ANON,
+ .uffd_feature_required = UFFD_FEATURE_MOVE | UFFD_FEATURE_RWP,
+ .test_case_ops = &uffd_move_test_case_ops,
+ },
{
.name = "wp-fork",
.uffd_fn = uffd_wp_fork_test,
--
2.53.0
next prev parent reply other threads:[~2026-10-03 10:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-03 10:30 [PATCH v4 0/2] userfaultfd: clear the inherited uffd bit in move_swap_pte() Donggeun Yoo
2026-10-03 10:30 ` [PATCH v4 1/2] " Donggeun Yoo
2026-10-03 10:30 ` Donggeun Yoo [this message]
2026-10-05 10:43 ` [PATCH v4 2/2] selftests/mm: add tests for UFFDIO_MOVE of a uffd-protected swap entry David Hildenbrand (Arm)
2026-10-05 11:50 ` Donggeun Yoo
2026-10-07 10:03 ` David Hildenbrand (Arm)
2026-10-04 20:07 ` [PATCH v4 0/2] userfaultfd: clear the inherited uffd bit in move_swap_pte() Andrew Morton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261003103030.63380-3-donggeunyoo.kernel@gmail.com \
--to=donggeunyoo.kernel@gmail.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=kas@kernel.org \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=peterx@redhat.com \
--cc=rppt@kernel.org \
--cc=shuah@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.