Commit d1e9086d authored by Dmitry Safonov's avatar Dmitry Safonov Committed by Linus Torvalds

hexagon: add show_stack_loglvl()

Currently, the log-level of show_stack() depends on a platform
realization.  It creates situations where the headers are printed with
lower log level or higher than the stacktrace (depending on a platform or
user).

Furthermore, it forces the logic decision from user to an architecture
side.  In result, some users as sysrq/kdb/etc are doing tricks with
temporary rising console_loglevel while printing their messages.  And in
result it not only may print unwanted messages from other CPUs, but also
omit printing at all in the unlucky case where the printk() was deferred.

Introducing log-level parameter and KERN_UNSUPPRESSED [1] seems an easier
approach than introducing more printk buffers.  Also, it will consolidate
printings with headers.

Introduce show_stack_loglvl(), that eventually will substitute
show_stack().

As a good side-effect die() now prints the stacktrace with KERN_EMERG
aligned with other messages.

[1]: https://lore.kernel.org/lkml/20190528002412.1625-1-dima@arista.com/T/#uSigned-off-by: default avatarDmitry Safonov <dima@arista.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Acked-by: default avatarBrian Cain <bcain@codeaurora.org>
Link: http://lkml.kernel.org/r/20200418201944.482088-15-dima@arista.comSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 0b2ad0c7
...@@ -79,7 +79,7 @@ static const char *ex_name(int ex) ...@@ -79,7 +79,7 @@ static const char *ex_name(int ex)
} }
static void do_show_stack(struct task_struct *task, unsigned long *fp, static void do_show_stack(struct task_struct *task, unsigned long *fp,
unsigned long ip) unsigned long ip, const char *loglvl)
{ {
int kstack_depth_to_print = 24; int kstack_depth_to_print = 24;
unsigned long offset, size; unsigned long offset, size;
...@@ -93,9 +93,8 @@ static void do_show_stack(struct task_struct *task, unsigned long *fp, ...@@ -93,9 +93,8 @@ static void do_show_stack(struct task_struct *task, unsigned long *fp,
if (task == NULL) if (task == NULL)
task = current; task = current;
printk(KERN_INFO "CPU#%d, %s/%d, Call Trace:\n", printk("%sCPU#%d, %s/%d, Call Trace:\n", loglvl, raw_smp_processor_id(),
raw_smp_processor_id(), task->comm, task->comm, task_pid_nr(task));
task_pid_nr(task));
if (fp == NULL) { if (fp == NULL) {
if (task == current) { if (task == current) {
...@@ -108,7 +107,7 @@ static void do_show_stack(struct task_struct *task, unsigned long *fp, ...@@ -108,7 +107,7 @@ static void do_show_stack(struct task_struct *task, unsigned long *fp,
} }
if ((((unsigned long) fp) & 0x3) || ((unsigned long) fp < 0x1000)) { if ((((unsigned long) fp) & 0x3) || ((unsigned long) fp < 0x1000)) {
printk(KERN_INFO "-- Corrupt frame pointer %p\n", fp); printk("%s-- Corrupt frame pointer %p\n", loglvl, fp);
return; return;
} }
...@@ -125,8 +124,7 @@ static void do_show_stack(struct task_struct *task, unsigned long *fp, ...@@ -125,8 +124,7 @@ static void do_show_stack(struct task_struct *task, unsigned long *fp,
name = kallsyms_lookup(ip, &size, &offset, &modname, tmpstr); name = kallsyms_lookup(ip, &size, &offset, &modname, tmpstr);
printk(KERN_INFO "[%p] 0x%lx: %s + 0x%lx", fp, ip, name, printk("%s[%p] 0x%lx: %s + 0x%lx", loglvl, fp, ip, name, offset);
offset);
if (((unsigned long) fp < low) || (high < (unsigned long) fp)) if (((unsigned long) fp < low) || (high < (unsigned long) fp))
printk(KERN_CONT " (FP out of bounds!)"); printk(KERN_CONT " (FP out of bounds!)");
if (modname) if (modname)
...@@ -136,8 +134,7 @@ static void do_show_stack(struct task_struct *task, unsigned long *fp, ...@@ -136,8 +134,7 @@ static void do_show_stack(struct task_struct *task, unsigned long *fp,
newfp = (unsigned long *) *fp; newfp = (unsigned long *) *fp;
if (((unsigned long) newfp) & 0x3) { if (((unsigned long) newfp) & 0x3) {
printk(KERN_INFO "-- Corrupt frame pointer %p\n", printk("%s-- Corrupt frame pointer %p\n", loglvl, newfp);
newfp);
break; break;
} }
...@@ -147,7 +144,7 @@ static void do_show_stack(struct task_struct *task, unsigned long *fp, ...@@ -147,7 +144,7 @@ static void do_show_stack(struct task_struct *task, unsigned long *fp,
+ 8); + 8);
if (regs->syscall_nr != -1) { if (regs->syscall_nr != -1) {
printk(KERN_INFO "-- trap0 -- syscall_nr: %ld", printk("%s-- trap0 -- syscall_nr: %ld", loglvl,
regs->syscall_nr); regs->syscall_nr);
printk(KERN_CONT " psp: %lx elr: %lx\n", printk(KERN_CONT " psp: %lx elr: %lx\n",
pt_psp(regs), pt_elr(regs)); pt_psp(regs), pt_elr(regs));
...@@ -155,7 +152,7 @@ static void do_show_stack(struct task_struct *task, unsigned long *fp, ...@@ -155,7 +152,7 @@ static void do_show_stack(struct task_struct *task, unsigned long *fp,
} else { } else {
/* really want to see more ... */ /* really want to see more ... */
kstack_depth_to_print += 6; kstack_depth_to_print += 6;
printk(KERN_INFO "-- %s (0x%lx) badva: %lx\n", printk("%s-- %s (0x%lx) badva: %lx\n", loglvl,
ex_name(pt_cause(regs)), pt_cause(regs), ex_name(pt_cause(regs)), pt_cause(regs),
pt_badva(regs)); pt_badva(regs));
} }
...@@ -178,10 +175,16 @@ static void do_show_stack(struct task_struct *task, unsigned long *fp, ...@@ -178,10 +175,16 @@ static void do_show_stack(struct task_struct *task, unsigned long *fp,
} }
} }
void show_stack(struct task_struct *task, unsigned long *fp) void show_stack_loglvl(struct task_struct *task, unsigned long *fp,
const char *loglvl)
{ {
/* Saved link reg is one word above FP */ /* Saved link reg is one word above FP */
do_show_stack(task, fp, 0); do_show_stack(task, fp, 0, loglvl);
}
void show_stack(struct task_struct *task, unsigned long *fp)
{
show_stack_loglvl(task, fp, 0, KERN_INFO);
} }
int die(const char *str, struct pt_regs *regs, long err) int die(const char *str, struct pt_regs *regs, long err)
...@@ -207,7 +210,7 @@ int die(const char *str, struct pt_regs *regs, long err) ...@@ -207,7 +210,7 @@ int die(const char *str, struct pt_regs *regs, long err)
print_modules(); print_modules();
show_regs(regs); show_regs(regs);
do_show_stack(current, &regs->r30, pt_elr(regs)); do_show_stack(current, &regs->r30, pt_elr(regs), KERN_EMERG);
bust_spinlocks(0); bust_spinlocks(0);
add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE); add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment