Devicetree
 help / color / mirror / Atom feed
* [PATCH] riscv: mm: reserve the DTB before scanning reserved memory
       [not found] <CGME20261104104615eucas1p2583cd5bc9ae36bd9ff2d28f87d6e7583@eucas1p2.samsung.com>
@ 2026-11-04 10:46 ` Marek Szyprowski
  2026-11-18  3:35   ` Paul Walmsley
  0 siblings, 1 reply; 2+ messages in thread
From: Marek Szyprowski @ 2026-11-04 10:46 UTC (permalink / raw)
  To: linux-riscv, devicetree, linux-mm
  Cc: Marek Szyprowski, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Alexandre Ghiti, Conor Dooley, Geert Uytterhoeven, Rob Herring,
	Mike Rapoport, Saravana Kannan, Andrew Morton

early_init_fdt_scan_reserved_mem() allocates memory from memblock while
it scans /reserved-memory: the reserved_mem array, and the regions that
are placed dynamically by size. On RISC-V the DTB was only reserved
after that scan, so memblock could hand out the memory the DTB occupies
while the DTB was still being parsed.

Reserve the DTB before the scan, so that memblock never allocates from
it.

Fixes: ef69d2559fe9 ("riscv: Move early dtb mapping into the fixmap region")
Closes: https://lore.kernel.org/all/b71ac175-fba5-4f61-bbdb-0b98dec9ccee@samsung.com/
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
---
 arch/riscv/mm/init.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index e822fce0af4b..bbc2d8cb4627 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -294,13 +294,6 @@ static void __init setup_bootmem(void)
 
 	reserve_initrd_mem();
 
-	/*
-	 * No allocation should be done before reserving the memory as defined
-	 * in the device tree, otherwise the allocation could end up in a
-	 * reserved region.
-	 */
-	early_init_fdt_scan_reserved_mem();
-
 	/*
 	 * If DTB is built in, no need to reserve its memblock.
 	 * Otherwise, do reserve it but avoid using
@@ -309,6 +302,13 @@ static void __init setup_bootmem(void)
 	 */
 	if (!IS_ENABLED(CONFIG_BUILTIN_DTB))
 		memblock_reserve(dtb_early_pa, fdt_totalsize(dtb_early_va));
+
+	/*
+	 * No allocation should be done before reserving the memory as defined
+	 * in the device tree, otherwise the allocation could end up in a
+	 * reserved region.
+	 */
+	early_init_fdt_scan_reserved_mem();
 }
 
 #ifdef CONFIG_RELOCATABLE
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] riscv: mm: reserve the DTB before scanning reserved memory
  2026-11-04 10:46 ` [PATCH] riscv: mm: reserve the DTB before scanning reserved memory Marek Szyprowski
@ 2026-11-18  3:35   ` Paul Walmsley
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Walmsley @ 2026-11-18  3:35 UTC (permalink / raw)
  To: Marek Szyprowski
  Cc: linux-riscv, devicetree, linux-mm, Paul Walmsley, Palmer Dabbelt,
	Albert Ou, Alexandre Ghiti, Conor Dooley, Geert Uytterhoeven,
	Rob Herring, Mike Rapoport, Saravana Kannan, Andrew Morton

On Wed, 4 Nov 2026, Marek Szyprowski wrote:

> early_init_fdt_scan_reserved_mem() allocates memory from memblock while
> it scans /reserved-memory: the reserved_mem array, and the regions that
> are placed dynamically by size. On RISC-V the DTB was only reserved
> after that scan, so memblock could hand out the memory the DTB occupies
> while the DTB was still being parsed.
> 
> Reserve the DTB before the scan, so that memblock never allocates from
> it.
> 
> Fixes: ef69d2559fe9 ("riscv: Move early dtb mapping into the fixmap region")
> Closes: https://lore.kernel.org/all/b71ac175-fba5-4f61-bbdb-0b98dec9ccee@samsung.com/
> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>

Thanks, queued for v7.4-rc with a stable@ cc.


- Paul

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-18  3:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CGME20261104104615eucas1p2583cd5bc9ae36bd9ff2d28f87d6e7583@eucas1p2.samsung.com>
2026-11-04 10:46 ` [PATCH] riscv: mm: reserve the DTB before scanning reserved memory Marek Szyprowski
2026-11-18  3:35   ` Paul Walmsley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox