From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796359385; b=hXFhlUPJT/lJqetaA+9iMSoFaQ9rbMo7WBnHaguAPdhQDLZJHxQsD9BzIcUp2TqQJy0U U+NAjAjURBA4Fc36N+0/hCSZ3TL5BaGhmQV6VXB4DZCBeHHiWxXgPNDOuzntbrbBxElNs /5216PTZ6P37eq9by1VnYa6vdiHZwUWfZ54Pdl2jBs9tq/zwvZwagn3J/Eklxvx5WcQ+O Dipi3k4K7fnfEpMLzoi6xwqk2HSY5s46MR6myEJyDiwvGyuS3H/aWnZxaRWjlaChQEJYi H6BeaPgJ8LJOVrKRJMYIERDfhqH2i4SOUhcMYEFrAnLDbxJ/NRllqepurAf1vFEC4bw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796359385; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=Zeeyjxy1LLUBVCu52CxeRT5JHXNjGXRFvcK869ZVRok=; b=hNEeelTkyOhKC9eT9Mz5J3Sqkvx/cePRzRHrCtdbDoRzh881DH+1K/PTQWFcbSBF6QIh VbKy7xAk0zt5maT5dyfexT5sv+CoRL2Jo99jjchCABWCnm9BqAgKhGYRO0DGocAWzo3YW PkukIVG3z+iMSNorPasL+dfuJd7VoWo0FtjvZTiTzNtojUPRK+7xKh9HLSbozhrmzN/ch 3Iuf5ZSrDRxWqG/43vzMUVQIm8nAzbk+JXuIA6s+lsw5ImkzevA0uBKgijHhTexalzhWH C8VldSL/RjG8Lt8yxr7Tw1SLLeu8HYDoX4YfPJ7bDPp7qhFWLXlfrMBiLXCdXe8+z4A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=n5EF72NA; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B121F606A322 for ; Fri, 4 Dec 2026 04:43:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=n5EF72NA Received: by smtp.kernel.org (Postfix) with ESMTPSA id B761E1F000CE; Fri, 4 Dec 2026 04:43:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796359385; bh=Zeeyjxy1LLUBVCu52CxeRT5JHXNjGXRFvcK869ZVRok=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=n5EF72NAmwTWSdZjvzjo0DQ7lIFuiiWr2J/PcPrbi8+SOLL8Rdhb0li7l++5SjMLp BIomtUJ9bWdB1ZO7eoEXMyxfbUVzGDD36VR/rd94N+An+/JOyqczSxNTWagVMij/vv SkL2JADSuP6wUKKisAjiLFjDL9B7GOyc5PrUF1BUp6WXenoztbXGF4LOieo4PeLwZv 0ijTYlnISWOLFq+7c7LyVzwDlzr8BUPnoyC8j029IdL7slTdX3wvsKdNmkPNDlzU27 rD5q0eNWboTAap3vKUTH64I9cjTT+PDTL5OtU5U8t3tnehVCPWes6JS0pwkgk+O3lI lIam1J+DHGA8A== From: Sasha Levin To: stable@vger.kernel.org Cc: Marek Szyprowski , Paul Walmsley , Sasha Levin Subject: [PATCH 6.6.y] riscv: mm: reserve the DTB before scanning reserved memory Date: Thu, 3 Dec 2026 23:43:03 -0500 Message-ID: <20261204044252.2650959-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026120231-unchain-virus-1036@gregkh> References: <2026120231-unchain-virus-1036@gregkh> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Marek Szyprowski [ 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 Link: https://patch.msgid.link/20261104104604.3370384-1-m.szyprowski@samsung.com Cc: stable@vger.kernel.org Signed-off-by: Paul Walmsley [ sashal: adjusted context: the early_init_fdt_scan_reserved_mem() call is placed after the DTB memblock_reserve, directly before dma_contiguous_reserve(), since the backport lacks the upstream trailing context. ] Signed-off-by: Sasha Levin --- 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 70d06dfa2a868..64750fb2f091d 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -281,13 +281,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 @@ -297,6 +290,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