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