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=1796358897; b=F8QxS3YA2VIYTrM573QkqkbezDszQRZN2cTgT/y1hstf78psExEKW2+JVjD8s0Yl1LZW RioK3fQKQjyZ8c2rgtj6L6y73RYrwhtqs0RMTu2T/OYRfL8S8gRq22X5VPeXL6/aqZVas AEHfoYLzm6Hsl3oxS4qgugEEYbRi5unJI3YXOLwPmDXU1QrX8qeCOJHdMJcydqSeTIDHK yMBxoLQdrCEUCwlv1aH9u4vTawThj3edGIqDYOFNyUOFd1730iHxi/r67IzAwaLXjvRAS E5w4Uxk840N9adgFy/1RAp/oo9LmcUhx3FeNe0npdTlgaBHLcjZ2m4FojVcdwmF/08w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796358897; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=qSSie5BzRUTy5VyY3XB2doErnY5nuStknUhE8bI0kmw=; b=QAEZUdc0bm8rMYa/lmWgdDldkfgHbum+intxemxdYd60u2G+Mz8SCxho7pcCPR5QTHne W2ARyLDgUu/4qwlnJ3L/w0/3ZK/Q4YvoIO0SCPjT5AmHU5p+DjAkHA3eiYpa5hmCRHCkE Ex8M/2IxbJ5enrj4LBKGnrpXQ3vlyRAbD/Of5Tm9BawusmlZf1AwRUypez372zSznbp5W 8zXVvNk+eYBKEfHwlFwdr7aQ4XZAPTBKql47xRX8LOhGjWCLwFpCBqkWQYl9admdWt/BK mAO88DPEZq/de+CRNrsnjGG60+H4icpYqVcKuvVbmIK4wZOgDSSexkf6b0P5bXYgpGA== 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=KgGIRGeX; 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 509A0606A322 for ; Fri, 4 Dec 2026 04:34:57 +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=KgGIRGeX Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3815B1F000C2; Fri, 4 Dec 2026 04:34:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796358896; bh=qSSie5BzRUTy5VyY3XB2doErnY5nuStknUhE8bI0kmw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=KgGIRGeXtnTLL7FgCj2oxUYPFDFLYRePntNq/lrhwriz62onfTSfyxndguc7Bpfjy 7qvUPVaiNCFcyVCUTlOyilien0cYyCRhGw1DdmQuUN43XUD/iTGwZCED0GqqrKzSxe Q8lUV18dpEqGoaSTzzZqTzSSeL182GjxjmAbeLHCi4uVpCCKT7/6pVRynQHluSoqEj GSUlxOrK8i+iQBytVPS6ZZn5FQ3/am3bJKp/OSM85bIAHWyMZryj1jda+N+3qD164W X31dw+K0QEj+oOrn1YPF3m/Z8J0APplVzD6vZKfVWh7E5Z/wub1OAdDktTt5f0o0Lo Nz+w5yrStgTww== From: Sasha Levin To: stable@vger.kernel.org Cc: Marek Szyprowski , Paul Walmsley , Sasha Levin Subject: [PATCH 6.18.y] riscv: mm: reserve the DTB before scanning reserved memory Date: Thu, 3 Dec 2026 23:34:54 -0500 Message-ID: <20261204043447.2630525-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026120230-phonics-sandy-b5fb@gregkh> References: <2026120230-phonics-sandy-b5fb@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: 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 --- 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