Add and use fixup_exception helper function in order to remove the duplicated exception handler fixup code at several places.
Unified · Split
| @@ -49,17 +49,6 @@ ex_fixup_handler(const struct exception_table_entry *x) · 48 unmodified lines | ||
| 49 | 49 | return (ex_handler_t)((unsigned long)&x->handler + x->handler); |
| 50 | 50 | } |
| 51 | 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 | − | |
| 63 | 52 | #define ARCH_HAS_RELATIVE_EXTABLE |
| 64 | 53 | |
| 65 | 54 | static inline void swap_ex_entry_fixup(struct exception_table_entry *a, |
| @@ -78,4 +67,6 @@ static inline void swap_ex_entry_fixup(struct exception_table_entry *a, · 12 unmodified lines | ||
| 78 | 67 | } |
| 79 | 68 | #define swap_ex_entry_fixup swap_ex_entry_fixup |
| 80 | 69 | |
| 70 | +bool fixup_exception(struct pt_regs *regs); | |
| 71 | + | |
| 81 | 72 | #endif |
| @@ -151,12 +151,8 @@ static __init void setup_topology(void) · 150 unmodified lines | ||
| 151 | 151 | |
| 152 | 152 | static void early_pgm_check_handler(struct pt_regs *regs) |
| 153 | 153 | { |
| 154 | − const struct exception_table_entry *fixup; | |
| 155 | − | |
| 156 | − fixup = s390_search_extables(regs->psw.addr); | |
| 157 | − if (!fixup) | |
| 154 | + if (!fixup_exception(regs)) | |
| 158 | 155 | disabled_wait(); |
| 159 | − regs->psw.addr = extable_fixup(fixup); | |
| 160 | 156 | } |
| 161 | 157 | |
| 162 | 158 | static noinline __init void setup_lowcore_early(void) |
| @@ -465,7 +465,6 @@ static int kprobe_trap_handler(struct pt_regs *regs, int trapnr) · 464 unmodified lines | ||
| 465 | 465 | { |
| 466 | 466 | struct kprobe_ctlblk *kcb = get_kprobe_ctlblk(); |
| 467 | 467 | struct kprobe *p = kprobe_running(); |
| 468 | − const struct exception_table_entry *entry; | |
| 469 | 468 | |
| 470 | 469 | switch(kcb->kprobe_status) { |
| 471 | 470 | case KPROBE_HIT_SS: |
| @@ -487,10 +486,8 @@ static int kprobe_trap_handler(struct pt_regs *regs, int trapnr) · 15 unmodified lines | ||
| 487 | 486 | * In case the user-specified fault handler returned |
| 488 | 487 | * zero, try to fix up. |
| 489 | 488 | */ |
| 490 | − entry = s390_search_extables(regs->psw.addr); | |
| 491 | − if (entry && ex_handle(entry, regs)) | |
| 489 | + if (fixup_exception(regs)) | |
| 492 | 490 | return 1; |
| 493 | − | |
| 494 | 491 | /* |
| 495 | 492 | * fixup_exception() could not handle it, |
| 496 | 493 | * Let do_page_fault() fix it. |
| @@ -54,9 +54,7 @@ void do_report_trap(struct pt_regs *regs, int si_signo, int si_code, char *str) · 53 unmodified lines | ||
| 54 | 54 | force_sig_fault(si_signo, si_code, get_trap_ip(regs)); |
| 55 | 55 | report_user_fault(regs, si_signo, 0); |
| 56 | 56 | } else { |
| 57 | − const struct exception_table_entry *fixup; | |
| 58 | − fixup = s390_search_extables(regs->psw.addr); | |
| 59 | − if (!fixup || !ex_handle(fixup, regs)) | |
| 57 | + if (!fixup_exception(regs)) | |
| 60 | 58 | die(regs, str); |
| 61 | 59 | } |
| 62 | 60 | } |
| @@ -245,16 +243,12 @@ static void space_switch_exception(struct pt_regs *regs) · 182 unmodified lines | ||
| 245 | 243 | |
| 246 | 244 | static void monitor_event_exception(struct pt_regs *regs) |
| 247 | 245 | { |
| 248 | − const struct exception_table_entry *fixup; | |
| 249 | − | |
| 250 | 246 | if (user_mode(regs)) |
| 251 | 247 | return; |
| 252 | 248 | |
| 253 | 249 | switch (report_bug(regs->psw.addr - (regs->int_code >> 16), regs)) { |
| 254 | 250 | case BUG_TRAP_TYPE_NONE: |
| 255 | − fixup = s390_search_extables(regs->psw.addr); | |
| 256 | − if (fixup) | |
| 257 | − ex_handle(fixup, regs); | |
| 251 | + fixup_exception(regs); | |
| 258 | 252 | break; |
| 259 | 253 | case BUG_TRAP_TYPE_WARN: |
| 260 | 254 | break; |
| @@ -14,3 +14,18 @@ const struct exception_table_entry *s390_search_extables(unsigned long addr) · 13 unmodified lines | ||
| 14 | 14 | num = __stop_amode31_ex_table - __start_amode31_ex_table; |
| 15 | 15 | return search_extable(__start_amode31_ex_table, num, addr); |
| 16 | 16 | } |
| 17 | + | |
| 18 | +bool fixup_exception(struct pt_regs *regs) | |
| 19 | +{ | |
| 20 | + const struct exception_table_entry *ex; | |
| 21 | + ex_handler_t handler; | |
| 22 | + | |
| 23 | + ex = s390_search_extables(instruction_pointer(regs)); | |
| 24 | + if (!ex) | |
| 25 | + return false; | |
| 26 | + handler = ex_fixup_handler(ex); | |
| 27 | + if (unlikely(handler)) | |
| 28 | + return handler(ex, regs); | |
| 29 | + regs->psw.addr = extable_fixup(ex); | |
| 30 | + return true; | |
| 31 | +} | |
| @@ -230,13 +230,8 @@ static noinline void do_sigsegv(struct pt_regs *regs, int si_code) · 229 unmodified lines | ||
| 230 | 230 | |
| 231 | 231 | static noinline void do_no_context(struct pt_regs *regs) |
| 232 | 232 | { |
| 233 | − const struct exception_table_entry *fixup; | |
| 234 | − | |
| 235 | − /* Are we prepared to handle this kernel fault? */ | |
| 236 | − fixup = s390_search_extables(regs->psw.addr); | |
| 237 | − if (fixup && ex_handle(fixup, regs)) | |
| 233 | + if (fixup_exception(regs)) | |
| 238 | 234 | return; |
| 239 | − | |
| 240 | 235 | /* |
| 241 | 236 | * Oops. The kernel tried to access some bad page. We'll have to |
| 242 | 237 | * terminate things with extreme prejudice. |