From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Marek Szyprowski <m.szyprowski@samsung.com>,
Paul Walmsley <pjw@kernel.org>, Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.18.y] riscv: mm: reserve the DTB before scanning reserved memory
Date: Thu, 3 Dec 2026 23:34:54 -0500 [thread overview]
Message-ID: <20261204043447.2630525-1-sashal@kernel.org> (raw)
In-Reply-To: <2026120230-phonics-sandy-b5fb@gregkh>
From: Marek Szyprowski <m.szyprowski@samsung.com>
[ Upstream commit fc91dacd0c2b4f9ca7e0ce30016f5aee6256cba5 ]
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>
[ sashal: Moved the early_init_fdt_scan_reserved_mem() call to just after the DTB memblock_reserve(), placing it before the extra dma_contiguous_reserve()/hugetlb_cma_reserve() lines that this tree has after the DTB reserve. ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
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 557bf160b503a..4418e4d3ff14e 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -298,13 +298,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
@@ -314,6 +307,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();
+
dma_contiguous_reserve(dma32_phys_limit);
if (IS_ENABLED(CONFIG_64BIT))
hugetlb_cma_reserve(PUD_SHIFT - PAGE_SHIFT);
--
2.53.0
prev parent reply other threads:[~2026-12-04 4:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 13:41 FAILED: patch "[PATCH] riscv: mm: reserve the DTB before scanning reserved memory" failed to apply to 6.18-stable tree gregkh
2026-12-04 4:34 ` Sasha Levin [this message]
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=20261204043447.2630525-1-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=pjw@kernel.org \
--cc=stable@vger.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