blob: 70ecfc5fe8f0acc87b7fe0036df511f283b22dbe [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * S390 version
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02003 * Copyright IBM Corp. 1999, 2000
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/sched.h>
16#include <linux/kernel.h>
17#include <linux/string.h>
18#include <linux/errno.h>
Martin Schwidefsky73b7d402011-07-24 10:48:33 +020019#include <linux/ptrace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/timer.h>
21#include <linux/mm.h>
22#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/init.h>
24#include <linux/interrupt.h>
Eric W. Biedermandf5f8312008-02-08 04:18:33 -080025#include <linux/seq_file.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/delay.h>
27#include <linux/module.h>
Christoph Hellwig1eeb66a2007-05-08 00:27:03 -070028#include <linux/kdebug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/kallsyms.h>
Heiko Carstens5d3f2292005-08-01 21:11:33 -070030#include <linux/reboot.h>
Michael Grundy4ba069b2006-09-20 15:58:39 +020031#include <linux/kprobes.h>
Heiko Carstensc0007f12007-04-27 16:01:42 +020032#include <linux/bug.h>
Heiko Carstens5c699712008-01-26 14:11:01 +010033#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <asm/uaccess.h>
35#include <asm/io.h>
Arun Sharma600634972011-07-26 16:09:06 -070036#include <linux/atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <asm/mathemu.h>
38#include <asm/cpcmd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <asm/lowcore.h>
40#include <asm/debug.h>
Michael Holzheu3ab121a2012-03-11 11:59:32 -040041#include <asm/ipl.h>
Heiko Carstensa8061702008-04-17 07:46:26 +020042#include "entry.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Heiko Carstens02834ee2011-12-27 11:27:31 +010044int show_unhandled_signals = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#define stack_pointer ({ void **sp; asm("la %0,0(15)" : "=&d" (sp)); sp; })
47
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -080048#ifndef CONFIG_64BIT
Christian Borntraegerd7fd5f12009-03-26 15:23:42 +010049#define LONG "%08lx "
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#define FOURLONG "%08lx %08lx %08lx %08lx\n"
51static int kstack_depth_to_print = 12;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -080052#else /* CONFIG_64BIT */
Christian Borntraegerd7fd5f12009-03-26 15:23:42 +010053#define LONG "%016lx "
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#define FOURLONG "%016lx %016lx %016lx %016lx\n"
55static int kstack_depth_to_print = 20;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -080056#endif /* CONFIG_64BIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Martin Schwidefskyd35339a2012-07-31 11:03:04 +020058static inline void __user *get_trap_ip(struct pt_regs *regs)
59{
60#ifdef CONFIG_64BIT
61 unsigned long address;
62
63 if (regs->int_code & 0x200)
64 address = *(unsigned long *)(current->thread.trap_tdb + 24);
65 else
66 address = regs->psw.addr;
67 return (void __user *)
68 ((address - (regs->int_code >> 16)) & PSW_ADDR_INSN);
69#else
70 return (void __user *)
71 ((regs->psw.addr - (regs->int_code >> 16)) & PSW_ADDR_INSN);
72#endif
73}
74
Linus Torvalds1da177e2005-04-16 15:20:36 -070075/*
76 * For show_trace we have tree different stack to consider:
77 * - the panic stack which is used if the kernel stack has overflown
78 * - the asynchronous interrupt stack (cpu related)
79 * - the synchronous kernel stack (process related)
80 * The stack trace can start at any of the three stack and can potentially
81 * touch all of them. The order is: panic stack, async stack, sync stack.
82 */
83static unsigned long
84__show_trace(unsigned long sp, unsigned long low, unsigned long high)
85{
86 struct stack_frame *sf;
87 struct pt_regs *regs;
88
89 while (1) {
90 sp = sp & PSW_ADDR_INSN;
91 if (sp < low || sp > high - sizeof(*sf))
92 return sp;
93 sf = (struct stack_frame *) sp;
94 printk("([<%016lx>] ", sf->gprs[8] & PSW_ADDR_INSN);
95 print_symbol("%s)\n", sf->gprs[8] & PSW_ADDR_INSN);
96 /* Follow the backchain. */
97 while (1) {
98 low = sp;
99 sp = sf->back_chain & PSW_ADDR_INSN;
100 if (!sp)
101 break;
102 if (sp <= low || sp > high - sizeof(*sf))
103 return sp;
104 sf = (struct stack_frame *) sp;
105 printk(" [<%016lx>] ", sf->gprs[8] & PSW_ADDR_INSN);
106 print_symbol("%s\n", sf->gprs[8] & PSW_ADDR_INSN);
107 }
108 /* Zero backchain detected, check for interrupt frame. */
109 sp = (unsigned long) (sf + 1);
110 if (sp <= low || sp > high - sizeof(*regs))
111 return sp;
112 regs = (struct pt_regs *) sp;
113 printk(" [<%016lx>] ", regs->psw.addr & PSW_ADDR_INSN);
114 print_symbol("%s\n", regs->psw.addr & PSW_ADDR_INSN);
115 low = sp;
116 sp = regs->gprs[15];
117 }
118}
119
Heiko Carstens4e83be72008-04-30 13:38:34 +0200120static void show_trace(struct task_struct *task, unsigned long *stack)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121{
122 register unsigned long __r15 asm ("15");
123 unsigned long sp;
124
125 sp = (unsigned long) stack;
126 if (!sp)
127 sp = task ? task->thread.ksp : __r15;
128 printk("Call Trace:\n");
129#ifdef CONFIG_CHECK_STACK
130 sp = __show_trace(sp, S390_lowcore.panic_stack - 4096,
131 S390_lowcore.panic_stack);
132#endif
133 sp = __show_trace(sp, S390_lowcore.async_stack - ASYNC_SIZE,
134 S390_lowcore.async_stack);
135 if (task)
Al Viro30af7122006-01-12 01:05:50 -0800136 __show_trace(sp, (unsigned long) task_stack_page(task),
137 (unsigned long) task_stack_page(task) + THREAD_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 else
139 __show_trace(sp, S390_lowcore.thread_info,
140 S390_lowcore.thread_info + THREAD_SIZE);
Heiko Carstens236257e2006-12-04 15:40:47 +0100141 if (!task)
142 task = current;
143 debug_show_held_locks(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144}
145
146void show_stack(struct task_struct *task, unsigned long *sp)
147{
148 register unsigned long * __r15 asm ("15");
149 unsigned long *stack;
150 int i;
151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 if (!sp)
Heiko Carstens73805342006-06-29 14:56:23 +0200153 stack = task ? (unsigned long *) task->thread.ksp : __r15;
154 else
155 stack = sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 for (i = 0; i < kstack_depth_to_print; i++) {
158 if (((addr_t) stack & (THREAD_SIZE-1)) == 0)
159 break;
Heiko Carstensddadfa82012-03-11 11:59:35 -0400160 if ((i * sizeof(long) % 32) == 0)
161 printk("%s ", i == 0 ? "" : "\n");
Christian Borntraegerd7fd5f12009-03-26 15:23:42 +0100162 printk(LONG, *stack++);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 }
164 printk("\n");
165 show_trace(task, sp);
166}
167
Heiko Carstens4e83be72008-04-30 13:38:34 +0200168static void show_last_breaking_event(struct pt_regs *regs)
Christian Borntraeger9e74a6b82008-04-17 07:46:30 +0200169{
Heiko Carstens4e83be72008-04-30 13:38:34 +0200170#ifdef CONFIG_64BIT
Christian Borntraeger9e74a6b82008-04-17 07:46:30 +0200171 printk("Last Breaking-Event-Address:\n");
172 printk(" [<%016lx>] ", regs->args[0] & PSW_ADDR_INSN);
173 print_symbol("%s\n", regs->args[0] & PSW_ADDR_INSN);
Christian Borntraeger9e74a6b82008-04-17 07:46:30 +0200174#endif
Heiko Carstens4e83be72008-04-30 13:38:34 +0200175}
Christian Borntraeger9e74a6b82008-04-17 07:46:30 +0200176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177/*
178 * The architecture-independent dump_stack generator
179 */
180void dump_stack(void)
181{
Heiko Carstens5c699712008-01-26 14:11:01 +0100182 printk("CPU: %d %s %s %.*s\n",
183 task_thread_info(current)->cpu, print_tainted(),
184 init_utsname()->release,
185 (int)strcspn(init_utsname()->version, " "),
186 init_utsname()->version);
187 printk("Process %s (pid: %d, task: %p, ksp: %p)\n",
188 current->comm, current->pid, current,
189 (void *) current->thread.ksp);
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200190 show_stack(NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192EXPORT_SYMBOL(dump_stack);
193
Martin Schwidefskybb11e3b2007-04-27 16:01:41 +0200194static inline int mask_bits(struct pt_regs *regs, unsigned long bits)
195{
196 return (regs->psw.mask & bits) / ((~bits + 1) & bits);
197}
198
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199void show_registers(struct pt_regs *regs)
200{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 char *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
Heiko Carstens7d256172012-07-27 10:31:12 +0200203 mode = user_mode(regs) ? "User" : "Krnl";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 printk("%s PSW : %p %p",
205 mode, (void *) regs->psw.mask,
206 (void *) regs->psw.addr);
207 print_symbol(" (%s)\n", regs->psw.addr & PSW_ADDR_INSN);
Martin Schwidefskybb11e3b2007-04-27 16:01:41 +0200208 printk(" R:%x T:%x IO:%x EX:%x Key:%x M:%x W:%x "
209 "P:%x AS:%x CC:%x PM:%x", mask_bits(regs, PSW_MASK_PER),
210 mask_bits(regs, PSW_MASK_DAT), mask_bits(regs, PSW_MASK_IO),
211 mask_bits(regs, PSW_MASK_EXT), mask_bits(regs, PSW_MASK_KEY),
212 mask_bits(regs, PSW_MASK_MCHECK), mask_bits(regs, PSW_MASK_WAIT),
213 mask_bits(regs, PSW_MASK_PSTATE), mask_bits(regs, PSW_MASK_ASC),
214 mask_bits(regs, PSW_MASK_CC), mask_bits(regs, PSW_MASK_PM));
215#ifdef CONFIG_64BIT
Martin Schwidefskyb50511e2011-10-30 15:16:50 +0100216 printk(" EA:%x", mask_bits(regs, PSW_MASK_EA | PSW_MASK_BA));
Martin Schwidefskybb11e3b2007-04-27 16:01:41 +0200217#endif
218 printk("\n%s GPRS: " FOURLONG, mode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 regs->gprs[0], regs->gprs[1], regs->gprs[2], regs->gprs[3]);
220 printk(" " FOURLONG,
221 regs->gprs[4], regs->gprs[5], regs->gprs[6], regs->gprs[7]);
222 printk(" " FOURLONG,
223 regs->gprs[8], regs->gprs[9], regs->gprs[10], regs->gprs[11]);
224 printk(" " FOURLONG,
225 regs->gprs[12], regs->gprs[13], regs->gprs[14], regs->gprs[15]);
226
Martin Schwidefskybb11e3b2007-04-27 16:01:41 +0200227 show_code(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228}
229
Heiko Carstens4e83be72008-04-30 13:38:34 +0200230void show_regs(struct pt_regs *regs)
231{
Heiko Carstens4e83be72008-04-30 13:38:34 +0200232 printk("CPU: %d %s %s %.*s\n",
233 task_thread_info(current)->cpu, print_tainted(),
234 init_utsname()->release,
235 (int)strcspn(init_utsname()->version, " "),
236 init_utsname()->version);
237 printk("Process %s (pid: %d, task: %p, ksp: %p)\n",
238 current->comm, current->pid, current,
239 (void *) current->thread.ksp);
240 show_registers(regs);
241 /* Show stack backtrace if pt_regs is from kernel mode */
Heiko Carstens7d256172012-07-27 10:31:12 +0200242 if (!user_mode(regs))
Heiko Carstens4e83be72008-04-30 13:38:34 +0200243 show_trace(NULL, (unsigned long *) regs->gprs[15]);
244 show_last_breaking_event(regs);
245}
246
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100247static DEFINE_SPINLOCK(die_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100249void die(struct pt_regs *regs, const char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250{
251 static int die_counter;
252
Heiko Carstensbca0fb862007-06-19 13:10:05 +0200253 oops_enter();
Michael Holzheu3ab121a2012-03-11 11:59:32 -0400254 lgr_info_log();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 debug_stop_all();
256 console_verbose();
257 spin_lock_irq(&die_lock);
258 bust_spinlocks(1);
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100259 printk("%s: %04x [#%d] ", str, regs->int_code & 0xffff, ++die_counter);
Heiko Carstens5c699712008-01-26 14:11:01 +0100260#ifdef CONFIG_PREEMPT
261 printk("PREEMPT ");
262#endif
263#ifdef CONFIG_SMP
Heiko Carstens24855792008-02-05 16:50:37 +0100264 printk("SMP ");
265#endif
266#ifdef CONFIG_DEBUG_PAGEALLOC
267 printk("DEBUG_PAGEALLOC");
Heiko Carstens5c699712008-01-26 14:11:01 +0100268#endif
269 printk("\n");
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100270 notify_die(DIE_OOPS, str, regs, 0, regs->int_code & 0xffff, SIGSEGV);
Heiko Carstens02291252012-09-24 08:22:00 +0200271 print_modules();
Heiko Carstensbca0fb862007-06-19 13:10:05 +0200272 show_regs(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 bust_spinlocks(0);
Pavel Emelianovbcdcd8e2007-07-17 04:03:42 -0700274 add_taint(TAINT_DIE);
Heiko Carstensbca0fb862007-06-19 13:10:05 +0200275 spin_unlock_irq(&die_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 if (in_interrupt())
277 panic("Fatal exception in interrupt");
278 if (panic_on_oops)
279 panic("Fatal exception: panic_on_oops");
Heiko Carstensbca0fb862007-06-19 13:10:05 +0200280 oops_exit();
281 do_exit(SIGSEGV);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282}
283
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100284static inline void report_user_fault(struct pt_regs *regs, int signr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285{
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200286 if ((task_pid_nr(current) > 1) && !show_unhandled_signals)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 return;
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200288 if (!unhandled_signal(current, signr))
289 return;
290 if (!printk_ratelimit())
291 return;
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100292 printk("User process fault: interruption code 0x%X ", regs->int_code);
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200293 print_vma_addr("in ", regs->psw.addr & PSW_ADDR_INSN);
294 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 show_regs(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296}
297
Heiko Carstensc0007f12007-04-27 16:01:42 +0200298int is_valid_bugaddr(unsigned long addr)
299{
300 return 1;
301}
302
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100303static void __kprobes do_trap(struct pt_regs *regs,
304 int si_signo, int si_code, char *str)
305{
306 siginfo_t info;
307
308 if (notify_die(DIE_TRAP, str, regs, 0,
309 regs->int_code, si_signo) == NOTIFY_STOP)
Michael Grundy4ba069b2006-09-20 15:58:39 +0200310 return;
311
Heiko Carstens7d256172012-07-27 10:31:12 +0200312 if (user_mode(regs)) {
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100313 info.si_signo = si_signo;
314 info.si_errno = 0;
315 info.si_code = si_code;
Martin Schwidefskyd35339a2012-07-31 11:03:04 +0200316 info.si_addr = get_trap_ip(regs);
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100317 force_sig_info(si_signo, &info, current);
318 report_user_fault(regs, si_signo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 } else {
320 const struct exception_table_entry *fixup;
321 fixup = search_exception_tables(regs->psw.addr & PSW_ADDR_INSN);
322 if (fixup)
Heiko Carstenseb608fb2012-09-05 13:26:11 +0200323 regs->psw.addr = extable_fixup(fixup) | PSW_ADDR_AMODE;
Heiko Carstensc0007f12007-04-27 16:01:42 +0200324 else {
325 enum bug_trap_type btt;
326
Heiko Carstens608e2612007-07-15 23:41:39 -0700327 btt = report_bug(regs->psw.addr & PSW_ADDR_INSN, regs);
Heiko Carstensc0007f12007-04-27 16:01:42 +0200328 if (btt == BUG_TRAP_TYPE_WARN)
329 return;
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100330 die(regs, str);
Heiko Carstensc0007f12007-04-27 16:01:42 +0200331 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 }
333}
334
Martin Schwidefsky5e9a2692011-01-05 12:48:10 +0100335void __kprobes do_per_trap(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336{
Martin Schwidefsky73b7d402011-07-24 10:48:33 +0200337 siginfo_t info;
338
Martin Schwidefsky5e9a2692011-01-05 12:48:10 +0100339 if (notify_die(DIE_SSTEP, "sstep", regs, 0, 0, SIGTRAP) == NOTIFY_STOP)
Michael Grundy4ba069b2006-09-20 15:58:39 +0200340 return;
Martin Schwidefsky73b7d402011-07-24 10:48:33 +0200341 if (!current->ptrace)
342 return;
343 info.si_signo = SIGTRAP;
344 info.si_errno = 0;
345 info.si_code = TRAP_HWBKPT;
Martin Schwidefsky3c52e492011-10-30 15:17:15 +0100346 info.si_addr =
347 (void __force __user *) current->thread.per_event.address;
Martin Schwidefsky73b7d402011-07-24 10:48:33 +0200348 force_sig_info(SIGTRAP, &info, current);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349}
350
Heiko Carstensb01a37a2012-10-18 18:10:06 +0200351void default_trap_handler(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352{
Heiko Carstens7d256172012-07-27 10:31:12 +0200353 if (user_mode(regs)) {
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100354 report_user_fault(regs, SIGSEGV);
Heiko Carstens6ea50962010-05-17 10:00:13 +0200355 do_exit(SIGSEGV);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 } else
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100357 die(regs, "Unknown program exception");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358}
359
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200360#define DO_ERROR_INFO(name, signr, sicode, str) \
Heiko Carstensb01a37a2012-10-18 18:10:06 +0200361void name(struct pt_regs *regs) \
362{ \
363 do_trap(regs, signr, sicode, str); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364}
365
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200366DO_ERROR_INFO(addressing_exception, SIGILL, ILL_ILLADR,
367 "addressing exception")
368DO_ERROR_INFO(execute_exception, SIGILL, ILL_ILLOPN,
369 "execute exception")
370DO_ERROR_INFO(divide_exception, SIGFPE, FPE_INTDIV,
371 "fixpoint divide exception")
372DO_ERROR_INFO(overflow_exception, SIGFPE, FPE_INTOVF,
373 "fixpoint overflow exception")
374DO_ERROR_INFO(hfp_overflow_exception, SIGFPE, FPE_FLTOVF,
375 "HFP overflow exception")
376DO_ERROR_INFO(hfp_underflow_exception, SIGFPE, FPE_FLTUND,
377 "HFP underflow exception")
378DO_ERROR_INFO(hfp_significance_exception, SIGFPE, FPE_FLTRES,
379 "HFP significance exception")
380DO_ERROR_INFO(hfp_divide_exception, SIGFPE, FPE_FLTDIV,
381 "HFP divide exception")
382DO_ERROR_INFO(hfp_sqrt_exception, SIGFPE, FPE_FLTINV,
383 "HFP square root exception")
384DO_ERROR_INFO(operand_exception, SIGILL, ILL_ILLOPN,
385 "operand exception")
386DO_ERROR_INFO(privileged_op, SIGILL, ILL_PRVOPC,
387 "privileged operation")
388DO_ERROR_INFO(special_op_exception, SIGILL, ILL_ILLOPN,
389 "special operation exception")
390DO_ERROR_INFO(translation_exception, SIGILL, ILL_ILLOPN,
391 "translation exception")
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
Martin Schwidefskyd35339a2012-07-31 11:03:04 +0200393#ifdef CONFIG_64BIT
394DO_ERROR_INFO(transaction_exception, SIGILL, ILL_ILLOPN,
395 "transaction constraint exception")
396#endif
397
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100398static inline void do_fp_trap(struct pt_regs *regs, int fpc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399{
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100400 int si_code = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 /* FPC[2] is Data Exception Code */
402 if ((fpc & 0x00000300) == 0) {
403 /* bits 6 and 7 of DXC are 0 iff IEEE exception */
404 if (fpc & 0x8000) /* invalid fp operation */
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100405 si_code = FPE_FLTINV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 else if (fpc & 0x4000) /* div by 0 */
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100407 si_code = FPE_FLTDIV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 else if (fpc & 0x2000) /* overflow */
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100409 si_code = FPE_FLTOVF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 else if (fpc & 0x1000) /* underflow */
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100411 si_code = FPE_FLTUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 else if (fpc & 0x0800) /* inexact */
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100413 si_code = FPE_FLTRES;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 }
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100415 do_trap(regs, SIGFPE, si_code, "floating point exception");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416}
417
Heiko Carstensb01a37a2012-10-18 18:10:06 +0200418void __kprobes illegal_op(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419{
420 siginfo_t info;
421 __u8 opcode[6];
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200422 __u16 __user *location;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 int signal = 0;
424
Martin Schwidefskyd35339a2012-07-31 11:03:04 +0200425 location = get_trap_ip(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
Heiko Carstens7d256172012-07-27 10:31:12 +0200427 if (user_mode(regs)) {
Heiko Carstens12bae232006-10-27 12:39:22 +0200428 if (get_user(*((__u16 *) opcode), (__u16 __user *) location))
429 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 if (*((__u16 *) opcode) == S390_BREAKPOINT_U16) {
Martin Schwidefsky73b7d402011-07-24 10:48:33 +0200431 if (current->ptrace) {
432 info.si_signo = SIGTRAP;
433 info.si_errno = 0;
434 info.si_code = TRAP_BRKPT;
435 info.si_addr = location;
436 force_sig_info(SIGTRAP, &info, current);
437 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 signal = SIGILL;
439#ifdef CONFIG_MATHEMU
440 } else if (opcode[0] == 0xb3) {
Heiko Carstens12bae232006-10-27 12:39:22 +0200441 if (get_user(*((__u16 *) (opcode+2)), location+1))
442 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 signal = math_emu_b3(opcode, regs);
444 } else if (opcode[0] == 0xed) {
Heiko Carstens12bae232006-10-27 12:39:22 +0200445 if (get_user(*((__u32 *) (opcode+2)),
446 (__u32 __user *)(location+1)))
447 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 signal = math_emu_ed(opcode, regs);
449 } else if (*((__u16 *) opcode) == 0xb299) {
Heiko Carstens12bae232006-10-27 12:39:22 +0200450 if (get_user(*((__u16 *) (opcode+2)), location+1))
451 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 signal = math_emu_srnm(opcode, regs);
453 } else if (*((__u16 *) opcode) == 0xb29c) {
Heiko Carstens12bae232006-10-27 12:39:22 +0200454 if (get_user(*((__u16 *) (opcode+2)), location+1))
455 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 signal = math_emu_stfpc(opcode, regs);
457 } else if (*((__u16 *) opcode) == 0xb29d) {
Heiko Carstens12bae232006-10-27 12:39:22 +0200458 if (get_user(*((__u16 *) (opcode+2)), location+1))
459 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 signal = math_emu_lfpc(opcode, regs);
461#endif
462 } else
463 signal = SIGILL;
Heiko Carstens35df8d52007-02-05 21:17:29 +0100464 } else {
465 /*
466 * If we get an illegal op in kernel mode, send it through the
467 * kprobes notifier. If kprobes doesn't pick it up, SIGILL
468 */
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100469 if (notify_die(DIE_BPT, "bpt", regs, 0,
Heiko Carstens35df8d52007-02-05 21:17:29 +0100470 3, SIGTRAP) != NOTIFY_STOP)
471 signal = SIGILL;
472 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
474#ifdef CONFIG_MATHEMU
475 if (signal == SIGFPE)
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100476 do_fp_trap(regs, current->thread.fp_regs.fpc);
477 else if (signal == SIGSEGV)
478 do_trap(regs, signal, SEGV_MAPERR, "user address fault");
479 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480#endif
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100481 if (signal)
482 do_trap(regs, signal, ILL_ILLOPC, "illegal operation");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483}
484
485
486#ifdef CONFIG_MATHEMU
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100487void specification_exception(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488{
489 __u8 opcode[6];
Al Viro5a42b812006-10-09 20:28:03 +0100490 __u16 __user *location = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 int signal = 0;
492
Martin Schwidefskyd35339a2012-07-31 11:03:04 +0200493 location = (__u16 __user *) get_trap_ip(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
Heiko Carstens7d256172012-07-27 10:31:12 +0200495 if (user_mode(regs)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 get_user(*((__u16 *) opcode), location);
497 switch (opcode[0]) {
498 case 0x28: /* LDR Rx,Ry */
499 signal = math_emu_ldr(opcode);
500 break;
501 case 0x38: /* LER Rx,Ry */
502 signal = math_emu_ler(opcode);
503 break;
504 case 0x60: /* STD R,D(X,B) */
505 get_user(*((__u16 *) (opcode+2)), location+1);
506 signal = math_emu_std(opcode, regs);
507 break;
508 case 0x68: /* LD R,D(X,B) */
509 get_user(*((__u16 *) (opcode+2)), location+1);
510 signal = math_emu_ld(opcode, regs);
511 break;
512 case 0x70: /* STE R,D(X,B) */
513 get_user(*((__u16 *) (opcode+2)), location+1);
514 signal = math_emu_ste(opcode, regs);
515 break;
516 case 0x78: /* LE R,D(X,B) */
517 get_user(*((__u16 *) (opcode+2)), location+1);
518 signal = math_emu_le(opcode, regs);
519 break;
520 default:
521 signal = SIGILL;
522 break;
523 }
524 } else
525 signal = SIGILL;
526
527 if (signal == SIGFPE)
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100528 do_fp_trap(regs, current->thread.fp_regs.fpc);
529 else if (signal)
530 do_trap(regs, signal, ILL_ILLOPN, "specification exception");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531}
532#else
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200533DO_ERROR_INFO(specification_exception, SIGILL, ILL_ILLOPN,
534 "specification exception");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535#endif
536
Heiko Carstensb01a37a2012-10-18 18:10:06 +0200537void data_exception(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538{
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200539 __u16 __user *location;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 int signal = 0;
541
Martin Schwidefskyd35339a2012-07-31 11:03:04 +0200542 location = get_trap_ip(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
544 if (MACHINE_HAS_IEEE)
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200545 asm volatile("stfpc %0" : "=m" (current->thread.fp_regs.fpc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
547#ifdef CONFIG_MATHEMU
Heiko Carstens7d256172012-07-27 10:31:12 +0200548 else if (user_mode(regs)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 __u8 opcode[6];
550 get_user(*((__u16 *) opcode), location);
551 switch (opcode[0]) {
552 case 0x28: /* LDR Rx,Ry */
553 signal = math_emu_ldr(opcode);
554 break;
555 case 0x38: /* LER Rx,Ry */
556 signal = math_emu_ler(opcode);
557 break;
558 case 0x60: /* STD R,D(X,B) */
559 get_user(*((__u16 *) (opcode+2)), location+1);
560 signal = math_emu_std(opcode, regs);
561 break;
562 case 0x68: /* LD R,D(X,B) */
563 get_user(*((__u16 *) (opcode+2)), location+1);
564 signal = math_emu_ld(opcode, regs);
565 break;
566 case 0x70: /* STE R,D(X,B) */
567 get_user(*((__u16 *) (opcode+2)), location+1);
568 signal = math_emu_ste(opcode, regs);
569 break;
570 case 0x78: /* LE R,D(X,B) */
571 get_user(*((__u16 *) (opcode+2)), location+1);
572 signal = math_emu_le(opcode, regs);
573 break;
574 case 0xb3:
575 get_user(*((__u16 *) (opcode+2)), location+1);
576 signal = math_emu_b3(opcode, regs);
577 break;
578 case 0xed:
579 get_user(*((__u32 *) (opcode+2)),
Al Viro5a42b812006-10-09 20:28:03 +0100580 (__u32 __user *)(location+1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 signal = math_emu_ed(opcode, regs);
582 break;
583 case 0xb2:
584 if (opcode[1] == 0x99) {
585 get_user(*((__u16 *) (opcode+2)), location+1);
586 signal = math_emu_srnm(opcode, regs);
587 } else if (opcode[1] == 0x9c) {
588 get_user(*((__u16 *) (opcode+2)), location+1);
589 signal = math_emu_stfpc(opcode, regs);
590 } else if (opcode[1] == 0x9d) {
591 get_user(*((__u16 *) (opcode+2)), location+1);
592 signal = math_emu_lfpc(opcode, regs);
593 } else
594 signal = SIGILL;
595 break;
596 default:
597 signal = SIGILL;
598 break;
599 }
600 }
601#endif
602 if (current->thread.fp_regs.fpc & FPC_DXC_MASK)
603 signal = SIGFPE;
604 else
605 signal = SIGILL;
606 if (signal == SIGFPE)
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100607 do_fp_trap(regs, current->thread.fp_regs.fpc);
608 else if (signal)
609 do_trap(regs, signal, ILL_ILLOPN, "data exception");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610}
611
Heiko Carstensb01a37a2012-10-18 18:10:06 +0200612void space_switch_exception(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 /* Set user psw back to home space mode. */
Heiko Carstens7d256172012-07-27 10:31:12 +0200615 if (user_mode(regs))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 regs->psw.mask |= PSW_ASC_HOME;
617 /* Send SIGILL. */
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100618 do_trap(regs, SIGILL, ILL_PRVOPC, "space switch event");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619}
620
Martin Schwidefskyfdb204d2011-07-24 10:48:24 +0200621void __kprobes kernel_stack_overflow(struct pt_regs * regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622{
Heiko Carstens77eb65c2005-06-21 17:16:28 -0700623 bust_spinlocks(1);
624 printk("Kernel stack overflow.\n");
625 show_regs(regs);
626 bust_spinlocks(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 panic("Corrupt kernel stack, can't continue.");
628}
629
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630void __init trap_init(void)
631{
Heiko Carstensf3e1a272011-01-05 12:48:00 +0100632 local_mcck_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633}