* [PATCH] riscv: patch: Avoid early page_to_phys()
@ 2026-03-10 8:25 Vivian Wang
2026-03-10 9:05 ` Thomas Weißschuh
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Vivian Wang @ 2026-03-10 8:25 UTC (permalink / raw)
To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
Andrew Morton, Mike Rapoport (Microsoft)
Cc: linux-riscv, linux-kernel, Thomas Weißschuh, Vivian Wang
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>
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
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH] riscv: patch: Avoid early page_to_phys()
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
2026-03-18 17:42 ` Paul Walmsley
2 siblings, 0 replies; 6+ messages in thread
From: Thomas Weißschuh @ 2026-03-10 9:05 UTC (permalink / raw)
To: Vivian Wang
Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
Andrew Morton, Mike Rapoport (Microsoft), linux-riscv,
linux-kernel
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>
> Signed-off-by: Vivian Wang <wangruikang@iscas.ac.cn>
Thanks!
Tested-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
(...)
Thomas
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] riscv: patch: Avoid early page_to_phys()
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
2026-03-18 17:42 ` Paul Walmsley
2 siblings, 0 replies; 6+ messages in thread
From: Mike Rapoport @ 2026-03-10 10:16 UTC (permalink / raw)
To: Vivian Wang
Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
Andrew Morton, linux-riscv, linux-kernel, Thomas Weißschuh
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.
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] riscv: patch: Avoid early page_to_phys()
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
@ 2026-03-18 17:42 ` Paul Walmsley
2026-03-23 1:58 ` Vivian Wang
2 siblings, 1 reply; 6+ messages in thread
From: Paul Walmsley @ 2026-03-18 17:42 UTC (permalink / raw)
To: Vivian Wang
Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
Andrew Morton, Mike Rapoport (Microsoft), linux-riscv,
linux-kernel, Thomas Weißschuh
[-- Attachment #1: Type: text/plain, Size: 943 bytes --]
On Tue, 10 Mar 2026, 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>
> Signed-off-by: Vivian Wang <wangruikang@iscas.ac.cn>
Thanks, queued for v7.0-rc.
- Paul
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] riscv: patch: Avoid early page_to_phys()
2026-03-18 17:42 ` Paul Walmsley
@ 2026-03-23 1:58 ` Vivian Wang
2026-03-23 16:34 ` Andrew Morton
0 siblings, 1 reply; 6+ messages in thread
From: Vivian Wang @ 2026-03-23 1:58 UTC (permalink / raw)
To: Paul Walmsley, Andrew Morton
Cc: Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
Mike Rapoport (Microsoft), linux-riscv, linux-kernel,
Thomas Weißschuh
Hi Andrew and Paul,
On 3/19/26 01:42, Paul Walmsley wrote:
> On Tue, 10 Mar 2026, 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>
>> Signed-off-by: Vivian Wang <wangruikang@iscas.ac.cn>
> Thanks, queued for v7.0-rc.
I have only just noticed that this patch was commited to both
mm-hotfixes-stable [1] by Andrew and riscv fixes [2] by Paul. Is this
intended?
While we're at it, Paul's subject correction is correct - it should have
said phys_to_page(), not page_to_phys(). Not that I can blame this on
anyone else, but apparently I wrote it while looking at the arm64 commit
without noticing.
Thanks and sorry for the hopefully minor inconvenience.
Vivian "dramforever" Wang
[1]: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git/commit/?h=mm-hotfixes-stable&id=ac5f2c1256ede8b0acb2661f6441530d53d8f126
[2]: https://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux.git/commit/?h=fixes&id=3a876501fd9aaae9845026f046379c9507365bb5
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] riscv: patch: Avoid early page_to_phys()
2026-03-23 1:58 ` Vivian Wang
@ 2026-03-23 16:34 ` Andrew Morton
0 siblings, 0 replies; 6+ messages in thread
From: Andrew Morton @ 2026-03-23 16:34 UTC (permalink / raw)
To: Vivian Wang
Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
Mike Rapoport (Microsoft), linux-riscv, linux-kernel,
Thomas Weißschuh
On Mon, 23 Mar 2026 09:58:05 +0800 Vivian Wang <wangruikang@iscas.ac.cn> wrote:
> On 3/19/26 01:42, Paul Walmsley wrote:
> > On Tue, 10 Mar 2026, 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>
> >> Signed-off-by: Vivian Wang <wangruikang@iscas.ac.cn>
> > Thanks, queued for v7.0-rc.
>
> I have only just noticed that this patch was commited to both
> mm-hotfixes-stable [1] by Andrew and riscv fixes [2] by Paul. Is this
> intended?
It happens - better both than neither!
I'll drop the mm.git copy.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-03-23 16:34 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2026-03-18 17:42 ` Paul Walmsley
2026-03-23 1:58 ` Vivian Wang
2026-03-23 16:34 ` Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox