]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - arch/s390/kernel/traps.c
Merge tag 'efi-urgent' of git://git.kernel.org/pub/scm/linux/kernel/git/efi/efi into...
[mirror_ubuntu-artful-kernel.git] / arch / s390 / kernel / traps.c
CommitLineData
1da177e4 1/*
1da177e4 2 * S390 version
a53c8fab 3 * Copyright IBM Corp. 1999, 2000
1da177e4
LT
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 */
1bca09f7
HC
15#include <linux/kprobes.h>
16#include <linux/kdebug.h>
dcc096c5 17#include <linux/extable.h>
73b7d40f 18#include <linux/ptrace.h>
1bca09f7 19#include <linux/sched.h>
b17b0153 20#include <linux/sched/debug.h>
1da177e4 21#include <linux/mm.h>
80703617 22#include <linux/slab.h>
7c0f6ba6 23#include <linux/uaccess.h>
b0753902 24#include <asm/fpu/api.h>
a806170e 25#include "entry.h"
1da177e4 26
d35339a4
MS
27static inline void __user *get_trap_ip(struct pt_regs *regs)
28{
d35339a4
MS
29 unsigned long address;
30
31 if (regs->int_code & 0x200)
32 address = *(unsigned long *)(current->thread.trap_tdb + 24);
33 else
34 address = regs->psw.addr;
9cb1ccec 35 return (void __user *) (address - (regs->int_code >> 16));
d35339a4
MS
36}
37
c0007f1a
HC
38int is_valid_bugaddr(unsigned long addr)
39{
40 return 1;
41}
42
2a0a5b22 43void do_report_trap(struct pt_regs *regs, int si_signo, int si_code, char *str)
aa33c8cb
MS
44{
45 siginfo_t info;
46
7d256175 47 if (user_mode(regs)) {
aa33c8cb
MS
48 info.si_signo = si_signo;
49 info.si_errno = 0;
50 info.si_code = si_code;
d35339a4 51 info.si_addr = get_trap_ip(regs);
aa33c8cb 52 force_sig_info(si_signo, &info, current);
5d7eccec 53 report_user_fault(regs, si_signo, 0);
1da177e4
LT
54 } else {
55 const struct exception_table_entry *fixup;
9cb1ccec 56 fixup = search_exception_tables(regs->psw.addr);
1da177e4 57 if (fixup)
fecc868a 58 regs->psw.addr = extable_fixup(fixup);
c0007f1a
HC
59 else {
60 enum bug_trap_type btt;
61
9cb1ccec 62 btt = report_bug(regs->psw.addr, regs);
c0007f1a
HC
63 if (btt == BUG_TRAP_TYPE_WARN)
64 return;
aa33c8cb 65 die(regs, str);
c0007f1a 66 }
1da177e4
LT
67 }
68}
69
7a5388de 70static void do_trap(struct pt_regs *regs, int si_signo, int si_code, char *str)
2a0a5b22
JW
71{
72 if (notify_die(DIE_TRAP, str, regs, 0,
73 regs->int_code, si_signo) == NOTIFY_STOP)
74 return;
75 do_report_trap(regs, si_signo, si_code, str);
76}
7a5388de 77NOKPROBE_SYMBOL(do_trap);
2a0a5b22 78
7a5388de 79void do_per_trap(struct pt_regs *regs)
1da177e4 80{
73b7d40f
MS
81 siginfo_t info;
82
5e9a2692 83 if (notify_die(DIE_SSTEP, "sstep", regs, 0, 0, SIGTRAP) == NOTIFY_STOP)
4ba069b8 84 return;
73b7d40f
MS
85 if (!current->ptrace)
86 return;
87 info.si_signo = SIGTRAP;
88 info.si_errno = 0;
89 info.si_code = TRAP_HWBKPT;
3c52e49d
MS
90 info.si_addr =
91 (void __force __user *) current->thread.per_event.address;
73b7d40f 92 force_sig_info(SIGTRAP, &info, current);
1da177e4 93}
7a5388de 94NOKPROBE_SYMBOL(do_per_trap);
1da177e4 95
b01a37a7 96void default_trap_handler(struct pt_regs *regs)
1da177e4 97{
7d256175 98 if (user_mode(regs)) {
5d7eccec 99 report_user_fault(regs, SIGSEGV, 0);
6ea50968 100 do_exit(SIGSEGV);
1da177e4 101 } else
aa33c8cb 102 die(regs, "Unknown program exception");
1da177e4
LT
103}
104
1e54622e 105#define DO_ERROR_INFO(name, signr, sicode, str) \
b01a37a7
HC
106void name(struct pt_regs *regs) \
107{ \
108 do_trap(regs, signr, sicode, str); \
1da177e4
LT
109}
110
1e54622e
MS
111DO_ERROR_INFO(addressing_exception, SIGILL, ILL_ILLADR,
112 "addressing exception")
113DO_ERROR_INFO(execute_exception, SIGILL, ILL_ILLOPN,
114 "execute exception")
115DO_ERROR_INFO(divide_exception, SIGFPE, FPE_INTDIV,
116 "fixpoint divide exception")
117DO_ERROR_INFO(overflow_exception, SIGFPE, FPE_INTOVF,
118 "fixpoint overflow exception")
119DO_ERROR_INFO(hfp_overflow_exception, SIGFPE, FPE_FLTOVF,
120 "HFP overflow exception")
121DO_ERROR_INFO(hfp_underflow_exception, SIGFPE, FPE_FLTUND,
122 "HFP underflow exception")
123DO_ERROR_INFO(hfp_significance_exception, SIGFPE, FPE_FLTRES,
124 "HFP significance exception")
125DO_ERROR_INFO(hfp_divide_exception, SIGFPE, FPE_FLTDIV,
126 "HFP divide exception")
127DO_ERROR_INFO(hfp_sqrt_exception, SIGFPE, FPE_FLTINV,
128 "HFP square root exception")
129DO_ERROR_INFO(operand_exception, SIGILL, ILL_ILLOPN,
130 "operand exception")
131DO_ERROR_INFO(privileged_op, SIGILL, ILL_PRVOPC,
132 "privileged operation")
133DO_ERROR_INFO(special_op_exception, SIGILL, ILL_ILLOPN,
134 "special operation exception")
d35339a4
MS
135DO_ERROR_INFO(transaction_exception, SIGILL, ILL_ILLOPN,
136 "transaction constraint exception")
d35339a4 137
9977e886 138static inline void do_fp_trap(struct pt_regs *regs, __u32 fpc)
1da177e4 139{
aa33c8cb 140 int si_code = 0;
1da177e4
LT
141 /* FPC[2] is Data Exception Code */
142 if ((fpc & 0x00000300) == 0) {
143 /* bits 6 and 7 of DXC are 0 iff IEEE exception */
144 if (fpc & 0x8000) /* invalid fp operation */
aa33c8cb 145 si_code = FPE_FLTINV;
1da177e4 146 else if (fpc & 0x4000) /* div by 0 */
aa33c8cb 147 si_code = FPE_FLTDIV;
1da177e4 148 else if (fpc & 0x2000) /* overflow */
aa33c8cb 149 si_code = FPE_FLTOVF;
1da177e4 150 else if (fpc & 0x1000) /* underflow */
aa33c8cb 151 si_code = FPE_FLTUND;
1da177e4 152 else if (fpc & 0x0800) /* inexact */
aa33c8cb 153 si_code = FPE_FLTRES;
1da177e4 154 }
aa33c8cb 155 do_trap(regs, SIGFPE, si_code, "floating point exception");
1da177e4
LT
156}
157
e56da345
HC
158void translation_exception(struct pt_regs *regs)
159{
160 /* May never happen. */
e1d12d70 161 panic("Translation exception");
e56da345
HC
162}
163
7a5388de 164void illegal_op(struct pt_regs *regs)
1da177e4
LT
165{
166 siginfo_t info;
167 __u8 opcode[6];
d2c993d8 168 __u16 __user *location;
2a0a5b22 169 int is_uprobe_insn = 0;
1da177e4
LT
170 int signal = 0;
171
d35339a4 172 location = get_trap_ip(regs);
1da177e4 173
7d256175 174 if (user_mode(regs)) {
12bae235
HC
175 if (get_user(*((__u16 *) opcode), (__u16 __user *) location))
176 return;
1da177e4 177 if (*((__u16 *) opcode) == S390_BREAKPOINT_U16) {
73b7d40f
MS
178 if (current->ptrace) {
179 info.si_signo = SIGTRAP;
180 info.si_errno = 0;
181 info.si_code = TRAP_BRKPT;
182 info.si_addr = location;
183 force_sig_info(SIGTRAP, &info, current);
184 } else
1da177e4 185 signal = SIGILL;
2a0a5b22
JW
186#ifdef CONFIG_UPROBES
187 } else if (*((__u16 *) opcode) == UPROBE_SWBP_INSN) {
188 is_uprobe_insn = 1;
1da177e4
LT
189#endif
190 } else
191 signal = SIGILL;
2a0a5b22
JW
192 }
193 /*
194 * We got either an illegal op in kernel mode, or user space trapped
195 * on a uprobes illegal instruction. See if kprobes or uprobes picks
196 * it up. If not, SIGILL.
197 */
198 if (is_uprobe_insn || !user_mode(regs)) {
aa33c8cb 199 if (notify_die(DIE_BPT, "bpt", regs, 0,
35df8d53
HC
200 3, SIGTRAP) != NOTIFY_STOP)
201 signal = SIGILL;
202 }
aa33c8cb
MS
203 if (signal)
204 do_trap(regs, signal, ILL_ILLOPC, "illegal operation");
1da177e4 205}
7a5388de 206NOKPROBE_SYMBOL(illegal_op);
1da177e4 207
1e54622e
MS
208DO_ERROR_INFO(specification_exception, SIGILL, ILL_ILLOPN,
209 "specification exception");
1da177e4 210
80703617
MS
211void vector_exception(struct pt_regs *regs)
212{
213 int si_code, vic;
214
215 if (!MACHINE_HAS_VX) {
216 do_trap(regs, SIGILL, ILL_ILLOPN, "illegal operation");
217 return;
218 }
219
220 /* get vector interrupt code from fpc */
d0164ee2 221 save_fpu_regs();
904818e2 222 vic = (current->thread.fpu.fpc & 0xf00) >> 8;
80703617
MS
223 switch (vic) {
224 case 1: /* invalid vector operation */
225 si_code = FPE_FLTINV;
226 break;
227 case 2: /* division by zero */
228 si_code = FPE_FLTDIV;
229 break;
230 case 3: /* overflow */
231 si_code = FPE_FLTOVF;
232 break;
233 case 4: /* underflow */
234 si_code = FPE_FLTUND;
235 break;
236 case 5: /* inexact */
237 si_code = FPE_FLTRES;
238 break;
239 default: /* unknown cause */
240 si_code = 0;
241 }
242 do_trap(regs, SIGFPE, si_code, "vector exception");
243}
244
b01a37a7 245void data_exception(struct pt_regs *regs)
1da177e4 246{
1da177e4
LT
247 int signal = 0;
248
d0164ee2 249 save_fpu_regs();
904818e2 250 if (current->thread.fpu.fpc & FPC_DXC_MASK)
1da177e4
LT
251 signal = SIGFPE;
252 else
253 signal = SIGILL;
5a79859a 254 if (signal == SIGFPE)
904818e2 255 do_fp_trap(regs, current->thread.fpu.fpc);
aa33c8cb
MS
256 else if (signal)
257 do_trap(regs, signal, ILL_ILLOPN, "data exception");
1da177e4
LT
258}
259
b01a37a7 260void space_switch_exception(struct pt_regs *regs)
1da177e4 261{
1da177e4 262 /* Set user psw back to home space mode. */
7d256175 263 if (user_mode(regs))
1da177e4
LT
264 regs->psw.mask |= PSW_ASC_HOME;
265 /* Send SIGILL. */
aa33c8cb 266 do_trap(regs, SIGILL, ILL_PRVOPC, "space switch event");
1da177e4
LT
267}
268
7a5388de 269void kernel_stack_overflow(struct pt_regs *regs)
1da177e4 270{
77eb65cb
HC
271 bust_spinlocks(1);
272 printk("Kernel stack overflow.\n");
273 show_regs(regs);
274 bust_spinlocks(0);
1da177e4
LT
275 panic("Corrupt kernel stack, can't continue.");
276}
7a5388de 277NOKPROBE_SYMBOL(kernel_stack_overflow);
1da177e4 278
1da177e4
LT
279void __init trap_init(void)
280{
f3e1a273 281 local_mcck_enable();
1da177e4 282}