Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

riscv: patch: Avoid early phys_to_page()

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>
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>

authored by

Vivian Wang and committed by
Paul Walmsley
6b60a128 834911eb

+11 -10
+11 -10
arch/riscv/kernel/patch.c
··· 42 42 static __always_inline void *patch_map(void *addr, const unsigned int fixmap) 43 43 { 44 44 uintptr_t uintaddr = (uintptr_t) addr; 45 - struct page *page; 45 + phys_addr_t phys; 46 46 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 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); 51 + 52 + BUG_ON(!page); 53 + phys = page_to_phys(page) + offset_in_page(addr); 54 + } else { 52 55 return addr; 56 + } 53 57 54 - BUG_ON(!page); 55 - 56 - return (void *)set_fixmap_offset(fixmap, page_to_phys(page) + 57 - offset_in_page(addr)); 58 + return (void *)set_fixmap_offset(fixmap, phys); 58 59 } 59 60 60 61 static void patch_unmap(int fixmap)