Skip to content

Commit 12bb40b

Browse files
ThreeBottleCapLinux RISC-V bot
authored andcommitted
riscv: patch: skip fixmap mapping when kernel text is already writable
Currently patch_map() always creates a temporary writable mapping via fixmap for kernel text addresses, even when CONFIG_STRICT_MODULE_RWX is disabled and the kernel text is already mapped with _PAGE_WRITE. This is unnecessary overhead at best, and on minimal configurations it can cause page faults. Skip the fixmap path for kernel text when CONFIG_STRICT_MODULE_RWX is not enabled, since the text pages are already writable in this case. Signed-off-by: Xiaofeng Yuan <xiaofengmian@163.com> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
1 parent 6832114 commit 12bb40b

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

arch/riscv/kernel/patch.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,16 @@ static __always_inline void *patch_map(void *addr, const unsigned int fixmap)
4444
uintptr_t uintaddr = (uintptr_t) addr;
4545
phys_addr_t phys;
4646

47+
if (!IS_ENABLED(CONFIG_STRICT_MODULE_RWX))
48+
return addr;
49+
4750
if (core_kernel_text(uintaddr) || is_kernel_exittext(uintaddr)) {
4851
phys = __pa_symbol(addr);
49-
} else if (IS_ENABLED(CONFIG_STRICT_MODULE_RWX)) {
52+
} else {
5053
struct page *page = vmalloc_to_page(addr);
5154

5255
BUG_ON(!page);
5356
phys = page_to_phys(page) + offset_in_page(addr);
54-
} else {
55-
return addr;
5657
}
5758

5859
return (void *)set_fixmap_offset(fixmap, phys);

0 commit comments

Comments
 (0)