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>
11 const struct exception_table_entry *s390_search_extables(unsigned long addr)
13 const struct exception_table_entry *fixup;
16 fixup = search_exception_tables(addr);
19 num = __stop_amode31_ex_table - __start_amode31_ex_table;
20 return search_extable(__start_amode31_ex_table, num, addr);
23 static bool ex_handler_fixup(const struct exception_table_entry *ex, struct pt_regs *regs)
25 regs->psw.addr = extable_fixup(ex);
29 static bool ex_handler_ua_store(const struct exception_table_entry *ex, struct pt_regs *regs)
31 unsigned int reg_err = FIELD_GET(EX_DATA_REG_ERR, ex->data);
33 regs->gprs[reg_err] = -EFAULT;
34 regs->psw.addr = extable_fixup(ex);
38 static bool ex_handler_ua_load_mem(const struct exception_table_entry *ex, struct pt_regs *regs)
40 unsigned int reg_addr = FIELD_GET(EX_DATA_REG_ADDR, ex->data);
41 unsigned int reg_err = FIELD_GET(EX_DATA_REG_ERR, ex->data);
42 size_t len = FIELD_GET(EX_DATA_LEN, ex->data);
44 regs->gprs[reg_err] = -EFAULT;
45 memset((void *)regs->gprs[reg_addr], 0, len);
46 regs->psw.addr = extable_fixup(ex);
50 static bool ex_handler_ua_load_reg(const struct exception_table_entry *ex,
51 bool pair, struct pt_regs *regs)
53 unsigned int reg_zero = FIELD_GET(EX_DATA_REG_ADDR, ex->data);
54 unsigned int reg_err = FIELD_GET(EX_DATA_REG_ERR, ex->data);
56 regs->gprs[reg_err] = -EFAULT;
57 regs->gprs[reg_zero] = 0;
59 regs->gprs[reg_zero + 1] = 0;
60 regs->psw.addr = extable_fixup(ex);
64 static bool ex_handler_zeropad(const struct exception_table_entry *ex, struct pt_regs *regs)
66 unsigned int reg_addr = FIELD_GET(EX_DATA_REG_ADDR, ex->data);
67 unsigned int reg_data = FIELD_GET(EX_DATA_REG_ERR, ex->data);
68 unsigned long data, addr, offset;
70 addr = regs->gprs[reg_addr];
71 offset = addr & (sizeof(unsigned long) - 1);
72 addr &= ~(sizeof(unsigned long) - 1);
73 data = *(unsigned long *)addr;
74 data <<= BITS_PER_BYTE * offset;
75 regs->gprs[reg_data] = data;
76 regs->psw.addr = extable_fixup(ex);
80 bool fixup_exception(struct pt_regs *regs)
82 const struct exception_table_entry *ex;
84 ex = s390_search_extables(instruction_pointer(regs));
89 return ex_handler_fixup(ex, regs);
91 return ex_handler_bpf(ex, regs);
92 case EX_TYPE_UA_STORE:
93 return ex_handler_ua_store(ex, regs);
94 case EX_TYPE_UA_LOAD_MEM:
95 return ex_handler_ua_load_mem(ex, regs);
96 case EX_TYPE_UA_LOAD_REG:
97 return ex_handler_ua_load_reg(ex, false, regs);
98 case EX_TYPE_UA_LOAD_REGPAIR:
99 return ex_handler_ua_load_reg(ex, true, regs);
100 case EX_TYPE_ZEROPAD:
101 return ex_handler_zeropad(ex, regs);
103 panic("invalid exception table entry");