Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

arc: 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 header "Stack Trace:" is now printed with the same
log level as the rest of backtrace.

[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: Vineet Gupta <vgupta@synopsys.com>
Link: http://lkml.kernel.org/r/20200418201944.482088-4-dima@arista.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Dmitry Safonov and committed by
Linus Torvalds
8ca4d199 8c49a909

+18 -8
+2 -1
arch/arc/include/asm/bug.h
··· 13 13 struct task_struct; 14 14 15 15 void show_regs(struct pt_regs *regs); 16 - void show_stacktrace(struct task_struct *tsk, struct pt_regs *regs); 16 + void show_stacktrace(struct task_struct *tsk, struct pt_regs *regs, 17 + const char *loglvl); 17 18 void show_kernel_fault_diag(const char *str, struct pt_regs *regs, 18 19 unsigned long address); 19 20 void die(const char *str, struct pt_regs *regs, unsigned long address);
+15 -6
arch/arc/kernel/stacktrace.c
··· 158 158 /* Call-back which plugs into unwinding core to dump the stack in 159 159 * case of panic/OOPs/BUG etc 160 160 */ 161 - static int __print_sym(unsigned int address, void *unused) 161 + static int __print_sym(unsigned int address, void *arg) 162 162 { 163 - printk(" %pS\n", (void *)address); 163 + const char *loglvl = arg; 164 + 165 + printk("%s %pS\n", loglvl, (void *)address); 164 166 return 0; 165 167 } 166 168 ··· 219 217 *------------------------------------------------------------------------- 220 218 */ 221 219 222 - noinline void show_stacktrace(struct task_struct *tsk, struct pt_regs *regs) 220 + noinline void show_stacktrace(struct task_struct *tsk, struct pt_regs *regs, 221 + const char *loglvl) 223 222 { 224 - pr_info("\nStack Trace:\n"); 225 - arc_unwind_core(tsk, regs, __print_sym, NULL); 223 + printk("%s\nStack Trace:\n", loglvl); 224 + arc_unwind_core(tsk, regs, __print_sym, (void *)loglvl); 226 225 } 227 226 EXPORT_SYMBOL(show_stacktrace); 228 227 229 228 /* Expected by sched Code */ 229 + void show_stack_loglvl(struct task_struct *tsk, unsigned long *sp, 230 + const char *loglvl) 231 + { 232 + show_stacktrace(tsk, NULL, loglvl); 233 + } 234 + 230 235 void show_stack(struct task_struct *tsk, unsigned long *sp) 231 236 { 232 - show_stacktrace(tsk, NULL); 237 + show_stack_loglvl(tsk, sp, KERN_DEFAULT); 233 238 } 234 239 235 240 /* Another API expected by schedular, shows up in "ps" as Wait Channel
+1 -1
arch/arc/kernel/troubleshoot.c
··· 240 240 241 241 /* Show stack trace if this Fatality happened in kernel mode */ 242 242 if (!user_mode(regs)) 243 - show_stacktrace(current, regs); 243 + show_stacktrace(current, regs, KERN_DEFAULT); 244 244 }