Re: [PATCH v2] selftests/mm: fix pointer width warnings on 32-bit architectures
From: Andrew Morton
Date: Tue Nov 03 2026 - 20:22:11 EST
On Tue, 3 Nov 2026 16:28:05 -0500 Sasha Levin <sashal@xxxxxxxxxx> wrote:
> Several mm tests convert between pointers and 64-bit integers with a
> plain cast, which warns on 32-bit architectures, and hugetlb-mremap
> passes 47-bit mmap() hints that don't fit in an unsigned long:
>
> uffd-unit-tests.c:344:31: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
>
> Add ptr_to_u64() and u64_to_ptr() to vm_util.h, which cast through
> uintptr_t, and use them where pointers meet the 64-bit UAPI fields and
> the 64-bit address arithmetic in mremap_test. The hugetlb-mremap hints
> don't fit in a 32-bit address space, so only pass them when long is 64
> bits.
lgtm, thanks. I used this as the first test case for my shiny new
kernel testing bunnybot,
Turns out, you accidentally fixed a bug!
: I compiled all six affected C files with GCC 13.3 for i386 and x86-64.
: The patch eliminated all 40 targeted warnings on i386. In a Debian VM,
: both ABIs passed checks for pointer round trips and high-bit addresses.
: All three hugepage mmap hints were NULL on i386 and retained their
: requested values on x86-64.
:
: There's also a runtime fix worth mentioning in the changelog. In the
: unpatched i386 wp-unpopulated test, UFFDIO_REGISTER successfully
: registered 0xf3f7a000. The test then passed the sign-extended address
: 0xfffffffff3f7a000 to UFFDIO_WRITEPROTECT and got EINVAL. With the
: cast through uintptr_t, wp-unpopulated passed on every run.
:
: With userfaultfd enabled, hugetlb-mremap and the userfaultfd case in
: mremap_test passed on both ABIs, with and without the patch.
:
: Separately, mremap_test cases 10-13 failed with EINVAL on i386 both
: before and after the patch. Each tries to move a 2 GiB mapping from a
: 1 GiB-aligned source to a nonoverlapping destination. Only the
: destination alignment varies: 4 KiB, 1 MiB, 2 MiB or 1 GiB. The two
: ranges alone would fill a 32-bit address space. As a follow-up, I'd
: make these four cases report SKIP for 32-bit userspace and keep the
: existing coverage on 64-bit.
:
: Tested-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
By my count, we have 15 implementations of ptr_to_u64() splattered all
over the tree.
> --- a/tools/testing/selftests/mm/vm_util.h
> +++ b/tools/testing/selftests/mm/vm_util.h
> @@ -59,6 +59,16 @@ static inline unsigned int pshift(void)
> return __page_shift;
> }
>
> +static inline uint64_t ptr_to_u64(const void *ptr)
> +{
> + return (uintptr_t)ptr;
> +}
16!