mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] selftests/mm: allocate nr_pages based on pmd size for uffd pmd_move tests
@ 2026-11-13  4:00 John J. Coleman
  0 siblings, 0 replies; only message 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	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-13  4:01 UTC | newest]

Thread overview: (only message) (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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®