The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Heiko Carstens <hca@linux.ibm.com>
To: Alexander Gordeev <agordeev@linux.ibm.com>,
	Sven Schnelle <svens@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Mike Rapoport <rppt@kernel.org>,
	Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Cc: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org
Subject: [PATCH 17/17] s390/execmem: Enable EXECMEM_ARCH_ROX
Date: Thu,  3 Dec 2026 11:33:45 +0100	[thread overview]
Message-ID: <20261203103345.1206548-18-hca@linux.ibm.com> (raw)
In-Reply-To: <20261203103345.1206548-1-hca@linux.ibm.com>

Select ARCH_HAS_EXECMEM_ROX and use the execmem ROX cache for module
text, kprobes and ftrace allocations if EDAT1 is available. This allows
executable memory in the module area to be mapped with large read-only
pages.

Add the required execmem_fill_trapping_insns(), which fills memory with
invalid opcodes.

Define the EXECMEM_BPF and EXECMEM_MODULE_DATA ranges explicitly, since
they need writable memory and must not use the ROX cache.

Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
 arch/s390/Kconfig   |  1 +
 arch/s390/mm/init.c | 39 +++++++++++++++++++++++++++++++++++----
 2 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index 04b401e9b680..da468b01d6b6 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -97,6 +97,7 @@ config S390
 	select ARCH_HAS_DEVMEM_IS_ALLOWED
 	select ARCH_HAS_DMA_OPS if PCI
 	select ARCH_HAS_ELF_RANDOMIZE
+	select ARCH_HAS_EXECMEM_ROX if STRICT_MODULE_RWX || STRICT_KERNEL_RWX
 	select ARCH_HAS_FORCE_DMA_UNENCRYPTED
 	select ARCH_HAS_FORTIFY_SOURCE
 	select ARCH_HAS_GCOV_PROFILE_ALL
diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
index 0cac76ddb700..139ca6461fc8 100644
--- a/arch/s390/mm/init.c
+++ b/arch/s390/mm/init.c
@@ -312,39 +312,70 @@ void arch_remove_memory(u64 start, u64 size, struct vmem_altmap *altmap)
 #ifdef CONFIG_EXECMEM
 static struct execmem_info execmem_info __ro_after_init;
 
+#ifdef CONFIG_ARCH_HAS_EXECMEM_ROX
+void execmem_fill_trapping_insns(void *ptr, size_t size)
+{
+	memset(ptr, 0, size);
+}
+#endif
+
 struct execmem_info __init *execmem_arch_setup(void)
 {
 	unsigned long module_load_offset = 0;
+	enum execmem_range_flags flags;
 	unsigned long start;
+	pgprot_t pgprot;
 
 	if (kaslr_enabled())
 		module_load_offset = get_random_u32_inclusive(1, 1024) * PAGE_SIZE;
 
 	start = MODULES_VADDR + module_load_offset;
 
+	if (IS_ENABLED(CONFIG_ARCH_HAS_EXECMEM_ROX) && cpu_has_edat1()) {
+		pgprot = PAGE_KERNEL_ROX;
+		flags = EXECMEM_KASAN_SHADOW | EXECMEM_ROX_CACHE;
+	} else {
+		pgprot = PAGE_KERNEL;
+		flags = EXECMEM_KASAN_SHADOW;
+	}
+
 	execmem_info = (struct execmem_info){
 		.ranges = {
 			[EXECMEM_DEFAULT] = {
-				.flags	= EXECMEM_KASAN_SHADOW,
+				.flags	= flags,
 				.start	= start,
 				.end	= MODULES_END,
-				.pgprot	= PAGE_KERNEL,
+				.pgprot	= pgprot,
 				.alignment = MODULE_ALIGN,
 			},
 			[EXECMEM_KPROBES] = {
-				.flags	= EXECMEM_KASAN_SHADOW,
+				.flags	= flags,
 				.start	= start,
 				.end	= MODULES_END,
 				.pgprot	= PAGE_KERNEL_ROX,
 				.alignment = MODULE_ALIGN,
 			},
 			[EXECMEM_FTRACE] = {
-				.flags	= EXECMEM_KASAN_SHADOW,
+				.flags	= flags,
 				.start	= start,
 				.end	= MODULES_END,
 				.pgprot	= PAGE_KERNEL_ROX,
 				.alignment = MODULE_ALIGN,
 			},
+			[EXECMEM_BPF] = {
+				.flags	= EXECMEM_KASAN_SHADOW,
+				.start	= start,
+				.end	= MODULES_END,
+				.pgprot	= PAGE_KERNEL,
+				.alignment = MODULE_ALIGN,
+			},
+			[EXECMEM_MODULE_DATA] = {
+				.flags	= EXECMEM_KASAN_SHADOW,
+				.start	= start,
+				.end	= MODULES_END,
+				.pgprot	= PAGE_KERNEL,
+				.alignment = MODULE_ALIGN,
+			},
 		},
 	};
 
-- 
2.53.0


      parent reply	other threads:[~2026-12-03 10:34 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 10:33 [PATCH 00/17] s390/mm: Large kernel mappings for vmalloc and execmem ROX cache Heiko Carstens
2026-12-03 10:33 ` [PATCH 01/17] s390/boot: Initialize asce_limit for init_mm properly Heiko Carstens
2026-12-03 10:33 ` [PATCH 02/17] s390/pageattr: Only account direct mapping in direct map page counters Heiko Carstens
2026-12-03 10:33 ` [PATCH 03/17] s390/mm: Serialize kernel page table changes with init_mm mmap lock Heiko Carstens
2026-12-03 10:33 ` [PATCH 04/17] s390/vmem: Use generic page table allocators for vmem page tables Heiko Carstens
2026-12-03 10:33 ` [PATCH 05/17] s390/mm: Show write-combining attribute in page table dump Heiko Carstens
2026-12-03 10:33 ` [PATCH 06/17] s390/mm: Implement HAVE_ARCH_HUGE_VMAP Heiko Carstens
2026-12-03 10:33 ` [PATCH 07/17] s390/mm: Implement HAVE_ARCH_HUGE_VMALLOC Heiko Carstens
2026-12-03 10:33 ` [PATCH 08/17] s390/pageattr: Add helpers to replace kernel page table entries Heiko Carstens
2026-12-03 10:33 ` [PATCH 09/17] s390/mm: Add _SEGMENT_ENTRY_TYPE Heiko Carstens
2026-12-03 10:33 ` [PATCH 10/17] s390/pageattr: Use common helper to change kernel page table permissions Heiko Carstens
2026-12-03 10:33 ` [PATCH 11/17] s390/pageattr: Avoid splitting mappings if permissions do not change Heiko Carstens
2026-12-03 10:33 ` [PATCH 12/17] s390/pageattr: Mark intentional 4k kernel mappings Heiko Carstens
2026-12-03 10:33 ` [PATCH 13/17] s390/pageattr: Collapse kernel mappings after changing page attributes Heiko Carstens
2026-12-03 10:33 ` [PATCH 14/17] s390/mm: Add PAGE_KERNEL_ROX Heiko Carstens
2026-12-03 10:33 ` [PATCH 15/17] s390/execmem: Add EXECMEM_KPROBES range Heiko Carstens
2026-12-03 10:33 ` [PATCH 16/17] s390/execmem: Add EXECMEM_FTRACE range Heiko Carstens
2026-12-03 10:33 ` Heiko Carstens [this message]

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=20261203103345.1206548-18-hca@linux.ibm.com \
    --to=hca@linux.ibm.com \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=gerald.schaefer@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=rppt@kernel.org \
    --cc=svens@linux.ibm.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