* [PATCH 1/8] s390/kfence: Add error handling to arch_kfence_init_pool()
2026-11-18 14:47 [PATCH 0/8] s390: Add __must_check to set_memory() primitives Heiko Carstens
@ 2026-11-18 14:47 ` Heiko Carstens
2026-11-18 14:53 ` sashiko-bot
2026-11-18 14:47 ` [PATCH 2/8] s390/kprobes: Add error handling to alloc_insn_page() Heiko Carstens
` (6 subsequent siblings)
7 siblings, 1 reply; 17+ messages in thread
From: Heiko Carstens @ 2026-11-18 14:47 UTC (permalink / raw)
To: Vasily Gorbik, Alexander Gordeev
Cc: Mike Rapoport, Sven Schnelle, Christian Borntraeger, linux-kernel,
linux-s390
If set_memory_4k() fails, return false from arch_kfence_init_pool()
instead of silently ignoring.
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
arch/s390/include/asm/kfence.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/s390/include/asm/kfence.h b/arch/s390/include/asm/kfence.h
index e95e35eb8a3f..414c235a91b8 100644
--- a/arch/s390/include/asm/kfence.h
+++ b/arch/s390/include/asm/kfence.h
@@ -15,7 +15,8 @@ static __always_inline bool arch_kfence_init_pool(void)
#ifdef CONFIG_KFENCE
unsigned long pool_pages = KFENCE_POOL_SIZE >> PAGE_SHIFT;
- set_memory_4k((unsigned long)__kfence_pool, pool_pages);
+ if (set_memory_4k((unsigned long)__kfence_pool, pool_pages))
+ return false;
#endif
return true;
}
--
2.56.1
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH 2/8] s390/kprobes: Add error handling to alloc_insn_page()
2026-11-18 14:47 [PATCH 0/8] s390: Add __must_check to set_memory() primitives Heiko Carstens
2026-11-18 14:47 ` [PATCH 1/8] s390/kfence: Add error handling to arch_kfence_init_pool() Heiko Carstens
@ 2026-11-18 14:47 ` Heiko Carstens
2026-11-18 14:54 ` sashiko-bot
2026-11-18 14:47 ` [PATCH 3/8] s390/kexec: Let crash_protect_pages() warn in case of an error Heiko Carstens
` (5 subsequent siblings)
7 siblings, 1 reply; 17+ messages in thread
From: Heiko Carstens @ 2026-11-18 14:47 UTC (permalink / raw)
To: Vasily Gorbik, Alexander Gordeev
Cc: Mike Rapoport, Sven Schnelle, Christian Borntraeger, linux-kernel,
linux-s390
If set_memory_rox() fails, let alloc_insn_page return NULL, instead of
a pointer to a not executable page.
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
arch/s390/kernel/kprobes.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/arch/s390/kernel/kprobes.c b/arch/s390/kernel/kprobes.c
index e806b124e4ba..90efe90c609e 100644
--- a/arch/s390/kernel/kprobes.c
+++ b/arch/s390/kernel/kprobes.c
@@ -40,7 +40,10 @@ void *alloc_insn_page(void)
page = execmem_alloc(EXECMEM_KPROBES, PAGE_SIZE);
if (!page)
return NULL;
- set_memory_rox((unsigned long)page, 1);
+ if (set_memory_rox((unsigned long)page, 1)) {
+ execmem_free(page);
+ return NULL;
+ }
return page;
}
--
2.56.1
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH 3/8] s390/kexec: Let crash_protect_pages() warn in case of an error
2026-11-18 14:47 [PATCH 0/8] s390: Add __must_check to set_memory() primitives Heiko Carstens
2026-11-18 14:47 ` [PATCH 1/8] s390/kfence: Add error handling to arch_kfence_init_pool() Heiko Carstens
2026-11-18 14:47 ` [PATCH 2/8] s390/kprobes: Add error handling to alloc_insn_page() Heiko Carstens
@ 2026-11-18 14:47 ` Heiko Carstens
2026-11-18 15:05 ` sashiko-bot
2026-11-18 14:47 ` [PATCH 4/8] s390/module: Add error handling to module_alloc_ftrace_hotpatch_trampolines() Heiko Carstens
` (4 subsequent siblings)
7 siblings, 1 reply; 17+ messages in thread
From: Heiko Carstens @ 2026-11-18 14:47 UTC (permalink / raw)
To: Vasily Gorbik, Alexander Gordeev
Cc: Mike Rapoport, Sven Schnelle, Christian Borntraeger, linux-kernel,
linux-s390
Let crash_protect_pages() print an error message in case set_memory*()
fails.
This doesn't buy too much since a failing set_memory_rw() would result in
a crash of the caller as soon as a write to the memory area happens.
Fixing that requires larger changes - for now only print a message.
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
arch/s390/kernel/machine_kexec.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/arch/s390/kernel/machine_kexec.c b/arch/s390/kernel/machine_kexec.c
index baeb3dcfc1c8..bf65bea5fa01 100644
--- a/arch/s390/kernel/machine_kexec.c
+++ b/arch/s390/kernel/machine_kexec.c
@@ -152,14 +152,17 @@ void crash_free_reserved_phys_range(unsigned long begin, unsigned long end)
static void crash_protect_pages(int protect)
{
unsigned long size;
+ int rc;
if (!crashk_res.end)
return;
size = resource_size(&crashk_res);
if (protect)
- set_memory_ro(crashk_res.start, size >> PAGE_SHIFT);
+ rc = set_memory_ro(crashk_res.start, size >> PAGE_SHIFT);
else
- set_memory_rw(crashk_res.start, size >> PAGE_SHIFT);
+ rc = set_memory_rw(crashk_res.start, size >> PAGE_SHIFT);
+ if (rc)
+ pr_warn("Failed to %sprotect crashkernel memory: %d\n", protect ? "" : "un", rc);
}
void arch_kexec_protect_crashkres(void)
--
2.56.1
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH 4/8] s390/module: Add error handling to module_alloc_ftrace_hotpatch_trampolines()
2026-11-18 14:47 [PATCH 0/8] s390: Add __must_check to set_memory() primitives Heiko Carstens
` (2 preceding siblings ...)
2026-11-18 14:47 ` [PATCH 3/8] s390/kexec: Let crash_protect_pages() warn in case of an error Heiko Carstens
@ 2026-11-18 14:47 ` Heiko Carstens
2026-11-18 15:01 ` sashiko-bot
2026-11-18 14:47 ` [PATCH 5/8] s390/mm: Add error handling to arch_setup_zero_pages() Heiko Carstens
` (3 subsequent siblings)
7 siblings, 1 reply; 17+ messages in thread
From: Heiko Carstens @ 2026-11-18 14:47 UTC (permalink / raw)
To: Vasily Gorbik, Alexander Gordeev
Cc: Mike Rapoport, Sven Schnelle, Christian Borntraeger, linux-kernel,
linux-s390
Let module_alloc_ftrace_hotpatch_trampolines() return NULL, instead of
a pointer to a not executable page if set_memory_rox() fails.
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
arch/s390/kernel/module.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
index 9d1f8a50f5a4..86ace854e22d 100644
--- a/arch/s390/kernel/module.c
+++ b/arch/s390/kernel/module.c
@@ -473,13 +473,18 @@ static int module_alloc_ftrace_hotpatch_trampolines(struct module *me,
char *start, *end;
int numpages;
size_t size;
+ int rc;
size = FTRACE_HOTPATCH_TRAMPOLINES_SIZE(s->sh_size);
numpages = DIV_ROUND_UP(size, PAGE_SIZE);
start = execmem_alloc(EXECMEM_FTRACE, numpages * PAGE_SIZE);
if (!start)
return -ENOMEM;
- set_memory_rox((unsigned long)start, numpages);
+ rc = set_memory_rox((unsigned long)start, numpages);
+ if (rc) {
+ execmem_free(start);
+ return rc;
+ }
end = start + size;
me->arch.trampolines_start = (struct ftrace_hotpatch_trampoline *)start;
--
2.56.1
^ permalink raw reply related [flat|nested] 17+ messages in thread* Re: [PATCH 4/8] s390/module: Add error handling to module_alloc_ftrace_hotpatch_trampolines()
2026-11-18 14:47 ` [PATCH 4/8] s390/module: Add error handling to module_alloc_ftrace_hotpatch_trampolines() Heiko Carstens
@ 2026-11-18 15:01 ` sashiko-bot
0 siblings, 0 replies; 17+ messages in thread
From: sashiko-bot @ 2026-11-18 15:01 UTC (permalink / raw)
To: Heiko Carstens
Cc: linux-s390, Vasily Gorbik, Alexander Gordeev,
Christian Borntraeger
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] s390/module: inaccurate return value in commit message for
trampoline alloc
--
commit 1f1b0c01e4a7101a1a14aadfdd4c9c1dbcd1303a
Author: Heiko Carstens <hca@linux.ibm.com>
s390/module: Add error handling to module_alloc_ftrace_hotpatch_trampolines()
This commit checks the return value of set_memory_rox() in
module_alloc_ftrace_hotpatch_trampolines() and frees the allocated
trampoline memory on failure.
> Let module_alloc_ftrace_hotpatch_trampolines() return NULL, instead of
> a pointer to a not executable page if set_memory_rox() fails.
[Severity: Low]
This isn't a bug in the code, but
module_alloc_ftrace_hotpatch_trampolines() returns an int error code (rc)
and leaves me->arch.trampolines_start unset rather than returning a
pointer or NULL.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118144709.202520-1-hca@linux.ibm.com?part=4
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH 5/8] s390/mm: Add error handling to arch_setup_zero_pages()
2026-11-18 14:47 [PATCH 0/8] s390: Add __must_check to set_memory() primitives Heiko Carstens
` (3 preceding siblings ...)
2026-11-18 14:47 ` [PATCH 4/8] s390/module: Add error handling to module_alloc_ftrace_hotpatch_trampolines() Heiko Carstens
@ 2026-11-18 14:47 ` Heiko Carstens
2026-11-18 14:51 ` sashiko-bot
2026-11-18 14:47 ` [PATCH 6/8] s390/mm: Add error handling to mark_rodata_ro() Heiko Carstens
` (2 subsequent siblings)
7 siblings, 1 reply; 17+ messages in thread
From: Heiko Carstens @ 2026-11-18 14:47 UTC (permalink / raw)
To: Vasily Gorbik, Alexander Gordeev
Cc: Mike Rapoport, Sven Schnelle, Christian Borntraeger, linux-kernel,
linux-s390
If set_memory_ro() fails early in arch_setup_zero_pages() just
panic. This should never happen.
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
arch/s390/mm/init.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
index be7e009e7b59..4d5a13b19dca 100644
--- a/arch/s390/mm/init.c
+++ b/arch/s390/mm/init.c
@@ -74,6 +74,7 @@ void __init arch_setup_zero_pages(void)
{
unsigned long total_pages = memblock_estimated_nr_free_pages();
unsigned int order;
+ int rc;
/* Latest machines require a mapping granularity of 512KB */
order = 7;
@@ -86,7 +87,9 @@ void __init arch_setup_zero_pages(void)
zero_page_mask = ((PAGE_SIZE << order) - 1) & PAGE_MASK;
- set_memory_ro(empty_zero_page, 1UL << order);
+ rc = set_memory_ro(empty_zero_page, 1UL << order);
+ if (rc)
+ panic("%s() failed, err = %d\n", __func__, rc);
}
void __init arch_zone_limits_init(unsigned long *max_zone_pfns)
--
2.56.1
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH 6/8] s390/mm: Add error handling to mark_rodata_ro()
2026-11-18 14:47 [PATCH 0/8] s390: Add __must_check to set_memory() primitives Heiko Carstens
` (4 preceding siblings ...)
2026-11-18 14:47 ` [PATCH 5/8] s390/mm: Add error handling to arch_setup_zero_pages() Heiko Carstens
@ 2026-11-18 14:47 ` Heiko Carstens
2026-11-18 14:51 ` sashiko-bot
2026-11-18 14:47 ` [PATCH 7/8] s390/mm: Add error handling to vmem_map_init() Heiko Carstens
2026-11-18 14:47 ` [PATCH 8/8] s390/set_memory: Add __must_check to set_memory() primitives Heiko Carstens
7 siblings, 1 reply; 17+ messages in thread
From: Heiko Carstens @ 2026-11-18 14:47 UTC (permalink / raw)
To: Vasily Gorbik, Alexander Gordeev
Cc: Mike Rapoport, Sven Schnelle, Christian Borntraeger, linux-kernel,
linux-s390
If __set_memory_ro() fails early in mark_rodata_ro() just panic.
This should never happen.
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
arch/s390/mm/init.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
index 4d5a13b19dca..18ce7ea2f653 100644
--- a/arch/s390/mm/init.c
+++ b/arch/s390/mm/init.c
@@ -110,10 +110,13 @@ void __init paging_init(void)
void mark_rodata_ro(void)
{
unsigned long size = __end_ro_after_init - __start_ro_after_init;
+ int rc;
if (cpu_has_nx())
system_ctl_set_bit(0, CR0_INSTRUCTION_EXEC_PROTECTION_BIT);
- __set_memory_ro(__start_ro_after_init, __end_ro_after_init);
+ rc = __set_memory_ro(__start_ro_after_init, __end_ro_after_init);
+ if (rc)
+ panic("%s() failed, err = %d\n", __func__, rc);
pr_info("Write protected read-only-after-init data: %luk\n", size >> 10);
}
--
2.56.1
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH 7/8] s390/mm: Add error handling to vmem_map_init()
2026-11-18 14:47 [PATCH 0/8] s390: Add __must_check to set_memory() primitives Heiko Carstens
` (5 preceding siblings ...)
2026-11-18 14:47 ` [PATCH 6/8] s390/mm: Add error handling to mark_rodata_ro() Heiko Carstens
@ 2026-11-18 14:47 ` Heiko Carstens
2026-11-18 14:50 ` sashiko-bot
2026-11-18 14:47 ` [PATCH 8/8] s390/set_memory: Add __must_check to set_memory() primitives Heiko Carstens
7 siblings, 1 reply; 17+ messages in thread
From: Heiko Carstens @ 2026-11-18 14:47 UTC (permalink / raw)
To: Vasily Gorbik, Alexander Gordeev
Cc: Mike Rapoport, Sven Schnelle, Christian Borntraeger, linux-kernel,
linux-s390
If any of the set_memory() calls in vmem_map_init() fails just panic.
This should never happen, and would lead to a broken kernel mapping.
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
arch/s390/mm/vmem.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/arch/s390/mm/vmem.c b/arch/s390/mm/vmem.c
index d2879ce860a1..317bd01dca86 100644
--- a/arch/s390/mm/vmem.c
+++ b/arch/s390/mm/vmem.c
@@ -671,18 +671,22 @@ void vmem_unmap_4k_page(unsigned long addr)
void __init vmem_map_init(void)
{
- __set_memory_rox(_stext, _etext);
- __set_memory_ro(_etext, __end_rodata);
- __set_memory_rox(__stext_amode31, __etext_amode31);
+ int rc;
+
+ rc = __set_memory_rox(_stext, _etext);
+ rc |= __set_memory_ro(_etext, __end_rodata);
+ rc |= __set_memory_rox(__stext_amode31, __etext_amode31);
/*
* If the BEAR-enhancement facility is not installed the first
* prefix page is used to return to the previous context with
* an LPSWE instruction and therefore must be executable.
*/
if (!cpu_has_bear())
- set_memory_x(0, 1);
+ rc |= set_memory_x(0, 1);
if (debug_pagealloc_enabled())
- __set_memory_4k(__va(0), absolute_pointer(__va(0)) + ident_map_size);
+ rc |= __set_memory_4k(__va(0), absolute_pointer(__va(0)) + ident_map_size);
+ if (rc)
+ panic("Failed to set kernel mapping permissions");
pr_info("Write protected kernel read-only data: %luk\n",
(unsigned long)(__end_rodata - _stext) >> 10);
}
--
2.56.1
^ permalink raw reply related [flat|nested] 17+ messages in thread* [PATCH 8/8] s390/set_memory: Add __must_check to set_memory() primitives
2026-11-18 14:47 [PATCH 0/8] s390: Add __must_check to set_memory() primitives Heiko Carstens
` (6 preceding siblings ...)
2026-11-18 14:47 ` [PATCH 7/8] s390/mm: Add error handling to vmem_map_init() Heiko Carstens
@ 2026-11-18 14:47 ` Heiko Carstens
2026-11-18 14:52 ` sashiko-bot
7 siblings, 1 reply; 17+ messages in thread
From: Heiko Carstens @ 2026-11-18 14:47 UTC (permalink / raw)
To: Vasily Gorbik, Alexander Gordeev
Cc: Mike Rapoport, Sven Schnelle, Christian Borntraeger, linux-kernel,
linux-s390
All set_memory() callers in s390 architecture code check the returned
value. Add __must_check to all variants to make sure no new callers
which don't check the return value are added.
This is the s390 version of commit 2abbd6d5fbe0 ("powerpc: Add
__must_check to set_memory_...()")
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
arch/s390/include/asm/set_memory.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/s390/include/asm/set_memory.h b/arch/s390/include/asm/set_memory.h
index e3562bf0c1aa..036295215a1a 100644
--- a/arch/s390/include/asm/set_memory.h
+++ b/arch/s390/include/asm/set_memory.h
@@ -39,12 +39,12 @@ int __set_memory(unsigned long addr, unsigned long numpages, unsigned long flags
* for areas larger than 8TB, which may happen at memory initialization.
*/
#define __SET_MEMORY_FUNC(fname, flags) \
-static inline int fname(unsigned long addr, int numpages) \
+static inline int __must_check fname(unsigned long addr, int numpages) \
{ \
return __set_memory(addr, numpages, (flags)); \
} \
\
-static inline int __##fname(void *start, void *end) \
+static inline int __must_check __##fname(void *start, void *end) \
{ \
unsigned long numpages; \
\
--
2.56.1
^ permalink raw reply related [flat|nested] 17+ messages in thread