Skip to content

Commit 6b60a12

Browse files
dramforeverPaul Walmsley
authored andcommitted
riscv: patch: Avoid early phys_to_page()
Similarly to commit 8d09e2d ("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 4267739 ("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: 4267739 ("arch, mm: consolidate initialization of SPARSE memory model") Suggested-by: Mike Rapoport <rppt@kernel.org> Signed-off-by: Vivian Wang <wangruikang@iscas.ac.cn> Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Tested-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de> Link: https://patch.msgid.link/20260310-riscv-sparsemem-alternatives-fix-v1-1-659d5dd257e2@iscas.ac.cn [pjw@kernel.org: fix the subject line to align with the patch description] Signed-off-by: Paul Walmsley <pjw@kernel.org>
1 parent 834911e commit 6b60a12

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

arch/riscv/kernel/patch.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,20 @@ static inline bool is_kernel_exittext(uintptr_t addr)
4242
static __always_inline void *patch_map(void *addr, const unsigned int fixmap)
4343
{
4444
uintptr_t uintaddr = (uintptr_t) addr;
45-
struct page *page;
45+
phys_addr_t phys;
4646

47-
if (core_kernel_text(uintaddr) || is_kernel_exittext(uintaddr))
48-
page = phys_to_page(__pa_symbol(addr));
49-
else if (IS_ENABLED(CONFIG_STRICT_MODULE_RWX))
50-
page = vmalloc_to_page(addr);
51-
else
52-
return addr;
47+
if (core_kernel_text(uintaddr) || is_kernel_exittext(uintaddr)) {
48+
phys = __pa_symbol(addr);
49+
} else if (IS_ENABLED(CONFIG_STRICT_MODULE_RWX)) {
50+
struct page *page = vmalloc_to_page(addr);
5351

54-
BUG_ON(!page);
52+
BUG_ON(!page);
53+
phys = page_to_phys(page) + offset_in_page(addr);
54+
} else {
55+
return addr;
56+
}
5557

56-
return (void *)set_fixmap_offset(fixmap, page_to_phys(page) +
57-
offset_in_page(addr));
58+
return (void *)set_fixmap_offset(fixmap, phys);
5859
}
5960

6061
static void patch_unmap(int fixmap)

0 commit comments

Comments
 (0)