From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CBCC836EA89 for ; Tue, 10 Mar 2026 10:16:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773137789; cv=none; b=U7MgE0DNbu48J9z4x4OIRTAc08xkM4OsE0o5ZgcG4Zj/fsKPUDZkVmrowlLDyuOa0tQTye8K99OcA5JU8Lo2P0SW16TXvjiHsUagbkBISHGbTREolAR2MgYt7PmlhwHNHMkf8cK2UEULgHeYsGy2HoluS6BwjjAhdIF35PUoSFc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773137789; c=relaxed/simple; bh=UxcGXdDlPYAQeJJ+SPPyEPeVgjFOrndX+2mVDREjEq8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZmHmL0GP7El+gGHUi8Oi3LHjFb0iz4bro4Rsnm4zxxXaWCB9JcCp0nkhhKQVP9V86HAx+mh26sAJeLs97LgrCYd1H9c7k1Q/NSY2e+a5lqTycxfqvRwqj5SulHPQZ5R2u7kIPQE7m2Ru0YVI91P/2XIFUy9acTFpI/zb9+nOhL4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=u3cWzl8l; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="u3cWzl8l" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2309EC19423; Tue, 10 Mar 2026 10:16:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773137789; bh=UxcGXdDlPYAQeJJ+SPPyEPeVgjFOrndX+2mVDREjEq8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=u3cWzl8l6zZd2+YMQ/BWEZw4vD7jHUP9sP9tOZuE9iRHk9eSifXnZGOFrfwttp0E2 SBRBSBzDO/AVXfGxVjf4irrAIgn51ovnZz/rzu3g6QpkhuSvZoQc2rr4M/kzqu4Up/ 7CaKSeup4M/loo3PY+93EPhcAccXSlzZ0QcU2WVOdk3XN0lEvdMPnT9FKCwTb9JewB 7JMcNYL+Xt+ipXpHk39jCY/0TEyr+V+Z8zm5tDzhh4Il4C7y7ps0WNM1MTfUXOv7+l /TnY3hxrXcpeO9SAem7ezIBiyyGzPG8Xw1/Wd344DokS7j+5OSFoVW4I0U2W3QKYc/ g1BZXgW2BZuOQ== Date: Tue, 10 Mar 2026 12:16:22 +0200 From: Mike Rapoport To: Vivian Wang Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Andrew Morton , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Thomas =?iso-8859-1?Q?Wei=DFschuh?= Subject: Re: [PATCH] riscv: patch: Avoid early page_to_phys() Message-ID: References: <20260310-riscv-sparsemem-alternatives-fix-v1-1-659d5dd257e2@iscas.ac.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20260310-riscv-sparsemem-alternatives-fix-v1-1-659d5dd257e2@iscas.ac.cn> On Tue, Mar 10, 2026 at 04:25:33PM +0800, Vivian Wang wrote: > Similarly to commit 8d09e2d569f6 ("arm64: patching: avoid early > page_to_phys()"), avoid using phys_to_page() for the kernel address case > in patch_map(). > > Since this is called from apply_boot_alternatives() in setup_arch(), and > commit 4267739cabb8 ("arch, mm: consolidate initialization of SPARSE > memory model") has moved sparse_init() to after setup_arch(), > phys_to_page() is not available there yet, and it panics on boot with > SPARSEMEM on RV32, which does not use SPARSEMEM_VMEMMAP. > > Reported-by: Thomas Weißschuh > Closes: https://lore.kernel.org/r/20260223144108-dcace0b9-02e8-4b67-a7ce-f263bed36f26@linutronix.de/ > Fixes: 4267739cabb8 ("arch, mm: consolidate initialization of SPARSE memory model") > Suggested-by: Mike Rapoport Acked-by: Mike Rapoport (Microsoft) > Signed-off-by: Vivian Wang > --- > checkpatch.pl complains about the BUG_ON which was already there > --- > arch/riscv/kernel/patch.c | 21 +++++++++++---------- > 1 file changed, 11 insertions(+), 10 deletions(-) > > diff --git a/arch/riscv/kernel/patch.c b/arch/riscv/kernel/patch.c > index db13c9ddf9e3..16b243376f36 100644 > --- a/arch/riscv/kernel/patch.c > +++ b/arch/riscv/kernel/patch.c > @@ -42,19 +42,20 @@ static inline bool is_kernel_exittext(uintptr_t addr) > static __always_inline void *patch_map(void *addr, const unsigned int fixmap) > { > uintptr_t uintaddr = (uintptr_t) addr; > - struct page *page; > + phys_addr_t phys; > > - if (core_kernel_text(uintaddr) || is_kernel_exittext(uintaddr)) > - page = phys_to_page(__pa_symbol(addr)); > - else if (IS_ENABLED(CONFIG_STRICT_MODULE_RWX)) > - page = vmalloc_to_page(addr); > - else > + if (core_kernel_text(uintaddr) || is_kernel_exittext(uintaddr)) { > + phys = __pa_symbol(addr); > + } else if (IS_ENABLED(CONFIG_STRICT_MODULE_RWX)) { > + struct page *page = vmalloc_to_page(addr); > + > + BUG_ON(!page); > + phys = page_to_phys(page) + offset_in_page(addr); > + } else { > return addr; > + } > > - BUG_ON(!page); > - > - return (void *)set_fixmap_offset(fixmap, page_to_phys(page) + > - offset_in_page(addr)); > + return (void *)set_fixmap_offset(fixmap, phys); > } > > static void patch_unmap(int fixmap) > > --- > base-commit: 1f318b96cc84d7c2ab792fcc0bfd42a7ca890681 > change-id: 20260310-riscv-sparsemem-alternatives-fix-f9ea051b1694 > > Best regards, > -- > Vivian "dramforever" Wang > -- Sincerely yours, Mike.