Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Marek Szyprowski <m.szyprowski@samsung.com>
To: Wandun Chen <chenwandun1@gmail.com>,
	robh@kernel.org, saravanak@kernel.org, rppt@kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org
Cc: akpm@linux-foundation.org
Subject: Re: [PATCH v2 2/5] of: reserved_mem: reject static regions overlapping no-map memory
Date: Wed, 26 Aug 2026 15:16:20 +0200	[thread overview]
Message-ID: <aa0fc15c-eb46-4abc-9260-7aaa8a39c040@samsung.com> (raw)
In-Reply-To: <20260818092420.2859026-3-chenwandun1@gmail.com>

On 18.08.2026 11:24, Wandun Chen wrote:
> From: Wandun Chen <chenwandun@lixiang.com>
>
> Static no-map reserved-memory regions are marked in memblock.memory rather
> than memblock.reserved. So the reservation overlap check does not reject
> a static region that overlaps existing no-map memory.
>
> Both regions can then be initialized and hand the same physical memory to
> different reserved-memory drivers. So reject a static region that overlaps
> existing no-map memory.
>
> Sashiko found this issue in [1].
>
> Fixes: 86588296acbf ("fdt: Properly handle "no-map" field in the memory region")
> Signed-off-by: Wandun Chen <chenwandun@lixiang.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
> Link: https://protect2.fireeye.com/v1/url?k=c110879a-a8abef28-c1110cd5-905a08a8515a-5165b48469b02786&q=1&e=6166144c-5cef-48c6-9f6f-b36a72f258ac&u=https%3A%2F%2Fsashiko.dev%2F%23%2Fmessage%2F20260814084718.29C341F000E9%2540smtp.kernel.org [1]
> ---
>  drivers/of/of_reserved_mem.c |  3 ++-
>  include/linux/memblock.h     |  1 +
>  mm/memblock.c                | 14 ++++++++++++++
>  3 files changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
> index c6e73d710ee1..9fb2e4c29443 100644
> --- a/drivers/of/of_reserved_mem.c
> +++ b/drivers/of/of_reserved_mem.c
> @@ -152,7 +152,8 @@ static int __init early_init_dt_reserve_memory(phys_addr_t base,
>  		 * if the region isn't memory as it won't be mapped.
>  		 */
>  		if (memblock_overlaps_region(&memblock.memory, base, size) &&
> -		    memblock_is_region_reserved(base, size))
> +		    (memblock_is_region_reserved(base, size) ||
> +		     memblock_overlaps_nomap(base, size)))
>  			return -EBUSY;
>  
>  		return memblock_mark_nomap(base, size);
> diff --git a/include/linux/memblock.h b/include/linux/memblock.h
> index d62db9e776cf..27d68fbb3157 100644
> --- a/include/linux/memblock.h
> +++ b/include/linux/memblock.h
> @@ -148,6 +148,7 @@ int memblock_physmem_add(phys_addr_t base, phys_addr_t size);
>  void memblock_trim_memory(phys_addr_t align);
>  unsigned long memblock_addrs_overlap(phys_addr_t base1, phys_addr_t size1,
>  				     phys_addr_t base2, phys_addr_t size2);
> +bool memblock_overlaps_nomap(phys_addr_t base, phys_addr_t size);
>  bool memblock_overlaps_region(struct memblock_type *type,
>  			      phys_addr_t base, phys_addr_t size);
>  bool memblock_validate_numa_coverage(unsigned long threshold_bytes);
> diff --git a/mm/memblock.c b/mm/memblock.c
> index 9ce86349a29f..4cabfe365ac4 100644
> --- a/mm/memblock.c
> +++ b/mm/memblock.c
> @@ -202,6 +202,20 @@ memblock_addrs_overlap(phys_addr_t base1, phys_addr_t size1, phys_addr_t base2,
>  	return ((base1 < (base2 + size2)) && (base2 < (base1 + size1)));
>  }
>  
> +bool __init memblock_overlaps_nomap(phys_addr_t base, phys_addr_t size)
> +{
> +	struct memblock_region *region;
> +
> +	memblock_cap_size(base, &size);
> +	for_each_mem_region(region) {
> +		if (memblock_is_nomap(region) &&
> +		    memblock_addrs_overlap(base, size, region->base, region->size))
> +			return true;
> +	}
> +
> +	return false;
> +}
> +
>  bool __init_memblock memblock_overlaps_region(struct memblock_type *type,
>  					phys_addr_t base, phys_addr_t size)
>  {

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland



  reply	other threads:[~2026-08-26 13:16 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-18  9:24 [PATCH v2 0/5] of: reserved_mem: several fixes about reserved memory Wandun Chen
2026-08-18  9:24 ` [PATCH v2 1/5] of: reserved_mem: skip init for regions whose early reservation failed Wandun Chen
2026-08-26 13:14   ` Marek Szyprowski
2026-08-18  9:24 ` [PATCH v2 2/5] of: reserved_mem: reject static regions overlapping no-map memory Wandun Chen
2026-08-26 13:16   ` Marek Szyprowski [this message]
2026-08-18  9:24 ` [PATCH v2 3/5] of: reserved_mem: reject statically placed regions overlapping existing reservations Wandun Chen
2026-08-26 13:16   ` Marek Szyprowski
2026-08-18  9:24 ` [PATCH v2 4/5] of: reserved_mem: release dynamically allocated no-map region on init failure Wandun Chen
2026-08-26 13:17   ` Marek Szyprowski
2026-08-18  9:24 ` [PATCH v2 5/5] of: reserved_mem: retain static no-map memory " Wandun Chen
2026-08-26 13:18   ` Marek Szyprowski

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=aa0fc15c-eb46-4abc-9260-7aaa8a39c040@samsung.com \
    --to=m.szyprowski@samsung.com \
    --cc=akpm@linux-foundation.org \
    --cc=chenwandun1@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=robh@kernel.org \
    --cc=rppt@kernel.org \
    --cc=saravanak@kernel.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