[PATCH v2 08/10] s390/alternative: Serialize text patching with text_mutex

From: Heiko Carstens

Date: Tue Oct 27 2026 - 10:36:20 EST


Acquire text_mutex inside __apply_alternatives() around the patching
loop.

Serialization is not required for __apply_alternatives(), however this is
part of larger series where at the end s390_kernel_write() requires that
callers hold text_mutex.

Signed-off-by: Heiko Carstens <hca@xxxxxxxxxxxxx>
---
arch/s390/kernel/alternative.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/arch/s390/kernel/alternative.c b/arch/s390/kernel/alternative.c
index 02d04ae621ba..6013a75f5241 100644
--- a/arch/s390/kernel/alternative.c
+++ b/arch/s390/kernel/alternative.c
@@ -5,6 +5,7 @@
#endif

#include <linux/hex.h>
+#include <linux/memory.h>
#include <linux/uaccess.h>
#include <linux/printk.h>
#include <asm/nospec-branch.h>
@@ -55,6 +56,9 @@ void __apply_alternatives(struct alt_instr *start, struct alt_instr *end, unsign
bool debug, replace;
u8 *old, *new;

+#ifndef __DECOMPRESSOR
+ guard(mutex)(&text_mutex);
+#endif
/*
* The scan order should be from start to end. A later scanned
* alternative code can overwrite previously scanned alternative code.
--
2.53.0