Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * S390 version |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 3 | * Copyright IBM Corp. 1999, 2000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com), |
| 5 | * Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com), |
| 6 | * |
| 7 | * Derived from "arch/i386/kernel/traps.c" |
| 8 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 9 | */ |
| 10 | |
| 11 | /* |
| 12 | * 'Traps.c' handles hardware traps and faults after we have saved some |
| 13 | * state in 'asm.s'. |
| 14 | */ |
Michael Grundy | 4ba069b | 2006-09-20 15:58:39 +0200 | [diff] [blame] | 15 | #include <linux/kprobes.h> |
Heiko Carstens | 1bca09f | 2013-03-14 13:44:25 +0100 | [diff] [blame] | 16 | #include <linux/kdebug.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/ptrace.h> |
| 19 | #include <linux/sched.h> |
| 20 | #include <linux/mm.h> |
Martin Schwidefsky | 8070361 | 2014-10-06 17:53:53 +0200 | [diff] [blame] | 21 | #include <linux/slab.h> |
| 22 | #include <asm/switch_to.h> |
Heiko Carstens | a806170 | 2008-04-17 07:46:26 +0200 | [diff] [blame] | 23 | #include "entry.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
Heiko Carstens | 02834ee | 2011-12-27 11:27:31 +0100 | [diff] [blame] | 25 | int show_unhandled_signals = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Martin Schwidefsky | d35339a | 2012-07-31 11:03:04 +0200 | [diff] [blame] | 27 | static inline void __user *get_trap_ip(struct pt_regs *regs) |
| 28 | { |
| 29 | #ifdef CONFIG_64BIT |
| 30 | unsigned long address; |
| 31 | |
| 32 | if (regs->int_code & 0x200) |
| 33 | address = *(unsigned long *)(current->thread.trap_tdb + 24); |
| 34 | else |
| 35 | address = regs->psw.addr; |
| 36 | return (void __user *) |
| 37 | ((address - (regs->int_code >> 16)) & PSW_ADDR_INSN); |
| 38 | #else |
| 39 | return (void __user *) |
| 40 | ((regs->psw.addr - (regs->int_code >> 16)) & PSW_ADDR_INSN); |
| 41 | #endif |
| 42 | } |
| 43 | |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 44 | static inline void report_user_fault(struct pt_regs *regs, int signr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | { |
Heiko Carstens | ab3c68e | 2010-05-17 10:00:21 +0200 | [diff] [blame] | 46 | if ((task_pid_nr(current) > 1) && !show_unhandled_signals) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | return; |
Heiko Carstens | ab3c68e | 2010-05-17 10:00:21 +0200 | [diff] [blame] | 48 | if (!unhandled_signal(current, signr)) |
| 49 | return; |
| 50 | if (!printk_ratelimit()) |
| 51 | return; |
Heiko Carstens | 413d404 | 2014-11-19 13:31:08 +0100 | [diff] [blame] | 52 | printk("User process fault: interruption code %04x ilc:%d ", |
| 53 | regs->int_code & 0xffff, regs->int_code >> 17); |
Heiko Carstens | ab3c68e | 2010-05-17 10:00:21 +0200 | [diff] [blame] | 54 | print_vma_addr("in ", regs->psw.addr & PSW_ADDR_INSN); |
| 55 | printk("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | show_regs(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Heiko Carstens | c0007f1 | 2007-04-27 16:01:42 +0200 | [diff] [blame] | 59 | int is_valid_bugaddr(unsigned long addr) |
| 60 | { |
| 61 | return 1; |
| 62 | } |
| 63 | |
Jan Willeke | 2a0a5b2 | 2014-09-22 16:39:06 +0200 | [diff] [blame] | 64 | void do_report_trap(struct pt_regs *regs, int si_signo, int si_code, char *str) |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 65 | { |
| 66 | siginfo_t info; |
| 67 | |
Heiko Carstens | 7d25617 | 2012-07-27 10:31:12 +0200 | [diff] [blame] | 68 | if (user_mode(regs)) { |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 69 | info.si_signo = si_signo; |
| 70 | info.si_errno = 0; |
| 71 | info.si_code = si_code; |
Martin Schwidefsky | d35339a | 2012-07-31 11:03:04 +0200 | [diff] [blame] | 72 | info.si_addr = get_trap_ip(regs); |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 73 | force_sig_info(si_signo, &info, current); |
| 74 | report_user_fault(regs, si_signo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | } else { |
| 76 | const struct exception_table_entry *fixup; |
| 77 | fixup = search_exception_tables(regs->psw.addr & PSW_ADDR_INSN); |
| 78 | if (fixup) |
Heiko Carstens | eb608fb | 2012-09-05 13:26:11 +0200 | [diff] [blame] | 79 | regs->psw.addr = extable_fixup(fixup) | PSW_ADDR_AMODE; |
Heiko Carstens | c0007f1 | 2007-04-27 16:01:42 +0200 | [diff] [blame] | 80 | else { |
| 81 | enum bug_trap_type btt; |
| 82 | |
Heiko Carstens | 608e261 | 2007-07-15 23:41:39 -0700 | [diff] [blame] | 83 | btt = report_bug(regs->psw.addr & PSW_ADDR_INSN, regs); |
Heiko Carstens | c0007f1 | 2007-04-27 16:01:42 +0200 | [diff] [blame] | 84 | if (btt == BUG_TRAP_TYPE_WARN) |
| 85 | return; |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 86 | die(regs, str); |
Heiko Carstens | c0007f1 | 2007-04-27 16:01:42 +0200 | [diff] [blame] | 87 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | } |
| 89 | } |
| 90 | |
Heiko Carstens | 7a5388d | 2014-10-22 12:42:38 +0200 | [diff] [blame] | 91 | static void do_trap(struct pt_regs *regs, int si_signo, int si_code, char *str) |
Jan Willeke | 2a0a5b2 | 2014-09-22 16:39:06 +0200 | [diff] [blame] | 92 | { |
| 93 | if (notify_die(DIE_TRAP, str, regs, 0, |
| 94 | regs->int_code, si_signo) == NOTIFY_STOP) |
| 95 | return; |
| 96 | do_report_trap(regs, si_signo, si_code, str); |
| 97 | } |
Heiko Carstens | 7a5388d | 2014-10-22 12:42:38 +0200 | [diff] [blame] | 98 | NOKPROBE_SYMBOL(do_trap); |
Jan Willeke | 2a0a5b2 | 2014-09-22 16:39:06 +0200 | [diff] [blame] | 99 | |
Heiko Carstens | 7a5388d | 2014-10-22 12:42:38 +0200 | [diff] [blame] | 100 | void do_per_trap(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | { |
Martin Schwidefsky | 73b7d40 | 2011-07-24 10:48:33 +0200 | [diff] [blame] | 102 | siginfo_t info; |
| 103 | |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 104 | if (notify_die(DIE_SSTEP, "sstep", regs, 0, 0, SIGTRAP) == NOTIFY_STOP) |
Michael Grundy | 4ba069b | 2006-09-20 15:58:39 +0200 | [diff] [blame] | 105 | return; |
Martin Schwidefsky | 73b7d40 | 2011-07-24 10:48:33 +0200 | [diff] [blame] | 106 | if (!current->ptrace) |
| 107 | return; |
| 108 | info.si_signo = SIGTRAP; |
| 109 | info.si_errno = 0; |
| 110 | info.si_code = TRAP_HWBKPT; |
Martin Schwidefsky | 3c52e49 | 2011-10-30 15:17:15 +0100 | [diff] [blame] | 111 | info.si_addr = |
| 112 | (void __force __user *) current->thread.per_event.address; |
Martin Schwidefsky | 73b7d40 | 2011-07-24 10:48:33 +0200 | [diff] [blame] | 113 | force_sig_info(SIGTRAP, &info, current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } |
Heiko Carstens | 7a5388d | 2014-10-22 12:42:38 +0200 | [diff] [blame] | 115 | NOKPROBE_SYMBOL(do_per_trap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
Heiko Carstens | b01a37a | 2012-10-18 18:10:06 +0200 | [diff] [blame] | 117 | void default_trap_handler(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | { |
Heiko Carstens | 7d25617 | 2012-07-27 10:31:12 +0200 | [diff] [blame] | 119 | if (user_mode(regs)) { |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 120 | report_user_fault(regs, SIGSEGV); |
Heiko Carstens | 6ea5096 | 2010-05-17 10:00:13 +0200 | [diff] [blame] | 121 | do_exit(SIGSEGV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | } else |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 123 | die(regs, "Unknown program exception"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Martin Schwidefsky | 1e54622 | 2010-10-25 16:10:37 +0200 | [diff] [blame] | 126 | #define DO_ERROR_INFO(name, signr, sicode, str) \ |
Heiko Carstens | b01a37a | 2012-10-18 18:10:06 +0200 | [diff] [blame] | 127 | void name(struct pt_regs *regs) \ |
| 128 | { \ |
| 129 | do_trap(regs, signr, sicode, str); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Martin Schwidefsky | 1e54622 | 2010-10-25 16:10:37 +0200 | [diff] [blame] | 132 | DO_ERROR_INFO(addressing_exception, SIGILL, ILL_ILLADR, |
| 133 | "addressing exception") |
| 134 | DO_ERROR_INFO(execute_exception, SIGILL, ILL_ILLOPN, |
| 135 | "execute exception") |
| 136 | DO_ERROR_INFO(divide_exception, SIGFPE, FPE_INTDIV, |
| 137 | "fixpoint divide exception") |
| 138 | DO_ERROR_INFO(overflow_exception, SIGFPE, FPE_INTOVF, |
| 139 | "fixpoint overflow exception") |
| 140 | DO_ERROR_INFO(hfp_overflow_exception, SIGFPE, FPE_FLTOVF, |
| 141 | "HFP overflow exception") |
| 142 | DO_ERROR_INFO(hfp_underflow_exception, SIGFPE, FPE_FLTUND, |
| 143 | "HFP underflow exception") |
| 144 | DO_ERROR_INFO(hfp_significance_exception, SIGFPE, FPE_FLTRES, |
| 145 | "HFP significance exception") |
| 146 | DO_ERROR_INFO(hfp_divide_exception, SIGFPE, FPE_FLTDIV, |
| 147 | "HFP divide exception") |
| 148 | DO_ERROR_INFO(hfp_sqrt_exception, SIGFPE, FPE_FLTINV, |
| 149 | "HFP square root exception") |
| 150 | DO_ERROR_INFO(operand_exception, SIGILL, ILL_ILLOPN, |
| 151 | "operand exception") |
| 152 | DO_ERROR_INFO(privileged_op, SIGILL, ILL_PRVOPC, |
| 153 | "privileged operation") |
| 154 | DO_ERROR_INFO(special_op_exception, SIGILL, ILL_ILLOPN, |
| 155 | "special operation exception") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
Martin Schwidefsky | d35339a | 2012-07-31 11:03:04 +0200 | [diff] [blame] | 157 | #ifdef CONFIG_64BIT |
| 158 | DO_ERROR_INFO(transaction_exception, SIGILL, ILL_ILLOPN, |
| 159 | "transaction constraint exception") |
| 160 | #endif |
| 161 | |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 162 | static inline void do_fp_trap(struct pt_regs *regs, int fpc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | { |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 164 | int si_code = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | /* FPC[2] is Data Exception Code */ |
| 166 | if ((fpc & 0x00000300) == 0) { |
| 167 | /* bits 6 and 7 of DXC are 0 iff IEEE exception */ |
| 168 | if (fpc & 0x8000) /* invalid fp operation */ |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 169 | si_code = FPE_FLTINV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | else if (fpc & 0x4000) /* div by 0 */ |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 171 | si_code = FPE_FLTDIV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | else if (fpc & 0x2000) /* overflow */ |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 173 | si_code = FPE_FLTOVF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | else if (fpc & 0x1000) /* underflow */ |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 175 | si_code = FPE_FLTUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | else if (fpc & 0x0800) /* inexact */ |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 177 | si_code = FPE_FLTRES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | } |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 179 | do_trap(regs, SIGFPE, si_code, "floating point exception"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Heiko Carstens | e56da34 | 2014-11-19 14:05:52 +0100 | [diff] [blame] | 182 | void translation_exception(struct pt_regs *regs) |
| 183 | { |
| 184 | /* May never happen. */ |
| 185 | die(regs, "Translation exception"); |
| 186 | } |
| 187 | |
Heiko Carstens | 7a5388d | 2014-10-22 12:42:38 +0200 | [diff] [blame] | 188 | void illegal_op(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | { |
| 190 | siginfo_t info; |
| 191 | __u8 opcode[6]; |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 192 | __u16 __user *location; |
Jan Willeke | 2a0a5b2 | 2014-09-22 16:39:06 +0200 | [diff] [blame] | 193 | int is_uprobe_insn = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | int signal = 0; |
| 195 | |
Martin Schwidefsky | d35339a | 2012-07-31 11:03:04 +0200 | [diff] [blame] | 196 | location = get_trap_ip(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
Heiko Carstens | 7d25617 | 2012-07-27 10:31:12 +0200 | [diff] [blame] | 198 | if (user_mode(regs)) { |
Heiko Carstens | 12bae23 | 2006-10-27 12:39:22 +0200 | [diff] [blame] | 199 | if (get_user(*((__u16 *) opcode), (__u16 __user *) location)) |
| 200 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | if (*((__u16 *) opcode) == S390_BREAKPOINT_U16) { |
Martin Schwidefsky | 73b7d40 | 2011-07-24 10:48:33 +0200 | [diff] [blame] | 202 | if (current->ptrace) { |
| 203 | info.si_signo = SIGTRAP; |
| 204 | info.si_errno = 0; |
| 205 | info.si_code = TRAP_BRKPT; |
| 206 | info.si_addr = location; |
| 207 | force_sig_info(SIGTRAP, &info, current); |
| 208 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | signal = SIGILL; |
Jan Willeke | 2a0a5b2 | 2014-09-22 16:39:06 +0200 | [diff] [blame] | 210 | #ifdef CONFIG_UPROBES |
| 211 | } else if (*((__u16 *) opcode) == UPROBE_SWBP_INSN) { |
| 212 | is_uprobe_insn = 1; |
| 213 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | #ifdef CONFIG_MATHEMU |
| 215 | } else if (opcode[0] == 0xb3) { |
Heiko Carstens | 12bae23 | 2006-10-27 12:39:22 +0200 | [diff] [blame] | 216 | if (get_user(*((__u16 *) (opcode+2)), location+1)) |
| 217 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | signal = math_emu_b3(opcode, regs); |
| 219 | } else if (opcode[0] == 0xed) { |
Heiko Carstens | 12bae23 | 2006-10-27 12:39:22 +0200 | [diff] [blame] | 220 | if (get_user(*((__u32 *) (opcode+2)), |
| 221 | (__u32 __user *)(location+1))) |
| 222 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | signal = math_emu_ed(opcode, regs); |
| 224 | } else if (*((__u16 *) opcode) == 0xb299) { |
Heiko Carstens | 12bae23 | 2006-10-27 12:39:22 +0200 | [diff] [blame] | 225 | if (get_user(*((__u16 *) (opcode+2)), location+1)) |
| 226 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | signal = math_emu_srnm(opcode, regs); |
| 228 | } else if (*((__u16 *) opcode) == 0xb29c) { |
Heiko Carstens | 12bae23 | 2006-10-27 12:39:22 +0200 | [diff] [blame] | 229 | if (get_user(*((__u16 *) (opcode+2)), location+1)) |
| 230 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | signal = math_emu_stfpc(opcode, regs); |
| 232 | } else if (*((__u16 *) opcode) == 0xb29d) { |
Heiko Carstens | 12bae23 | 2006-10-27 12:39:22 +0200 | [diff] [blame] | 233 | if (get_user(*((__u16 *) (opcode+2)), location+1)) |
| 234 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | signal = math_emu_lfpc(opcode, regs); |
| 236 | #endif |
| 237 | } else |
| 238 | signal = SIGILL; |
Jan Willeke | 2a0a5b2 | 2014-09-22 16:39:06 +0200 | [diff] [blame] | 239 | } |
| 240 | /* |
| 241 | * We got either an illegal op in kernel mode, or user space trapped |
| 242 | * on a uprobes illegal instruction. See if kprobes or uprobes picks |
| 243 | * it up. If not, SIGILL. |
| 244 | */ |
| 245 | if (is_uprobe_insn || !user_mode(regs)) { |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 246 | if (notify_die(DIE_BPT, "bpt", regs, 0, |
Heiko Carstens | 35df8d5 | 2007-02-05 21:17:29 +0100 | [diff] [blame] | 247 | 3, SIGTRAP) != NOTIFY_STOP) |
| 248 | signal = SIGILL; |
| 249 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
| 251 | #ifdef CONFIG_MATHEMU |
| 252 | if (signal == SIGFPE) |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 253 | do_fp_trap(regs, current->thread.fp_regs.fpc); |
| 254 | else if (signal == SIGSEGV) |
| 255 | do_trap(regs, signal, SEGV_MAPERR, "user address fault"); |
| 256 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | #endif |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 258 | if (signal) |
| 259 | do_trap(regs, signal, ILL_ILLOPC, "illegal operation"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | } |
Heiko Carstens | 7a5388d | 2014-10-22 12:42:38 +0200 | [diff] [blame] | 261 | NOKPROBE_SYMBOL(illegal_op); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
| 263 | #ifdef CONFIG_MATHEMU |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 264 | void specification_exception(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | { |
| 266 | __u8 opcode[6]; |
Al Viro | 5a42b81 | 2006-10-09 20:28:03 +0100 | [diff] [blame] | 267 | __u16 __user *location = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | int signal = 0; |
| 269 | |
Martin Schwidefsky | d35339a | 2012-07-31 11:03:04 +0200 | [diff] [blame] | 270 | location = (__u16 __user *) get_trap_ip(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
Heiko Carstens | 7d25617 | 2012-07-27 10:31:12 +0200 | [diff] [blame] | 272 | if (user_mode(regs)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | get_user(*((__u16 *) opcode), location); |
| 274 | switch (opcode[0]) { |
| 275 | case 0x28: /* LDR Rx,Ry */ |
| 276 | signal = math_emu_ldr(opcode); |
| 277 | break; |
| 278 | case 0x38: /* LER Rx,Ry */ |
| 279 | signal = math_emu_ler(opcode); |
| 280 | break; |
| 281 | case 0x60: /* STD R,D(X,B) */ |
| 282 | get_user(*((__u16 *) (opcode+2)), location+1); |
| 283 | signal = math_emu_std(opcode, regs); |
| 284 | break; |
| 285 | case 0x68: /* LD R,D(X,B) */ |
| 286 | get_user(*((__u16 *) (opcode+2)), location+1); |
| 287 | signal = math_emu_ld(opcode, regs); |
| 288 | break; |
| 289 | case 0x70: /* STE R,D(X,B) */ |
| 290 | get_user(*((__u16 *) (opcode+2)), location+1); |
| 291 | signal = math_emu_ste(opcode, regs); |
| 292 | break; |
| 293 | case 0x78: /* LE R,D(X,B) */ |
| 294 | get_user(*((__u16 *) (opcode+2)), location+1); |
| 295 | signal = math_emu_le(opcode, regs); |
| 296 | break; |
| 297 | default: |
| 298 | signal = SIGILL; |
| 299 | break; |
| 300 | } |
| 301 | } else |
| 302 | signal = SIGILL; |
| 303 | |
| 304 | if (signal == SIGFPE) |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 305 | do_fp_trap(regs, current->thread.fp_regs.fpc); |
| 306 | else if (signal) |
| 307 | do_trap(regs, signal, ILL_ILLOPN, "specification exception"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | } |
| 309 | #else |
Martin Schwidefsky | 1e54622 | 2010-10-25 16:10:37 +0200 | [diff] [blame] | 310 | DO_ERROR_INFO(specification_exception, SIGILL, ILL_ILLOPN, |
| 311 | "specification exception"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | #endif |
| 313 | |
Martin Schwidefsky | 8070361 | 2014-10-06 17:53:53 +0200 | [diff] [blame] | 314 | #ifdef CONFIG_64BIT |
| 315 | int alloc_vector_registers(struct task_struct *tsk) |
| 316 | { |
| 317 | __vector128 *vxrs; |
| 318 | int i; |
| 319 | |
| 320 | /* Allocate vector register save area. */ |
| 321 | vxrs = kzalloc(sizeof(__vector128) * __NUM_VXRS, |
| 322 | GFP_KERNEL|__GFP_REPEAT); |
| 323 | if (!vxrs) |
| 324 | return -ENOMEM; |
| 325 | preempt_disable(); |
| 326 | if (tsk == current) |
| 327 | save_fp_regs(tsk->thread.fp_regs.fprs); |
| 328 | /* Copy the 16 floating point registers */ |
| 329 | for (i = 0; i < 16; i++) |
| 330 | *(freg_t *) &vxrs[i] = tsk->thread.fp_regs.fprs[i]; |
| 331 | tsk->thread.vxrs = vxrs; |
| 332 | if (tsk == current) { |
| 333 | __ctl_set_bit(0, 17); |
| 334 | restore_vx_regs(vxrs); |
| 335 | } |
| 336 | preempt_enable(); |
| 337 | return 0; |
| 338 | } |
| 339 | |
| 340 | void vector_exception(struct pt_regs *regs) |
| 341 | { |
| 342 | int si_code, vic; |
| 343 | |
| 344 | if (!MACHINE_HAS_VX) { |
| 345 | do_trap(regs, SIGILL, ILL_ILLOPN, "illegal operation"); |
| 346 | return; |
| 347 | } |
| 348 | |
| 349 | /* get vector interrupt code from fpc */ |
| 350 | asm volatile("stfpc %0" : "=m" (current->thread.fp_regs.fpc)); |
| 351 | vic = (current->thread.fp_regs.fpc & 0xf00) >> 8; |
| 352 | switch (vic) { |
| 353 | case 1: /* invalid vector operation */ |
| 354 | si_code = FPE_FLTINV; |
| 355 | break; |
| 356 | case 2: /* division by zero */ |
| 357 | si_code = FPE_FLTDIV; |
| 358 | break; |
| 359 | case 3: /* overflow */ |
| 360 | si_code = FPE_FLTOVF; |
| 361 | break; |
| 362 | case 4: /* underflow */ |
| 363 | si_code = FPE_FLTUND; |
| 364 | break; |
| 365 | case 5: /* inexact */ |
| 366 | si_code = FPE_FLTRES; |
| 367 | break; |
| 368 | default: /* unknown cause */ |
| 369 | si_code = 0; |
| 370 | } |
| 371 | do_trap(regs, SIGFPE, si_code, "vector exception"); |
| 372 | } |
| 373 | |
| 374 | static int __init disable_vector_extension(char *str) |
| 375 | { |
| 376 | S390_lowcore.machine_flags &= ~MACHINE_FLAG_VX; |
| 377 | return 1; |
| 378 | } |
| 379 | __setup("novx", disable_vector_extension); |
| 380 | #endif |
| 381 | |
Heiko Carstens | b01a37a | 2012-10-18 18:10:06 +0200 | [diff] [blame] | 382 | void data_exception(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | { |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 384 | __u16 __user *location; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | int signal = 0; |
| 386 | |
Martin Schwidefsky | d35339a | 2012-07-31 11:03:04 +0200 | [diff] [blame] | 387 | location = get_trap_ip(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | |
| 389 | if (MACHINE_HAS_IEEE) |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 390 | asm volatile("stfpc %0" : "=m" (current->thread.fp_regs.fpc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | |
| 392 | #ifdef CONFIG_MATHEMU |
Heiko Carstens | 7d25617 | 2012-07-27 10:31:12 +0200 | [diff] [blame] | 393 | else if (user_mode(regs)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | __u8 opcode[6]; |
| 395 | get_user(*((__u16 *) opcode), location); |
| 396 | switch (opcode[0]) { |
| 397 | case 0x28: /* LDR Rx,Ry */ |
| 398 | signal = math_emu_ldr(opcode); |
| 399 | break; |
| 400 | case 0x38: /* LER Rx,Ry */ |
| 401 | signal = math_emu_ler(opcode); |
| 402 | break; |
| 403 | case 0x60: /* STD R,D(X,B) */ |
| 404 | get_user(*((__u16 *) (opcode+2)), location+1); |
| 405 | signal = math_emu_std(opcode, regs); |
| 406 | break; |
| 407 | case 0x68: /* LD R,D(X,B) */ |
| 408 | get_user(*((__u16 *) (opcode+2)), location+1); |
| 409 | signal = math_emu_ld(opcode, regs); |
| 410 | break; |
| 411 | case 0x70: /* STE R,D(X,B) */ |
| 412 | get_user(*((__u16 *) (opcode+2)), location+1); |
| 413 | signal = math_emu_ste(opcode, regs); |
| 414 | break; |
| 415 | case 0x78: /* LE R,D(X,B) */ |
| 416 | get_user(*((__u16 *) (opcode+2)), location+1); |
| 417 | signal = math_emu_le(opcode, regs); |
| 418 | break; |
| 419 | case 0xb3: |
| 420 | get_user(*((__u16 *) (opcode+2)), location+1); |
| 421 | signal = math_emu_b3(opcode, regs); |
| 422 | break; |
| 423 | case 0xed: |
| 424 | get_user(*((__u32 *) (opcode+2)), |
Al Viro | 5a42b81 | 2006-10-09 20:28:03 +0100 | [diff] [blame] | 425 | (__u32 __user *)(location+1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | signal = math_emu_ed(opcode, regs); |
| 427 | break; |
| 428 | case 0xb2: |
| 429 | if (opcode[1] == 0x99) { |
| 430 | get_user(*((__u16 *) (opcode+2)), location+1); |
| 431 | signal = math_emu_srnm(opcode, regs); |
| 432 | } else if (opcode[1] == 0x9c) { |
| 433 | get_user(*((__u16 *) (opcode+2)), location+1); |
| 434 | signal = math_emu_stfpc(opcode, regs); |
| 435 | } else if (opcode[1] == 0x9d) { |
| 436 | get_user(*((__u16 *) (opcode+2)), location+1); |
| 437 | signal = math_emu_lfpc(opcode, regs); |
| 438 | } else |
| 439 | signal = SIGILL; |
| 440 | break; |
| 441 | default: |
| 442 | signal = SIGILL; |
| 443 | break; |
| 444 | } |
| 445 | } |
| 446 | #endif |
Martin Schwidefsky | 8070361 | 2014-10-06 17:53:53 +0200 | [diff] [blame] | 447 | #ifdef CONFIG_64BIT |
| 448 | /* Check for vector register enablement */ |
| 449 | if (MACHINE_HAS_VX && !current->thread.vxrs && |
| 450 | (current->thread.fp_regs.fpc & FPC_DXC_MASK) == 0xfe00) { |
| 451 | alloc_vector_registers(current); |
| 452 | /* Vector data exception is suppressing, rewind psw. */ |
| 453 | regs->psw.addr = __rewind_psw(regs->psw, regs->int_code >> 16); |
| 454 | clear_pt_regs_flag(regs, PIF_PER_TRAP); |
| 455 | return; |
| 456 | } |
| 457 | #endif |
| 458 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | if (current->thread.fp_regs.fpc & FPC_DXC_MASK) |
| 460 | signal = SIGFPE; |
| 461 | else |
| 462 | signal = SIGILL; |
| 463 | if (signal == SIGFPE) |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 464 | do_fp_trap(regs, current->thread.fp_regs.fpc); |
| 465 | else if (signal) |
| 466 | do_trap(regs, signal, ILL_ILLOPN, "data exception"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Heiko Carstens | b01a37a | 2012-10-18 18:10:06 +0200 | [diff] [blame] | 469 | void space_switch_exception(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | /* Set user psw back to home space mode. */ |
Heiko Carstens | 7d25617 | 2012-07-27 10:31:12 +0200 | [diff] [blame] | 472 | if (user_mode(regs)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | regs->psw.mask |= PSW_ASC_HOME; |
| 474 | /* Send SIGILL. */ |
Martin Schwidefsky | aa33c8c | 2011-12-27 11:27:18 +0100 | [diff] [blame] | 475 | do_trap(regs, SIGILL, ILL_PRVOPC, "space switch event"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | } |
| 477 | |
Heiko Carstens | 7a5388d | 2014-10-22 12:42:38 +0200 | [diff] [blame] | 478 | void kernel_stack_overflow(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | { |
Heiko Carstens | 77eb65c | 2005-06-21 17:16:28 -0700 | [diff] [blame] | 480 | bust_spinlocks(1); |
| 481 | printk("Kernel stack overflow.\n"); |
| 482 | show_regs(regs); |
| 483 | bust_spinlocks(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | panic("Corrupt kernel stack, can't continue."); |
| 485 | } |
Heiko Carstens | 7a5388d | 2014-10-22 12:42:38 +0200 | [diff] [blame] | 486 | NOKPROBE_SYMBOL(kernel_stack_overflow); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | void __init trap_init(void) |
| 489 | { |
Heiko Carstens | f3e1a27 | 2011-01-05 12:48:00 +0100 | [diff] [blame] | 490 | local_mcck_enable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | } |