mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] memblock tests: fix BUILD=32 address conversions
@ 2026-09-16 16:11 Tianyi Chen
  2026-09-16 16:11 ` [PATCH 1/2] memblock tests: use physical free for the maximum-address check Tianyi Chen
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Tianyi Chen @ 2026-09-16 16:11 UTC (permalink / raw)
  To: Mike Rapoport; +Cc: linux-mm, linux-kernel

Fix two BUILD=32 failures: truncating a physical address before freeing
it, and sign-extending simulated memory addresses. Existing assertions
cover both regressions.

The runner passes with GCC in both allocation directions across 32-bit
builds, 32-bit phys_addr_t, and NUMA configurations. BUILD=32 NUMA=1 also
passes with Clang.

Tianyi Chen (2):
  memblock tests: use physical free for the maximum-address check
  memblock tests: zero-extend simulated memory addresses

 tools/testing/memblock/tests/basic_api.c | 6 +++---
 tools/testing/memblock/tests/common.c    | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)


base-commit: 5728d3523f12826a2b180c1c5738f74e33197e14
-- 
2.55.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] memblock tests: use physical free for the maximum-address check
  2026-09-16 16:11 [PATCH 0/2] memblock tests: fix BUILD=32 address conversions Tianyi Chen
@ 2026-09-16 16:11 ` Tianyi Chen
  2026-09-16 16:11 ` [PATCH 2/2] memblock tests: zero-extend simulated memory addresses Tianyi Chen
  2026-09-22 10:10 ` [PATCH 0/2] memblock tests: fix BUILD=32 address conversions Mike Rapoport
  2 siblings, 0 replies; 5+ messages in thread
From: Tianyi Chen @ 2026-09-16 16:11 UTC (permalink / raw)
  To: Mike Rapoport; +Cc: linux-mm, linux-kernel

With BUILD=32, phys_addr_t remains 64-bit while pointers are 32-bit.
Casting the address near PHYS_ADDR_MAX to void * truncates it before
memblock_free() converts it back with __pa(). The reserved region is
therefore left unchanged and memblock_free_near_max_check() fails.

Use memblock_phys_free() for this synthetic physical range and retain
the checks that freeing past PHYS_ADDR_MAX clips the removed region.

Fixes: 21a233f68afe ("memblock tests: add additional tests for basic api and memblock_alloc")
Assisted-by: LLM
Signed-off-by: Tianyi Chen <hi@tychen.cc>
---
 tools/testing/memblock/tests/basic_api.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/testing/memblock/tests/basic_api.c b/tools/testing/memblock/tests/basic_api.c
index 01e836fba488..dfca0153b6b1 100644
--- a/tools/testing/memblock/tests/basic_api.c
+++ b/tools/testing/memblock/tests/basic_api.c
@@ -2003,7 +2003,7 @@ static int memblock_free_only_region_check(void)
  * Expect the total size of reserved memory to be updated and the counter to
  * not be updated.
  */
-static int memblock_free_near_max_check(void)
+static int memblock_phys_free_near_max_check(void)
 {
 	struct memblock_region *rgn;
 	phys_addr_t total_size;
@@ -2026,7 +2026,7 @@ static int memblock_free_near_max_check(void)
 
 	reset_memblock_regions();
 	memblock_reserve(r1.base, r1.size);
-	memblock_free((void *)r2.base, r2.size);
+	memblock_phys_free(r2.base, r2.size);
 
 	ASSERT_EQ(rgn->base, r1.base);
 	ASSERT_EQ(rgn->size, total_size);
@@ -2114,7 +2114,7 @@ static int memblock_free_checks(void)
 	memblock_free_overlap_bottom_check();
 	memblock_free_within_check();
 	memblock_free_only_region_check();
-	memblock_free_near_max_check();
+	memblock_phys_free_near_max_check();
 	memblock_free_overlap_two_check();
 
 	prefix_pop();
-- 
2.55.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/2] memblock tests: zero-extend simulated memory addresses
  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
  2026-09-22 10:10 ` [PATCH 0/2] memblock tests: fix BUILD=32 address conversions Mike Rapoport
  2 siblings, 0 replies; 5+ messages in thread
From: Tianyi Chen @ 2026-09-16 16:11 UTC (permalink / raw)
  To: Mike Rapoport; +Cc: linux-mm, linux-kernel

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] memblock tests: fix BUILD=32 address conversions
  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 ` [PATCH 2/2] memblock tests: zero-extend simulated memory addresses Tianyi Chen
@ 2026-09-22 10:10 ` Mike Rapoport
  2026-09-23  2:32   ` Tianyi Chen
  2 siblings, 1 reply; 5+ messages in thread
From: Mike Rapoport @ 2026-09-22 10:10 UTC (permalink / raw)
  To: Tianyi Chen; +Cc: Mike Rapoport, linux-mm, linux-kernel

> Fix two BUILD=32 failures: truncating a physical address before freeing
> it, and sign-extending simulated memory addresses. Existing assertions
> cover both regressions.
> 
> The runner passes with GCC in both allocation directions across 32-bit
> builds, 32-bit phys_addr_t, and NUMA configurations. BUILD=32 NUMA=1 also
> passes with Clang.

Does it mean BUILD=32 without NUMA does not pass with clang?

I see a lot of warnings with gcc and BUILD=32. Do you mind fixing them
as well?

-- 
Sincerely yours,
Mike.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] memblock tests: fix BUILD=32 address conversions
  2026-09-22 10:10 ` [PATCH 0/2] memblock tests: fix BUILD=32 address conversions Mike Rapoport
@ 2026-09-23  2:32   ` Tianyi Chen
  0 siblings, 0 replies; 5+ messages in thread
From: Tianyi Chen @ 2026-09-23  2:32 UTC (permalink / raw)
  To: Mike Rapoport; +Cc: linux-mm, linux-kernel

Hi Mike,

> Does it mean BUILD=32 without NUMA does not pass with clang?

No. I reran v1 with Clang 18.1.3 and BUILD=32 without NUMA: all 189
checks pass. The previous cover letter only mentioned the NUMA-enabled
configuration tested then. Sorry for the ambiguity.

> I see a lot of warnings with gcc and BUILD=32. Do you mind fixing them
> as well?

Done in v2. I reproduced them with GCC 13.3.0 and removed the remaining
physical-address-to-pointer casts, used __pa() in tools virt_to_phys(),
and initialized end_rgn to address the maybe-uninitialized warning.
The latter is a false positive; each insertion already sets the index.

The virt_to_phys() cast also sign-extended 0x80000000 to
0xffffffff80000000 with GCC BUILD=32. A separate boundary check now
passes with both compilers in 32- and 64-bit builds.

GCC and Clang each pass seven configurations with -Werror and the default
ASan/UBSan flags, including BUILD=32 with and without NUMA. Details are
in the v2 cover letter, sent as a new thread:
https://lore.kernel.org/r/20260923023126.1910311-1-hi@tychen.cc

Thanks,
Tianyi

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-09-23  2:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 2/2] memblock tests: zero-extend simulated memory addresses Tianyi Chen
2026-09-22 10:10 ` [PATCH 0/2] memblock tests: fix BUILD=32 address conversions Mike Rapoport
2026-09-23  2:32   ` Tianyi Chen

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®