2017-11-24 17:00:32 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2013-03-14 16:44:25 +04:00
|
|
|
/*
|
|
|
|
* 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>
|
2016-03-16 00:57:36 +03:00
|
|
|
#include <linux/mm.h>
|
2013-03-14 16:44:25 +04:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/sched.h>
|
2017-02-08 20:51:35 +03:00
|
|
|
#include <linux/sched/debug.h>
|
2017-02-08 20:51:37 +03:00
|
|
|
#include <linux/sched/task_stack.h>
|
2013-03-14 16:44:25 +04:00
|
|
|
#include <asm/processor.h>
|
|
|
|
#include <asm/debug.h>
|
2013-09-13 15:36:25 +04:00
|
|
|
#include <asm/dis.h>
|
2013-03-14 16:44:25 +04:00
|
|
|
#include <asm/ipl.h>
|
2019-01-28 10:33:08 +03:00
|
|
|
#include <asm/unwind.h>
|
2013-03-14 16:44:25 +04:00
|
|
|
|
2019-01-28 10:33:08 +03:00
|
|
|
const char *stack_type_name(enum stack_type type)
|
2013-03-14 16:44:25 +04:00
|
|
|
{
|
2019-01-28 10:33:08 +03:00
|
|
|
switch (type) {
|
|
|
|
case STACK_TYPE_TASK:
|
|
|
|
return "task";
|
|
|
|
case STACK_TYPE_IRQ:
|
|
|
|
return "irq";
|
|
|
|
case STACK_TYPE_NODAT:
|
|
|
|
return "nodat";
|
|
|
|
case STACK_TYPE_RESTART:
|
|
|
|
return "restart";
|
|
|
|
default:
|
|
|
|
return "unknown";
|
2013-03-14 16:44:25 +04:00
|
|
|
}
|
|
|
|
}
|
2019-11-22 20:52:40 +03:00
|
|
|
EXPORT_SYMBOL_GPL(stack_type_name);
|
2013-03-14 16:44:25 +04:00
|
|
|
|
2019-01-28 10:33:08 +03:00
|
|
|
static inline bool in_stack(unsigned long sp, struct stack_info *info,
|
|
|
|
enum stack_type type, unsigned long low,
|
|
|
|
unsigned long high)
|
|
|
|
{
|
|
|
|
if (sp < low || sp >= high)
|
|
|
|
return false;
|
|
|
|
info->type = type;
|
|
|
|
info->begin = low;
|
|
|
|
info->end = high;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool in_task_stack(unsigned long sp, struct task_struct *task,
|
|
|
|
struct stack_info *info)
|
|
|
|
{
|
|
|
|
unsigned long stack;
|
|
|
|
|
|
|
|
stack = (unsigned long) task_stack_page(task);
|
|
|
|
return in_stack(sp, info, STACK_TYPE_TASK, stack, stack + THREAD_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool in_irq_stack(unsigned long sp, struct stack_info *info)
|
|
|
|
{
|
|
|
|
unsigned long frame_size, top;
|
|
|
|
|
|
|
|
frame_size = STACK_FRAME_OVERHEAD + sizeof(struct pt_regs);
|
|
|
|
top = S390_lowcore.async_stack + frame_size;
|
|
|
|
return in_stack(sp, info, STACK_TYPE_IRQ, top - THREAD_SIZE, top);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool in_nodat_stack(unsigned long sp, struct stack_info *info)
|
2013-03-14 16:44:25 +04:00
|
|
|
{
|
2019-01-28 10:33:08 +03:00
|
|
|
unsigned long frame_size, top;
|
2013-03-14 16:44:25 +04:00
|
|
|
|
2016-02-09 14:58:54 +03:00
|
|
|
frame_size = STACK_FRAME_OVERHEAD + sizeof(struct pt_regs);
|
2019-01-28 10:33:08 +03:00
|
|
|
top = S390_lowcore.nodat_stack + frame_size;
|
|
|
|
return in_stack(sp, info, STACK_TYPE_NODAT, top - THREAD_SIZE, top);
|
2016-02-09 14:58:54 +03:00
|
|
|
}
|
|
|
|
|
2021-03-31 12:44:50 +03:00
|
|
|
static bool in_mcck_stack(unsigned long sp, struct stack_info *info)
|
|
|
|
{
|
|
|
|
unsigned long frame_size, top;
|
|
|
|
|
|
|
|
frame_size = STACK_FRAME_OVERHEAD + sizeof(struct pt_regs);
|
|
|
|
top = S390_lowcore.mcck_stack + frame_size;
|
|
|
|
return in_stack(sp, info, STACK_TYPE_MCCK, top - THREAD_SIZE, top);
|
|
|
|
}
|
|
|
|
|
2019-01-28 10:33:08 +03:00
|
|
|
static bool in_restart_stack(unsigned long sp, struct stack_info *info)
|
2016-02-09 14:58:54 +03:00
|
|
|
{
|
2019-01-28 10:33:08 +03:00
|
|
|
unsigned long frame_size, top;
|
|
|
|
|
|
|
|
frame_size = STACK_FRAME_OVERHEAD + sizeof(struct pt_regs);
|
|
|
|
top = S390_lowcore.restart_stack + frame_size;
|
|
|
|
return in_stack(sp, info, STACK_TYPE_RESTART, top - THREAD_SIZE, top);
|
|
|
|
}
|
|
|
|
|
|
|
|
int get_stack_info(unsigned long sp, struct task_struct *task,
|
|
|
|
struct stack_info *info, unsigned long *visit_mask)
|
|
|
|
{
|
|
|
|
if (!sp)
|
|
|
|
goto unknown;
|
|
|
|
|
2019-11-27 21:35:19 +03:00
|
|
|
/* Sanity check: ABI requires SP to be aligned 8 bytes. */
|
|
|
|
if (sp & 0x7)
|
|
|
|
goto unknown;
|
|
|
|
|
2019-01-28 10:33:08 +03:00
|
|
|
/* Check per-task stack */
|
|
|
|
if (in_task_stack(sp, task, info))
|
|
|
|
goto recursion_check;
|
|
|
|
|
|
|
|
if (task != current)
|
|
|
|
goto unknown;
|
|
|
|
|
|
|
|
/* Check per-cpu stacks */
|
|
|
|
if (!in_irq_stack(sp, info) &&
|
|
|
|
!in_nodat_stack(sp, info) &&
|
2021-03-31 12:44:50 +03:00
|
|
|
!in_restart_stack(sp, info) &&
|
|
|
|
!in_mcck_stack(sp, info))
|
2019-01-28 10:33:08 +03:00
|
|
|
goto unknown;
|
|
|
|
|
|
|
|
recursion_check:
|
|
|
|
/*
|
|
|
|
* Make sure we don't iterate through any given stack more than once.
|
|
|
|
* If it comes up a second time then there's something wrong going on:
|
|
|
|
* just break out and report an unknown stack type.
|
|
|
|
*/
|
2019-08-05 16:07:19 +03:00
|
|
|
if (*visit_mask & (1UL << info->type))
|
2019-01-28 10:33:08 +03:00
|
|
|
goto unknown;
|
|
|
|
*visit_mask |= 1UL << info->type;
|
2016-02-09 14:58:54 +03:00
|
|
|
return 0;
|
2019-01-28 10:33:08 +03:00
|
|
|
unknown:
|
|
|
|
info->type = STACK_TYPE_UNKNOWN;
|
|
|
|
return -EINVAL;
|
2016-02-09 14:58:54 +03:00
|
|
|
}
|
|
|
|
|
2020-06-09 07:32:29 +03:00
|
|
|
void show_stack(struct task_struct *task, unsigned long *stack,
|
2020-06-09 07:31:20 +03:00
|
|
|
const char *loglvl)
|
2016-02-09 14:58:54 +03:00
|
|
|
{
|
2019-01-28 10:33:08 +03:00
|
|
|
struct unwind_state state;
|
2017-06-06 11:04:26 +03:00
|
|
|
|
2020-06-09 07:31:20 +03:00
|
|
|
printk("%sCall Trace:\n", loglvl);
|
2019-01-28 10:33:08 +03:00
|
|
|
unwind_for_each_frame(&state, task, NULL, (unsigned long) stack)
|
2020-06-09 07:31:20 +03:00
|
|
|
printk(state.reliable ? "%s [<%016lx>] %pSR \n" :
|
|
|
|
"%s([<%016lx>] %pSR)\n",
|
|
|
|
loglvl, state.ip, (void *) state.ip);
|
2019-01-28 10:33:08 +03:00
|
|
|
debug_show_held_locks(task ? : current);
|
2013-03-14 16:44:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void show_last_breaking_event(struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
printk("Last Breaking-Event-Address:\n");
|
2013-09-02 13:20:00 +04:00
|
|
|
printk(" [<%016lx>] %pSR\n", regs->args[0], (void *)regs->args[0]);
|
2013-03-14 16:44:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void show_registers(struct pt_regs *regs)
|
|
|
|
{
|
2016-01-31 19:36:59 +03:00
|
|
|
struct psw_bits *psw = &psw_bits(regs->psw);
|
2013-03-14 16:44:25 +04:00
|
|
|
char *mode;
|
|
|
|
|
|
|
|
mode = user_mode(regs) ? "User" : "Krnl";
|
2018-10-09 13:32:56 +03:00
|
|
|
printk("%s PSW : %px %px", mode, (void *)regs->psw.mask, (void *)regs->psw.addr);
|
2014-04-07 18:26:37 +04:00
|
|
|
if (!user_mode(regs))
|
2016-10-17 12:59:58 +03:00
|
|
|
pr_cont(" (%pSR)", (void *)regs->psw.addr);
|
|
|
|
pr_cont("\n");
|
2013-03-14 16:44:25 +04:00
|
|
|
printk(" R:%x T:%x IO:%x EX:%x Key:%x M:%x W:%x "
|
2017-06-03 11:56:07 +03:00
|
|
|
"P:%x AS:%x CC:%x PM:%x", psw->per, psw->dat, psw->io, psw->ext,
|
|
|
|
psw->key, psw->mcheck, psw->wait, psw->pstate, psw->as, psw->cc, psw->pm);
|
2016-10-17 12:59:58 +03:00
|
|
|
pr_cont(" RI:%x EA:%x\n", psw->ri, psw->eaba);
|
|
|
|
printk("%s GPRS: %016lx %016lx %016lx %016lx\n", mode,
|
2013-03-14 16:44:25 +04:00
|
|
|
regs->gprs[0], regs->gprs[1], regs->gprs[2], regs->gprs[3]);
|
2015-02-12 15:08:27 +03:00
|
|
|
printk(" %016lx %016lx %016lx %016lx\n",
|
2013-03-14 16:44:25 +04:00
|
|
|
regs->gprs[4], regs->gprs[5], regs->gprs[6], regs->gprs[7]);
|
2015-02-12 15:08:27 +03:00
|
|
|
printk(" %016lx %016lx %016lx %016lx\n",
|
2013-03-14 16:44:25 +04:00
|
|
|
regs->gprs[8], regs->gprs[9], regs->gprs[10], regs->gprs[11]);
|
2015-02-12 15:08:27 +03:00
|
|
|
printk(" %016lx %016lx %016lx %016lx\n",
|
2013-03-14 16:44:25 +04:00
|
|
|
regs->gprs[12], regs->gprs[13], regs->gprs[14], regs->gprs[15]);
|
|
|
|
show_code(regs);
|
|
|
|
}
|
|
|
|
|
|
|
|
void show_regs(struct pt_regs *regs)
|
|
|
|
{
|
dump_stack: unify debug information printed by show_regs()
show_regs() is inherently arch-dependent but it does make sense to print
generic debug information and some archs already do albeit in slightly
different forms. This patch introduces a generic function to print debug
information from show_regs() so that different archs print out the same
information and it's much easier to modify what's printed.
show_regs_print_info() prints out the same debug info as dump_stack()
does plus task and thread_info pointers.
* Archs which didn't print debug info now do.
alpha, arc, blackfin, c6x, cris, frv, h8300, hexagon, ia64, m32r,
metag, microblaze, mn10300, openrisc, parisc, score, sh64, sparc,
um, xtensa
* Already prints debug info. Replaced with show_regs_print_info().
The printed information is superset of what used to be there.
arm, arm64, avr32, mips, powerpc, sh32, tile, unicore32, x86
* s390 is special in that it used to print arch-specific information
along with generic debug info. Heiko and Martin think that the
arch-specific extra isn't worth keeping s390 specfic implementation.
Converted to use the generic version.
Note that now all archs print the debug info before actual register
dumps.
An example BUG() dump follows.
kernel BUG at /work/os/work/kernel/workqueue.c:4841!
invalid opcode: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC
Modules linked in:
CPU: 0 PID: 1 Comm: swapper/0 Not tainted 3.9.0-rc1-work+ #7
Hardware name: empty empty/S3992, BIOS 080011 10/26/2007
task: ffff88007c85e040 ti: ffff88007c860000 task.ti: ffff88007c860000
RIP: 0010:[<ffffffff8234a07e>] [<ffffffff8234a07e>] init_workqueues+0x4/0x6
RSP: 0000:ffff88007c861ec8 EFLAGS: 00010246
RAX: ffff88007c861fd8 RBX: ffffffff824466a8 RCX: 0000000000000001
RDX: 0000000000000046 RSI: 0000000000000001 RDI: ffffffff8234a07a
RBP: ffff88007c861ec8 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000001 R11: 0000000000000000 R12: ffffffff8234a07a
R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
FS: 0000000000000000(0000) GS:ffff88007dc00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b
CR2: ffff88015f7ff000 CR3: 00000000021f1000 CR4: 00000000000007f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
Stack:
ffff88007c861ef8 ffffffff81000312 ffffffff824466a8 ffff88007c85e650
0000000000000003 0000000000000000 ffff88007c861f38 ffffffff82335e5d
ffff88007c862080 ffffffff8223d8c0 ffff88007c862080 ffffffff81c47760
Call Trace:
[<ffffffff81000312>] do_one_initcall+0x122/0x170
[<ffffffff82335e5d>] kernel_init_freeable+0x9b/0x1c8
[<ffffffff81c47760>] ? rest_init+0x140/0x140
[<ffffffff81c4776e>] kernel_init+0xe/0xf0
[<ffffffff81c6be9c>] ret_from_fork+0x7c/0xb0
[<ffffffff81c47760>] ? rest_init+0x140/0x140
...
v2: Typo fix in x86-32.
v3: CPU number dropped from show_regs_print_info() as
dump_stack_print_info() has been updated to print it. s390
specific implementation dropped as requested by s390 maintainers.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: David S. Miller <davem@davemloft.net>
Acked-by: Jesper Nilsson <jesper.nilsson@axis.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Cc: Vineet Gupta <vgupta@synopsys.com>
Cc: Sam Ravnborg <sam@ravnborg.org>
Acked-by: Chris Metcalf <cmetcalf@tilera.com> [tile bits]
Acked-by: Richard Kuo <rkuo@codeaurora.org> [hexagon bits]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-05-01 02:27:17 +04:00
|
|
|
show_regs_print_info(KERN_DEFAULT);
|
2013-03-14 16:44:25 +04:00
|
|
|
show_registers(regs);
|
|
|
|
/* Show stack backtrace if pt_regs is from kernel mode */
|
|
|
|
if (!user_mode(regs))
|
2020-06-09 07:32:29 +03:00
|
|
|
show_stack(NULL, (unsigned long *) regs->gprs[15], KERN_DEFAULT);
|
2013-03-14 16:44:25 +04:00
|
|
|
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);
|
2014-11-19 15:31:08 +03:00
|
|
|
printk("%s: %04x ilc:%d [#%d] ", str, regs->int_code & 0xffff,
|
|
|
|
regs->int_code >> 17, ++die_counter);
|
2013-03-14 16:44:25 +04:00
|
|
|
#ifdef CONFIG_PREEMPT
|
2016-10-19 14:42:55 +03:00
|
|
|
pr_cont("PREEMPT ");
|
2019-10-15 22:18:04 +03:00
|
|
|
#elif defined(CONFIG_PREEMPT_RT)
|
|
|
|
pr_cont("PREEMPT_RT ");
|
2013-03-14 16:44:25 +04:00
|
|
|
#endif
|
2016-10-19 14:42:55 +03:00
|
|
|
pr_cont("SMP ");
|
2016-03-16 00:57:36 +03:00
|
|
|
if (debug_pagealloc_enabled())
|
2016-10-19 14:42:55 +03:00
|
|
|
pr_cont("DEBUG_PAGEALLOC");
|
|
|
|
pr_cont("\n");
|
2013-03-14 16:44:25 +04:00
|
|
|
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);
|
|
|
|
}
|