^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef __S390_EXTABLE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define __S390_EXTABLE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <asm/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * The exception table consists of three addresses:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * - Address of an instruction that is allowed to fault.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * - Address at which the program should continue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * - Optional address of handler that takes pt_regs * argument and runs in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * interrupt context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * No registers are modified, so it is entirely up to the continuation code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * to figure out what to do.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * All the routines below use bits of fixup code that are out of line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * with the main instruction path. This means when everything is well,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * we don't even have to jump over them. Further, they do not intrude
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * on our cache or tlb entries.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct exception_table_entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) int insn, fixup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) long handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) extern struct exception_table_entry *__start_dma_ex_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) extern struct exception_table_entry *__stop_dma_ex_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) const struct exception_table_entry *s390_search_extables(unsigned long addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) static inline unsigned long extable_fixup(const struct exception_table_entry *x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) return (unsigned long)&x->fixup + x->fixup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) typedef bool (*ex_handler_t)(const struct exception_table_entry *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct pt_regs *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static inline ex_handler_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) ex_fixup_handler(const struct exception_table_entry *x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) if (likely(!x->handler))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) return (ex_handler_t)((unsigned long)&x->handler + x->handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static inline bool ex_handle(const struct exception_table_entry *x,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) ex_handler_t handler = ex_fixup_handler(x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) if (unlikely(handler))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) return handler(x, regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) regs->psw.addr = extable_fixup(x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #define ARCH_HAS_RELATIVE_EXTABLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) static inline void swap_ex_entry_fixup(struct exception_table_entry *a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct exception_table_entry *b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct exception_table_entry tmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) int delta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) a->fixup = b->fixup + delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) b->fixup = tmp.fixup - delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) a->handler = b->handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (a->handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) a->handler += delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) b->handler = tmp.handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) if (b->handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) b->handler -= delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #define swap_ex_entry_fixup swap_ex_entry_fixup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #endif