From: Xiaofeng Yuan <xiaofengmian@163.com>
To: Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>
Cc: Alexandre Ghiti <alex@ghiti.fr>, Nam Cao <namcao@linutronix.de>,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
xiaofengmian@163.com
Subject: [PATCH v4 2/2] riscv: patch: skip fixmap mapping when kernel text is already writable
Date: Mon, 20 Jul 2026 03:22:57 +0000 [thread overview]
Message-ID: <20260720032258.5188-3-xiaofengmian@163.com> (raw)
In-Reply-To: <20260720032258.5188-1-xiaofengmian@163.com>
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>
---
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;
}
return (void *)set_fixmap_offset(fixmap, phys);
--
2.43.0
next prev parent reply other threads:[~2026-07-20 3:23 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-20 3:22 [PATCH v4 0/2] riscv: fix kprobes on minimal kernel configs Xiaofeng Yuan
2026-07-20 3:22 ` [PATCH v4 1/2] riscv: mm: make EXECMEM_KPROBES writable without CONFIG_STRICT_MODULE_RWX Xiaofeng Yuan
2026-07-20 3:22 ` Xiaofeng Yuan [this message]
2026-08-11 20:39 ` [PATCH v4 2/2] riscv: patch: skip fixmap mapping when kernel text is already writable Klara Modin
2026-08-12 6:45 ` Nam Cao
2026-08-14 5:55 ` Paul Walmsley
2026-08-13 14:14 ` Lad, Prabhakar
2026-07-20 7:11 ` [PATCH v4 0/2] riscv: fix kprobes on minimal kernel configs Nam Cao
2026-08-07 2:01 ` 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=20260720032258.5188-3-xiaofengmian@163.com \
--to=xiaofengmian@163.com \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=namcao@linutronix.de \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
/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
all inboxes | Powered by JetHome®