mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vladimir Murzin <vladimir.murzin@arm.com>
To: Brad Hawthorne <brad@sim.vu>,
	linux@armlinux.org.uk, linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/5] ARM: NOMMU: pmsa-v7: Do not allocate more RAM regions than the limit
Date: Wed, 25 Nov 2026 13:16:46 +0000	[thread overview]
Message-ID: <b0502bb9-4840-4099-ba97-822a4913ca3a@arm.com> (raw)
In-Reply-To: <20261125025757.1159931-3-brad@sim.vu>

On 11/25/26 02:57, Brad Hawthorne wrote:
> deviation from their usual behavior, this may indicate that their account has been compromised. Be extra cautious before opening links or attachments. *
> allocate_region() checks "count > limit" only after it has filled
> regions[count], so it can return one region more than the limit. The
> caller passes the number of MPU regions left for RAM, so the setup
> then programs a region the MPU does not have. Under QEMU (mps2-an385,
> 8 regions) with a memory node of 0x21000000 + 0x9f9000, which needs
> more regions than are left, QEMU logs "MPU region out of range 8/8"
> and the kernel reports:
> 
>   Using ARMv7 PMSA Compliant MPU. Region independence: No, Used 9 of 8 regions
> 
> Stop allocating once the limit is reached, so the memory that does not
> fit is truncated, as intended.
> 
> Tested under QEMU (mps2-an385): the same case now truncates memory and
> 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 | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/arch/arm/mm/pmsa-v7.c b/arch/arm/mm/pmsa-v7.c
> index a20a43867210..f2ad0f3ff480 100644
> --- a/arch/arm/mm/pmsa-v7.c
> +++ b/arch/arm/mm/pmsa-v7.c
> @@ -193,7 +193,7 @@ static int __init allocate_region(phys_addr_t base, phys_addr_t size,
>  	phys_addr_t diff = size;
>  	int attempts = MPU_MAX_REGIONS;
>  
> -	while (diff) {
> +	while (diff && count < limit) {
>  		/* Try cover region as is (maybe with help of subregions) */
>  		if (try_split_region(base, size, &regions[count])) {
>  			count++;
> @@ -215,9 +215,6 @@ static int __init allocate_region(phys_addr_t base, phys_addr_t size,
>  			size = asize < p2size ? asize + 1 : p2size + 1;
>  		}
>  
> -		if (count > limit)
> -			break;
> -
>  		if (!attempts)
>  			break;
>  
> -- 2.43.0

Reviewed-by: Vladimir Murzin <vladimir.murzin@arm.com>


  reply	other threads:[~2026-11-25 13:16 UTC|newest]

Thread overview: 11+ 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 13:12   ` Vladimir Murzin
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 13:16   ` Vladimir Murzin [this message]
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 13:18   ` Vladimir Murzin
2026-11-25  2:57 ` [PATCH 4/5] ARM: NOMMU: pmsa-v7: Align a split region's base to its size Brad Hawthorne
2026-11-25  2:57 ` [PATCH 5/5] ARM: NOMMU: pmsa-v8: Fix off-by-one in __pmsav8_setup_region() Brad Hawthorne
2026-11-25 13:20   ` Vladimir Murzin
2026-11-25  7:46 ` [PATCH 0/5] ARM: NOMMU: fix PMSAv7/v8 MPU setup on M-class Arnd Bergmann

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=b0502bb9-4840-4099-ba97-822a4913ca3a@arm.com \
    --to=vladimir.murzin@arm.com \
    --cc=brad@sim.vu \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    /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®