Skip to content

Commit

Permalink
riscv: Add dump stack in show_regs
Browse files Browse the repository at this point in the history
Like commit 1149aad ("arm64: Add dump_backtrace() in show_regs"),
dump the stack in riscv show_regs as common code expects.

Reviewed-by: Atish Patra <atish.patra@wdc.com>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
  • Loading branch information
Kefeng Wang authored and Palmer Dabbelt committed Jan 14, 2021
1 parent fea2fed commit 091b945
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions arch/riscv/include/asm/bug.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ do { \
struct pt_regs;
struct task_struct;

void __show_regs(struct pt_regs *regs);
void die(struct pt_regs *regs, const char *str);
void do_trap(struct pt_regs *regs, int signo, int code, unsigned long addr);

Expand Down
2 changes: 2 additions & 0 deletions arch/riscv/include/asm/stacktrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ struct stackframe {

extern void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,
bool (*fn)(void *, unsigned long), void *arg);
extern void dump_backtrace(struct pt_regs *regs, struct task_struct *task,
const char *loglvl);

#endif /* _ASM_RISCV_STACKTRACE_H */
9 changes: 8 additions & 1 deletion arch/riscv/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <asm/unistd.h>
#include <asm/processor.h>
#include <asm/csr.h>
#include <asm/stacktrace.h>
#include <asm/string.h>
#include <asm/switch_to.h>
#include <asm/thread_info.h>
Expand All @@ -39,7 +40,7 @@ void arch_cpu_idle(void)
raw_local_irq_enable();
}

void show_regs(struct pt_regs *regs)
void __show_regs(struct pt_regs *regs)
{
show_regs_print_info(KERN_DEFAULT);

Expand Down Expand Up @@ -69,6 +70,12 @@ void show_regs(struct pt_regs *regs)
pr_cont("status: " REG_FMT " badaddr: " REG_FMT " cause: " REG_FMT "\n",
regs->status, regs->badaddr, regs->cause);
}
void show_regs(struct pt_regs *regs)
{
__show_regs(regs);
if (!user_mode(regs))
dump_backtrace(regs, NULL, KERN_DEFAULT);
}

void start_thread(struct pt_regs *regs, unsigned long pc,
unsigned long sp)
Expand Down
10 changes: 8 additions & 2 deletions arch/riscv/kernel/stacktrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,16 @@ static bool print_trace_address(void *arg, unsigned long pc)
return true;
}

void dump_backtrace(struct pt_regs *regs, struct task_struct *task,
const char *loglvl)
{
pr_cont("%sCall Trace:\n", loglvl);
walk_stackframe(task, regs, print_trace_address, (void *)loglvl);
}

void show_stack(struct task_struct *task, unsigned long *sp, const char *loglvl)
{
pr_cont("Call Trace:\n");
walk_stackframe(task, NULL, print_trace_address, (void *)loglvl);
dump_backtrace(NULL, task, loglvl);
}

static bool save_wchan(void *arg, unsigned long pc)
Expand Down
3 changes: 2 additions & 1 deletion arch/riscv/kernel/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <linux/module.h>
#include <linux/irq.h>

#include <asm/bug.h>
#include <asm/processor.h>
#include <asm/ptrace.h>
#include <asm/csr.h>
Expand Down Expand Up @@ -67,7 +68,7 @@ void do_trap(struct pt_regs *regs, int signo, int code, unsigned long addr)
tsk->comm, task_pid_nr(tsk), signo, code, addr);
print_vma_addr(KERN_CONT " in ", instruction_pointer(regs));
pr_cont("\n");
show_regs(regs);
__show_regs(regs);
}

force_sig_fault(signo, code, (void __user *)addr);
Expand Down

0 comments on commit 091b945

Please sign in to comment.