mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Sasha Levin <sashal@kernel.org>
Cc: Jason Gunthorpe <jgg@ziepe.ca>, Leon Romanovsky <leon@kernel.org>,
	David Hildenbrand <david@kernel.org>,
	Lorenzo Stoakes <ljs@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	Vlastimil Babka <vbabka@kernel.org>,
	Mike Rapoport <rppt@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>, Shuah Khan <shuah@kernel.org>,
	Peter Xu <peterx@redhat.com>,
	linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] selftests/mm: fix pointer width warnings on 32-bit architectures
Date: Tue, 3 Nov 2026 17:21:50 -0800	[thread overview]
Message-ID: <20261103172150.3753dfa00f3106b6014e4d2c@linux-foundation.org> (raw)
In-Reply-To: <20261103212805.1537354-1-sashal@kernel.org>

On Tue,  3 Nov 2026 16:28:05 -0500 Sasha Levin <sashal@kernel.org> 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@linux-foundation.org>


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!



      reply	other threads:[~2026-11-04  1:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 21:28 Sasha Levin
2026-11-04  1:21 ` Andrew Morton [this message]

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=20261103172150.3753dfa00f3106b6014e4d2c@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=david@kernel.org \
    --cc=jgg@ziepe.ca \
    --cc=leon@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=sashal@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 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®