From: Brad Hawthorne <brad@sim.vu>
To: linux@armlinux.org.uk, linux-arm-kernel@lists.infradead.org
Cc: vladimir.murzin@arm.com, linux-kernel@vger.kernel.org
Subject: [PATCH 4/5] ARM: NOMMU: pmsa-v7: Align a split region's base to its size
Date: Tue, 24 Nov 2026 20:57:56 -0600 [thread overview]
Message-ID: <20261125025757.1159931-5-brad@sim.vu> (raw)
In-Reply-To: <20261125025757.1159931-1-brad@sim.vu>
try_split_region() masks the base with size - 1, which aligns it only
when size is a power of two, then rounds the region size up without
aligning the base again. An MPU region's base must be aligned to its
size. For memory at 0x21400000 + 0xa00000, the kernel asks for a 16MB
region at 0x21400000. QEMU ignores such a region. Hardware that
ignores the low bits would map 0x21000000-0x219fffff and leave
0x21a00000-0x21dfffff, which the kernel uses, unmapped.
Start from the size rounded down to a power of two, align the base to
it, and double it until the aligned region covers the request.
Tested under QEMU (mps2-an385) with that memory layout: QEMU no longer
reports a misaligned region, and the kernel boots to user space. Not
tested on PMSAv7 hardware.
This patch was written with an AI coding assistant (Claude Opus 5.5,
Anthropic): it found the bug in review, wrote the fix, the QEMU tests
and this changelog, and ran them; I reviewed the reasoning and the test
results.
Fixes: 5c9d9a1b3a54 ("ARM: 8712/1: NOMMU: Use more MPU regions to cover memory")
Cc: stable@vger.kernel.org
Signed-off-by: Brad Hawthorne <brad@sim.vu>
---
arch/arm/mm/pmsa-v7.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/arch/arm/mm/pmsa-v7.c b/arch/arm/mm/pmsa-v7.c
index af0c71135a6e..bd776ea90934 100644
--- a/arch/arm/mm/pmsa-v7.c
+++ b/arch/arm/mm/pmsa-v7.c
@@ -146,13 +146,19 @@ static inline unsigned long irbar_read(void) {return 0;}
static bool __init try_split_region(phys_addr_t base, phys_addr_t size, struct region *region)
{
unsigned long subreg, bslots, sslots;
- phys_addr_t abase = base & ~(size - 1);
- phys_addr_t asize = base + size - abase;
- phys_addr_t p2size = 1 << __fls(asize);
- phys_addr_t bdiff, sdiff;
-
- if (p2size != asize)
+ phys_addr_t p2size = 1 << __fls(size);
+ phys_addr_t abase, asize, bdiff, sdiff;
+
+ /* The base must be aligned to the region size */
+ for (;;) {
+ abase = base & ~(p2size - 1);
+ asize = base + size - abase;
+ if (asize <= p2size)
+ break;
p2size *= 2;
+ if (!p2size)
+ return false; /* would need a 4GB region */
+ }
bdiff = base - abase;
sdiff = p2size - asize;
--
2.43.0
next prev parent reply other threads:[~2026-11-25 2:58 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 2:57 [PATCH 0/5] ARM: NOMMU: fix PMSAv7/v8 MPU setup on M-class Brad Hawthorne
2026-11-25 2:57 ` [PATCH 1/5] ARM: NOMMU: pmsa-v7: Do not probe the region order " Brad Hawthorne
2026-11-25 2:57 ` [PATCH 2/5] ARM: NOMMU: pmsa-v7: Do not allocate more RAM regions than the limit Brad Hawthorne
2026-11-25 2:57 ` [PATCH 3/5] ARM: NOMMU: pmsa-v7: Fix off-by-one in mpu_setup_region() Brad Hawthorne
2026-11-25 2:57 ` Brad Hawthorne [this message]
2026-11-25 2:57 ` [PATCH 5/5] ARM: NOMMU: pmsa-v8: Fix off-by-one in __pmsav8_setup_region() Brad Hawthorne
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=20261125025757.1159931-5-brad@sim.vu \
--to=brad@sim.vu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=vladimir.murzin@arm.com \
/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®