From nobody Tue Sep 29 00:33:20 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C604B43CE53 for ; Fri, 14 Aug 2026 08:28:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.3 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786696140; cv=none; b=U9OfHEYEBqJ2cCxkFTrLHznie601S3xabj4xd82fL7QX2nQCYmpZiI2wyT6D07PeZ0VnEIV0pgCELrZSg3SvSDxh5hSybqZ9tEyJWLM+rXYxiTFkNozqS3CnNbPB0hKNd2hafnyBRFDv6KnX06nCJwnEvS9ld8VhueN6j2qrabM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786696140; c=relaxed/simple; bh=BXQI2dPDiJ9j/BD5iq+CBs3a9PNWVBnx+jgQWUX0qzw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FoQqoUexf+8MwcLhgrWoXDxa9qHNCC7N9dNcVkbGdJovh18TVXImLDfAw4L9M7rktZkLofcVLudiNgYkJU9KuDGeXIprGA0An5AtnPTuijqRXgSqDHanr3AfCZ8sCcGUFo6/Rfmj4ecWY7EnY5drv7Rhzr+K+wnU0b4HbDvOoh4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=SaQx4KCz; arc=none smtp.client-ip=117.135.210.3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="SaQx4KCz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=Jg 6xZqu7dbxREDlYqdaqjxUcNWuSqpTI5jZPGX3Lx8I=; b=SaQx4KCzFknWRUU+My qqDlz/PrYEpMsn+nWztHiOH5UBYrr4ltMFp0szrvDGoAiTA/8RqtKSHIiAx61JIT SzPs0316P0KV8xugsfGFQonDVzH9tVQj0jov4yCkWj1wdb1QDlKz7AxwXfOXdCKN lNuiHmXN1OlSkSb2GyQe9P4zM= Received: from Ubuntu.. (unknown []) by gzga-smtp-mtada-g1-4 (Coremail) with SMTP id _____wD3dIl_0X5qdVL2Pg--.57693S3; Fri, 14 Aug 2026 16:27:45 +0800 (CST) From: Xiaofeng Yuan To: Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: Alexandre Ghiti , Nam Cao , Klara Modin , prabhakar.csengg@gmail.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, xiaofengmian@163.com Subject: [PATCH v5 1/2] riscv: mm: make EXECMEM_KPROBES writable without CONFIG_STRICT_MODULE_RWX Date: Fri, 14 Aug 2026 08:27:41 +0000 Message-ID: <20260814082742.148403-2-xiaofengmian@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260814082742.148403-1-xiaofengmian@163.com> References: <20260814082742.148403-1-xiaofengmian@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wD3dIl_0X5qdVL2Pg--.57693S3 X-Coremail-Antispam: 1Uf129KBjvdXoW7Xw43Cw1DJF43uF15XrWrZrb_yoWkCrb_G3 WxWryfuayrW39Fg3WfKr4fC3W2kas7CF1UGrn7XFyqgrnrZ3s8X343XF15Xw45Cr1SgF4f Aa9xXayI9rn2vjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7sR_rb1UUUUUU== X-CM-SenderInfo: p0ld0w5hqjzxldq6il2tof0z/xtbC5gHO0Wp+0YEYYwAA3H Content-Type: text/plain; charset="utf-8" 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 Tested-by: Lad Prabhakar --- arch/riscv/mm/init.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 85bdcce63a..b084a72e5d 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -1462,7 +1462,9 @@ struct execmem_info __init *execmem_arch_setup(void) [EXECMEM_KPROBES] =3D { .start =3D VMALLOC_START, .end =3D VMALLOC_END, - .pgprot =3D PAGE_KERNEL_READ_EXEC, + .pgprot =3D IS_ENABLED(CONFIG_STRICT_MODULE_RWX) ? + PAGE_KERNEL_READ_EXEC : + PAGE_KERNEL_EXEC, .alignment =3D 1, }, [EXECMEM_BPF] =3D { --=20 2.43.0 From nobody Tue Sep 29 00:33:20 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ACC5B3ED5BB for ; Fri, 14 Aug 2026 08:28:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786696143; cv=none; b=i2sRaheEgIxVvX3RCme+JtcXWAoX/kRghufcBJTuY3unShCU7Ovy3Yix0SFItm4+avzLkupeycZDa3McniGiQJ/3YZckWb/lb9QIDVozscNxVa3RoLdNrkplYIQuYvehZKhqeS0hWz34haTC4Ars3ZCD2sVvjnLGx7fPFuTybUA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786696143; c=relaxed/simple; bh=WkBPzMNXT9S8SXDRbK1Y5CDhZNgntYou2z226qkbIuA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RGwfhswoqopYnOl2mPluHujQ5XS7rAJLGN/mYk71nsP43j872JZjienlkAyms4q7iwjM3d2RhhYxIWDRBRS/FZNoop8McGYu3T3eKTfpolAA/LT2Q04UYv6Q0X78I/7RdFlaLpbLhDGWEBLRpr0R+PafrmnYTtgEi58PJM3tVHA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=fpoL/1Ij; arc=none smtp.client-ip=117.135.210.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="fpoL/1Ij" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=f/ Rp3afxHVt11GiYQfwg2x9WpjUQqy7bLvcIUQuUuck=; b=fpoL/1Ij9tgRXPWPC3 vdC/wCBSxoz/FtDHyEL12e8DvvEgykmcL9lfbI4T6T2ZFDUpOnTf8TVVzo0cWa9w lTmLXTpFD1E+QkodmslckytwaZvpS02Beg4NG6ZxeE1xTWOf9mu9Kw2e5a6AvyaT hlXq88bYs3qD8gWoFanJ4JAv4= Received: from Ubuntu.. (unknown []) by gzga-smtp-mtada-g1-4 (Coremail) with SMTP id _____wD3dIl_0X5qdVL2Pg--.57693S4; Fri, 14 Aug 2026 16:27:45 +0800 (CST) From: Xiaofeng Yuan To: Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: Alexandre Ghiti , Nam Cao , Klara Modin , prabhakar.csengg@gmail.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, xiaofengmian@163.com Subject: [PATCH v5 2/2] riscv: patch: skip fixmap mapping when kernel text is already writable Date: Fri, 14 Aug 2026 08:27:42 +0000 Message-ID: <20260814082742.148403-3-xiaofengmian@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260814082742.148403-1-xiaofengmian@163.com> References: <20260814082742.148403-1-xiaofengmian@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wD3dIl_0X5qdVL2Pg--.57693S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7CF17CrW7WryxXw17XrW8Zwb_yoW8ZF48p3 ykAr45AFWrGF1Sy39Fk34DuryYvwn5trW3WF9xG34Svw4DZ3y5Awn2gw17XF1kXr1j9r4S yFsayrsIva4UK37anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0z_5l1DUUUUU= X-CM-SenderInfo: p0ld0w5hqjzxldq6il2tof0z/xtbC5gLO0Wp+0YIYfwAA3b Content-Type: text/plain; charset="utf-8" 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 Closes: https://lore.kernel.org/all/ant_8TaBbov_GS4i@soda.int.kasm.eu/ Reported-by: Lad Prabhakar Closes: https://lore.kernel.org/all/CA+V-a8tQK8rih9SGGTyqrEBGpNkx4H0eX2YccC= RrgkVAPr+EBg@mail.gmail.com/ Tested-by: Klara Modin Tested-by: Lad Prabhakar --- 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=3Dn 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 --- 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; =20 if (core_kernel_text(uintaddr) || is_kernel_exittext(uintaddr)) { + if (!IS_ENABLED(CONFIG_STRICT_KERNEL_RWX)) + return addr; phys =3D __pa_symbol(addr); } else if (IS_ENABLED(CONFIG_STRICT_MODULE_RWX)) { struct page *page =3D vmalloc_to_page(addr); --=20 2.43.0