s390/dis: move common definitions to a header file
[linux-block.git] / arch / s390 / kernel / dumpstack.c
CommitLineData
1bca09f7
HC
1/*
2 * Stack dumping functions
3 *
4 * Copyright IBM Corp. 1999, 2013
5 */
6
7#include <linux/kallsyms.h>
8#include <linux/hardirq.h>
9#include <linux/kprobes.h>
10#include <linux/utsname.h>
11#include <linux/export.h>
12#include <linux/kdebug.h>
13#include <linux/ptrace.h>
14#include <linux/module.h>
15#include <linux/sched.h>
16#include <asm/processor.h>
17#include <asm/debug.h>
18#include <asm/ipl.h>
19
20#ifndef CONFIG_64BIT
21#define LONG "%08lx "
22#define FOURLONG "%08lx %08lx %08lx %08lx\n"
23static int kstack_depth_to_print = 12;
24#else /* CONFIG_64BIT */
25#define LONG "%016lx "
26#define FOURLONG "%016lx %016lx %016lx %016lx\n"
27static int kstack_depth_to_print = 20;
28#endif /* CONFIG_64BIT */
29
30/*
31 * For show_trace we have tree different stack to consider:
32 * - the panic stack which is used if the kernel stack has overflown
33 * - the asynchronous interrupt stack (cpu related)
34 * - the synchronous kernel stack (process related)
35 * The stack trace can start at any of the three stack and can potentially
36 * touch all of them. The order is: panic stack, async stack, sync stack.
37 */
38static unsigned long
39__show_trace(unsigned long sp, unsigned long low, unsigned long high)
40{
41 struct stack_frame *sf;
42 struct pt_regs *regs;
8237ac3c 43 unsigned long addr;
1bca09f7
HC
44
45 while (1) {
46 sp = sp & PSW_ADDR_INSN;
47 if (sp < low || sp > high - sizeof(*sf))
48 return sp;
49 sf = (struct stack_frame *) sp;
8237ac3c
HC
50 addr = sf->gprs[8] & PSW_ADDR_INSN;
51 printk("([<%016lx>] %pSR)\n", addr, (void *)addr);
1bca09f7
HC
52 /* Follow the backchain. */
53 while (1) {
54 low = sp;
55 sp = sf->back_chain & PSW_ADDR_INSN;
56 if (!sp)
57 break;
58 if (sp <= low || sp > high - sizeof(*sf))
59 return sp;
60 sf = (struct stack_frame *) sp;
8237ac3c
HC
61 addr = sf->gprs[8] & PSW_ADDR_INSN;
62 printk(" [<%016lx>] %pSR\n", addr, (void *)addr);
1bca09f7
HC
63 }
64 /* Zero backchain detected, check for interrupt frame. */
65 sp = (unsigned long) (sf + 1);
66 if (sp <= low || sp > high - sizeof(*regs))
67 return sp;
68 regs = (struct pt_regs *) sp;
8237ac3c
HC
69 addr = regs->psw.addr & PSW_ADDR_INSN;
70 printk(" [<%016lx>] %pSR\n", addr, (void *)addr);
1bca09f7
HC
71 low = sp;
72 sp = regs->gprs[15];
73 }
74}
75
76static void show_trace(struct task_struct *task, unsigned long *stack)
77{
9cc5c206
MS
78 const unsigned long frame_size =
79 STACK_FRAME_OVERHEAD + sizeof(struct pt_regs);
1bca09f7
HC
80 register unsigned long __r15 asm ("15");
81 unsigned long sp;
82
83 sp = (unsigned long) stack;
84 if (!sp)
85 sp = task ? task->thread.ksp : __r15;
86 printk("Call Trace:\n");
87#ifdef CONFIG_CHECK_STACK
9cc5c206
MS
88 sp = __show_trace(sp,
89 S390_lowcore.panic_stack + frame_size - 4096,
90 S390_lowcore.panic_stack + frame_size);
1bca09f7 91#endif
9cc5c206
MS
92 sp = __show_trace(sp,
93 S390_lowcore.async_stack + frame_size - ASYNC_SIZE,
94 S390_lowcore.async_stack + frame_size);
1bca09f7
HC
95 if (task)
96 __show_trace(sp, (unsigned long) task_stack_page(task),
97 (unsigned long) task_stack_page(task) + THREAD_SIZE);
98 else
99 __show_trace(sp, S390_lowcore.thread_info,
100 S390_lowcore.thread_info + THREAD_SIZE);
101 if (!task)
102 task = current;
103 debug_show_held_locks(task);
104}
105
106void show_stack(struct task_struct *task, unsigned long *sp)
107{
108 register unsigned long *__r15 asm ("15");
109 unsigned long *stack;
110 int i;
111
112 if (!sp)
113 stack = task ? (unsigned long *) task->thread.ksp : __r15;
114 else
115 stack = sp;
116
117 for (i = 0; i < kstack_depth_to_print; i++) {
118 if (((addr_t) stack & (THREAD_SIZE-1)) == 0)
119 break;
120 if ((i * sizeof(long) % 32) == 0)
121 printk("%s ", i == 0 ? "" : "\n");
122 printk(LONG, *stack++);
123 }
124 printk("\n");
125 show_trace(task, sp);
126}
127
128static void show_last_breaking_event(struct pt_regs *regs)
129{
130#ifdef CONFIG_64BIT
131 printk("Last Breaking-Event-Address:\n");
8237ac3c 132 printk(" [<%016lx>] %pSR\n", regs->args[0], (void *)regs->args[0]);
1bca09f7
HC
133#endif
134}
135
1bca09f7
HC
136static inline int mask_bits(struct pt_regs *regs, unsigned long bits)
137{
138 return (regs->psw.mask & bits) / ((~bits + 1) & bits);
139}
140
141void show_registers(struct pt_regs *regs)
142{
143 char *mode;
144
145 mode = user_mode(regs) ? "User" : "Krnl";
8237ac3c 146 printk("%s PSW : %p %p (%pSR)\n",
1bca09f7 147 mode, (void *) regs->psw.mask,
8237ac3c 148 (void *) regs->psw.addr,
1bca09f7 149 (void *) regs->psw.addr);
1bca09f7
HC
150 printk(" R:%x T:%x IO:%x EX:%x Key:%x M:%x W:%x "
151 "P:%x AS:%x CC:%x PM:%x", mask_bits(regs, PSW_MASK_PER),
152 mask_bits(regs, PSW_MASK_DAT), mask_bits(regs, PSW_MASK_IO),
153 mask_bits(regs, PSW_MASK_EXT), mask_bits(regs, PSW_MASK_KEY),
154 mask_bits(regs, PSW_MASK_MCHECK), mask_bits(regs, PSW_MASK_WAIT),
155 mask_bits(regs, PSW_MASK_PSTATE), mask_bits(regs, PSW_MASK_ASC),
156 mask_bits(regs, PSW_MASK_CC), mask_bits(regs, PSW_MASK_PM));
157#ifdef CONFIG_64BIT
158 printk(" EA:%x", mask_bits(regs, PSW_MASK_EA | PSW_MASK_BA));
159#endif
160 printk("\n%s GPRS: " FOURLONG, mode,
161 regs->gprs[0], regs->gprs[1], regs->gprs[2], regs->gprs[3]);
162 printk(" " FOURLONG,
163 regs->gprs[4], regs->gprs[5], regs->gprs[6], regs->gprs[7]);
164 printk(" " FOURLONG,
165 regs->gprs[8], regs->gprs[9], regs->gprs[10], regs->gprs[11]);
166 printk(" " FOURLONG,
167 regs->gprs[12], regs->gprs[13], regs->gprs[14], regs->gprs[15]);
168 show_code(regs);
169}
170
171void show_regs(struct pt_regs *regs)
172{
a43cb95d 173 show_regs_print_info(KERN_DEFAULT);
1bca09f7
HC
174 show_registers(regs);
175 /* Show stack backtrace if pt_regs is from kernel mode */
176 if (!user_mode(regs))
177 show_trace(NULL, (unsigned long *) regs->gprs[15]);
178 show_last_breaking_event(regs);
179}
180
181static DEFINE_SPINLOCK(die_lock);
182
183void die(struct pt_regs *regs, const char *str)
184{
185 static int die_counter;
186
187 oops_enter();
188 lgr_info_log();
189 debug_stop_all();
190 console_verbose();
191 spin_lock_irq(&die_lock);
192 bust_spinlocks(1);
193 printk("%s: %04x [#%d] ", str, regs->int_code & 0xffff, ++die_counter);
194#ifdef CONFIG_PREEMPT
195 printk("PREEMPT ");
196#endif
197#ifdef CONFIG_SMP
198 printk("SMP ");
199#endif
200#ifdef CONFIG_DEBUG_PAGEALLOC
201 printk("DEBUG_PAGEALLOC");
202#endif
203 printk("\n");
204 notify_die(DIE_OOPS, str, regs, 0, regs->int_code & 0xffff, SIGSEGV);
205 print_modules();
206 show_regs(regs);
207 bust_spinlocks(0);
208 add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
209 spin_unlock_irq(&die_lock);
210 if (in_interrupt())
211 panic("Fatal exception in interrupt");
212 if (panic_on_oops)
213 panic("Fatal exception: panic_on_oops");
214 oops_exit();
215 do_exit(SIGSEGV);
216}