Commit fc91dacd0c2b for kernel
commit fc91dacd0c2b4f9ca7e0ce30016f5aee6256cba5
Author: Marek Szyprowski <m.szyprowski@samsung.com>
Date: Wed Nov 4 11:46:03 2026 +0100
riscv: mm: reserve the DTB before scanning reserved memory
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>
Link: https://patch.msgid.link/20261104104604.3370384-1-m.szyprowski@samsung.com
Cc: stable@vger.kernel.org
Signed-off-by: Paul Walmsley <pjw@kernel.org>
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 070ee69eabb3..d73688402b50 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