dumpstack.c 5.66 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
 * Stack dumping functions
 *
 *  Copyright IBM Corp. 1999, 2013
 */

#include <linux/kallsyms.h>
#include <linux/hardirq.h>
#include <linux/kprobes.h>
#include <linux/utsname.h>
#include <linux/export.h>
#include <linux/kdebug.h>
#include <linux/ptrace.h>
14
#include <linux/mm.h>
15 16 17 18
#include <linux/module.h>
#include <linux/sched.h>
#include <asm/processor.h>
#include <asm/debug.h>
19
#include <asm/dis.h>
20 21 22
#include <asm/ipl.h>

/*
23
 * For dump_trace we have tree different stack to consider:
24 25 26
 *   - the panic stack which is used if the kernel stack has overflown
 *   - the asynchronous interrupt stack (cpu related)
 *   - the synchronous kernel stack (process related)
27
 * The stack trace can start at any of the three stacks and can potentially
28 29 30
 * touch all of them. The order is: panic stack, async stack, sync stack.
 */
static unsigned long
31 32
__dump_trace(dump_trace_func_t func, void *data, unsigned long sp,
	     unsigned long low, unsigned long high)
33 34 35 36 37 38 39 40
{
	struct stack_frame *sf;
	struct pt_regs *regs;

	while (1) {
		if (sp < low || sp > high - sizeof(*sf))
			return sp;
		sf = (struct stack_frame *) sp;
41 42
		if (func(data, sf->gprs[8], 0))
			return sp;
43 44 45
		/* Follow the backchain. */
		while (1) {
			low = sp;
46
			sp = sf->back_chain;
47 48 49 50 51
			if (!sp)
				break;
			if (sp <= low || sp > high - sizeof(*sf))
				return sp;
			sf = (struct stack_frame *) sp;
52 53
			if (func(data, sf->gprs[8], 1))
				return sp;
54 55 56 57 58 59
		}
		/* Zero backchain detected, check for interrupt frame. */
		sp = (unsigned long) (sf + 1);
		if (sp <= low || sp > high - sizeof(*regs))
			return sp;
		regs = (struct pt_regs *) sp;
60
		if (!user_mode(regs)) {
61
			if (func(data, regs->psw.addr, 1))
62 63
				return sp;
		}
64 65 66 67 68
		low = sp;
		sp = regs->gprs[15];
	}
}

69 70
void dump_trace(dump_trace_func_t func, void *data, struct task_struct *task,
		unsigned long sp)
71
{
72
	unsigned long frame_size;
73

74
	frame_size = STACK_FRAME_OVERHEAD + sizeof(struct pt_regs);
75
#ifdef CONFIG_CHECK_STACK
76
	sp = __dump_trace(func, data, sp,
77 78
			  S390_lowcore.panic_stack + frame_size - 4096,
			  S390_lowcore.panic_stack + frame_size);
79
#endif
80
	sp = __dump_trace(func, data, sp,
81 82
			  S390_lowcore.async_stack + frame_size - ASYNC_SIZE,
			  S390_lowcore.async_stack + frame_size);
83 84 85 86
	task = task ?: current;
	__dump_trace(func, data, sp,
		     (unsigned long)task_stack_page(task),
		     (unsigned long)task_stack_page(task) + THREAD_SIZE);
87 88 89
}
EXPORT_SYMBOL_GPL(dump_trace);

90
static int show_address(void *data, unsigned long address, int reliable)
91
{
92 93 94 95
	if (reliable)
		printk(" [<%016lx>] %pSR \n", address, (void *)address);
	else
		printk("([<%016lx>] %pSR)\n", address, (void *)address);
96 97 98 99 100 101 102 103 104
	return 0;
}

static void show_trace(struct task_struct *task, unsigned long sp)
{
	if (!sp)
		sp = task ? task->thread.ksp : current_stack_pointer();
	printk("Call Trace:\n");
	dump_trace(show_address, NULL, task, sp);
105 106 107 108 109 110 111 112 113 114
	if (!task)
		task = current;
	debug_show_held_locks(task);
}

void show_stack(struct task_struct *task, unsigned long *sp)
{
	unsigned long *stack;
	int i;

115 116 117 118 119 120 121
	stack = sp;
	if (!stack) {
		if (!task)
			stack = (unsigned long *)current_stack_pointer();
		else
			stack = (unsigned long *)task->thread.ksp;
	}
122
	printk(KERN_DEFAULT "Stack:\n");
Heiko Carstens's avatar
Heiko Carstens committed
123
	for (i = 0; i < 20; i++) {
124 125
		if (((addr_t) stack & (THREAD_SIZE-1)) == 0)
			break;
126 127 128
		if (i % 4 == 0)
			printk(KERN_DEFAULT "       ");
		pr_cont("%016lx%c", *stack++, i % 4 == 3 ? '\n' : ' ');
129
	}
130
	show_trace(task, (unsigned long)sp);
131 132 133 134 135
}

static void show_last_breaking_event(struct pt_regs *regs)
{
	printk("Last Breaking-Event-Address:\n");
136
	printk(" [<%016lx>] %pSR\n", regs->args[0], (void *)regs->args[0]);
137 138 139 140
}

void show_registers(struct pt_regs *regs)
{
141
	struct psw_bits *psw = &psw_bits(regs->psw);
142 143 144
	char *mode;

	mode = user_mode(regs) ? "User" : "Krnl";
145 146
	printk("%s PSW : %p %p", mode, (void *)regs->psw.mask, (void *)regs->psw.addr);
	if (!user_mode(regs))
147 148
		pr_cont(" (%pSR)", (void *)regs->psw.addr);
	pr_cont("\n");
149
	printk("           R:%x T:%x IO:%x EX:%x Key:%x M:%x W:%x "
150 151
	       "P:%x AS:%x CC:%x PM:%x", psw->r, psw->t, psw->i, psw->e,
	       psw->key, psw->m, psw->w, psw->p, psw->as, psw->cc, psw->pm);
152 153
	pr_cont(" RI:%x EA:%x\n", psw->ri, psw->eaba);
	printk("%s GPRS: %016lx %016lx %016lx %016lx\n", mode,
154
	       regs->gprs[0], regs->gprs[1], regs->gprs[2], regs->gprs[3]);
Heiko Carstens's avatar
Heiko Carstens committed
155
	printk("           %016lx %016lx %016lx %016lx\n",
156
	       regs->gprs[4], regs->gprs[5], regs->gprs[6], regs->gprs[7]);
Heiko Carstens's avatar
Heiko Carstens committed
157
	printk("           %016lx %016lx %016lx %016lx\n",
158
	       regs->gprs[8], regs->gprs[9], regs->gprs[10], regs->gprs[11]);
Heiko Carstens's avatar
Heiko Carstens committed
159
	printk("           %016lx %016lx %016lx %016lx\n",
160 161 162 163 164 165
	       regs->gprs[12], regs->gprs[13], regs->gprs[14], regs->gprs[15]);
	show_code(regs);
}

void show_regs(struct pt_regs *regs)
{
166
	show_regs_print_info(KERN_DEFAULT);
167 168 169
	show_registers(regs);
	/* Show stack backtrace if pt_regs is from kernel mode */
	if (!user_mode(regs))
170
		show_trace(NULL, regs->gprs[15]);
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
	show_last_breaking_event(regs);
}

static DEFINE_SPINLOCK(die_lock);

void die(struct pt_regs *regs, const char *str)
{
	static int die_counter;

	oops_enter();
	lgr_info_log();
	debug_stop_all();
	console_verbose();
	spin_lock_irq(&die_lock);
	bust_spinlocks(1);
186 187
	printk("%s: %04x ilc:%d [#%d] ", str, regs->int_code & 0xffff,
	       regs->int_code >> 17, ++die_counter);
188
#ifdef CONFIG_PREEMPT
189
	pr_cont("PREEMPT ");
190 191
#endif
#ifdef CONFIG_SMP
192
	pr_cont("SMP ");
193
#endif
194
	if (debug_pagealloc_enabled())
195 196
		pr_cont("DEBUG_PAGEALLOC");
	pr_cont("\n");
197 198 199 200 201 202 203 204 205 206 207 208 209
	notify_die(DIE_OOPS, str, regs, 0, regs->int_code & 0xffff, SIGSEGV);
	print_modules();
	show_regs(regs);
	bust_spinlocks(0);
	add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
	spin_unlock_irq(&die_lock);
	if (in_interrupt())
		panic("Fatal exception in interrupt");
	if (panic_on_oops)
		panic("Fatal exception: panic_on_oops");
	oops_exit();
	do_exit(SIGSEGV);
}