3 * Copyright IBM Corp. 1999, 2000
4 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
5 * Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com),
7 * Derived from "arch/i386/kernel/traps.c"
8 * Copyright (C) 1991, 1992 Linus Torvalds
12 * 'Traps.c' handles hardware traps and faults after we have saved some
15 #include <linux/sched.h>
16 #include <linux/kernel.h>
17 #include <linux/string.h>
18 #include <linux/errno.h>
19 #include <linux/ptrace.h>
20 #include <linux/timer.h>
22 #include <linux/smp.h>
23 #include <linux/init.h>
24 #include <linux/interrupt.h>
25 #include <linux/seq_file.h>
26 #include <linux/delay.h>
27 #include <linux/module.h>
28 #include <linux/kdebug.h>
29 #include <linux/kallsyms.h>
30 #include <linux/reboot.h>
31 #include <linux/kprobes.h>
32 #include <linux/bug.h>
33 #include <linux/utsname.h>
34 #include <asm/uaccess.h>
36 #include <linux/atomic.h>
37 #include <asm/mathemu.h>
38 #include <asm/cpcmd.h>
39 #include <asm/lowcore.h>
40 #include <asm/debug.h>
44 int show_unhandled_signals
= 1;
46 #define stack_pointer ({ void **sp; asm("la %0,0(15)" : "=&d" (sp)); sp; })
50 #define FOURLONG "%08lx %08lx %08lx %08lx\n"
51 static int kstack_depth_to_print
= 12;
52 #else /* CONFIG_64BIT */
53 #define LONG "%016lx "
54 #define FOURLONG "%016lx %016lx %016lx %016lx\n"
55 static int kstack_depth_to_print
= 20;
56 #endif /* CONFIG_64BIT */
58 static inline void __user
*get_trap_ip(struct pt_regs
*regs
)
61 unsigned long address
;
63 if (regs
->int_code
& 0x200)
64 address
= *(unsigned long *)(current
->thread
.trap_tdb
+ 24);
66 address
= regs
->psw
.addr
;
67 return (void __user
*)
68 ((address
- (regs
->int_code
>> 16)) & PSW_ADDR_INSN
);
70 return (void __user
*)
71 ((regs
->psw
.addr
- (regs
->int_code
>> 16)) & PSW_ADDR_INSN
);
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.
84 __show_trace(unsigned long sp
, unsigned long low
, unsigned long high
)
86 struct stack_frame
*sf
;
90 sp
= sp
& PSW_ADDR_INSN
;
91 if (sp
< low
|| sp
> high
- sizeof(*sf
))
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. */
99 sp
= sf
->back_chain
& PSW_ADDR_INSN
;
102 if (sp
<= low
|| sp
> high
- sizeof(*sf
))
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
);
108 /* Zero backchain detected, check for interrupt frame. */
109 sp
= (unsigned long) (sf
+ 1);
110 if (sp
<= low
|| sp
> high
- sizeof(*regs
))
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
);
120 static void show_trace(struct task_struct
*task
, unsigned long *stack
)
122 register unsigned long __r15
asm ("15");
125 sp
= (unsigned long) stack
;
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
);
133 sp
= __show_trace(sp
, S390_lowcore
.async_stack
- ASYNC_SIZE
,
134 S390_lowcore
.async_stack
);
136 __show_trace(sp
, (unsigned long) task_stack_page(task
),
137 (unsigned long) task_stack_page(task
) + THREAD_SIZE
);
139 __show_trace(sp
, S390_lowcore
.thread_info
,
140 S390_lowcore
.thread_info
+ THREAD_SIZE
);
143 debug_show_held_locks(task
);
146 void show_stack(struct task_struct
*task
, unsigned long *sp
)
148 register unsigned long * __r15
asm ("15");
149 unsigned long *stack
;
153 stack
= task
? (unsigned long *) task
->thread
.ksp
: __r15
;
157 for (i
= 0; i
< kstack_depth_to_print
; i
++) {
158 if (((addr_t
) stack
& (THREAD_SIZE
-1)) == 0)
160 if ((i
* sizeof(long) % 32) == 0)
161 printk("%s ", i
== 0 ? "" : "\n");
162 printk(LONG
, *stack
++);
165 show_trace(task
, sp
);
168 static void show_last_breaking_event(struct pt_regs
*regs
)
171 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
);
178 * The architecture-independent dump_stack generator
180 void dump_stack(void)
182 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
);
190 show_stack(NULL
, NULL
);
192 EXPORT_SYMBOL(dump_stack
);
194 static inline int mask_bits(struct pt_regs
*regs
, unsigned long bits
)
196 return (regs
->psw
.mask
& bits
) / ((~bits
+ 1) & bits
);
199 void show_registers(struct pt_regs
*regs
)
203 mode
= user_mode(regs
) ? "User" : "Krnl";
204 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
);
208 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
));
216 printk(" EA:%x", mask_bits(regs
, PSW_MASK_EA
| PSW_MASK_BA
));
218 printk("\n%s GPRS: " FOURLONG
, mode
,
219 regs
->gprs
[0], regs
->gprs
[1], regs
->gprs
[2], regs
->gprs
[3]);
221 regs
->gprs
[4], regs
->gprs
[5], regs
->gprs
[6], regs
->gprs
[7]);
223 regs
->gprs
[8], regs
->gprs
[9], regs
->gprs
[10], regs
->gprs
[11]);
225 regs
->gprs
[12], regs
->gprs
[13], regs
->gprs
[14], regs
->gprs
[15]);
230 void show_regs(struct pt_regs
*regs
)
232 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 */
242 if (!user_mode(regs
))
243 show_trace(NULL
, (unsigned long *) regs
->gprs
[15]);
244 show_last_breaking_event(regs
);
247 static DEFINE_SPINLOCK(die_lock
);
249 void die(struct pt_regs
*regs
, const char *str
)
251 static int die_counter
;
257 spin_lock_irq(&die_lock
);
259 printk("%s: %04x [#%d] ", str
, regs
->int_code
& 0xffff, ++die_counter
);
260 #ifdef CONFIG_PREEMPT
266 #ifdef CONFIG_DEBUG_PAGEALLOC
267 printk("DEBUG_PAGEALLOC");
270 notify_die(DIE_OOPS
, str
, regs
, 0, regs
->int_code
& 0xffff, SIGSEGV
);
274 add_taint(TAINT_DIE
);
275 spin_unlock_irq(&die_lock
);
277 panic("Fatal exception in interrupt");
279 panic("Fatal exception: panic_on_oops");
284 static inline void report_user_fault(struct pt_regs
*regs
, int signr
)
286 if ((task_pid_nr(current
) > 1) && !show_unhandled_signals
)
288 if (!unhandled_signal(current
, signr
))
290 if (!printk_ratelimit())
292 printk("User process fault: interruption code 0x%X ", regs
->int_code
);
293 print_vma_addr("in ", regs
->psw
.addr
& PSW_ADDR_INSN
);
298 int is_valid_bugaddr(unsigned long addr
)
303 static void __kprobes
do_trap(struct pt_regs
*regs
,
304 int si_signo
, int si_code
, char *str
)
308 if (notify_die(DIE_TRAP
, str
, regs
, 0,
309 regs
->int_code
, si_signo
) == NOTIFY_STOP
)
312 if (user_mode(regs
)) {
313 info
.si_signo
= si_signo
;
315 info
.si_code
= si_code
;
316 info
.si_addr
= get_trap_ip(regs
);
317 force_sig_info(si_signo
, &info
, current
);
318 report_user_fault(regs
, si_signo
);
320 const struct exception_table_entry
*fixup
;
321 fixup
= search_exception_tables(regs
->psw
.addr
& PSW_ADDR_INSN
);
323 regs
->psw
.addr
= extable_fixup(fixup
) | PSW_ADDR_AMODE
;
325 enum bug_trap_type btt
;
327 btt
= report_bug(regs
->psw
.addr
& PSW_ADDR_INSN
, regs
);
328 if (btt
== BUG_TRAP_TYPE_WARN
)
335 void __kprobes
do_per_trap(struct pt_regs
*regs
)
339 if (notify_die(DIE_SSTEP
, "sstep", regs
, 0, 0, SIGTRAP
) == NOTIFY_STOP
)
341 if (!current
->ptrace
)
343 info
.si_signo
= SIGTRAP
;
345 info
.si_code
= TRAP_HWBKPT
;
347 (void __force __user
*) current
->thread
.per_event
.address
;
348 force_sig_info(SIGTRAP
, &info
, current
);
351 void default_trap_handler(struct pt_regs
*regs
)
353 if (user_mode(regs
)) {
354 report_user_fault(regs
, SIGSEGV
);
357 die(regs
, "Unknown program exception");
360 #define DO_ERROR_INFO(name, signr, sicode, str) \
361 void name(struct pt_regs *regs) \
363 do_trap(regs, signr, sicode, str); \
366 DO_ERROR_INFO(addressing_exception
, SIGILL
, ILL_ILLADR
,
367 "addressing exception")
368 DO_ERROR_INFO(execute_exception
, SIGILL
, ILL_ILLOPN
,
370 DO_ERROR_INFO(divide_exception
, SIGFPE
, FPE_INTDIV
,
371 "fixpoint divide exception")
372 DO_ERROR_INFO(overflow_exception
, SIGFPE
, FPE_INTOVF
,
373 "fixpoint overflow exception")
374 DO_ERROR_INFO(hfp_overflow_exception
, SIGFPE
, FPE_FLTOVF
,
375 "HFP overflow exception")
376 DO_ERROR_INFO(hfp_underflow_exception
, SIGFPE
, FPE_FLTUND
,
377 "HFP underflow exception")
378 DO_ERROR_INFO(hfp_significance_exception
, SIGFPE
, FPE_FLTRES
,
379 "HFP significance exception")
380 DO_ERROR_INFO(hfp_divide_exception
, SIGFPE
, FPE_FLTDIV
,
381 "HFP divide exception")
382 DO_ERROR_INFO(hfp_sqrt_exception
, SIGFPE
, FPE_FLTINV
,
383 "HFP square root exception")
384 DO_ERROR_INFO(operand_exception
, SIGILL
, ILL_ILLOPN
,
386 DO_ERROR_INFO(privileged_op
, SIGILL
, ILL_PRVOPC
,
387 "privileged operation")
388 DO_ERROR_INFO(special_op_exception
, SIGILL
, ILL_ILLOPN
,
389 "special operation exception")
390 DO_ERROR_INFO(translation_exception
, SIGILL
, ILL_ILLOPN
,
391 "translation exception")
394 DO_ERROR_INFO(transaction_exception
, SIGILL
, ILL_ILLOPN
,
395 "transaction constraint exception")
398 static inline void do_fp_trap(struct pt_regs
*regs
, int fpc
)
401 /* 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 */
405 si_code
= FPE_FLTINV
;
406 else if (fpc
& 0x4000) /* div by 0 */
407 si_code
= FPE_FLTDIV
;
408 else if (fpc
& 0x2000) /* overflow */
409 si_code
= FPE_FLTOVF
;
410 else if (fpc
& 0x1000) /* underflow */
411 si_code
= FPE_FLTUND
;
412 else if (fpc
& 0x0800) /* inexact */
413 si_code
= FPE_FLTRES
;
415 do_trap(regs
, SIGFPE
, si_code
, "floating point exception");
418 void __kprobes
illegal_op(struct pt_regs
*regs
)
422 __u16 __user
*location
;
425 location
= get_trap_ip(regs
);
427 if (user_mode(regs
)) {
428 if (get_user(*((__u16
*) opcode
), (__u16 __user
*) location
))
430 if (*((__u16
*) opcode
) == S390_BREAKPOINT_U16
) {
431 if (current
->ptrace
) {
432 info
.si_signo
= SIGTRAP
;
434 info
.si_code
= TRAP_BRKPT
;
435 info
.si_addr
= location
;
436 force_sig_info(SIGTRAP
, &info
, current
);
439 #ifdef CONFIG_MATHEMU
440 } else if (opcode
[0] == 0xb3) {
441 if (get_user(*((__u16
*) (opcode
+2)), location
+1))
443 signal
= math_emu_b3(opcode
, regs
);
444 } else if (opcode
[0] == 0xed) {
445 if (get_user(*((__u32
*) (opcode
+2)),
446 (__u32 __user
*)(location
+1)))
448 signal
= math_emu_ed(opcode
, regs
);
449 } else if (*((__u16
*) opcode
) == 0xb299) {
450 if (get_user(*((__u16
*) (opcode
+2)), location
+1))
452 signal
= math_emu_srnm(opcode
, regs
);
453 } else if (*((__u16
*) opcode
) == 0xb29c) {
454 if (get_user(*((__u16
*) (opcode
+2)), location
+1))
456 signal
= math_emu_stfpc(opcode
, regs
);
457 } else if (*((__u16
*) opcode
) == 0xb29d) {
458 if (get_user(*((__u16
*) (opcode
+2)), location
+1))
460 signal
= math_emu_lfpc(opcode
, regs
);
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
469 if (notify_die(DIE_BPT
, "bpt", regs
, 0,
470 3, SIGTRAP
) != NOTIFY_STOP
)
474 #ifdef CONFIG_MATHEMU
475 if (signal
== SIGFPE
)
476 do_fp_trap(regs
, current
->thread
.fp_regs
.fpc
);
477 else if (signal
== SIGSEGV
)
478 do_trap(regs
, signal
, SEGV_MAPERR
, "user address fault");
482 do_trap(regs
, signal
, ILL_ILLOPC
, "illegal operation");
486 #ifdef CONFIG_MATHEMU
487 void specification_exception(struct pt_regs
*regs
)
490 __u16 __user
*location
= NULL
;
493 location
= (__u16 __user
*) get_trap_ip(regs
);
495 if (user_mode(regs
)) {
496 get_user(*((__u16
*) opcode
), location
);
498 case 0x28: /* LDR Rx,Ry */
499 signal
= math_emu_ldr(opcode
);
501 case 0x38: /* LER Rx,Ry */
502 signal
= math_emu_ler(opcode
);
504 case 0x60: /* STD R,D(X,B) */
505 get_user(*((__u16
*) (opcode
+2)), location
+1);
506 signal
= math_emu_std(opcode
, regs
);
508 case 0x68: /* LD R,D(X,B) */
509 get_user(*((__u16
*) (opcode
+2)), location
+1);
510 signal
= math_emu_ld(opcode
, regs
);
512 case 0x70: /* STE R,D(X,B) */
513 get_user(*((__u16
*) (opcode
+2)), location
+1);
514 signal
= math_emu_ste(opcode
, regs
);
516 case 0x78: /* LE R,D(X,B) */
517 get_user(*((__u16
*) (opcode
+2)), location
+1);
518 signal
= math_emu_le(opcode
, regs
);
527 if (signal
== SIGFPE
)
528 do_fp_trap(regs
, current
->thread
.fp_regs
.fpc
);
530 do_trap(regs
, signal
, ILL_ILLOPN
, "specification exception");
533 DO_ERROR_INFO(specification_exception
, SIGILL
, ILL_ILLOPN
,
534 "specification exception");
537 void data_exception(struct pt_regs
*regs
)
539 __u16 __user
*location
;
542 location
= get_trap_ip(regs
);
544 if (MACHINE_HAS_IEEE
)
545 asm volatile("stfpc %0" : "=m" (current
->thread
.fp_regs
.fpc
));
547 #ifdef CONFIG_MATHEMU
548 else if (user_mode(regs
)) {
550 get_user(*((__u16
*) opcode
), location
);
552 case 0x28: /* LDR Rx,Ry */
553 signal
= math_emu_ldr(opcode
);
555 case 0x38: /* LER Rx,Ry */
556 signal
= math_emu_ler(opcode
);
558 case 0x60: /* STD R,D(X,B) */
559 get_user(*((__u16
*) (opcode
+2)), location
+1);
560 signal
= math_emu_std(opcode
, regs
);
562 case 0x68: /* LD R,D(X,B) */
563 get_user(*((__u16
*) (opcode
+2)), location
+1);
564 signal
= math_emu_ld(opcode
, regs
);
566 case 0x70: /* STE R,D(X,B) */
567 get_user(*((__u16
*) (opcode
+2)), location
+1);
568 signal
= math_emu_ste(opcode
, regs
);
570 case 0x78: /* LE R,D(X,B) */
571 get_user(*((__u16
*) (opcode
+2)), location
+1);
572 signal
= math_emu_le(opcode
, regs
);
575 get_user(*((__u16
*) (opcode
+2)), location
+1);
576 signal
= math_emu_b3(opcode
, regs
);
579 get_user(*((__u32
*) (opcode
+2)),
580 (__u32 __user
*)(location
+1));
581 signal
= math_emu_ed(opcode
, regs
);
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
);
602 if (current
->thread
.fp_regs
.fpc
& FPC_DXC_MASK
)
606 if (signal
== SIGFPE
)
607 do_fp_trap(regs
, current
->thread
.fp_regs
.fpc
);
609 do_trap(regs
, signal
, ILL_ILLOPN
, "data exception");
612 void space_switch_exception(struct pt_regs
*regs
)
614 /* Set user psw back to home space mode. */
616 regs
->psw
.mask
|= PSW_ASC_HOME
;
618 do_trap(regs
, SIGILL
, ILL_PRVOPC
, "space switch event");
621 void __kprobes
kernel_stack_overflow(struct pt_regs
* regs
)
624 printk("Kernel stack overflow.\n");
627 panic("Corrupt kernel stack, can't continue.");
630 void __init
trap_init(void)