mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tianyi Chen <hi@tychen.cc>
To: Mike Rapoport <rppt@kernel.org>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] memblock tests: zero-extend simulated memory addresses
Date: Thu, 17 Sep 2026 00:11:05 +0800	[thread overview]
Message-ID: <20260916161105.2548281-3-hi@tychen.cc> (raw)
In-Reply-To: <20260916161105.2548281-1-hi@tychen.cc>

Converting a 32-bit pointer directly to the 64-bit phys_addr_t can
sign-extend it when BUILD=32 is used. A dummy allocation above 2 GiB
then gets registered at an address different from its unsigned pointer
value. The low-address tests compare that value against the registered
range and fail once the earlier maximum-address free test is fixed.

Convert through uintptr_t when registering and reporting dummy memory.
This preserves the pointer bits and agrees with the simulator __pa()
conversion and the allocation tests.

Fixes: 284d950dd6b0 ("memblock tests: Add simulation of physical memory")
Assisted-by: LLM
Signed-off-by: Tianyi Chen <hi@tychen.cc>
---
 tools/testing/memblock/tests/common.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/testing/memblock/tests/common.c b/tools/testing/memblock/tests/common.c
index ac032610a56e..2a248973eb4c 100644
--- a/tools/testing/memblock/tests/common.c
+++ b/tools/testing/memblock/tests/common.c
@@ -67,7 +67,7 @@ static inline void fill_memblock(void)
 void setup_memblock(void)
 {
 	reset_memblock_regions();
-	memblock_add((phys_addr_t)memory_block.base, MEM_SIZE);
+	memblock_add((phys_addr_t)(uintptr_t)memory_block.base, MEM_SIZE);
 	fill_memblock();
 }
 
@@ -88,7 +88,7 @@ void setup_numa_memblock(const unsigned int node_fracs[])
 	int flags;
 
 	reset_memblock_regions();
-	base = (phys_addr_t)memory_block.base;
+	base = (phys_addr_t)(uintptr_t)memory_block.base;
 	flags = (movable_node_is_enabled()) ? MEMBLOCK_NONE : MEMBLOCK_HOTPLUG;
 
 	for (int i = 0; i < NUMA_NODES; i++) {
@@ -115,7 +115,7 @@ void dummy_physical_memory_cleanup(void)
 
 phys_addr_t dummy_physical_memory_base(void)
 {
-	return (phys_addr_t)memory_block.base;
+	return (phys_addr_t)(uintptr_t)memory_block.base;
 }
 
 phys_addr_t dummy_physical_memory_low_limit(void)
-- 
2.55.0


      parent reply	other threads:[~2026-09-16 16:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16 16:11 [PATCH 0/2] memblock tests: fix BUILD=32 address conversions Tianyi Chen
2026-09-16 16:11 ` [PATCH 1/2] memblock tests: use physical free for the maximum-address check Tianyi Chen
2026-09-16 16:11 ` Tianyi Chen [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=20260916161105.2548281-3-hi@tychen.cc \
    --to=hi@tychen.cc \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=rppt@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®