public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: Vivian Wang <wangruikang@iscas.ac.cn>
Cc: "Paul Walmsley" <pjw@kernel.org>,
	"Palmer Dabbelt" <palmer@dabbelt.com>,
	"Albert Ou" <aou@eecs.berkeley.edu>,
	"Alexandre Ghiti" <alex@ghiti.fr>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
	"Thomas Weißschuh" <thomas.weissschuh@linutronix.de>
Subject: Re: [PATCH] riscv: patch: Avoid early page_to_phys()
Date: Tue, 10 Mar 2026 12:16:22 +0200	[thread overview]
Message-ID: <aa_vds3WhAK1FHW5@kernel.org> (raw)
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 <thomas.weissschuh@linutronix.de>
> 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 <rppt@kernel.org>

Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

> Signed-off-by: Vivian Wang <wangruikang@iscas.ac.cn>
> ---
> 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.

  parent reply	other threads:[~2026-03-10 10:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-10  8:25 [PATCH] riscv: patch: Avoid early page_to_phys() Vivian Wang
2026-03-10  9:05 ` Thomas Weißschuh
2026-03-10 10:16 ` Mike Rapoport [this message]
2026-03-18 17:42 ` Paul Walmsley
2026-03-23  1:58   ` Vivian Wang
2026-03-23 16:34     ` Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aa_vds3WhAK1FHW5@kernel.org \
    --to=rppt@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    --cc=thomas.weissschuh@linutronix.de \
    --cc=wangruikang@iscas.ac.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox