Commit 96f0458a authored by Dmitry Safonov's avatar Dmitry Safonov Committed by Linus Torvalds

mips: 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().

[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>
Cc: James Hogan <jhogan@kernel.org>
Cc: Paul Burton <paulburton@kernel.org>
Cc: Ralf Baechle <ralf@linux-mips.org>
Link: http://lkml.kernel.org/r/20200418201944.482088-22-dima@arista.comSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 35f3968b
...@@ -108,26 +108,26 @@ void (*board_bind_eic_interrupt)(int irq, int regset); ...@@ -108,26 +108,26 @@ void (*board_bind_eic_interrupt)(int irq, int regset);
void (*board_ebase_setup)(void); void (*board_ebase_setup)(void);
void(*board_cache_error_setup)(void); void(*board_cache_error_setup)(void);
static void show_raw_backtrace(unsigned long reg29) static void show_raw_backtrace(unsigned long reg29, const char *loglvl)
{ {
unsigned long *sp = (unsigned long *)(reg29 & ~3); unsigned long *sp = (unsigned long *)(reg29 & ~3);
unsigned long addr; unsigned long addr;
printk("Call Trace:"); printk("%sCall Trace:", loglvl);
#ifdef CONFIG_KALLSYMS #ifdef CONFIG_KALLSYMS
printk("\n"); printk("%s\n", loglvl);
#endif #endif
while (!kstack_end(sp)) { while (!kstack_end(sp)) {
unsigned long __user *p = unsigned long __user *p =
(unsigned long __user *)(unsigned long)sp++; (unsigned long __user *)(unsigned long)sp++;
if (__get_user(addr, p)) { if (__get_user(addr, p)) {
printk(" (Bad stack address)"); printk("%s (Bad stack address)", loglvl);
break; break;
} }
if (__kernel_text_address(addr)) if (__kernel_text_address(addr))
print_ip_sym(KERN_DEFAULT, addr); print_ip_sym(loglvl, addr);
} }
printk("\n"); printk("%s\n", loglvl);
} }
#ifdef CONFIG_KALLSYMS #ifdef CONFIG_KALLSYMS
...@@ -140,7 +140,8 @@ static int __init set_raw_show_trace(char *str) ...@@ -140,7 +140,8 @@ static int __init set_raw_show_trace(char *str)
__setup("raw_show_trace", set_raw_show_trace); __setup("raw_show_trace", set_raw_show_trace);
#endif #endif
static void show_backtrace(struct task_struct *task, const struct pt_regs *regs) static void show_backtrace(struct task_struct *task, const struct pt_regs *regs,
const char *loglvl)
{ {
unsigned long sp = regs->regs[29]; unsigned long sp = regs->regs[29];
unsigned long ra = regs->regs[31]; unsigned long ra = regs->regs[31];
...@@ -150,12 +151,12 @@ static void show_backtrace(struct task_struct *task, const struct pt_regs *regs) ...@@ -150,12 +151,12 @@ static void show_backtrace(struct task_struct *task, const struct pt_regs *regs)
task = current; task = current;
if (raw_show_trace || user_mode(regs) || !__kernel_text_address(pc)) { if (raw_show_trace || user_mode(regs) || !__kernel_text_address(pc)) {
show_raw_backtrace(sp); show_raw_backtrace(sp, loglvl);
return; return;
} }
printk("Call Trace:\n"); printk("%sCall Trace:\n", loglvl);
do { do {
print_ip_sym(KERN_DEFAULT, pc); print_ip_sym(loglvl, pc);
pc = unwind_stack(task, &sp, pc, &ra); pc = unwind_stack(task, &sp, pc, &ra);
} while (pc); } while (pc);
pr_cont("\n"); pr_cont("\n");
...@@ -166,19 +167,19 @@ static void show_backtrace(struct task_struct *task, const struct pt_regs *regs) ...@@ -166,19 +167,19 @@ static void show_backtrace(struct task_struct *task, const struct pt_regs *regs)
* with at least a bit of error checking ... * with at least a bit of error checking ...
*/ */
static void show_stacktrace(struct task_struct *task, static void show_stacktrace(struct task_struct *task,
const struct pt_regs *regs) const struct pt_regs *regs, const char *loglvl)
{ {
const int field = 2 * sizeof(unsigned long); const int field = 2 * sizeof(unsigned long);
long stackdata; long stackdata;
int i; int i;
unsigned long __user *sp = (unsigned long __user *)regs->regs[29]; unsigned long __user *sp = (unsigned long __user *)regs->regs[29];
printk("Stack :"); printk("%sStack :", loglvl);
i = 0; i = 0;
while ((unsigned long) sp & (PAGE_SIZE - 1)) { while ((unsigned long) sp & (PAGE_SIZE - 1)) {
if (i && ((i % (64 / field)) == 0)) { if (i && ((i % (64 / field)) == 0)) {
pr_cont("\n"); pr_cont("\n");
printk(" "); printk("%s ", loglvl);
} }
if (i > 39) { if (i > 39) {
pr_cont(" ..."); pr_cont(" ...");
...@@ -194,10 +195,11 @@ static void show_stacktrace(struct task_struct *task, ...@@ -194,10 +195,11 @@ static void show_stacktrace(struct task_struct *task,
i++; i++;
} }
pr_cont("\n"); pr_cont("\n");
show_backtrace(task, regs); show_backtrace(task, regs, loglvl);
} }
void show_stack(struct task_struct *task, unsigned long *sp) void show_stack_loglvl(struct task_struct *task, unsigned long *sp,
const char *loglvl)
{ {
struct pt_regs regs; struct pt_regs regs;
mm_segment_t old_fs = get_fs(); mm_segment_t old_fs = get_fs();
...@@ -221,10 +223,15 @@ void show_stack(struct task_struct *task, unsigned long *sp) ...@@ -221,10 +223,15 @@ void show_stack(struct task_struct *task, unsigned long *sp)
* the stack in the kernel (not user) address space. * the stack in the kernel (not user) address space.
*/ */
set_fs(KERNEL_DS); set_fs(KERNEL_DS);
show_stacktrace(task, &regs); show_stacktrace(task, &regs, loglvl);
set_fs(old_fs); set_fs(old_fs);
} }
void show_stack(struct task_struct *task, unsigned long *sp)
{
show_stack_loglvl(task, sp, KERN_DEFAULT)
}
static void show_code(unsigned int __user *pc) static void show_code(unsigned int __user *pc)
{ {
long i; long i;
...@@ -373,7 +380,7 @@ void show_registers(struct pt_regs *regs) ...@@ -373,7 +380,7 @@ void show_registers(struct pt_regs *regs)
if (!user_mode(regs)) if (!user_mode(regs))
/* Necessary for getting the correct stack content */ /* Necessary for getting the correct stack content */
set_fs(KERNEL_DS); set_fs(KERNEL_DS);
show_stacktrace(current, regs); show_stacktrace(current, regs, KERN_DEFAULT);
show_code((unsigned int __user *) regs->cp0_epc); show_code((unsigned int __user *) regs->cp0_epc);
printk("\n"); printk("\n");
set_fs(old_fs); set_fs(old_fs);
......
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