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=1796359590; b=LuLX4F2kbIqyaXgDeHcadugbTsstsUxV9opBUgfsw4rOg3Nhl2J5RmU6ajFWT29xVunl bGB1Ln6VTfZPM+j6LgraFKEc8+E0TYu+iTRcxbNI7nNstECwMIo398REaYJbOIx8zucaa cgL2tHVFUBYzTFQvhEkiB9EsAQ58N04mRP9XhcNQOdTCIgZuU2saMSMR8osHnDrNAp5fM OkWsz8L5PqEdrDu66TQkkGIgNHC+HWhUwlPQ8zOTvblDDGuimJZHLmdcudegfQMHykvej 4nt2jtF8IPP1cmx29/iiPQp2H7acmfgLQAxNNGMf9uLQn6S1vG+icn9wWcSBHMvzb9Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796359590; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=kNkQSwJy8xhbL9tHtXZKXZ77/rNmptwgBmy/sJ+MUYE=; b=hDFtYXYRJvaI96LcGscEpejr6/6R+KPqlkXsTk74oMcBc+QTADZEDkLChHdH49L2mZ07 VFuHjZyvkw19oIzblYgzT4ImQrITvqiyO4PmsnIi8aiL4EJq4bcqYC8KRbZHKpWYtgGFK O58ICp1Rmfv6WJaYPK/daGo9hYzJCcezQ3nptZt/EQd8PLVlHQ7vj2MZY5YUFpZHamycq 3CaMAskfE9aXdykyZtAw7CtCIE8Tq47ZAk5q6eOPYMSg4GqIFrCUL6vgizONVl4zs2SiX LHuP9s3s0ZcmGH8BTGLA+zu+313cuGZ6RpDjPaVImftb8phjjc0DU42uzgSb0xF0O8g== 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=Rk6kVNfF; 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 14275606A322 for ; Fri, 4 Dec 2026 04:46:29 +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=Rk6kVNfF Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1216F1F000CE; Fri, 4 Dec 2026 04:46:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796359589; bh=kNkQSwJy8xhbL9tHtXZKXZ77/rNmptwgBmy/sJ+MUYE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Rk6kVNfFzlnPuYqPim1IufgZTo4kyFLsOoj+8QNcs8+AEzC6Du5SVjPC0LMbnPBlN vOEa14D9n30q54jgDeT6Fgv7Y3KywizNGrJ4tDgdBvZDXQ2a+22YEouCiuKBFGHIl2 VFSKQfybx819v7MgVlHs2PcxOstQrKZ8pn5JGhhyo2iVuG8XkNAnB4EwUszxVrGTaW 450u4HZQwJ/k4qx6dBedL212RLHH4uYnZeeTX+vsRDXYKNFK8zRTLSE5WMcEbz9LnK vjomWOJxQllv9SZZSm2/U/4YTnf/R6RmiKLeQzgqdbqijqJMxrESKftMgx69jMgpfn NbIBlepFWp2uw== From: Sasha Levin To: stable@vger.kernel.org Cc: Marek Szyprowski , Paul Walmsley , Sasha Levin Subject: [PATCH 6.1.y] riscv: mm: reserve the DTB before scanning reserved memory Date: Thu, 3 Dec 2026 23:46:27 -0500 Message-ID: <20261204044613.2661166-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026120231-unelected-earache-f97e@gregkh> References: <2026120231-unelected-earache-f97e@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 follow the DTB memblock_reserve() and sit before dma_contiguous_reserve(), because the surrounding context in setup_bootmem() differs. ] 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 d6cfa7de010a0..92f04404932a7 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -251,13 +251,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 @@ -267,6 +260,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