Re: [PATCH v5 2/2] riscv: patch: skip fixmap mapping when kernel text is already writable
"Lad, Prabhakar" <[email protected]>
| Newsgroups | org.infradead.lists.linux-riscv,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <CA+V-a8ugp9d8LESGcY1ZrwGbuL084BECERFxc8FmXfvmYmYGFA@mail.gmail.com> |
On Fri, Aug 14, 2026 at 9:29 AM Xiaofeng Yuan <[email protected]> wrote: > > patch_map() always creates a temporary writable mapping via fixmap for > kernel text addresses, even when CONFIG_STRICT_KERNEL_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_KERNEL_RWX > is not enabled, since the text pages are already writable in that case. > The module text path is already gated on CONFIG_STRICT_MODULE_RWX and > is kept unchanged. > > Reported-by: Klara Modin <[email protected]> > Closes: https://lore.kernel.org/all/[email protected]/ > Reported-by: Lad Prabhakar <[email protected]> > Closes: https://lore.kernel.org/all/CA+V-a8tQK8rih9SGGTyqrEBGpNkx4H0eX2YccCRrgkVAPr+EBg@mail.gmail.com/ > --- > v5: fix the fixmap gating for kernel text. The v4 early return on > CONFIG_STRICT_MODULE_RWX wrongly skipped the fixmap for kernel text > too, which panics on configs with CONFIG_MODULES=n where > CONFIG_STRICT_MODULE_RWX is unavailable but CONFIG_STRICT_KERNEL_RWX > is still enabled and kernel text is read-only. > v3: early return when !CONFIG_STRICT_MODULE_RWX (per Nam Cao's suggestion) > v2: add commit description > > Signed-off-by: Xiaofeng Yuan <[email protected]> > --- > arch/riscv/kernel/patch.c | 2 ++ > 1 file changed, 2 insertions(+) > Tested-by: Lad Prabhakar <[email protected]> Cheers, Prabhakar > diff --git a/arch/riscv/kernel/patch.c b/arch/riscv/kernel/patch.c > index 16b243376f..2239c28981 100644 > --- a/arch/riscv/kernel/patch.c > +++ b/arch/riscv/kernel/patch.c > @@ -45,6 +45,8 @@ static __always_inline void *patch_map(void *addr, const unsigned int fixmap) > phys_addr_t phys; > > if (core_kernel_text(uintaddr) || is_kernel_exittext(uintaddr)) { > + if (!IS_ENABLED(CONFIG_STRICT_KERNEL_RWX)) > + return addr; > phys = __pa_symbol(addr); > } else if (IS_ENABLED(CONFIG_STRICT_MODULE_RWX)) { > struct page *page = vmalloc_to_page(addr); > -- > 2.43.0 > _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv