blob: a63d34c3611e5c978df849f07c36b9b67e0a89fc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/s390/kernel/traps.c
3 *
4 * S390 version
5 * Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
6 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
7 * Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com),
8 *
9 * Derived from "arch/i386/kernel/traps.c"
10 * Copyright (C) 1991, 1992 Linus Torvalds
11 */
12
13/*
14 * 'Traps.c' handles hardware traps and faults after we have saved some
15 * state in 'asm.s'.
16 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/sched.h>
18#include <linux/kernel.h>
19#include <linux/string.h>
20#include <linux/errno.h>
Oleg Nesterovca633fd2009-12-18 17:43:24 +010021#include <linux/tracehook.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/timer.h>
23#include <linux/mm.h>
24#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/init.h>
26#include <linux/interrupt.h>
Eric W. Biedermandf5f8312008-02-08 04:18:33 -080027#include <linux/seq_file.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/delay.h>
29#include <linux/module.h>
Christoph Hellwig1eeb66a2007-05-08 00:27:03 -070030#include <linux/kdebug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/kallsyms.h>
Heiko Carstens5d3f2292005-08-01 21:11:33 -070032#include <linux/reboot.h>
Michael Grundy4ba069b2006-09-20 15:58:39 +020033#include <linux/kprobes.h>
Heiko Carstensc0007f12007-04-27 16:01:42 +020034#include <linux/bug.h>
Heiko Carstens5c699712008-01-26 14:11:01 +010035#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <asm/system.h>
37#include <asm/uaccess.h>
38#include <asm/io.h>
39#include <asm/atomic.h>
40#include <asm/mathemu.h>
41#include <asm/cpcmd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <asm/lowcore.h>
43#include <asm/debug.h>
Heiko Carstensa8061702008-04-17 07:46:26 +020044#include "entry.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Linus Torvalds1da177e2005-04-16 15:20:36 -070046pgm_check_handler_t *pgm_check_table[128];
47
Heiko Carstensab3c68e2010-05-17 10:00:21 +020048int show_unhandled_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50extern pgm_check_handler_t do_protection_exception;
51extern pgm_check_handler_t do_dat_exception;
Martin Schwidefsky6252d702008-02-09 18:24:37 +010052extern pgm_check_handler_t do_asce_exception;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54#define stack_pointer ({ void **sp; asm("la %0,0(15)" : "=&d" (sp)); sp; })
55
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -080056#ifndef CONFIG_64BIT
Christian Borntraegerd7fd5f12009-03-26 15:23:42 +010057#define LONG "%08lx "
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#define FOURLONG "%08lx %08lx %08lx %08lx\n"
59static int kstack_depth_to_print = 12;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -080060#else /* CONFIG_64BIT */
Christian Borntraegerd7fd5f12009-03-26 15:23:42 +010061#define LONG "%016lx "
Linus Torvalds1da177e2005-04-16 15:20:36 -070062#define FOURLONG "%016lx %016lx %016lx %016lx\n"
63static int kstack_depth_to_print = 20;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -080064#endif /* CONFIG_64BIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66/*
67 * For show_trace we have tree different stack to consider:
68 * - the panic stack which is used if the kernel stack has overflown
69 * - the asynchronous interrupt stack (cpu related)
70 * - the synchronous kernel stack (process related)
71 * The stack trace can start at any of the three stack and can potentially
72 * touch all of them. The order is: panic stack, async stack, sync stack.
73 */
74static unsigned long
75__show_trace(unsigned long sp, unsigned long low, unsigned long high)
76{
77 struct stack_frame *sf;
78 struct pt_regs *regs;
79
80 while (1) {
81 sp = sp & PSW_ADDR_INSN;
82 if (sp < low || sp > high - sizeof(*sf))
83 return sp;
84 sf = (struct stack_frame *) sp;
85 printk("([<%016lx>] ", sf->gprs[8] & PSW_ADDR_INSN);
86 print_symbol("%s)\n", sf->gprs[8] & PSW_ADDR_INSN);
87 /* Follow the backchain. */
88 while (1) {
89 low = sp;
90 sp = sf->back_chain & PSW_ADDR_INSN;
91 if (!sp)
92 break;
93 if (sp <= low || sp > high - sizeof(*sf))
94 return sp;
95 sf = (struct stack_frame *) sp;
96 printk(" [<%016lx>] ", sf->gprs[8] & PSW_ADDR_INSN);
97 print_symbol("%s\n", sf->gprs[8] & PSW_ADDR_INSN);
98 }
99 /* Zero backchain detected, check for interrupt frame. */
100 sp = (unsigned long) (sf + 1);
101 if (sp <= low || sp > high - sizeof(*regs))
102 return sp;
103 regs = (struct pt_regs *) sp;
104 printk(" [<%016lx>] ", regs->psw.addr & PSW_ADDR_INSN);
105 print_symbol("%s\n", regs->psw.addr & PSW_ADDR_INSN);
106 low = sp;
107 sp = regs->gprs[15];
108 }
109}
110
Heiko Carstens4e83be72008-04-30 13:38:34 +0200111static void show_trace(struct task_struct *task, unsigned long *stack)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112{
113 register unsigned long __r15 asm ("15");
114 unsigned long sp;
115
116 sp = (unsigned long) stack;
117 if (!sp)
118 sp = task ? task->thread.ksp : __r15;
119 printk("Call Trace:\n");
120#ifdef CONFIG_CHECK_STACK
121 sp = __show_trace(sp, S390_lowcore.panic_stack - 4096,
122 S390_lowcore.panic_stack);
123#endif
124 sp = __show_trace(sp, S390_lowcore.async_stack - ASYNC_SIZE,
125 S390_lowcore.async_stack);
126 if (task)
Al Viro30af7122006-01-12 01:05:50 -0800127 __show_trace(sp, (unsigned long) task_stack_page(task),
128 (unsigned long) task_stack_page(task) + THREAD_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 else
130 __show_trace(sp, S390_lowcore.thread_info,
131 S390_lowcore.thread_info + THREAD_SIZE);
Heiko Carstens236257e2006-12-04 15:40:47 +0100132 if (!task)
133 task = current;
134 debug_show_held_locks(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135}
136
137void show_stack(struct task_struct *task, unsigned long *sp)
138{
139 register unsigned long * __r15 asm ("15");
140 unsigned long *stack;
141 int i;
142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 if (!sp)
Heiko Carstens73805342006-06-29 14:56:23 +0200144 stack = task ? (unsigned long *) task->thread.ksp : __r15;
145 else
146 stack = sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 for (i = 0; i < kstack_depth_to_print; i++) {
149 if (((addr_t) stack & (THREAD_SIZE-1)) == 0)
150 break;
151 if (i && ((i * sizeof (long) % 32) == 0))
152 printk("\n ");
Christian Borntraegerd7fd5f12009-03-26 15:23:42 +0100153 printk(LONG, *stack++);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 }
155 printk("\n");
156 show_trace(task, sp);
157}
158
Heiko Carstens4e83be72008-04-30 13:38:34 +0200159static void show_last_breaking_event(struct pt_regs *regs)
Christian Borntraeger9e74a6b82008-04-17 07:46:30 +0200160{
Heiko Carstens4e83be72008-04-30 13:38:34 +0200161#ifdef CONFIG_64BIT
Christian Borntraeger9e74a6b82008-04-17 07:46:30 +0200162 printk("Last Breaking-Event-Address:\n");
163 printk(" [<%016lx>] ", regs->args[0] & PSW_ADDR_INSN);
164 print_symbol("%s\n", regs->args[0] & PSW_ADDR_INSN);
Christian Borntraeger9e74a6b82008-04-17 07:46:30 +0200165#endif
Heiko Carstens4e83be72008-04-30 13:38:34 +0200166}
Christian Borntraeger9e74a6b82008-04-17 07:46:30 +0200167
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168/*
169 * The architecture-independent dump_stack generator
170 */
171void dump_stack(void)
172{
Heiko Carstens5c699712008-01-26 14:11:01 +0100173 printk("CPU: %d %s %s %.*s\n",
174 task_thread_info(current)->cpu, print_tainted(),
175 init_utsname()->release,
176 (int)strcspn(init_utsname()->version, " "),
177 init_utsname()->version);
178 printk("Process %s (pid: %d, task: %p, ksp: %p)\n",
179 current->comm, current->pid, current,
180 (void *) current->thread.ksp);
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200181 show_stack(NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183EXPORT_SYMBOL(dump_stack);
184
Martin Schwidefskybb11e3b2007-04-27 16:01:41 +0200185static inline int mask_bits(struct pt_regs *regs, unsigned long bits)
186{
187 return (regs->psw.mask & bits) / ((~bits + 1) & bits);
188}
189
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190void show_registers(struct pt_regs *regs)
191{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 char *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
194 mode = (regs->psw.mask & PSW_MASK_PSTATE) ? "User" : "Krnl";
195 printk("%s PSW : %p %p",
196 mode, (void *) regs->psw.mask,
197 (void *) regs->psw.addr);
198 print_symbol(" (%s)\n", regs->psw.addr & PSW_ADDR_INSN);
Martin Schwidefskybb11e3b2007-04-27 16:01:41 +0200199 printk(" R:%x T:%x IO:%x EX:%x Key:%x M:%x W:%x "
200 "P:%x AS:%x CC:%x PM:%x", mask_bits(regs, PSW_MASK_PER),
201 mask_bits(regs, PSW_MASK_DAT), mask_bits(regs, PSW_MASK_IO),
202 mask_bits(regs, PSW_MASK_EXT), mask_bits(regs, PSW_MASK_KEY),
203 mask_bits(regs, PSW_MASK_MCHECK), mask_bits(regs, PSW_MASK_WAIT),
204 mask_bits(regs, PSW_MASK_PSTATE), mask_bits(regs, PSW_MASK_ASC),
205 mask_bits(regs, PSW_MASK_CC), mask_bits(regs, PSW_MASK_PM));
206#ifdef CONFIG_64BIT
207 printk(" EA:%x", mask_bits(regs, PSW_BASE_BITS));
208#endif
209 printk("\n%s GPRS: " FOURLONG, mode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 regs->gprs[0], regs->gprs[1], regs->gprs[2], regs->gprs[3]);
211 printk(" " FOURLONG,
212 regs->gprs[4], regs->gprs[5], regs->gprs[6], regs->gprs[7]);
213 printk(" " FOURLONG,
214 regs->gprs[8], regs->gprs[9], regs->gprs[10], regs->gprs[11]);
215 printk(" " FOURLONG,
216 regs->gprs[12], regs->gprs[13], regs->gprs[14], regs->gprs[15]);
217
Martin Schwidefskybb11e3b2007-04-27 16:01:41 +0200218 show_code(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219}
220
Heiko Carstens4e83be72008-04-30 13:38:34 +0200221void show_regs(struct pt_regs *regs)
222{
223 print_modules();
224 printk("CPU: %d %s %s %.*s\n",
225 task_thread_info(current)->cpu, print_tainted(),
226 init_utsname()->release,
227 (int)strcspn(init_utsname()->version, " "),
228 init_utsname()->version);
229 printk("Process %s (pid: %d, task: %p, ksp: %p)\n",
230 current->comm, current->pid, current,
231 (void *) current->thread.ksp);
232 show_registers(regs);
233 /* Show stack backtrace if pt_regs is from kernel mode */
234 if (!(regs->psw.mask & PSW_MASK_PSTATE))
235 show_trace(NULL, (unsigned long *) regs->gprs[15]);
236 show_last_breaking_event(regs);
237}
238
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100239static DEFINE_SPINLOCK(die_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
241void die(const char * str, struct pt_regs * regs, long err)
242{
243 static int die_counter;
244
Heiko Carstensbca0fb862007-06-19 13:10:05 +0200245 oops_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 debug_stop_all();
247 console_verbose();
248 spin_lock_irq(&die_lock);
249 bust_spinlocks(1);
Heiko Carstens5c699712008-01-26 14:11:01 +0100250 printk("%s: %04lx [#%d] ", str, err & 0xffff, ++die_counter);
251#ifdef CONFIG_PREEMPT
252 printk("PREEMPT ");
253#endif
254#ifdef CONFIG_SMP
Heiko Carstens24855792008-02-05 16:50:37 +0100255 printk("SMP ");
256#endif
257#ifdef CONFIG_DEBUG_PAGEALLOC
258 printk("DEBUG_PAGEALLOC");
Heiko Carstens5c699712008-01-26 14:11:01 +0100259#endif
260 printk("\n");
Heiko Carstens06770a62007-11-20 11:13:40 +0100261 notify_die(DIE_OOPS, str, regs, err, current->thread.trap_no, SIGSEGV);
Heiko Carstensbca0fb862007-06-19 13:10:05 +0200262 show_regs(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 bust_spinlocks(0);
Pavel Emelianovbcdcd8e2007-07-17 04:03:42 -0700264 add_taint(TAINT_DIE);
Heiko Carstensbca0fb862007-06-19 13:10:05 +0200265 spin_unlock_irq(&die_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 if (in_interrupt())
267 panic("Fatal exception in interrupt");
268 if (panic_on_oops)
269 panic("Fatal exception: panic_on_oops");
Heiko Carstensbca0fb862007-06-19 13:10:05 +0200270 oops_exit();
271 do_exit(SIGSEGV);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272}
273
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200274static void inline report_user_fault(struct pt_regs *regs, long int_code,
275 int signr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276{
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200277 if ((task_pid_nr(current) > 1) && !show_unhandled_signals)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 return;
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200279 if (!unhandled_signal(current, signr))
280 return;
281 if (!printk_ratelimit())
282 return;
283 printk("User process fault: interruption code 0x%lX ", int_code);
284 print_vma_addr("in ", regs->psw.addr & PSW_ADDR_INSN);
285 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 show_regs(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287}
288
Heiko Carstensc0007f12007-04-27 16:01:42 +0200289int is_valid_bugaddr(unsigned long addr)
290{
291 return 1;
292}
293
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200294static inline void __kprobes do_trap(long pgm_int_code, int signr, char *str,
295 struct pt_regs *regs, siginfo_t *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296{
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200297 if (notify_die(DIE_TRAP, str, regs, pgm_int_code,
298 pgm_int_code, signr) == NOTIFY_STOP)
Michael Grundy4ba069b2006-09-20 15:58:39 +0200299 return;
300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 if (regs->psw.mask & PSW_MASK_PSTATE) {
302 struct task_struct *tsk = current;
303
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200304 tsk->thread.trap_no = pgm_int_code & 0xffff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 force_sig_info(signr, info, tsk);
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200306 report_user_fault(regs, pgm_int_code, signr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 } else {
308 const struct exception_table_entry *fixup;
309 fixup = search_exception_tables(regs->psw.addr & PSW_ADDR_INSN);
310 if (fixup)
311 regs->psw.addr = fixup->fixup | PSW_ADDR_AMODE;
Heiko Carstensc0007f12007-04-27 16:01:42 +0200312 else {
313 enum bug_trap_type btt;
314
Heiko Carstens608e2612007-07-15 23:41:39 -0700315 btt = report_bug(regs->psw.addr & PSW_ADDR_INSN, regs);
Heiko Carstensc0007f12007-04-27 16:01:42 +0200316 if (btt == BUG_TRAP_TYPE_WARN)
317 return;
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200318 die(str, regs, pgm_int_code);
Heiko Carstensc0007f12007-04-27 16:01:42 +0200319 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 }
321}
322
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200323static inline void __user *get_psw_address(struct pt_regs *regs,
324 long pgm_int_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325{
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200326 return (void __user *)
327 ((regs->psw.addr - (pgm_int_code >> 16)) & PSW_ADDR_INSN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328}
329
Martin Schwidefsky5e9a2692011-01-05 12:48:10 +0100330void __kprobes do_per_trap(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331{
Martin Schwidefsky5e9a2692011-01-05 12:48:10 +0100332 if (notify_die(DIE_SSTEP, "sstep", regs, 0, 0, SIGTRAP) == NOTIFY_STOP)
Michael Grundy4ba069b2006-09-20 15:58:39 +0200333 return;
Tejun Heoa288eec2011-06-17 16:50:37 +0200334 if (current->ptrace)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 force_sig(SIGTRAP, current);
336}
337
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200338static void default_trap_handler(struct pt_regs *regs, long pgm_int_code,
339 unsigned long trans_exc_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340{
341 if (regs->psw.mask & PSW_MASK_PSTATE) {
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200342 report_user_fault(regs, pgm_int_code, SIGSEGV);
Heiko Carstens6ea50962010-05-17 10:00:13 +0200343 do_exit(SIGSEGV);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 } else
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200345 die("Unknown program exception", regs, pgm_int_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346}
347
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200348#define DO_ERROR_INFO(name, signr, sicode, str) \
349static void name(struct pt_regs *regs, long pgm_int_code, \
350 unsigned long trans_exc_code) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351{ \
352 siginfo_t info; \
353 info.si_signo = signr; \
354 info.si_errno = 0; \
355 info.si_code = sicode; \
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200356 info.si_addr = get_psw_address(regs, pgm_int_code); \
357 do_trap(pgm_int_code, signr, str, regs, &info); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358}
359
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200360DO_ERROR_INFO(addressing_exception, SIGILL, ILL_ILLADR,
361 "addressing exception")
362DO_ERROR_INFO(execute_exception, SIGILL, ILL_ILLOPN,
363 "execute exception")
364DO_ERROR_INFO(divide_exception, SIGFPE, FPE_INTDIV,
365 "fixpoint divide exception")
366DO_ERROR_INFO(overflow_exception, SIGFPE, FPE_INTOVF,
367 "fixpoint overflow exception")
368DO_ERROR_INFO(hfp_overflow_exception, SIGFPE, FPE_FLTOVF,
369 "HFP overflow exception")
370DO_ERROR_INFO(hfp_underflow_exception, SIGFPE, FPE_FLTUND,
371 "HFP underflow exception")
372DO_ERROR_INFO(hfp_significance_exception, SIGFPE, FPE_FLTRES,
373 "HFP significance exception")
374DO_ERROR_INFO(hfp_divide_exception, SIGFPE, FPE_FLTDIV,
375 "HFP divide exception")
376DO_ERROR_INFO(hfp_sqrt_exception, SIGFPE, FPE_FLTINV,
377 "HFP square root exception")
378DO_ERROR_INFO(operand_exception, SIGILL, ILL_ILLOPN,
379 "operand exception")
380DO_ERROR_INFO(privileged_op, SIGILL, ILL_PRVOPC,
381 "privileged operation")
382DO_ERROR_INFO(special_op_exception, SIGILL, ILL_ILLOPN,
383 "special operation exception")
384DO_ERROR_INFO(translation_exception, SIGILL, ILL_ILLOPN,
385 "translation exception")
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200387static inline void do_fp_trap(struct pt_regs *regs, void __user *location,
388 int fpc, long pgm_int_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389{
390 siginfo_t si;
391
392 si.si_signo = SIGFPE;
393 si.si_errno = 0;
394 si.si_addr = location;
395 si.si_code = 0;
396 /* FPC[2] is Data Exception Code */
397 if ((fpc & 0x00000300) == 0) {
398 /* bits 6 and 7 of DXC are 0 iff IEEE exception */
399 if (fpc & 0x8000) /* invalid fp operation */
400 si.si_code = FPE_FLTINV;
401 else if (fpc & 0x4000) /* div by 0 */
402 si.si_code = FPE_FLTDIV;
403 else if (fpc & 0x2000) /* overflow */
404 si.si_code = FPE_FLTOVF;
405 else if (fpc & 0x1000) /* underflow */
406 si.si_code = FPE_FLTUND;
407 else if (fpc & 0x0800) /* inexact */
408 si.si_code = FPE_FLTRES;
409 }
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200410 do_trap(pgm_int_code, SIGFPE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 "floating point exception", regs, &si);
412}
413
Martin Schwidefsky860dba42011-01-05 12:47:25 +0100414static void __kprobes illegal_op(struct pt_regs *regs, long pgm_int_code,
415 unsigned long trans_exc_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416{
417 siginfo_t info;
418 __u8 opcode[6];
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200419 __u16 __user *location;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 int signal = 0;
421
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200422 location = get_psw_address(regs, pgm_int_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
424 if (regs->psw.mask & PSW_MASK_PSTATE) {
Heiko Carstens12bae232006-10-27 12:39:22 +0200425 if (get_user(*((__u16 *) opcode), (__u16 __user *) location))
426 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 if (*((__u16 *) opcode) == S390_BREAKPOINT_U16) {
Tejun Heoa288eec2011-06-17 16:50:37 +0200428 if (current->ptrace)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 force_sig(SIGTRAP, current);
430 else
431 signal = SIGILL;
432#ifdef CONFIG_MATHEMU
433 } else if (opcode[0] == 0xb3) {
Heiko Carstens12bae232006-10-27 12:39:22 +0200434 if (get_user(*((__u16 *) (opcode+2)), location+1))
435 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 signal = math_emu_b3(opcode, regs);
437 } else if (opcode[0] == 0xed) {
Heiko Carstens12bae232006-10-27 12:39:22 +0200438 if (get_user(*((__u32 *) (opcode+2)),
439 (__u32 __user *)(location+1)))
440 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 signal = math_emu_ed(opcode, regs);
442 } else if (*((__u16 *) opcode) == 0xb299) {
Heiko Carstens12bae232006-10-27 12:39:22 +0200443 if (get_user(*((__u16 *) (opcode+2)), location+1))
444 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 signal = math_emu_srnm(opcode, regs);
446 } else if (*((__u16 *) opcode) == 0xb29c) {
Heiko Carstens12bae232006-10-27 12:39:22 +0200447 if (get_user(*((__u16 *) (opcode+2)), location+1))
448 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 signal = math_emu_stfpc(opcode, regs);
450 } else if (*((__u16 *) opcode) == 0xb29d) {
Heiko Carstens12bae232006-10-27 12:39:22 +0200451 if (get_user(*((__u16 *) (opcode+2)), location+1))
452 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 signal = math_emu_lfpc(opcode, regs);
454#endif
455 } else
456 signal = SIGILL;
Heiko Carstens35df8d52007-02-05 21:17:29 +0100457 } else {
458 /*
459 * If we get an illegal op in kernel mode, send it through the
460 * kprobes notifier. If kprobes doesn't pick it up, SIGILL
461 */
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200462 if (notify_die(DIE_BPT, "bpt", regs, pgm_int_code,
Heiko Carstens35df8d52007-02-05 21:17:29 +0100463 3, SIGTRAP) != NOTIFY_STOP)
464 signal = SIGILL;
465 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466
467#ifdef CONFIG_MATHEMU
468 if (signal == SIGFPE)
469 do_fp_trap(regs, location,
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200470 current->thread.fp_regs.fpc, pgm_int_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 else if (signal == SIGSEGV) {
472 info.si_signo = signal;
473 info.si_errno = 0;
474 info.si_code = SEGV_MAPERR;
Al Viro5a42b812006-10-09 20:28:03 +0100475 info.si_addr = (void __user *) location;
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200476 do_trap(pgm_int_code, signal,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 "user address fault", regs, &info);
478 } else
479#endif
480 if (signal) {
481 info.si_signo = signal;
482 info.si_errno = 0;
483 info.si_code = ILL_ILLOPC;
Al Viro793af242006-02-01 06:55:59 -0500484 info.si_addr = (void __user *) location;
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200485 do_trap(pgm_int_code, signal,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 "illegal operation", regs, &info);
487 }
488}
489
490
491#ifdef CONFIG_MATHEMU
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200492asmlinkage void specification_exception(struct pt_regs *regs,
493 long pgm_int_code,
494 unsigned long trans_exc_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495{
496 __u8 opcode[6];
Al Viro5a42b812006-10-09 20:28:03 +0100497 __u16 __user *location = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 int signal = 0;
499
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200500 location = (__u16 __user *) get_psw_address(regs, pgm_int_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
502 if (regs->psw.mask & PSW_MASK_PSTATE) {
503 get_user(*((__u16 *) opcode), location);
504 switch (opcode[0]) {
505 case 0x28: /* LDR Rx,Ry */
506 signal = math_emu_ldr(opcode);
507 break;
508 case 0x38: /* LER Rx,Ry */
509 signal = math_emu_ler(opcode);
510 break;
511 case 0x60: /* STD R,D(X,B) */
512 get_user(*((__u16 *) (opcode+2)), location+1);
513 signal = math_emu_std(opcode, regs);
514 break;
515 case 0x68: /* LD R,D(X,B) */
516 get_user(*((__u16 *) (opcode+2)), location+1);
517 signal = math_emu_ld(opcode, regs);
518 break;
519 case 0x70: /* STE R,D(X,B) */
520 get_user(*((__u16 *) (opcode+2)), location+1);
521 signal = math_emu_ste(opcode, regs);
522 break;
523 case 0x78: /* LE R,D(X,B) */
524 get_user(*((__u16 *) (opcode+2)), location+1);
525 signal = math_emu_le(opcode, regs);
526 break;
527 default:
528 signal = SIGILL;
529 break;
530 }
531 } else
532 signal = SIGILL;
533
534 if (signal == SIGFPE)
535 do_fp_trap(regs, location,
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200536 current->thread.fp_regs.fpc, pgm_int_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 else if (signal) {
538 siginfo_t info;
539 info.si_signo = signal;
540 info.si_errno = 0;
541 info.si_code = ILL_ILLOPN;
542 info.si_addr = location;
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200543 do_trap(pgm_int_code, signal,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 "specification exception", regs, &info);
545 }
546}
547#else
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200548DO_ERROR_INFO(specification_exception, SIGILL, ILL_ILLOPN,
549 "specification exception");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550#endif
551
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200552static void data_exception(struct pt_regs *regs, long pgm_int_code,
553 unsigned long trans_exc_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554{
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200555 __u16 __user *location;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 int signal = 0;
557
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200558 location = get_psw_address(regs, pgm_int_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559
560 if (MACHINE_HAS_IEEE)
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200561 asm volatile("stfpc %0" : "=m" (current->thread.fp_regs.fpc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
563#ifdef CONFIG_MATHEMU
564 else if (regs->psw.mask & PSW_MASK_PSTATE) {
565 __u8 opcode[6];
566 get_user(*((__u16 *) opcode), location);
567 switch (opcode[0]) {
568 case 0x28: /* LDR Rx,Ry */
569 signal = math_emu_ldr(opcode);
570 break;
571 case 0x38: /* LER Rx,Ry */
572 signal = math_emu_ler(opcode);
573 break;
574 case 0x60: /* STD R,D(X,B) */
575 get_user(*((__u16 *) (opcode+2)), location+1);
576 signal = math_emu_std(opcode, regs);
577 break;
578 case 0x68: /* LD R,D(X,B) */
579 get_user(*((__u16 *) (opcode+2)), location+1);
580 signal = math_emu_ld(opcode, regs);
581 break;
582 case 0x70: /* STE R,D(X,B) */
583 get_user(*((__u16 *) (opcode+2)), location+1);
584 signal = math_emu_ste(opcode, regs);
585 break;
586 case 0x78: /* LE R,D(X,B) */
587 get_user(*((__u16 *) (opcode+2)), location+1);
588 signal = math_emu_le(opcode, regs);
589 break;
590 case 0xb3:
591 get_user(*((__u16 *) (opcode+2)), location+1);
592 signal = math_emu_b3(opcode, regs);
593 break;
594 case 0xed:
595 get_user(*((__u32 *) (opcode+2)),
Al Viro5a42b812006-10-09 20:28:03 +0100596 (__u32 __user *)(location+1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 signal = math_emu_ed(opcode, regs);
598 break;
599 case 0xb2:
600 if (opcode[1] == 0x99) {
601 get_user(*((__u16 *) (opcode+2)), location+1);
602 signal = math_emu_srnm(opcode, regs);
603 } else if (opcode[1] == 0x9c) {
604 get_user(*((__u16 *) (opcode+2)), location+1);
605 signal = math_emu_stfpc(opcode, regs);
606 } else if (opcode[1] == 0x9d) {
607 get_user(*((__u16 *) (opcode+2)), location+1);
608 signal = math_emu_lfpc(opcode, regs);
609 } else
610 signal = SIGILL;
611 break;
612 default:
613 signal = SIGILL;
614 break;
615 }
616 }
617#endif
618 if (current->thread.fp_regs.fpc & FPC_DXC_MASK)
619 signal = SIGFPE;
620 else
621 signal = SIGILL;
622 if (signal == SIGFPE)
623 do_fp_trap(regs, location,
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200624 current->thread.fp_regs.fpc, pgm_int_code);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 else if (signal) {
626 siginfo_t info;
627 info.si_signo = signal;
628 info.si_errno = 0;
629 info.si_code = ILL_ILLOPN;
630 info.si_addr = location;
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200631 do_trap(pgm_int_code, signal, "data exception", regs, &info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 }
633}
634
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200635static void space_switch_exception(struct pt_regs *regs, long pgm_int_code,
636 unsigned long trans_exc_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637{
638 siginfo_t info;
639
640 /* Set user psw back to home space mode. */
641 if (regs->psw.mask & PSW_MASK_PSTATE)
642 regs->psw.mask |= PSW_ASC_HOME;
643 /* Send SIGILL. */
644 info.si_signo = SIGILL;
645 info.si_errno = 0;
646 info.si_code = ILL_PRVOPC;
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200647 info.si_addr = get_psw_address(regs, pgm_int_code);
648 do_trap(pgm_int_code, SIGILL, "space switch event", regs, &info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649}
650
Martin Schwidefsky860dba42011-01-05 12:47:25 +0100651asmlinkage void __kprobes kernel_stack_overflow(struct pt_regs * regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652{
Heiko Carstens77eb65c2005-06-21 17:16:28 -0700653 bust_spinlocks(1);
654 printk("Kernel stack overflow.\n");
655 show_regs(regs);
656 bust_spinlocks(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 panic("Corrupt kernel stack, can't continue.");
658}
659
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660/* init is done in lowcore.S and head.S */
661
662void __init trap_init(void)
663{
664 int i;
665
666 for (i = 0; i < 128; i++)
667 pgm_check_table[i] = &default_trap_handler;
668 pgm_check_table[1] = &illegal_op;
669 pgm_check_table[2] = &privileged_op;
670 pgm_check_table[3] = &execute_exception;
671 pgm_check_table[4] = &do_protection_exception;
672 pgm_check_table[5] = &addressing_exception;
673 pgm_check_table[6] = &specification_exception;
674 pgm_check_table[7] = &data_exception;
675 pgm_check_table[8] = &overflow_exception;
676 pgm_check_table[9] = &divide_exception;
677 pgm_check_table[0x0A] = &overflow_exception;
678 pgm_check_table[0x0B] = &divide_exception;
679 pgm_check_table[0x0C] = &hfp_overflow_exception;
680 pgm_check_table[0x0D] = &hfp_underflow_exception;
681 pgm_check_table[0x0E] = &hfp_significance_exception;
682 pgm_check_table[0x0F] = &hfp_divide_exception;
683 pgm_check_table[0x10] = &do_dat_exception;
684 pgm_check_table[0x11] = &do_dat_exception;
685 pgm_check_table[0x12] = &translation_exception;
686 pgm_check_table[0x13] = &special_op_exception;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800687#ifdef CONFIG_64BIT
Martin Schwidefsky6252d702008-02-09 18:24:37 +0100688 pgm_check_table[0x38] = &do_asce_exception;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 pgm_check_table[0x39] = &do_dat_exception;
690 pgm_check_table[0x3A] = &do_dat_exception;
691 pgm_check_table[0x3B] = &do_dat_exception;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800692#endif /* CONFIG_64BIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 pgm_check_table[0x15] = &operand_exception;
694 pgm_check_table[0x1C] = &space_switch_exception;
695 pgm_check_table[0x1D] = &hfp_sqrt_exception;
Heiko Carstensf3e1a272011-01-05 12:48:00 +0100696 /* Enable machine checks early. */
697 local_mcck_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698}