mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] ARM: mmu: panic after pr_debug_remap if base address is unaligned
Date: Wed, 14 Jan 2026 11:12:13 +0100	[thread overview]
Message-ID: <20260114101214.109449-1-a.fatoum@pengutronix.de> (raw)

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




                 reply	other threads:[~2026-01-14 10:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260114101214.109449-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.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