]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
mips: add show_stack_loglvl()
authorDmitry Safonov <dima@arista.com>
Tue, 9 Jun 2020 04:30:59 +0000 (21:30 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 9 Jun 2020 16:39:11 +0000 (09:39 -0700)
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/#u

Signed-off-by: Dmitry Safonov <dima@arista.com>
Signed-off-by: Andrew 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.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
arch/mips/kernel/traps.c

index 210fea63de75012b771f7df4e2d9cceb85d609c1..e49040739b61d5a77d5ab4dce63aa91e16c63082 100644 (file)
@@ -108,26 +108,26 @@ void (*board_bind_eic_interrupt)(int irq, int regset);
 void (*board_ebase_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 addr;
 
-       printk("Call Trace:");
+       printk("%sCall Trace:", loglvl);
 #ifdef CONFIG_KALLSYMS
-       printk("\n");
+       printk("%s\n", loglvl);
 #endif
        while (!kstack_end(sp)) {
                unsigned long __user *p =
                        (unsigned long __user *)(unsigned long)sp++;
                if (__get_user(addr, p)) {
-                       printk(" (Bad stack address)");
+                       printk("%s (Bad stack address)", loglvl);
                        break;
                }
                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
@@ -140,7 +140,8 @@ static int __init set_raw_show_trace(char *str)
 __setup("raw_show_trace", set_raw_show_trace);
 #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 ra = regs->regs[31];
@@ -150,12 +151,12 @@ static void show_backtrace(struct task_struct *task, const struct pt_regs *regs)
                task = current;
 
        if (raw_show_trace || user_mode(regs) || !__kernel_text_address(pc)) {
-               show_raw_backtrace(sp);
+               show_raw_backtrace(sp, loglvl);
                return;
        }
-       printk("Call Trace:\n");
+       printk("%sCall Trace:\n", loglvl);
        do {
-               print_ip_sym(KERN_DEFAULT, pc);
+               print_ip_sym(loglvl, pc);
                pc = unwind_stack(task, &sp, pc, &ra);
        } while (pc);
        pr_cont("\n");
@@ -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 ...
  */
 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);
        long stackdata;
        int i;
        unsigned long __user *sp = (unsigned long __user *)regs->regs[29];
 
-       printk("Stack :");
+       printk("%sStack :", loglvl);
        i = 0;
        while ((unsigned long) sp & (PAGE_SIZE - 1)) {
                if (i && ((i % (64 / field)) == 0)) {
                        pr_cont("\n");
-                       printk("       ");
+                       printk("%s       ", loglvl);
                }
                if (i > 39) {
                        pr_cont(" ...");
@@ -194,10 +195,11 @@ static void show_stacktrace(struct task_struct *task,
                i++;
        }
        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;
        mm_segment_t old_fs = get_fs();
@@ -221,10 +223,15 @@ void show_stack(struct task_struct *task, unsigned long *sp)
         * the stack in the kernel (not user) address space.
         */
        set_fs(KERNEL_DS);
-       show_stacktrace(task, &regs);
+       show_stacktrace(task, &regs, loglvl);
        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)
 {
        long i;
@@ -373,7 +380,7 @@ void show_registers(struct pt_regs *regs)
        if (!user_mode(regs))
                /* Necessary for getting the correct stack content */
                set_fs(KERNEL_DS);
-       show_stacktrace(current, regs);
+       show_stacktrace(current, regs, KERN_DEFAULT);
        show_code((unsigned int __user *) regs->cp0_epc);
        printk("\n");
        set_fs(old_fs);