* [PATCH] selftests/mm: allocate nr_pages based on pmd size for uffd pmd_move tests
@ 2026-11-13 4:00 John J. Coleman
2026-11-14 4:01 ` sashiko-bot
2026-11-18 4:09 ` Zenghui Yu
0 siblings, 2 replies; 5+ messages in thread
From: John J. Coleman @ 2026-11-13 4:00 UTC (permalink / raw)
To: linux-mm, linux-kernel
Cc: zenghui.yu, akpm, david, liam, ljs, mhocko, peterx, rppt, surenb,
vbabka, audra
When executing the uffd-unit-test, the "move-pmd on anon" test will fail
on aarch64+64k with a segmentation fault because the initial allocated
memory region is too small. This only happens with the move-pmd* tests
because the architecture base page size is still utilized even though the
memory region is specific to the size indicated by the pmd.
Patch 9f5c2aec3388 ("selftests/mm: fix uffd move-pmd test crash on 64K
base page systems") implements an initial fix to the segmentation fault
by skipping the test if the allocated memory region is not large enough
for the number of pages x page size requested. Since this will skip over
the aarch64+64k pmd tests, this patch is intended to resolve the problem
with 64k pages by pre-allocating the memory region with 2x the pmd page
size (for area_src and area_dst) for only the move_pmd tests by using the
uffd_test_case_ops pre_alloc hook.
Link: https://lore.kernel.org/all/20261103202049.499206-1-jocolema@redhat.com
Fixes: a2bf6a9ca805 ("selftests/mm: add UFFDIO_MOVE ioctl test")
Signed-off-by: John J. Coleman <jocolema@redhat.com>
---
I initially included patches V1 and V2 through the linked email thread.
V1 and V2 modified UFFD_TEST_MEM_SIZE contingent upon base page size and
a multiplier. However, sashiko review observed alignment issues with
powerpc64 with 2MiB and 16MiB pmd sizes as well as 32bit type overflows.
Subseqent to sashiko review I decided to make a significant change hence
why I created a new patch rather than continuing with V3. This patch
leaves UFFD_TEST_MEM_SIZE at the 32MiB arbitrary value and utilizes the
pre_alloc callback within the uffd_test_case_ops object to set nr_pages
based on 2x retrieved PMD size divided by the base page size for both
source and destination test allocated memory regions.
tools/testing/selftests/mm/uffd-unit-tests.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c
index 2a97ba1d6feb1b35d6281449fd1917793a64fab1..0846de62689f710bab320e399d0bb5849b9408ff 100644
--- a/tools/testing/selftests/mm/uffd-unit-tests.c
+++ b/tools/testing/selftests/mm/uffd-unit-tests.c
@@ -2226,6 +2226,20 @@ static void uffd_mmap_changing_test(uffd_global_test_opts_t *gopts, uffd_test_ar
uffd_test_pass();
}
+static int set_pmd_pagesize_nr_pages(uffd_global_test_opts_t *gopts, const char **errmsg)
+{
+ uint64_t pmd_pagesize = read_pmd_pagesize();
+ if (!pmd_pagesize) {
+ if(errmsg)
+ *errmsg = "failed to retrieve pmd page size";
+ return -1;
+ }
+
+ gopts->nr_pages = (2 * pmd_pagesize) / gopts->page_size;
+
+ return 0;
+}
+
static int prevent_hugepages(uffd_global_test_opts_t *gopts, const char **errmsg)
{
/* This should be done before source area is populated */
@@ -2259,6 +2273,7 @@ struct uffd_test_case_ops uffd_move_test_case_ops = {
};
struct uffd_test_case_ops uffd_move_test_pmd_case_ops = {
+ .pre_alloc = set_pmd_pagesize_nr_pages,
.post_alloc = request_hugepages,
};
--
2.56.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] selftests/mm: allocate nr_pages based on pmd size for uffd pmd_move tests 2026-11-13 4:00 [PATCH] selftests/mm: allocate nr_pages based on pmd size for uffd pmd_move tests John J. Coleman @ 2026-11-14 4:01 ` sashiko-bot 2026-11-14 18:44 ` Andrew Morton 2026-11-18 4:09 ` Zenghui Yu 1 sibling, 1 reply; 5+ messages in thread From: sashiko-bot @ 2026-11-14 4:01 UTC (permalink / raw) To: John J. Coleman, linux-mm Cc: zenghui.yu, akpm, david, liam, ljs, mhocko, peterx, rppt, surenb, vbabka, audra Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] selftests/mm: build failure from calling removed read_pmd_pagesize() -- commit baaff8c2bca44f86cbdf0bcae24ee9317be43974 Author: John J. Coleman <jocolema@redhat.com> selftests/mm: allocate nr_pages based on pmd size for uffd pmd_move tests This commit adds a pre_alloc callback for the move-pmd uffd unit tests to size nr_pages to twice the PMD page size divided by the base page size. Link: https://lore.kernel.org/all/20261103202049.499206-1-jocolema@redhat.com > diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c > index 9641f4730a355..9668dccc11599 100644 > --- a/tools/testing/selftests/mm/uffd-unit-tests.c > +++ b/tools/testing/selftests/mm/uffd-unit-tests.c > @@ -2484,6 +2484,20 @@ static void uffd_mmap_changing_test(uffd_global_test_opts_t *gopts, uffd_test_ar > uffd_test_pass(); > } > > +static int set_pmd_pagesize_nr_pages(uffd_global_test_opts_t *gopts, const char **errmsg) > +{ > + uint64_t pmd_pagesize = read_pmd_pagesize(); [Severity: Medium] Should this call pmd_psize() instead of read_pmd_pagesize()? Commit 3fe017016527 ("kselftest: mm: rename read_pmd_pagesize() to pmd_psize()") renamed this helper, so calling read_pmd_pagesize() breaks the build of uffd-unit-tests. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261113040045.1439391-1-jocolema@redhat.com?part=1 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] selftests/mm: allocate nr_pages based on pmd size for uffd pmd_move tests 2026-11-14 4:01 ` sashiko-bot @ 2026-11-14 18:44 ` Andrew Morton 2026-11-15 15:30 ` John J. Coleman 0 siblings, 1 reply; 5+ messages in thread From: Andrew Morton @ 2026-11-14 18:44 UTC (permalink / raw) To: sashiko-reviews Cc: sashiko-bot, John J. Coleman, linux-mm, zenghui.yu, david, liam, ljs, mhocko, peterx, rppt, surenb, vbabka, audra On Sat, 14 Nov 2026 04:01:42 +0000 sashiko-bot@kernel.org wrote: > Thank you for your contribution! Sashiko AI review found 1 potential > issue to consider: > - [Medium] selftests/mm: build failure from calling removed > read_pmd_pagesize() > -- > > commit baaff8c2bca44f86cbdf0bcae24ee9317be43974 > Author: John J. Coleman <jocolema@redhat.com> > > selftests/mm: allocate nr_pages based on pmd size for uffd pmd_move tests > > This commit adds a pre_alloc callback for the move-pmd uffd unit tests to > size nr_pages to twice the PMD page size divided by the base page size. > > Link: https://lore.kernel.org/all/20261103202049.499206-1-jocolema@redhat.com > > > diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c > > index 9641f4730a355..9668dccc11599 100644 > > --- a/tools/testing/selftests/mm/uffd-unit-tests.c > > +++ b/tools/testing/selftests/mm/uffd-unit-tests.c > > @@ -2484,6 +2484,20 @@ static void uffd_mmap_changing_test(uffd_global_test_opts_t *gopts, uffd_test_ar > > uffd_test_pass(); > > } > > > > +static int set_pmd_pagesize_nr_pages(uffd_global_test_opts_t *gopts, const char **errmsg) > > +{ > > + uint64_t pmd_pagesize = read_pmd_pagesize(); > > [Severity: Medium] > Should this call pmd_psize() instead of read_pmd_pagesize()? Commit > 3fe017016527 ("kselftest: mm: rename read_pmd_pagesize() to pmd_psize()") > renamed this helper, so calling read_pmd_pagesize() breaks the build of > uffd-unit-tests. yup, that's the sort of thing which I get to fix. my reviewbot said: : The pre_alloc hook fixes the sizing problem. But on 4K-page, : 2MiB-PMD systems it shrinks each test area from 32 MiB to 4 MiB. : After alignment, move-pmd usually exercises one PMD-sized move : instead of about fifteen. Please retain the existing minimum: : : gopts->nr_pages = MAX(UFFD_TEST_MEM_SIZE, 2 * pmd_pagesize) / : gopts->page_size; : : On arm64 with 64K pages, source initialization touches 1 GiB. : The test also does not verify a huge PMD mapping: MADV_HUGEPAGE is : advisory, and UFFDIO_MOVE can use its PTE path. That coverage : limitation predates this patch. So I came up with the below addition. John, can you please check it? From: Andrew Morton <akpm@linux-foundation.org> Subject: selftests/mm: retain move-pmd coverage and verify huge PMDs Date: Fri, 13 Nov 2026 20:35:51 -0800 The move-pmd tests need room for a PMD-aligned range. John J. Coleman's patch [1] provides two PMD spans, but replaces the 32 MiB default with 4 MiB on 4K-page, 2MiB-PMD systems. With unaligned mmap addresses, that reduces the test from about fifteen PMD-sized moves to one. Retain 32 MiB as the minimum. MADV_HUGEPAGE is advisory. If the source is PTE-mapped, a PMD-sized UFFDIO_MOVE can succeed through move_pages_ptes() without exercising the huge-PMD path. Collapse the first aligned source PMD and check its mapping before either PMD test. Report a skip when a huge PMD cannot be obtained, rather than reporting a pass for a PTE-only run. Link: https://lore.kernel.org/r/20261113040045.1439391-1-jocolema@redhat.com [1] Fixes: a2bf6a9ca805 ("selftests/mm: add UFFDIO_MOVE ioctl test") Signed-off-by: Andrew Morton <akpm@linux-foundation.org> --- This is a fixup on top of John J. Coleman's patch [1]. My LLM-driven live-kernel runtime testbot said: Result: PASS. On a two-node x86-64 7.4.0-rc1 guest, all three move-pmd selftests passed with and without the patch. A kprobe recorded 3 entries into move_pages_huge_pmd() without the patch and 17 with it, confirming the additional huge-PMD path coverage. A targeted allocation failure made MADV_COLLAPSE return ENOMEM; the patched test skipped as expected, while its no-fault control passed. An independent UFFDIO_MOVE partial-progress and cleanup probe passed. No test failure was observed. tools/testing/selftests/mm/uffd-unit-tests.c | 25 ++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) --- a/tools/testing/selftests/mm/uffd-unit-tests.c~selftests-mm-retain-move-pmd-coverage-and-verify-huge-pmds +++ a/tools/testing/selftests/mm/uffd-unit-tests.c @@ -2124,8 +2124,28 @@ static void uffd_move_test(uffd_global_t uffd_move_test_common(gopts, targs, gopts->page_size, uffd_move_handle_fault); } +/* + * A PMD-sized UFFDIO_MOVE can also move PTEs. Make sure these tests + * start with a huge PMD, rather than passing through the PTE path. + */ +static bool uffd_move_pmd_ready(uffd_global_test_opts_t *gopts) +{ + unsigned long pmd_size = pmd_psize(); + char *src = ALIGN_UP(gopts->area_src, pmd_size); + + if (madvise(src, pmd_size, MADV_COLLAPSE) || + !check_huge_anon(src, pmd_size, 1, pmd_size)) { + uffd_test_skip("could not obtain a huge PMD for the source"); + return false; + } + + return true; +} + static void uffd_move_pmd_test(uffd_global_test_opts_t *gopts, uffd_test_args_t *targs) { + if (!uffd_move_pmd_ready(gopts)) + return; if (madvise(gopts->area_dst, gopts->nr_pages * gopts->page_size, MADV_HUGEPAGE)) err("madvise(MADV_HUGEPAGE) failure"); uffd_move_test_common(gopts, targs, pmd_psize(), @@ -2225,6 +2245,8 @@ static void uffd_move_pmd_huge_zeropage_ static void uffd_move_pmd_split_test(uffd_global_test_opts_t *gopts, uffd_test_args_t *targs) { + if (!uffd_move_pmd_ready(gopts)) + return; if (madvise(gopts->area_dst, gopts->nr_pages * gopts->page_size, MADV_NOHUGEPAGE)) err("madvise(MADV_NOHUGEPAGE) failure"); uffd_move_test_common(gopts, targs, pmd_psize(), @@ -2493,7 +2515,8 @@ static int set_pmd_pagesize_nr_pages(uff return -1; } - gopts->nr_pages = (2 * pmd_pagesize) / gopts->page_size; + gopts->nr_pages = MAX(UFFD_TEST_MEM_SIZE, 2 * pmd_pagesize) / + gopts->page_size; return 0; } _ ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] selftests/mm: allocate nr_pages based on pmd size for uffd pmd_move tests 2026-11-14 18:44 ` Andrew Morton @ 2026-11-15 15:30 ` John J. Coleman 0 siblings, 0 replies; 5+ messages in thread From: John J. Coleman @ 2026-11-15 15:30 UTC (permalink / raw) To: akpm Cc: audra, david, jocolema, liam, linux-mm, ljs, mhocko, peterx, rppt, sashiko-bot, sashiko-reviews, surenb, vbabka, zenghui.yu Hi Andrew, thank you for checking this! And me-- for missing that MAX() input especially. I reviewed your patch and ran a test with the changes on my own systems as well, and it works great for me. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] selftests/mm: allocate nr_pages based on pmd size for uffd pmd_move tests 2026-11-13 4:00 [PATCH] selftests/mm: allocate nr_pages based on pmd size for uffd pmd_move tests John J. Coleman 2026-11-14 4:01 ` sashiko-bot @ 2026-11-18 4:09 ` Zenghui Yu 1 sibling, 0 replies; 5+ messages in thread From: Zenghui Yu @ 2026-11-18 4:09 UTC (permalink / raw) To: John J. Coleman Cc: linux-mm, linux-kernel, akpm, david, liam, ljs, mhocko, peterx, rppt, surenb, vbabka, audra Hi John, On 11/13/26 12:00 PM, John J. Coleman wrote: > When executing the uffd-unit-test, the "move-pmd on anon" test will fail > on aarch64+64k with a segmentation fault because the initial allocated > memory region is too small. This only happens with the move-pmd* tests > because the architecture base page size is still utilized even though the > memory region is specific to the size indicated by the pmd. > > Patch 9f5c2aec3388 ("selftests/mm: fix uffd move-pmd test crash on 64K > base page systems") implements an initial fix to the segmentation fault > by skipping the test if the allocated memory region is not large enough > for the number of pages x page size requested. Since this will skip over > the aarch64+64k pmd tests, this patch is intended to resolve the problem > with 64k pages by pre-allocating the memory region with 2x the pmd page > size (for area_src and area_dst) for only the move_pmd tests by using the > uffd_test_case_ops pre_alloc hook. > > Link: https://lore.kernel.org/all/20261103202049.499206-1-jocolema@redhat.com > > Fixes: a2bf6a9ca805 ("selftests/mm: add UFFDIO_MOVE ioctl test") > > Signed-off-by: John J. Coleman <jocolema@redhat.com> Thanks for chasing it. I've tested mm-new (which already contains this patch) on my 64k-page-size box. Before this patch: ok 14 # SKIP move-pmd on anon (chunk size does not fit in the test area) ok 15 # SKIP move-pmd-huge-zeropage on anon (not enough pages for one PMD-sized move) ok 16 # SKIP move-pmd-split on anon (chunk size does not fit in the test area) After this patch: ok 14 move-pmd on anon ok 15 move-pmd-huge-zeropage on anon ok 16 move-pmd-split on anon So, Tested-by: Zenghui Yu (Huawei) <zenghui.yu@linux.dev> Thanks, Zenghui ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-18 4:09 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-13 4:00 [PATCH] selftests/mm: allocate nr_pages based on pmd size for uffd pmd_move tests John J. Coleman 2026-11-14 4:01 ` sashiko-bot 2026-11-14 18:44 ` Andrew Morton 2026-11-15 15:30 ` John J. Coleman 2026-11-18 4:09 ` Zenghui Yu
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.