Skip to content

Commit

Permalink
dump_stack: consolidate dump_stack() implementations and unify their …
Browse files Browse the repository at this point in the history
…behaviors

Both dump_stack() and show_stack() are currently implemented by each
architecture.  show_stack(NULL, NULL) dumps the backtrace for the
current task as does dump_stack().  On some archs, dump_stack() prints
extra information - pid, utsname and so on - in addition to the
backtrace while the two are identical on other archs.

The usages in arch-independent code of the two functions indicate
show_stack(NULL, NULL) should print out bare backtrace while
dump_stack() is used for debugging purposes when something went wrong,
so it does make sense to print additional information on the task which
triggered dump_stack().

There's no reason to require archs to implement two separate but mostly
identical functions.  It leads to unnecessary subtle information.

This patch expands the dummy fallback dump_stack() implementation in
lib/dump_stack.c such that it prints out debug information (taken from
x86) and invokes show_stack(NULL, NULL) and drops arch-specific
dump_stack() implementations in all archs except blackfin.  Blackfin's
dump_stack() does something wonky that I don't understand.

Debug information can be printed separately by calling
dump_stack_print_info() so that arch-specific dump_stack()
implementation can still emit the same debug information.  This is used
in blackfin.

This patch brings the following behavior changes.

* On some archs, an extra level in backtrace for show_stack() could be
  printed.  This is because the top frame was determined in
  dump_stack() on those archs while generic dump_stack() can't do that
  reliably.  It can be compensated by inlining dump_stack() but not
  sure whether that'd be necessary.

* Most archs didn't use to print debug info on dump_stack().  They do
  now.

An example WARN dump follows.

 WARNING: at kernel/workqueue.c:4841 init_workqueues+0x35/0x505()
 Hardware name: empty
 Modules linked in:
 CPU: 0 PID: 1 Comm: swapper/0 Not tainted 3.9.0-rc1-work+ torvalds#9
  0000000000000009 ffff88007c861e08 ffffffff81c614dc ffff88007c861e48
  ffffffff8108f50f ffffffff82228240 0000000000000040 ffffffff8234a03c
  0000000000000000 0000000000000000 0000000000000000 ffff88007c861e58
 Call Trace:
  [<ffffffff81c614dc>] dump_stack+0x19/0x1b
  [<ffffffff8108f50f>] warn_slowpath_common+0x7f/0xc0
  [<ffffffff8108f56a>] warn_slowpath_null+0x1a/0x20
  [<ffffffff8234a071>] init_workqueues+0x35/0x505
  ...

v2: CPU number added to the generic debug info as requested by s390
    folks and dropped the s390 specific dump_stack().  This loses %ksp
    from the debug message which the maintainers think isn't important
    enough to keep the s390-specific dump_stack() implementation.

    dump_stack_print_info() is moved to kernel/printk.c from
    lib/dump_stack.c.  Because linkage is per objecct file,
    dump_stack_print_info() living in the same lib file as generic
    dump_stack() means that archs which implement custom dump_stack()
    - at this point, only blackfin - can't use dump_stack_print_info()
    as that will bring in the generic version of dump_stack() too.  v1
    The v1 patch broke build on blackfin due to this issue.  The build
    breakage was reported by Fengguang Wu.

Signed-off-by: Tejun Heo <[email protected]>
Acked-by: David S. Miller <[email protected]>
Acked-by: Vineet Gupta <[email protected]>
Acked-by: Jesper Nilsson <[email protected]>
Acked-by: Vineet Gupta <[email protected]>
Acked-by: Martin Schwidefsky <[email protected]>	[s390 bits]
Cc: Heiko Carstens <[email protected]>
Cc: Mike Frysinger <[email protected]>
Cc: Fengguang Wu <[email protected]>
Cc: Bjorn Helgaas <[email protected]>
Cc: Sam Ravnborg <[email protected]>
Acked-by: Richard Kuo <[email protected]>		[hexagon bits]
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
htejun authored and torvalds committed May 1, 2013
1 parent 89e3f23 commit 196779b
Show file tree
Hide file tree
Showing 33 changed files with 32 additions and 262 deletions.
7 changes: 0 additions & 7 deletions arch/alpha/kernel/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,6 @@ void show_stack(struct task_struct *task, unsigned long *sp)
dik_show_trace(sp);
}

void dump_stack(void)
{
show_stack(NULL, NULL);
}

EXPORT_SYMBOL(dump_stack);

void
die_if_kernel(char * str, struct pt_regs *regs, long err, unsigned long *r9_15)
{
Expand Down
7 changes: 0 additions & 7 deletions arch/arc/kernel/stacktrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,6 @@ void show_stack(struct task_struct *tsk, unsigned long *sp)
show_stacktrace(tsk, NULL);
}

/* Expected by Rest of kernel code */
void dump_stack(void)
{
show_stacktrace(NULL, NULL);
}
EXPORT_SYMBOL(dump_stack);

/* Another API expected by schedular, shows up in "ps" as Wait Channel
* Ofcourse just returning schedule( ) would be pointless so unwind until
* the function is not in schedular code
Expand Down
7 changes: 0 additions & 7 deletions arch/arm/kernel/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,6 @@ static void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk)
}
#endif

void dump_stack(void)
{
dump_backtrace(NULL, NULL);
}

EXPORT_SYMBOL(dump_stack);

void show_stack(struct task_struct *tsk, unsigned long *sp)
{
dump_backtrace(NULL, tsk);
Expand Down
7 changes: 0 additions & 7 deletions arch/arm64/kernel/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,6 @@ static void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk)
}
}

void dump_stack(void)
{
dump_backtrace(NULL, NULL);
}

EXPORT_SYMBOL(dump_stack);

void show_stack(struct task_struct *tsk, unsigned long *sp)
{
dump_backtrace(NULL, tsk);
Expand Down
8 changes: 0 additions & 8 deletions arch/avr32/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,6 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
show_stack_log_lvl(tsk, (unsigned long)stack, NULL, "");
}

void dump_stack(void)
{
unsigned long stack;

show_trace_log_lvl(current, &stack, NULL, "");
}
EXPORT_SYMBOL(dump_stack);

static const char *cpu_modes[] = {
"Application", "Supervisor", "Interrupt level 0", "Interrupt level 1",
"Interrupt level 2", "Interrupt level 3", "Exception", "NMI"
Expand Down
1 change: 1 addition & 0 deletions arch/blackfin/kernel/dumpstack.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ void dump_stack(void)
#endif
trace_buffer_save(tflags);
dump_bfin_trace_buffer();
dump_stack_print_info(KERN_DEFAULT);
show_stack(current, &stack);
trace_buffer_restore(tflags);
}
Expand Down
9 changes: 0 additions & 9 deletions arch/c6x/kernel/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,6 @@ void show_regs(struct pt_regs *regs)
pr_err("A31: %08lx B31: %08lx\n", regs->a31, regs->b31);
}

void dump_stack(void)
{
unsigned long stack;

show_stack(current, &stack);
}
EXPORT_SYMBOL(dump_stack);


void die(char *str, struct pt_regs *fp, int nr)
{
console_verbose();
Expand Down
7 changes: 0 additions & 7 deletions arch/cris/kernel/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,6 @@ show_stack(void)
}
#endif

void
dump_stack(void)
{
show_stack(NULL, NULL);
}
EXPORT_SYMBOL(dump_stack);

void
set_nmi_handler(void (*handler)(struct pt_regs *))
{
Expand Down
11 changes: 0 additions & 11 deletions arch/frv/kernel/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,17 +466,6 @@ asmlinkage void compound_exception(unsigned long esfr1,
BUG();
} /* end compound_exception() */

/*****************************************************************************/
/*
* The architecture-independent backtrace generator
*/
void dump_stack(void)
{
show_stack(NULL, NULL);
}

EXPORT_SYMBOL(dump_stack);

void show_stack(struct task_struct *task, unsigned long *sp)
{
}
Expand Down
7 changes: 0 additions & 7 deletions arch/h8300/kernel/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,3 @@ void show_trace_task(struct task_struct *tsk)
{
show_stack(tsk,(unsigned long *)tsk->thread.esp0);
}

void dump_stack(void)
{
show_stack(NULL,NULL);
}

EXPORT_SYMBOL(dump_stack);
8 changes: 0 additions & 8 deletions arch/hexagon/kernel/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,6 @@ void show_stack(struct task_struct *task, unsigned long *fp)
do_show_stack(task, fp, 0);
}

void dump_stack(void)
{
unsigned long *fp;
asm("%0 = r30" : "=r" (fp));
show_stack(current, fp);
}
EXPORT_SYMBOL(dump_stack);

int die(const char *str, struct pt_regs *regs, long err)
{
static struct {
Expand Down
8 changes: 0 additions & 8 deletions arch/ia64/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,6 @@ show_stack (struct task_struct *task, unsigned long *sp)
}
}

void
dump_stack (void)
{
show_stack(NULL, NULL);
}

EXPORT_SYMBOL(dump_stack);

void
show_regs (struct pt_regs *regs)
{
Expand Down
9 changes: 0 additions & 9 deletions arch/m32r/kernel/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,6 @@ void show_stack(struct task_struct *task, unsigned long *sp)
show_trace(task, sp);
}

void dump_stack(void)
{
unsigned long stack;

show_trace(current, &stack);
}

EXPORT_SYMBOL(dump_stack);

static void show_registers(struct pt_regs *regs)
{
int i = 0;
Expand Down
12 changes: 0 additions & 12 deletions arch/m68k/kernel/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -991,18 +991,6 @@ void show_stack(struct task_struct *task, unsigned long *stack)
show_trace(stack);
}

/*
* The architecture-independent backtrace generator
*/
void dump_stack(void)
{
unsigned long stack;

show_trace(&stack);
}

EXPORT_SYMBOL(dump_stack);

/*
* The vector number returned in the frame pointer may also contain
* the "fs" (Fault Status) bits on ColdFire. These are in the bottom
Expand Down
6 changes: 0 additions & 6 deletions arch/metag/kernel/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -987,9 +987,3 @@ void show_stack(struct task_struct *tsk, unsigned long *sp)

show_trace(tsk, sp, NULL);
}

void dump_stack(void)
{
show_stack(NULL, NULL);
}
EXPORT_SYMBOL(dump_stack);
6 changes: 0 additions & 6 deletions arch/microblaze/kernel/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,3 @@ void show_stack(struct task_struct *task, unsigned long *sp)

debug_show_held_locks(task);
}

void dump_stack(void)
{
show_stack(NULL, NULL);
}
EXPORT_SYMBOL(dump_stack);
13 changes: 0 additions & 13 deletions arch/mips/kernel/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,6 @@ void show_stack(struct task_struct *task, unsigned long *sp)
show_stacktrace(task, &regs);
}

/*
* The architecture-independent dump_stack generator
*/
void dump_stack(void)
{
struct pt_regs regs;

prepare_frametrace(&regs);
show_backtrace(current, &regs);
}

EXPORT_SYMBOL(dump_stack);

static void show_code(unsigned int __user *pc)
{
long i;
Expand Down
11 changes: 0 additions & 11 deletions arch/mn10300/kernel/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,17 +293,6 @@ void show_stack(struct task_struct *task, unsigned long *sp)
show_trace(sp);
}

/*
* the architecture-independent dump_stack generator
*/
void dump_stack(void)
{
unsigned long stack;

show_stack(current, &stack);
}
EXPORT_SYMBOL(dump_stack);

/*
* dump the register file in the specified exception frame
*/
Expand Down
11 changes: 0 additions & 11 deletions arch/openrisc/kernel/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,6 @@ void show_trace_task(struct task_struct *tsk)
*/
}

/*
* The architecture-independent backtrace generator
*/
void dump_stack(void)
{
unsigned long stack;

show_stack(current, &stack);
}
EXPORT_SYMBOL(dump_stack);

void show_registers(struct pt_regs *regs)
{
int i;
Expand Down
8 changes: 0 additions & 8 deletions arch/parisc/kernel/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,6 @@ void show_regs(struct pt_regs *regs)
}
}


void dump_stack(void)
{
show_stack(NULL, NULL);
}

EXPORT_SYMBOL(dump_stack);

static void do_show_stack(struct unwind_frame_info *info)
{
int i = 1;
Expand Down
6 changes: 0 additions & 6 deletions arch/powerpc/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -1362,12 +1362,6 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
} while (count++ < kstack_depth_to_print);
}

void dump_stack(void)
{
show_stack(current, NULL);
}
EXPORT_SYMBOL(dump_stack);

#ifdef CONFIG_PPC64
/* Called with hard IRQs off */
void __ppc64_runlatch_on(void)
Expand Down
17 changes: 0 additions & 17 deletions arch/s390/kernel/dumpstack.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,6 @@ static void show_last_breaking_event(struct pt_regs *regs)
#endif
}

/*
* The architecture-independent dump_stack generator
*/
void dump_stack(void)
{
printk("CPU: %d %s %s %.*s\n",
task_thread_info(current)->cpu, print_tainted(),
init_utsname()->release,
(int)strcspn(init_utsname()->version, " "),
init_utsname()->version);
printk("Process %s (pid: %d, task: %p, ksp: %p)\n",
current->comm, current->pid, current,
(void *) current->thread.ksp);
show_stack(NULL, NULL);
}
EXPORT_SYMBOL(dump_stack);

static inline int mask_bits(struct pt_regs *regs, unsigned long bits)
{
return (regs->psw.mask & bits) / ((~bits + 1) & bits);
Expand Down
10 changes: 0 additions & 10 deletions arch/score/kernel/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,6 @@ static void show_registers(struct pt_regs *regs)
printk(KERN_NOTICE "\n");
}

/*
* The architecture-independent dump_stack generator
*/
void dump_stack(void)
{
show_stack(current_thread_info()->task,
(long *) get_irq_regs()->regs[0]);
}
EXPORT_SYMBOL(dump_stack);

void __die(const char *str, struct pt_regs *regs, const char *file,
const char *func, unsigned long line)
{
Expand Down
6 changes: 0 additions & 6 deletions arch/sh/kernel/dumpstack.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,3 @@ void show_stack(struct task_struct *tsk, unsigned long *sp)
(unsigned long)task_stack_page(tsk));
show_trace(tsk, sp, NULL);
}

void dump_stack(void)
{
show_stack(NULL, NULL);
}
EXPORT_SYMBOL(dump_stack);
7 changes: 0 additions & 7 deletions arch/sparc/kernel/process_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,6 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
printk("\n");
}

void dump_stack(void)
{
show_stack(current, NULL);
}

EXPORT_SYMBOL(dump_stack);

/*
* Note: sparc64 has a pretty intricated thread_saved_pc, check it out.
*/
Expand Down
7 changes: 0 additions & 7 deletions arch/sparc/kernel/traps_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -2350,13 +2350,6 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
} while (++count < 16);
}

void dump_stack(void)
{
show_stack(current, NULL);
}

EXPORT_SYMBOL(dump_stack);

static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
{
unsigned long fp = rw->ins[6];
Expand Down
Loading

0 comments on commit 196779b

Please sign in to comment.