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=1796359172; b=f613zFWO7OxQtns1k0WptiW+xAQN2QxZhL0Mva8avHZZQFARcmPqx2dt2Caj6nrdWepA y/gelnnOXm3IHhKw0mgEuW5xxltmSnjLQNJxlQyi7YSENBdWjRZMS0Cm+LUmEgm2sBuq6 qsGTWU1MOsZgRJN25Nn7QuhKHpa5MPYmedMrOU85DXB0wSbP74IgyLQ3UwfOXiESffr7t +SrvPxaZYYI+y/EW6AN8gXhS126vdwBc9dE6ad6OQSryh/ZPVkmlOBXqdMHzq+iYWdixK GbkOLvkTwopOqmfgrvqjOU59zy3PG1zZEOJFkhAcCiL8numejCAYeYwSWUvmK/34YRQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796359172; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=6QvX8UzMdSL4QbYi/gKMRJvS16eYPWwdbYC71n0SMvE=; b=Oah7pnugnGY6QTN0U7Jv7kF5MP3UvOYbst60ww6GYzY2tTvgPw1UCMqoD+fB3TPRysMo dXxXAhsAKfag2ysP2aVx+tDmX7neJG3IrxjT5/lgCGjfvvuUFqJC2s9ApQUKqJMrfG2wj TB3SHDPrBL1GtaNaMrurA6sJwgHMOfaH4I19jsx7HlVfH/W57+QIWbiASmc+aBJiVMjGH hlYmloleoKMDL27WCzDWIgOCHE1+3zj7mYgz5cG88yW9el0gGVjqML7SKeqe6z5UHjou8 FiQ/TpSV8lMsehsk07B+kmR5QX8CytiKtKZZFppFy8TaG8SqRj5d0W4jF74o7F41tHw== 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=jrT4nC+D; 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 5BECF606A682 for ; Fri, 4 Dec 2026 04:39:32 +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=jrT4nC+D Received: by smtp.kernel.org (Postfix) with ESMTPSA id 515451F000C2; Fri, 4 Dec 2026 04:39:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796359171; bh=6QvX8UzMdSL4QbYi/gKMRJvS16eYPWwdbYC71n0SMvE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jrT4nC+DrEgdQ4JCJQ4xX9qlN6dgf3vwxd8bk1J1j4AiHdMKWlmUGS1R19GUON+23 7gJUE3UTtUoPOwyAhpKRVcfEMitf2qsppVwlGceB365M1hY50BBeUQGqEz9S0Le8s+ Nlimd3woQTMfes3LOAwYaTOHQ04OGTsfXHuNNPyiAJ72/Zg8obm+TNx5wuDPIGQHu/ PLrkSKRUVrenAT2OwPC8lD4IO8ifRKXXzI+fH4XlOLwyZXtzcK3tSHc7D5HyLHQr1z URnwNSrokqK8Jjn2Ihf+FL8J07/nMb7sMKC72JC8SAmz/Jj9JwYOHrUvWX4/rLSg1Q dr+eanPjXrSzw== From: Sasha Levin To: stable@vger.kernel.org Cc: Marek Szyprowski , Paul Walmsley , Sasha Levin Subject: [PATCH 6.12.y] riscv: mm: reserve the DTB before scanning reserved memory Date: Thu, 3 Dec 2026 23:39:30 -0500 Message-ID: <20261204043903.2642319-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026120230-stroller-atypical-3eb0@gregkh> References: <2026120230-stroller-atypical-3eb0@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 in setup_bootmem(): the call is placed after the DTB memblock_reserve and before dma_contiguous_reserve(), since the surrounding code differs here. ] 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 e52f7dabb370c..b19df2a592c9e 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