blob: 01775c04a90e63a2bbebc2eb5d3ebf0363abafe2 [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
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +010044void (*pgm_check_table[128])(struct pt_regs *regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Heiko Carstens02834ee2011-12-27 11:27:31 +010046int show_unhandled_signals = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#define stack_pointer ({ void **sp; asm("la %0,0(15)" : "=&d" (sp)); sp; })
49
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -080050#ifndef CONFIG_64BIT
Christian Borntraegerd7fd5f12009-03-26 15:23:42 +010051#define LONG "%08lx "
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#define FOURLONG "%08lx %08lx %08lx %08lx\n"
53static int kstack_depth_to_print = 12;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -080054#else /* CONFIG_64BIT */
Christian Borntraegerd7fd5f12009-03-26 15:23:42 +010055#define LONG "%016lx "
Linus Torvalds1da177e2005-04-16 15:20:36 -070056#define FOURLONG "%016lx %016lx %016lx %016lx\n"
57static int kstack_depth_to_print = 20;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -080058#endif /* CONFIG_64BIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60/*
61 * For show_trace we have tree different stack to consider:
62 * - the panic stack which is used if the kernel stack has overflown
63 * - the asynchronous interrupt stack (cpu related)
64 * - the synchronous kernel stack (process related)
65 * The stack trace can start at any of the three stack and can potentially
66 * touch all of them. The order is: panic stack, async stack, sync stack.
67 */
68static unsigned long
69__show_trace(unsigned long sp, unsigned long low, unsigned long high)
70{
71 struct stack_frame *sf;
72 struct pt_regs *regs;
73
74 while (1) {
75 sp = sp & PSW_ADDR_INSN;
76 if (sp < low || sp > high - sizeof(*sf))
77 return sp;
78 sf = (struct stack_frame *) sp;
79 printk("([<%016lx>] ", sf->gprs[8] & PSW_ADDR_INSN);
80 print_symbol("%s)\n", sf->gprs[8] & PSW_ADDR_INSN);
81 /* Follow the backchain. */
82 while (1) {
83 low = sp;
84 sp = sf->back_chain & PSW_ADDR_INSN;
85 if (!sp)
86 break;
87 if (sp <= low || sp > high - sizeof(*sf))
88 return sp;
89 sf = (struct stack_frame *) sp;
90 printk(" [<%016lx>] ", sf->gprs[8] & PSW_ADDR_INSN);
91 print_symbol("%s\n", sf->gprs[8] & PSW_ADDR_INSN);
92 }
93 /* Zero backchain detected, check for interrupt frame. */
94 sp = (unsigned long) (sf + 1);
95 if (sp <= low || sp > high - sizeof(*regs))
96 return sp;
97 regs = (struct pt_regs *) sp;
98 printk(" [<%016lx>] ", regs->psw.addr & PSW_ADDR_INSN);
99 print_symbol("%s\n", regs->psw.addr & PSW_ADDR_INSN);
100 low = sp;
101 sp = regs->gprs[15];
102 }
103}
104
Heiko Carstens4e83be72008-04-30 13:38:34 +0200105static void show_trace(struct task_struct *task, unsigned long *stack)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106{
107 register unsigned long __r15 asm ("15");
108 unsigned long sp;
109
110 sp = (unsigned long) stack;
111 if (!sp)
112 sp = task ? task->thread.ksp : __r15;
113 printk("Call Trace:\n");
114#ifdef CONFIG_CHECK_STACK
115 sp = __show_trace(sp, S390_lowcore.panic_stack - 4096,
116 S390_lowcore.panic_stack);
117#endif
118 sp = __show_trace(sp, S390_lowcore.async_stack - ASYNC_SIZE,
119 S390_lowcore.async_stack);
120 if (task)
Al Viro30af7122006-01-12 01:05:50 -0800121 __show_trace(sp, (unsigned long) task_stack_page(task),
122 (unsigned long) task_stack_page(task) + THREAD_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 else
124 __show_trace(sp, S390_lowcore.thread_info,
125 S390_lowcore.thread_info + THREAD_SIZE);
Heiko Carstens236257e2006-12-04 15:40:47 +0100126 if (!task)
127 task = current;
128 debug_show_held_locks(task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129}
130
131void show_stack(struct task_struct *task, unsigned long *sp)
132{
133 register unsigned long * __r15 asm ("15");
134 unsigned long *stack;
135 int i;
136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 if (!sp)
Heiko Carstens73805342006-06-29 14:56:23 +0200138 stack = task ? (unsigned long *) task->thread.ksp : __r15;
139 else
140 stack = sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 for (i = 0; i < kstack_depth_to_print; i++) {
143 if (((addr_t) stack & (THREAD_SIZE-1)) == 0)
144 break;
Heiko Carstensddadfa82012-03-11 11:59:35 -0400145 if ((i * sizeof(long) % 32) == 0)
146 printk("%s ", i == 0 ? "" : "\n");
Christian Borntraegerd7fd5f12009-03-26 15:23:42 +0100147 printk(LONG, *stack++);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 }
149 printk("\n");
150 show_trace(task, sp);
151}
152
Heiko Carstens4e83be72008-04-30 13:38:34 +0200153static void show_last_breaking_event(struct pt_regs *regs)
Christian Borntraeger9e74a6b82008-04-17 07:46:30 +0200154{
Heiko Carstens4e83be72008-04-30 13:38:34 +0200155#ifdef CONFIG_64BIT
Christian Borntraeger9e74a6b82008-04-17 07:46:30 +0200156 printk("Last Breaking-Event-Address:\n");
157 printk(" [<%016lx>] ", regs->args[0] & PSW_ADDR_INSN);
158 print_symbol("%s\n", regs->args[0] & PSW_ADDR_INSN);
Christian Borntraeger9e74a6b82008-04-17 07:46:30 +0200159#endif
Heiko Carstens4e83be72008-04-30 13:38:34 +0200160}
Christian Borntraeger9e74a6b82008-04-17 07:46:30 +0200161
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162/*
163 * The architecture-independent dump_stack generator
164 */
165void dump_stack(void)
166{
Heiko Carstens5c699712008-01-26 14:11:01 +0100167 printk("CPU: %d %s %s %.*s\n",
168 task_thread_info(current)->cpu, print_tainted(),
169 init_utsname()->release,
170 (int)strcspn(init_utsname()->version, " "),
171 init_utsname()->version);
172 printk("Process %s (pid: %d, task: %p, ksp: %p)\n",
173 current->comm, current->pid, current,
174 (void *) current->thread.ksp);
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200175 show_stack(NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177EXPORT_SYMBOL(dump_stack);
178
Martin Schwidefskybb11e3b2007-04-27 16:01:41 +0200179static inline int mask_bits(struct pt_regs *regs, unsigned long bits)
180{
181 return (regs->psw.mask & bits) / ((~bits + 1) & bits);
182}
183
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184void show_registers(struct pt_regs *regs)
185{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 char *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
Heiko Carstens7d256172012-07-27 10:31:12 +0200188 mode = user_mode(regs) ? "User" : "Krnl";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 printk("%s PSW : %p %p",
190 mode, (void *) regs->psw.mask,
191 (void *) regs->psw.addr);
192 print_symbol(" (%s)\n", regs->psw.addr & PSW_ADDR_INSN);
Martin Schwidefskybb11e3b2007-04-27 16:01:41 +0200193 printk(" R:%x T:%x IO:%x EX:%x Key:%x M:%x W:%x "
194 "P:%x AS:%x CC:%x PM:%x", mask_bits(regs, PSW_MASK_PER),
195 mask_bits(regs, PSW_MASK_DAT), mask_bits(regs, PSW_MASK_IO),
196 mask_bits(regs, PSW_MASK_EXT), mask_bits(regs, PSW_MASK_KEY),
197 mask_bits(regs, PSW_MASK_MCHECK), mask_bits(regs, PSW_MASK_WAIT),
198 mask_bits(regs, PSW_MASK_PSTATE), mask_bits(regs, PSW_MASK_ASC),
199 mask_bits(regs, PSW_MASK_CC), mask_bits(regs, PSW_MASK_PM));
200#ifdef CONFIG_64BIT
Martin Schwidefskyb50511e2011-10-30 15:16:50 +0100201 printk(" EA:%x", mask_bits(regs, PSW_MASK_EA | PSW_MASK_BA));
Martin Schwidefskybb11e3b2007-04-27 16:01:41 +0200202#endif
203 printk("\n%s GPRS: " FOURLONG, mode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 regs->gprs[0], regs->gprs[1], regs->gprs[2], regs->gprs[3]);
205 printk(" " FOURLONG,
206 regs->gprs[4], regs->gprs[5], regs->gprs[6], regs->gprs[7]);
207 printk(" " FOURLONG,
208 regs->gprs[8], regs->gprs[9], regs->gprs[10], regs->gprs[11]);
209 printk(" " FOURLONG,
210 regs->gprs[12], regs->gprs[13], regs->gprs[14], regs->gprs[15]);
211
Martin Schwidefskybb11e3b2007-04-27 16:01:41 +0200212 show_code(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213}
214
Heiko Carstens4e83be72008-04-30 13:38:34 +0200215void show_regs(struct pt_regs *regs)
216{
217 print_modules();
218 printk("CPU: %d %s %s %.*s\n",
219 task_thread_info(current)->cpu, print_tainted(),
220 init_utsname()->release,
221 (int)strcspn(init_utsname()->version, " "),
222 init_utsname()->version);
223 printk("Process %s (pid: %d, task: %p, ksp: %p)\n",
224 current->comm, current->pid, current,
225 (void *) current->thread.ksp);
226 show_registers(regs);
227 /* Show stack backtrace if pt_regs is from kernel mode */
Heiko Carstens7d256172012-07-27 10:31:12 +0200228 if (!user_mode(regs))
Heiko Carstens4e83be72008-04-30 13:38:34 +0200229 show_trace(NULL, (unsigned long *) regs->gprs[15]);
230 show_last_breaking_event(regs);
231}
232
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100233static DEFINE_SPINLOCK(die_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100235void die(struct pt_regs *regs, const char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236{
237 static int die_counter;
238
Heiko Carstensbca0fb862007-06-19 13:10:05 +0200239 oops_enter();
Michael Holzheu3ab121a2012-03-11 11:59:32 -0400240 lgr_info_log();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 debug_stop_all();
242 console_verbose();
243 spin_lock_irq(&die_lock);
244 bust_spinlocks(1);
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100245 printk("%s: %04x [#%d] ", str, regs->int_code & 0xffff, ++die_counter);
Heiko Carstens5c699712008-01-26 14:11:01 +0100246#ifdef CONFIG_PREEMPT
247 printk("PREEMPT ");
248#endif
249#ifdef CONFIG_SMP
Heiko Carstens24855792008-02-05 16:50:37 +0100250 printk("SMP ");
251#endif
252#ifdef CONFIG_DEBUG_PAGEALLOC
253 printk("DEBUG_PAGEALLOC");
Heiko Carstens5c699712008-01-26 14:11:01 +0100254#endif
255 printk("\n");
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100256 notify_die(DIE_OOPS, str, regs, 0, regs->int_code & 0xffff, SIGSEGV);
Heiko Carstensbca0fb862007-06-19 13:10:05 +0200257 show_regs(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 bust_spinlocks(0);
Pavel Emelianovbcdcd8e2007-07-17 04:03:42 -0700259 add_taint(TAINT_DIE);
Heiko Carstensbca0fb862007-06-19 13:10:05 +0200260 spin_unlock_irq(&die_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 if (in_interrupt())
262 panic("Fatal exception in interrupt");
263 if (panic_on_oops)
264 panic("Fatal exception: panic_on_oops");
Heiko Carstensbca0fb862007-06-19 13:10:05 +0200265 oops_exit();
266 do_exit(SIGSEGV);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267}
268
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100269static inline void report_user_fault(struct pt_regs *regs, int signr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270{
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200271 if ((task_pid_nr(current) > 1) && !show_unhandled_signals)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 return;
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200273 if (!unhandled_signal(current, signr))
274 return;
275 if (!printk_ratelimit())
276 return;
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100277 printk("User process fault: interruption code 0x%X ", regs->int_code);
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200278 print_vma_addr("in ", regs->psw.addr & PSW_ADDR_INSN);
279 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 show_regs(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281}
282
Heiko Carstensc0007f12007-04-27 16:01:42 +0200283int is_valid_bugaddr(unsigned long addr)
284{
285 return 1;
286}
287
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100288static inline void __user *get_psw_address(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100290 return (void __user *)
291 ((regs->psw.addr - (regs->int_code >> 16)) & PSW_ADDR_INSN);
292}
293
294static void __kprobes do_trap(struct pt_regs *regs,
295 int si_signo, int si_code, char *str)
296{
297 siginfo_t info;
298
299 if (notify_die(DIE_TRAP, str, regs, 0,
300 regs->int_code, si_signo) == NOTIFY_STOP)
Michael Grundy4ba069b2006-09-20 15:58:39 +0200301 return;
302
Heiko Carstens7d256172012-07-27 10:31:12 +0200303 if (user_mode(regs)) {
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100304 info.si_signo = si_signo;
305 info.si_errno = 0;
306 info.si_code = si_code;
307 info.si_addr = get_psw_address(regs);
308 force_sig_info(si_signo, &info, current);
309 report_user_fault(regs, si_signo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 } else {
311 const struct exception_table_entry *fixup;
312 fixup = search_exception_tables(regs->psw.addr & PSW_ADDR_INSN);
313 if (fixup)
314 regs->psw.addr = fixup->fixup | PSW_ADDR_AMODE;
Heiko Carstensc0007f12007-04-27 16:01:42 +0200315 else {
316 enum bug_trap_type btt;
317
Heiko Carstens608e2612007-07-15 23:41:39 -0700318 btt = report_bug(regs->psw.addr & PSW_ADDR_INSN, regs);
Heiko Carstensc0007f12007-04-27 16:01:42 +0200319 if (btt == BUG_TRAP_TYPE_WARN)
320 return;
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100321 die(regs, str);
Heiko Carstensc0007f12007-04-27 16:01:42 +0200322 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 }
324}
325
Martin Schwidefsky5e9a2692011-01-05 12:48:10 +0100326void __kprobes do_per_trap(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327{
Martin Schwidefsky73b7d402011-07-24 10:48:33 +0200328 siginfo_t info;
329
Martin Schwidefsky5e9a2692011-01-05 12:48:10 +0100330 if (notify_die(DIE_SSTEP, "sstep", regs, 0, 0, SIGTRAP) == NOTIFY_STOP)
Michael Grundy4ba069b2006-09-20 15:58:39 +0200331 return;
Martin Schwidefsky73b7d402011-07-24 10:48:33 +0200332 if (!current->ptrace)
333 return;
334 info.si_signo = SIGTRAP;
335 info.si_errno = 0;
336 info.si_code = TRAP_HWBKPT;
Martin Schwidefsky3c52e492011-10-30 15:17:15 +0100337 info.si_addr =
338 (void __force __user *) current->thread.per_event.address;
Martin Schwidefsky73b7d402011-07-24 10:48:33 +0200339 force_sig_info(SIGTRAP, &info, current);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340}
341
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100342static void default_trap_handler(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343{
Heiko Carstens7d256172012-07-27 10:31:12 +0200344 if (user_mode(regs)) {
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100345 report_user_fault(regs, SIGSEGV);
Heiko Carstens6ea50962010-05-17 10:00:13 +0200346 do_exit(SIGSEGV);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 } else
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100348 die(regs, "Unknown program exception");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349}
350
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200351#define DO_ERROR_INFO(name, signr, sicode, str) \
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100352static void name(struct pt_regs *regs) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353{ \
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100354 do_trap(regs, signr, sicode, str); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355}
356
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200357DO_ERROR_INFO(addressing_exception, SIGILL, ILL_ILLADR,
358 "addressing exception")
359DO_ERROR_INFO(execute_exception, SIGILL, ILL_ILLOPN,
360 "execute exception")
361DO_ERROR_INFO(divide_exception, SIGFPE, FPE_INTDIV,
362 "fixpoint divide exception")
363DO_ERROR_INFO(overflow_exception, SIGFPE, FPE_INTOVF,
364 "fixpoint overflow exception")
365DO_ERROR_INFO(hfp_overflow_exception, SIGFPE, FPE_FLTOVF,
366 "HFP overflow exception")
367DO_ERROR_INFO(hfp_underflow_exception, SIGFPE, FPE_FLTUND,
368 "HFP underflow exception")
369DO_ERROR_INFO(hfp_significance_exception, SIGFPE, FPE_FLTRES,
370 "HFP significance exception")
371DO_ERROR_INFO(hfp_divide_exception, SIGFPE, FPE_FLTDIV,
372 "HFP divide exception")
373DO_ERROR_INFO(hfp_sqrt_exception, SIGFPE, FPE_FLTINV,
374 "HFP square root exception")
375DO_ERROR_INFO(operand_exception, SIGILL, ILL_ILLOPN,
376 "operand exception")
377DO_ERROR_INFO(privileged_op, SIGILL, ILL_PRVOPC,
378 "privileged operation")
379DO_ERROR_INFO(special_op_exception, SIGILL, ILL_ILLOPN,
380 "special operation exception")
381DO_ERROR_INFO(translation_exception, SIGILL, ILL_ILLOPN,
382 "translation exception")
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100384static inline void do_fp_trap(struct pt_regs *regs, int fpc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385{
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100386 int si_code = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 /* FPC[2] is Data Exception Code */
388 if ((fpc & 0x00000300) == 0) {
389 /* bits 6 and 7 of DXC are 0 iff IEEE exception */
390 if (fpc & 0x8000) /* invalid fp operation */
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100391 si_code = FPE_FLTINV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 else if (fpc & 0x4000) /* div by 0 */
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100393 si_code = FPE_FLTDIV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 else if (fpc & 0x2000) /* overflow */
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100395 si_code = FPE_FLTOVF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 else if (fpc & 0x1000) /* underflow */
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100397 si_code = FPE_FLTUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 else if (fpc & 0x0800) /* inexact */
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100399 si_code = FPE_FLTRES;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 }
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100401 do_trap(regs, SIGFPE, si_code, "floating point exception");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402}
403
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100404static void __kprobes illegal_op(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405{
406 siginfo_t info;
407 __u8 opcode[6];
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200408 __u16 __user *location;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 int signal = 0;
410
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100411 location = get_psw_address(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
Heiko Carstens7d256172012-07-27 10:31:12 +0200413 if (user_mode(regs)) {
Heiko Carstens12bae232006-10-27 12:39:22 +0200414 if (get_user(*((__u16 *) opcode), (__u16 __user *) location))
415 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 if (*((__u16 *) opcode) == S390_BREAKPOINT_U16) {
Martin Schwidefsky73b7d402011-07-24 10:48:33 +0200417 if (current->ptrace) {
418 info.si_signo = SIGTRAP;
419 info.si_errno = 0;
420 info.si_code = TRAP_BRKPT;
421 info.si_addr = location;
422 force_sig_info(SIGTRAP, &info, current);
423 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 signal = SIGILL;
425#ifdef CONFIG_MATHEMU
426 } else if (opcode[0] == 0xb3) {
Heiko Carstens12bae232006-10-27 12:39:22 +0200427 if (get_user(*((__u16 *) (opcode+2)), location+1))
428 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 signal = math_emu_b3(opcode, regs);
430 } else if (opcode[0] == 0xed) {
Heiko Carstens12bae232006-10-27 12:39:22 +0200431 if (get_user(*((__u32 *) (opcode+2)),
432 (__u32 __user *)(location+1)))
433 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 signal = math_emu_ed(opcode, regs);
435 } else if (*((__u16 *) opcode) == 0xb299) {
Heiko Carstens12bae232006-10-27 12:39:22 +0200436 if (get_user(*((__u16 *) (opcode+2)), location+1))
437 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 signal = math_emu_srnm(opcode, regs);
439 } else if (*((__u16 *) opcode) == 0xb29c) {
Heiko Carstens12bae232006-10-27 12:39:22 +0200440 if (get_user(*((__u16 *) (opcode+2)), location+1))
441 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 signal = math_emu_stfpc(opcode, regs);
443 } else if (*((__u16 *) opcode) == 0xb29d) {
Heiko Carstens12bae232006-10-27 12:39:22 +0200444 if (get_user(*((__u16 *) (opcode+2)), location+1))
445 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 signal = math_emu_lfpc(opcode, regs);
447#endif
448 } else
449 signal = SIGILL;
Heiko Carstens35df8d52007-02-05 21:17:29 +0100450 } else {
451 /*
452 * If we get an illegal op in kernel mode, send it through the
453 * kprobes notifier. If kprobes doesn't pick it up, SIGILL
454 */
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100455 if (notify_die(DIE_BPT, "bpt", regs, 0,
Heiko Carstens35df8d52007-02-05 21:17:29 +0100456 3, SIGTRAP) != NOTIFY_STOP)
457 signal = SIGILL;
458 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
460#ifdef CONFIG_MATHEMU
461 if (signal == SIGFPE)
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100462 do_fp_trap(regs, current->thread.fp_regs.fpc);
463 else if (signal == SIGSEGV)
464 do_trap(regs, signal, SEGV_MAPERR, "user address fault");
465 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466#endif
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100467 if (signal)
468 do_trap(regs, signal, ILL_ILLOPC, "illegal operation");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469}
470
471
472#ifdef CONFIG_MATHEMU
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100473void specification_exception(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474{
475 __u8 opcode[6];
Al Viro5a42b812006-10-09 20:28:03 +0100476 __u16 __user *location = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 int signal = 0;
478
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100479 location = (__u16 __user *) get_psw_address(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
Heiko Carstens7d256172012-07-27 10:31:12 +0200481 if (user_mode(regs)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 get_user(*((__u16 *) opcode), location);
483 switch (opcode[0]) {
484 case 0x28: /* LDR Rx,Ry */
485 signal = math_emu_ldr(opcode);
486 break;
487 case 0x38: /* LER Rx,Ry */
488 signal = math_emu_ler(opcode);
489 break;
490 case 0x60: /* STD R,D(X,B) */
491 get_user(*((__u16 *) (opcode+2)), location+1);
492 signal = math_emu_std(opcode, regs);
493 break;
494 case 0x68: /* LD R,D(X,B) */
495 get_user(*((__u16 *) (opcode+2)), location+1);
496 signal = math_emu_ld(opcode, regs);
497 break;
498 case 0x70: /* STE R,D(X,B) */
499 get_user(*((__u16 *) (opcode+2)), location+1);
500 signal = math_emu_ste(opcode, regs);
501 break;
502 case 0x78: /* LE R,D(X,B) */
503 get_user(*((__u16 *) (opcode+2)), location+1);
504 signal = math_emu_le(opcode, regs);
505 break;
506 default:
507 signal = SIGILL;
508 break;
509 }
510 } else
511 signal = SIGILL;
512
513 if (signal == SIGFPE)
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100514 do_fp_trap(regs, current->thread.fp_regs.fpc);
515 else if (signal)
516 do_trap(regs, signal, ILL_ILLOPN, "specification exception");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517}
518#else
Martin Schwidefsky1e546222010-10-25 16:10:37 +0200519DO_ERROR_INFO(specification_exception, SIGILL, ILL_ILLOPN,
520 "specification exception");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521#endif
522
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100523static void data_exception(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524{
Heiko Carstensd2c993d2006-07-12 16:41:55 +0200525 __u16 __user *location;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 int signal = 0;
527
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100528 location = get_psw_address(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
530 if (MACHINE_HAS_IEEE)
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200531 asm volatile("stfpc %0" : "=m" (current->thread.fp_regs.fpc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
533#ifdef CONFIG_MATHEMU
Heiko Carstens7d256172012-07-27 10:31:12 +0200534 else if (user_mode(regs)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 __u8 opcode[6];
536 get_user(*((__u16 *) opcode), location);
537 switch (opcode[0]) {
538 case 0x28: /* LDR Rx,Ry */
539 signal = math_emu_ldr(opcode);
540 break;
541 case 0x38: /* LER Rx,Ry */
542 signal = math_emu_ler(opcode);
543 break;
544 case 0x60: /* STD R,D(X,B) */
545 get_user(*((__u16 *) (opcode+2)), location+1);
546 signal = math_emu_std(opcode, regs);
547 break;
548 case 0x68: /* LD R,D(X,B) */
549 get_user(*((__u16 *) (opcode+2)), location+1);
550 signal = math_emu_ld(opcode, regs);
551 break;
552 case 0x70: /* STE R,D(X,B) */
553 get_user(*((__u16 *) (opcode+2)), location+1);
554 signal = math_emu_ste(opcode, regs);
555 break;
556 case 0x78: /* LE R,D(X,B) */
557 get_user(*((__u16 *) (opcode+2)), location+1);
558 signal = math_emu_le(opcode, regs);
559 break;
560 case 0xb3:
561 get_user(*((__u16 *) (opcode+2)), location+1);
562 signal = math_emu_b3(opcode, regs);
563 break;
564 case 0xed:
565 get_user(*((__u32 *) (opcode+2)),
Al Viro5a42b812006-10-09 20:28:03 +0100566 (__u32 __user *)(location+1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 signal = math_emu_ed(opcode, regs);
568 break;
569 case 0xb2:
570 if (opcode[1] == 0x99) {
571 get_user(*((__u16 *) (opcode+2)), location+1);
572 signal = math_emu_srnm(opcode, regs);
573 } else if (opcode[1] == 0x9c) {
574 get_user(*((__u16 *) (opcode+2)), location+1);
575 signal = math_emu_stfpc(opcode, regs);
576 } else if (opcode[1] == 0x9d) {
577 get_user(*((__u16 *) (opcode+2)), location+1);
578 signal = math_emu_lfpc(opcode, regs);
579 } else
580 signal = SIGILL;
581 break;
582 default:
583 signal = SIGILL;
584 break;
585 }
586 }
587#endif
588 if (current->thread.fp_regs.fpc & FPC_DXC_MASK)
589 signal = SIGFPE;
590 else
591 signal = SIGILL;
592 if (signal == SIGFPE)
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100593 do_fp_trap(regs, current->thread.fp_regs.fpc);
594 else if (signal)
595 do_trap(regs, signal, ILL_ILLOPN, "data exception");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596}
597
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100598static void space_switch_exception(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 /* Set user psw back to home space mode. */
Heiko Carstens7d256172012-07-27 10:31:12 +0200601 if (user_mode(regs))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 regs->psw.mask |= PSW_ASC_HOME;
603 /* Send SIGILL. */
Martin Schwidefskyaa33c8c2011-12-27 11:27:18 +0100604 do_trap(regs, SIGILL, ILL_PRVOPC, "space switch event");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605}
606
Martin Schwidefskyfdb204d2011-07-24 10:48:24 +0200607void __kprobes kernel_stack_overflow(struct pt_regs * regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608{
Heiko Carstens77eb65c2005-06-21 17:16:28 -0700609 bust_spinlocks(1);
610 printk("Kernel stack overflow.\n");
611 show_regs(regs);
612 bust_spinlocks(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 panic("Corrupt kernel stack, can't continue.");
614}
615
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616/* init is done in lowcore.S and head.S */
617
618void __init trap_init(void)
619{
620 int i;
621
622 for (i = 0; i < 128; i++)
623 pgm_check_table[i] = &default_trap_handler;
624 pgm_check_table[1] = &illegal_op;
625 pgm_check_table[2] = &privileged_op;
626 pgm_check_table[3] = &execute_exception;
627 pgm_check_table[4] = &do_protection_exception;
628 pgm_check_table[5] = &addressing_exception;
629 pgm_check_table[6] = &specification_exception;
630 pgm_check_table[7] = &data_exception;
631 pgm_check_table[8] = &overflow_exception;
632 pgm_check_table[9] = &divide_exception;
633 pgm_check_table[0x0A] = &overflow_exception;
634 pgm_check_table[0x0B] = &divide_exception;
635 pgm_check_table[0x0C] = &hfp_overflow_exception;
636 pgm_check_table[0x0D] = &hfp_underflow_exception;
637 pgm_check_table[0x0E] = &hfp_significance_exception;
638 pgm_check_table[0x0F] = &hfp_divide_exception;
639 pgm_check_table[0x10] = &do_dat_exception;
640 pgm_check_table[0x11] = &do_dat_exception;
641 pgm_check_table[0x12] = &translation_exception;
642 pgm_check_table[0x13] = &special_op_exception;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800643#ifdef CONFIG_64BIT
Martin Schwidefsky6252d702008-02-09 18:24:37 +0100644 pgm_check_table[0x38] = &do_asce_exception;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 pgm_check_table[0x39] = &do_dat_exception;
646 pgm_check_table[0x3A] = &do_dat_exception;
647 pgm_check_table[0x3B] = &do_dat_exception;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800648#endif /* CONFIG_64BIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 pgm_check_table[0x15] = &operand_exception;
650 pgm_check_table[0x1C] = &space_switch_exception;
651 pgm_check_table[0x1D] = &hfp_sqrt_exception;
Heiko Carstensf3e1a272011-01-05 12:48:00 +0100652 /* Enable machine checks early. */
653 local_mcck_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654}