* [PATCH] ARM: mmu: panic after pr_debug_remap if base address is unaligned
@ 2026-01-14 10:12 Ahmad Fatoum
0 siblings, 0 replies; only message 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] only message in thread
only message in thread, other threads:[~2026-01-14 10:13 UTC | newest]
Thread overview: (only message) (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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox