[PATCH 09/32] s390/extable: Rework exception handling logic

From: Heiko Carstens

Date: Thu Oct 01 2026 - 06:42:04 EST


Add EX_TABLE_INSN macros which will replace the existing EX_TABLE
macros. The macros come with new semantics for the whole exception
handling: with the new exception handling the exception table entries
always point to the instruction which may cause an exception. This is
regardless of exception type, and whether an exception is nullifying,
suppressing, completing, or terminating.

This improves the current situation where exception table entries are
required which point to the instruction (nullifying) and/or behind the
instruction (suppressing, completing, or terminating), since depending
on usage an instruction can generate different exceptions.

The new EX_TABLE_INSN macros are aliases to the existing EX_TABLE
macros. The exception handling logic is changed to first perform a lookup
in the exception tables with get_trap_ip() / boot_get_trap_ip(). If that
finds nothing, it falls back to looking up with instruction_pointer().

This is a temporary solution until all EX_TABLE usages have been
converted to EX_TABLE_INSN. When that work is complete EX_TABLE will
be removed, exception tables will only be searched by using the return
value of get_trap_ip() / boot_get_trap_ip().

Signed-off-by: Heiko Carstens <hca@xxxxxxxxxxxxx>
---
arch/s390/boot/pgm_check.c | 35 ++++++++++++++++++++++++-----
arch/s390/include/asm/asm-extable.h | 10 +++++++++
arch/s390/mm/extable.c | 4 +++-
3 files changed, 42 insertions(+), 7 deletions(-)

diff --git a/arch/s390/boot/pgm_check.c b/arch/s390/boot/pgm_check.c
index fa621fa5bc02..56d0be7e2823 100644
--- a/arch/s390/boot/pgm_check.c
+++ b/arch/s390/boot/pgm_check.c
@@ -3,9 +3,11 @@
#include <linux/stdarg.h>
#include <linux/string.h>
#include <linux/ctype.h>
+#include <asm/pgmcheck-defs.h>
#include <asm/stacktrace.h>
#include <asm/boot_data.h>
#include <asm/lowcore.h>
+#include <asm/processor.h>
#include <asm/setup.h>
#include <asm/sclp.h>
#include <asm/uv.h>
@@ -40,19 +42,40 @@ static inline unsigned long extable_insn(const struct exception_table_entry *x)
return (unsigned long)&x->insn + x->insn;
}

-static bool ex_handler(struct pt_regs *regs)
+static unsigned long boot_get_trap_ip(struct pt_regs *regs)
+{
+ static const unsigned long nullified[2] = { PGM_CHECKS_NULLIFIED };
+
+ if (test_bit(regs->int_code & PGM_INT_CODE_MASK, nullified))
+ return regs->psw.addr;
+ return __rewind_psw(regs->psw, regs->int_code >> 16);
+}
+
+static const struct exception_table_entry *search_boot_extable(unsigned long ip)
{
const struct exception_table_entry *ex;

for (ex = __start___ex_table; ex < __stop___ex_table; ex++) {
- if (extable_insn(ex) != regs->psw.addr)
+ if (extable_insn(ex) != ip)
continue;
if (ex->type != EX_TYPE_FIXUP)
- return false;
- regs->psw.addr = extable_fixup(ex);
- return true;
+ return NULL;
+ return ex;
}
- return false;
+ return NULL;
+}
+
+static bool ex_handler(struct pt_regs *regs)
+{
+ const struct exception_table_entry *ex;
+
+ ex = search_boot_extable(boot_get_trap_ip(regs));
+ if (!ex)
+ ex = search_boot_extable(instruction_pointer(regs));
+ if (!ex)
+ return false;
+ regs->psw.addr = extable_fixup(ex);
+ return true;
}

void do_pgm_check(struct pt_regs *regs)
diff --git a/arch/s390/include/asm/asm-extable.h b/arch/s390/include/asm/asm-extable.h
index d23ea0c94e4e..488bd10452b3 100644
--- a/arch/s390/include/asm/asm-extable.h
+++ b/arch/s390/include/asm/asm-extable.h
@@ -92,4 +92,14 @@
#define EX_TABLE_UA_MVCOS_FROM(_fault, _target) \
__EX_TABLE(__ex_table, _fault, _target, EX_TYPE_UA_MVCOS_FROM, __stringify(%%r0), __stringify(%%r0), 0)

+#define EX_TABLE_INSN EX_TABLE
+#define EX_TABLE_INSN_AMODE31 EX_TABLE_AMODE31
+#define EX_TABLE_INSN_UA_FAULT EX_TABLE_UA_FAULT
+#define EX_TABLE_INSN_UA_LOAD_REG EX_TABLE_UA_LOAD_REG
+#define EX_TABLE_INSN_UA_LOAD_REGPAIR EX_TABLE_UA_LOAD_REGPAIR
+#define EX_TABLE_INSN_ZEROPAD EX_TABLE_ZEROPAD
+#define EX_TABLE_INSN_FPC EX_TABLE_FPC
+#define EX_TABLE_INSN_UA_MVCOS_TO EX_TABLE_UA_MVCOS_TO
+#define EX_TABLE_INSN_UA_MVCOS_FROM EX_TABLE_UA_MVCOS_FROM
+
#endif /* __ASM_EXTABLE_H */
diff --git a/arch/s390/mm/extable.c b/arch/s390/mm/extable.c
index 7498e858c401..ca6a1efa49ee 100644
--- a/arch/s390/mm/extable.c
+++ b/arch/s390/mm/extable.c
@@ -120,7 +120,9 @@ bool fixup_exception(struct pt_regs *regs)
{
const struct exception_table_entry *ex;

- ex = s390_search_extables(instruction_pointer(regs));
+ ex = s390_search_extables(get_trap_ip(regs));
+ if (!ex)
+ ex = s390_search_extables(instruction_pointer(regs));
if (!ex)
return false;
switch (ex->type) {
--
2.53.0