The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Klara Modin <klarasmodin@gmail.com>
To: Xiaofeng Yuan <xiaofengmian@163.com>
Cc: Paul Walmsley <pjw@kernel.org>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	 Albert Ou <aou@eecs.berkeley.edu>,
	Alexandre Ghiti <alex@ghiti.fr>, Nam Cao <namcao@linutronix.de>,
	 Klara Modin <klara@kasm.eu>,
	prabhakar.csengg@gmail.com, linux-riscv@lists.infradead.org,
	 linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 2/2] riscv: patch: skip fixmap mapping when kernel text is already writable
Date: Fri, 14 Aug 2026 14:04:53 +0200	[thread overview]
Message-ID: <an8ECsGLdzDgRafU@soda.int.kasm.eu> (raw)
In-Reply-To: <20260814082742.148403-3-xiaofengmian@163.com>

On 2026-08-14 08:27:42 +0000, Xiaofeng Yuan 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 <klara@kasm.eu>
> Closes: https://lore.kernel.org/all/ant_8TaBbov_GS4i@soda.int.kasm.eu/
> Reported-by: Lad Prabhakar <prabhakar.csengg@gmail.com>
> 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 <xiaofengmian@163.com>

This version works fine for me.

Thanks,
Tested-by: Klara Modin <klarasmodin@gmail.com>

> ---
>  arch/riscv/kernel/patch.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> 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
> 

  reply	other threads:[~2026-08-14 12:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-14  8:27 [PATCH v5 0/2] riscv: fix text patching on minimal kernel configs Xiaofeng Yuan
2026-08-14  8:27 ` [PATCH v5 1/2] riscv: mm: make EXECMEM_KPROBES writable without CONFIG_STRICT_MODULE_RWX Xiaofeng Yuan
2026-08-14 13:19   ` Lad, Prabhakar
2026-08-14  8:27 ` [PATCH v5 2/2] riscv: patch: skip fixmap mapping when kernel text is already writable Xiaofeng Yuan
2026-08-14 12:04   ` Klara Modin [this message]
2026-08-14 13:19   ` Lad, Prabhakar
2026-08-14 20:18 ` [PATCH v5 0/2] riscv: fix text patching on minimal kernel configs Paul Walmsley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=an8ECsGLdzDgRafU@soda.int.kasm.eu \
    --to=klarasmodin@gmail.com \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=klara@kasm.eu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=namcao@linutronix.de \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    --cc=prabhakar.csengg@gmail.com \
    --cc=xiaofengmian@163.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox