[PATCH v4 2/2] riscv: patch: skip fixmap mapping when kernel text is already writable

Lad, Prabhakar prabhakar.csengg at gmail.com
Thu Aug 13 07:14:26 PDT 2026


Hi Xiaofeng,

Thank you for the patch.

On Mon, Jul 20, 2026 at 5:19 AM Xiaofeng Yuan <xiaofengmian at 163.com> wrote:
>
> 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 at 163.com>
> ---
> v2: add commit description
> v3: early return when !CONFIG_STRICT_MODULE_RWX (per Nam Cao's suggestion)
> diff --git a/arch/riscv/kernel/patch.c b/arch/riscv/kernel/patch.c
> index 16b243376f..caef41d5ef 100644
> --- a/arch/riscv/kernel/patch.c
> +++ b/arch/riscv/kernel/patch.c
> @@ -44,15 +44,16 @@ static __always_inline void *patch_map(void *addr, const unsigned int fixmap)
>         uintptr_t uintaddr = (uintptr_t) addr;
>         phys_addr_t phys;
>
> +       if (!IS_ENABLED(CONFIG_STRICT_MODULE_RWX))
> +               return addr;
> +
>         if (core_kernel_text(uintaddr) || is_kernel_exittext(uintaddr)) {
>                 phys = __pa_symbol(addr);
> -       } else if (IS_ENABLED(CONFIG_STRICT_MODULE_RWX)) {
> +       } else {
>                 struct page *page = vmalloc_to_page(addr);
>
>                 BUG_ON(!page);
>                 phys = page_to_phys(page) + offset_in_page(addr);
> -       } else {
> -               return addr;
>         }
>
With this patch applied and using renesas_defconfig I see below Oops
on SMARC RZ/Five.

[    0.012814] printk: legacy console [tty0] enabled
[    0.017634] Calibrating delay loop (skipped), value calculated
using timer frequency.. 24.00 BogoMIPS (lpj=48000)
[    0.027914] pid_max: default: 32768 minimum: 301
[    0.033876] Mount-cache hash table entries: 2048 (order: 2, 16384
bytes, linear)
[    0.041343] Mountpoint-cache hash table entries: 2048 (order: 2,
16384 bytes, linear)
[    0.049639] Unable to handle kernel paging request at virtual
address 0000006f89abce08
[    0.057617] Current swapper/0 pgtable: 4K pagesize, 39-bit VAs,
pgdp=0x00000000494f9000
[    0.065626] [0000006f89abce08] pgd=0000000000000000,
p4d=0000000000000000, pud=0000000000000000
[    0.074352] Oops [#1]
[    0.076635] CPU: 0 UID: 0 PID: 0 Comm: swapper/0 Not tainted
7.2.0-rc7-next-20260812 #21 PREEMPT
[    0.085494] Hardware name: Renesas SMARC EVK based on r9a07g043f01 (DT)
[    0.092096] epc : kmem_cache_alloc_lru_noprof+0x1a/0x1ba
[    0.097418]  ra : __d_alloc+0x42/0x188
[    0.101177] epc : ffffffff80162e20 ra : ffffffff8019874e sp :
ffffffff81203b30
[    0.108385]  gp : ffffffff812ec750 tp : ffffffff8120c780 t0 :
ffffffd60189db18
[    0.115593]  t1 : 0000000000000014 t2 : 0000000016e00403 s0 :
ffffffff81203b90
[    0.122809]  s1 : ffffffd601895800 a0 : 89abcdef89abcdef a1 :
ffffffd601895d10
[    0.130022]  a2 : 0000000000000cc0 a3 : 0000000000000002 a4 :
dead4ead00000001
[    0.137235]  a5 : 0000000000000000 a6 : 000000001de3521b a7 :
ffffffffac7f4a0c
[    0.144448]  s2 : 0000000000000000 s3 : ffffffd601895800 s4 :
0000000000000000
[    0.151660]  s5 : 0000000000000000 s6 : ffffffff812ed018 s7 :
00000000000003e8
[    0.158872]  s8 : 00000000000003e6 s9 : 0000000000000000 s10:
0000000077f29340
[    0.166084]  s11: 0000000000000000 t3 : ffffffffa0aed022 t4 :
0000000002018efb
[    0.173297]  t5 : 00000000101d5200 t6 : ffffffff81203b68 ssp :
0000000000000000
[    0.180596] status: 0000000200000120 badaddr: 0000006f89abce08
cause: 000000000000000d
[    0.188502] [<ffffffff80162e20>] kmem_cache_alloc_lru_noprof+0x1a/0x1ba
[    0.195116] [<ffffffff8019874e>] __d_alloc+0x42/0x188
[    0.200171] [<ffffffff801988fe>] d_alloc_anon+0xe/0x16
[    0.205314] [<ffffffff80198c90>] d_make_root+0x18/0x3a
[    0.210457] [<ffffffff8012792a>] shmem_fill_super+0x218/0x244
[    0.216210] [<ffffffff801865aa>] vfs_get_super+0x42/0x70
[    0.221525] [<ffffffff801865e8>] get_tree_nodev+0x10/0x18
[    0.226925] [<ffffffff80125e6a>] shmem_get_tree+0x14/0x1c
[    0.232327] [<ffffffff801845ba>] vfs_get_tree+0x1a/0xb0
[    0.237561] [<ffffffff801a1fa2>] fc_mount+0x10/0x32
[    0.242445] [<ffffffff801a2016>] vfs_kern_mount.part.0+0x34/0x5c
[    0.248451] [<ffffffff801a204c>] vfs_kern_mount+0xe/0x1a
[    0.253764] [<ffffffff801a206c>] kern_mount+0x14/0x26
[    0.258818] [<ffffffff8080f70a>] shmem_init+0xbe/0x150
[    0.263963] [<ffffffff8081973e>] mnt_init+0x128/0x314
[    0.269020] [<ffffffff80819316>] vfs_caches_init+0xa0/0xce
[    0.274507] [<ffffffff80800fa2>] start_kernel+0x754/0x7ac
[    0.279923] Code: 1080 e0ca ec86 fc4e f852 3783 5402 3423 fcf4 4781
(6783) 01c5
[    0.287344] ---[ end trace 0000000000000000 ]---
[    0.291986] Kernel panic - not syncing: Attempted to kill the idle task!


Reverting this patch fixed the issue.

Cheers,
Prabhakar


>         return (void *)set_fixmap_offset(fixmap, phys);
> --
> 2.43.0
>
>
> _______________________________________________
> linux-riscv mailing list
> linux-riscv at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv



More information about the linux-riscv mailing list