Linux 6.14-rc1
[linux.git] / arch / s390 / mm / extable.c
bloba046be1715cf0019e1f8cbcd71572413ac4b2930
1 // SPDX-License-Identifier: GPL-2.0
3 #include <linux/bitfield.h>
4 #include <linux/extable.h>
5 #include <linux/string.h>
6 #include <linux/errno.h>
7 #include <linux/panic.h>
8 #include <asm/asm-extable.h>
9 #include <asm/extable.h>
10 #include <asm/fpu.h>
12 const struct exception_table_entry *s390_search_extables(unsigned long addr)
14 const struct exception_table_entry *fixup;
15 size_t num;
17 fixup = search_exception_tables(addr);
18 if (fixup)
19 return fixup;
20 num = __stop_amode31_ex_table - __start_amode31_ex_table;
21 return search_extable(__start_amode31_ex_table, num, addr);
24 static bool ex_handler_fixup(const struct exception_table_entry *ex, struct pt_regs *regs)
26 regs->psw.addr = extable_fixup(ex);
27 return true;
30 static bool ex_handler_ua_fault(const struct exception_table_entry *ex, struct pt_regs *regs)
32 unsigned int reg_err = FIELD_GET(EX_DATA_REG_ERR, ex->data);
34 regs->gprs[reg_err] = -EFAULT;
35 regs->psw.addr = extable_fixup(ex);
36 return true;
39 static bool ex_handler_ua_load_reg(const struct exception_table_entry *ex,
40 bool pair, struct pt_regs *regs)
42 unsigned int reg_zero = FIELD_GET(EX_DATA_REG_ADDR, ex->data);
43 unsigned int reg_err = FIELD_GET(EX_DATA_REG_ERR, ex->data);
45 regs->gprs[reg_err] = -EFAULT;
46 regs->gprs[reg_zero] = 0;
47 if (pair)
48 regs->gprs[reg_zero + 1] = 0;
49 regs->psw.addr = extable_fixup(ex);
50 return true;
53 static bool ex_handler_zeropad(const struct exception_table_entry *ex, struct pt_regs *regs)
55 unsigned int reg_addr = FIELD_GET(EX_DATA_REG_ADDR, ex->data);
56 unsigned int reg_data = FIELD_GET(EX_DATA_REG_ERR, ex->data);
57 unsigned long data, addr, offset;
59 addr = regs->gprs[reg_addr];
60 offset = addr & (sizeof(unsigned long) - 1);
61 addr &= ~(sizeof(unsigned long) - 1);
62 data = *(unsigned long *)addr;
63 data <<= BITS_PER_BYTE * offset;
64 regs->gprs[reg_data] = data;
65 regs->psw.addr = extable_fixup(ex);
66 return true;
69 static bool ex_handler_fpc(const struct exception_table_entry *ex, struct pt_regs *regs)
71 fpu_sfpc(0);
72 regs->psw.addr = extable_fixup(ex);
73 return true;
76 bool fixup_exception(struct pt_regs *regs)
78 const struct exception_table_entry *ex;
80 ex = s390_search_extables(instruction_pointer(regs));
81 if (!ex)
82 return false;
83 switch (ex->type) {
84 case EX_TYPE_FIXUP:
85 return ex_handler_fixup(ex, regs);
86 case EX_TYPE_BPF:
87 return ex_handler_bpf(ex, regs);
88 case EX_TYPE_UA_FAULT:
89 return ex_handler_ua_fault(ex, regs);
90 case EX_TYPE_UA_LOAD_REG:
91 return ex_handler_ua_load_reg(ex, false, regs);
92 case EX_TYPE_UA_LOAD_REGPAIR:
93 return ex_handler_ua_load_reg(ex, true, regs);
94 case EX_TYPE_ZEROPAD:
95 return ex_handler_zeropad(ex, regs);
96 case EX_TYPE_FPC:
97 return ex_handler_fpc(ex, regs);
99 panic("invalid exception table entry");