From: sashiko-bot@kernel.org
To: "John J. Coleman" <jocolema@redhat.com>, zenghui.yu@linux.dev
Cc: akpm@linux-foundation.org, david@kernel.org, liam@infradead.org,
linux-mm@kvack.org, ljs@kernel.org, mhocko@suse.com,
peterx@redhat.com, rppt@kernel.org, surenb@google.com,
vbabka@kernel.org, audra@redhat.com
Subject: Re: [PATCH] selftests/mm: scale uffd memory region contingent upon base page size
Date: Wed, 04 Nov 2026 20:21:57 +0000 [thread overview]
Message-ID: <sashiko-outbox-198006@kernel.org> (raw)
In-Reply-To: <20261103202049.499206-1-jocolema@redhat.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] selftests/mm: global UFFD_TEST_MEM_SIZE scaling inflates all tests to 1 GiB
- [Medium] selftests/mm: 32-bit off_t and address space overflow in shmem_allocate_area()
- [Low] selftests/mm: PAGE_SIZE macro duplicates psize() and risks redefinition
--
commit 10ea7f3e59b6ab7f3100a4c6de93cabccc122a33
Author: John J. Coleman <jocolema@redhat.com>
selftests/mm: scale uffd memory region contingent upon base page size
This patch scales UFFD_TEST_MEM_SIZE in uffd-unit-tests.c based on the
architecture base page size so that move-pmd tests on aarch64 with 64K base
pages have a large enough memory region instead of being skipped.
> diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c
> index 298609544445e..4037a7160b13d 100644
> --- a/tools/testing/selftests/mm/uffd-unit-tests.c
> +++ b/tools/testing/selftests/mm/uffd-unit-tests.c
> @@ -13,8 +13,14 @@
>
> #ifdef __NR_userfaultfd
>
> -/* The unit test doesn't need a large or random size, make it 32MB for now */
> -#define UFFD_TEST_MEM_SIZE (32UL << 20)
> +/*
> + * The unit test does not need a large or random size, but the allocation size
> + * needs to scale with base page size per architecture otherwise pmd alignment
> + * tests will fail for architectures like aarch64+64k. For standard 4k pages,
> + * this will allocate 64MiB, while allocating 1GiB for 64k page sizes.
> + */
> +#define PAGE_SIZE sysconf(_SC_PAGESIZE)
[Severity: Low]
This isn't a bug, but uffd-unit-tests.c already includes vm_util.h (via
uffd-common.h) and calls psize() in main():
tools/testing/selftests/mm/vm_util.h:psize() {
if (!__page_size)
__page_size = sysconf(_SC_PAGESIZE);
return __page_size;
}
An unguarded PAGE_SIZE macro can also collide with system headers on libcs
such as musl (which defines PAGE_SIZE in limits.h under _GNU_SOURCE), and
sysconf(_SC_PAGESIZE) returns a signed long rather than an unsigned value.
Could this reuse psize() instead of defining a new PAGE_SIZE macro?
> +#define UFFD_TEST_MEM_SIZE (PAGE_SIZE * (16 << 10))
[Severity: Medium]
Does scaling UFFD_TEST_MEM_SIZE globally inflate memory allocation, runtime,
and HugeTLB reservations across the entire test suite?
In main(), UFFD_TEST_MEM_SIZE is applied to every test case and memory type:
tools/testing/selftests/mm/uffd-unit-tests.c:main() {
...
/* Ensure we have at least 2 pages */
gopts.nr_pages = MAX(UFFD_TEST_MEM_SIZE, gopts.page_size * 2)
/ gopts.page_size;
...
}
And uffd_setup_hugetlb() reserves twice UFFD_TEST_MEM_SIZE in HugeTLB pages
up front for the entire test binary execution:
tools/testing/selftests/mm/uffd-unit-tests.c:uffd_setup_hugetlb() {
...
/* need twice UFFD_TEST_MEM_SIZE, one for src area and one for dst */
nr_hugepages = 2 * MAX(UFFD_TEST_MEM_SIZE, hp_size * 2) / hp_size;
hugetlb_set_nr_default_pages(nr_hugepages);
...
}
On 64K base page systems, only the PMD-granularity tests (such as move-pmd
and move-pmd-split in uffd_move_test_common(), which align area_src and
area_dst up to pmd_psize()) need a buffer of at least 2 * pmd_psize().
Scaling UFFD_TEST_MEM_SIZE globally increases every test on 64K base pages
from 32 MiB (512 pages) to 1 GiB (16,384 pages) per area (2 GiB total for
area_src and area_dst), forcing every base-page test to fault in 16,384
pages and scan 1 GiB byte-by-byte in helpers like check_memory_contents().
It also raises the HugeTLB reservation in uffd_setup_hugetlb() from 64 MiB
to 2 GiB on 64K-page systems with 2 MiB or 16 MiB default hugepages (such as
powerpc64 or arm64 cont-PTE hugepages), which causes all hugetlb tests to be
skipped if 2 GiB of hugepages cannot be reserved, or pins 2 GiB of RAM in
the HugeTLB pool while subsequent anon/shmem tests allocate another 2 GiB.
Additionally, PMD size is not a fixed multiple of base page size across
architectures (powerpc64 with 64K pages has a 2 MiB or 16 MiB PMD size, and
4K-page systems double from 32 MiB to 64 MiB).
Since struct uffd_test_case_ops provides a pre_alloc hook invoked in
uffd_test_ctx_init() before allocate_area(), would it be better to keep
UFFD_TEST_MEM_SIZE at 32 MiB and adjust gopts->nr_pages based on
2 * pmd_psize() in uffd_move_test_pmd_case_ops (and any other PMD-sized test)?
[Severity: Medium]
Can setting UFFD_TEST_MEM_SIZE to 1 GiB on 64K-page kernels overflow 32-bit
signed off_t and the 32-bit virtual address space when uffd-unit-tests is
built as a 32-bit binary (for example, a 32-bit compat binary on an
aarch64 or powerpc64 64K-page kernel, or 32-bit powerpc with 64K/256K pages)?
In main() -> uffd_test_ctx_init() -> shmem_allocate_area():
tools/testing/selftests/mm/uffd-common.c:shmem_allocate_area() {
size_t bytes = gopts->nr_pages * gopts->page_size, hpage_size = pmd_psize();
unsigned long offset = is_src ? 0 : bytes;
char *p = NULL, *p_alias = NULL;
int mem_fd = uffd_mem_fd_create(bytes * 2, false);
size_t region_size = bytes * 2 + hpage_size;
...
}
Because tools/testing/selftests/mm/Makefile does not define
_FILE_OFFSET_BITS=64, off_t and size_t are 32-bit on 32-bit builds. When
bytes is 1 GiB (0x40000000), bytes * 2 is 0x80000000, which overflows the
32-bit signed off_t parameter of uffd_mem_fd_create(off_t mem_size, bool hugetlb)
to -2147483648 and causes ftruncate() to fail with EINVAL, while mapping two
regions of size bytes * 2 + hpage_size exceeds the 32-bit address space. On
256K base page kernels (CONFIG_PPC_256K_PAGES), PAGE_SIZE * (16 << 10) also
overflows a 32-bit signed long directly.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261103202049.499206-1-jocolema@redhat.com?part=1
next prev parent reply other threads:[~2026-11-04 20:22 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-11 16:35 [PATCH] selftests/mm: fix uffd move-pmd test crash on 64K base page systems Zenghui Yu
2026-10-12 6:13 ` Sarthak Sharma
2026-10-29 13:10 ` Zenghui Yu
2026-10-12 12:12 ` Jose A. Perez de Azpillaga
2026-10-13 7:39 ` David Hildenbrand (Arm)
2026-10-13 10:33 ` Mike Rapoport
2026-10-13 11:46 ` David Hildenbrand (Arm)
2026-10-29 13:37 ` Zenghui Yu
2026-10-29 15:47 ` David Hildenbrand (Arm)
2026-11-03 20:20 ` [PATCH] selftests/mm: scale uffd memory region contingent upon base page size John J. Coleman
2026-11-04 20:21 ` sashiko-bot [this message]
2026-11-05 17:54 ` [PATCH v2] " John J. Coleman
2026-11-06 17:54 ` sashiko-bot
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=sashiko-outbox-198006@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=audra@redhat.com \
--cc=david@kernel.org \
--cc=jocolema@redhat.com \
--cc=liam@infradead.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=peterx@redhat.com \
--cc=rppt@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
--cc=zenghui.yu@linux.dev \
/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.