mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] ARM: mmu: panic after pr_debug_remap if base address is unaligned
@ 2026-01-14 10:12 Ahmad Fatoum
  2026-01-16  8:18 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2026-01-14 10:12 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

It's always a bug to call remap_range with an unaligned address and it's
the responsibility of the callers (whether it's an ELF parser or code
walking reserved memory entries) to ensure that this doesn't happen.

We enforce this on ARM32, but don't yet on ARM64, so have it follow
suit and have both do the enforcement directly after pr_debug_remap():
That way, a developer enabling debug ouptut can easily see what was
last attempted before the BUG().

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/arm/cpu/mmu_32.c | 6 +++---
 arch/arm/cpu/mmu_64.c | 3 +++
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/arm/cpu/mmu_32.c b/arch/arm/cpu/mmu_32.c
index 912d14e8cf82..62e6e785f07c 100644
--- a/arch/arm/cpu/mmu_32.c
+++ b/arch/arm/cpu/mmu_32.c
@@ -350,14 +350,14 @@ static void __arch_remap_range(void *_virt_addr, phys_addr_t phys_addr, size_t s
 	u32 pte_flags, pmd_flags;
 	uint32_t *ttb = get_ttb();
 
-	BUG_ON(!IS_ALIGNED(virt_addr, PAGE_SIZE));
-	BUG_ON(!IS_ALIGNED(phys_addr, PAGE_SIZE));
-
 	pte_flags = get_pte_flags(map_type);
 	pmd_flags = pte_flags_to_pmd(pte_flags);
 
 	pr_debug_remap(virt_addr, phys_addr, size, map_type);
 
+	BUG_ON(!IS_ALIGNED(virt_addr, PAGE_SIZE));
+	BUG_ON(!IS_ALIGNED(phys_addr, PAGE_SIZE));
+
 	size = PAGE_ALIGN(size);
 	if (!size)
 		return;
diff --git a/arch/arm/cpu/mmu_64.c b/arch/arm/cpu/mmu_64.c
index 56c6a21f2b2a..8bbaf04e7fad 100644
--- a/arch/arm/cpu/mmu_64.c
+++ b/arch/arm/cpu/mmu_64.c
@@ -214,6 +214,9 @@ static int __arch_remap_range(uint64_t virt, uint64_t phys, uint64_t size,
 
 	pr_debug_remap(addr, phys, size, map_type);
 
+	BUG_ON(!IS_ALIGNED(virt, PAGE_SIZE));
+	BUG_ON(!IS_ALIGNED(phys, PAGE_SIZE));
+
 	attr &= ~PTE_TYPE_MASK;
 
 	size = PAGE_ALIGN(size);
-- 
2.47.3




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

* Re: [PATCH] ARM: mmu: panic after pr_debug_remap if base address is unaligned
  2026-01-14 10:12 [PATCH] ARM: mmu: panic after pr_debug_remap if base address is unaligned Ahmad Fatoum
@ 2026-01-16  8:18 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2026-01-16  8:18 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Wed, 14 Jan 2026 11:12:13 +0100, Ahmad Fatoum wrote:
> It's always a bug to call remap_range with an unaligned address and it's
> the responsibility of the callers (whether it's an ELF parser or code
> walking reserved memory entries) to ensure that this doesn't happen.
> 
> We enforce this on ARM32, but don't yet on ARM64, so have it follow
> suit and have both do the enforcement directly after pr_debug_remap():
> That way, a developer enabling debug ouptut can easily see what was
> last attempted before the BUG().
> 
> [...]

Applied, thanks!

[1/1] ARM: mmu: panic after pr_debug_remap if base address is unaligned
      https://git.pengutronix.de/cgit/barebox/commit/?id=b9fb6845b763 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




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

end of thread, other threads:[~2026-01-16  8:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-14 10:12 [PATCH] ARM: mmu: panic after pr_debug_remap if base address is unaligned Ahmad Fatoum
2026-01-16  8:18 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox