[PATCH v4 1/2] riscv: mm: make EXECMEM_KPROBES writable without CONFIG_STRICT_MODULE_RWX

From: Xiaofeng Yuan

Date: Sun Jul 19 2026 - 23:26:23 EST


When CONFIG_STRICT_MODULE_RWX is not set, execmem cannot create
temporary writable mappings for read-only executable pages. In this
case, the execmem ranges must already have writable permissions.

Currently EXECMEM_KPROBES unconditionally uses PAGE_KERNEL_READ_EXEC,
which causes kprobe instruction slot writes to trigger page faults
on systems where CONFIG_STRICT_MODULE_RWX is not enabled.

Fix this by using PAGE_KERNEL_EXEC when CONFIG_STRICT_MODULE_RWX
is not available.

Signed-off-by: Xiaofeng Yuan <xiaofengmian@xxxxxxx>
---
v2: use CONFIG_STRICT_MODULE_RWX instead of CONFIG_ARCH_HAS_EXECMEM_ROX (per Nam Cao's review)
v3: add commit description
v4: fix indent alignment (per Nam Cao's review)
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 5b1b3c88b4..7951d72a12 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -1457,7 +1457,9 @@ struct execmem_info __init *execmem_arch_setup(void)
[EXECMEM_KPROBES] = {
.start = VMALLOC_START,
.end = VMALLOC_END,
- .pgprot = PAGE_KERNEL_READ_EXEC,
+ .pgprot = IS_ENABLED(CONFIG_STRICT_MODULE_RWX) ?
+ PAGE_KERNEL_READ_EXEC :
+ PAGE_KERNEL_EXEC,
.alignment = 1,
},
[EXECMEM_BPF] = {
--
2.43.0