Skip to content

Commit

Permalink
kallsyms/printk: add loglvl to print_ip_sym()
Browse files Browse the repository at this point in the history
Patch series "Add log level to show_stack()", v3.

Add log level argument to show_stack().

Done in three stages:
1. Introducing show_stack_loglvl() for every architecture
2. Migrating old users with an explicit log level
3. Renaming show_stack_loglvl() into show_stack()

Justification:

- It's a design mistake to move a business-logic decision into platform
  realization detail.

- I have currently two patches sets that would benefit from this work:
  Removing console_loglevel jumps in sysrq driver [1] Hung task warning
  before panic [2] - suggested by Tetsuo (but he probably didn't realise
  what it would involve).

- While doing (1), (2) the backtraces were adjusted to headers and other
  messages for each situation - so there won't be a situation when the
  backtrace is printed, but the headers are missing because they have
  lesser log level (or the reverse).

- As the result in (2) plays with console_loglevel for kdb are removed.

The least important for upstream, but maybe still worth to note that every
company I've worked in so far had an off-list patch to print backtrace
with the needed log level (but only for the architecture they cared
about).  If you have other ideas how you will benefit from show_stack()
with a log level - please, reply to this cover letter.

See also discussion on v1:
https://lore.kernel.org/linux-riscv/[email protected]/

This patch (of 50):

print_ip_sym() needs to have a log level parameter to comply with other
parts being printed.  Otherwise, half of the expected backtrace would be
printed and other may be missing with some logging level.

The following callee(s) are using now the adjusted log level:
- microblaze/unwind: the same level as headers & userspace unwind.
  Note that pr_debug()'s there are for debugging the unwinder itself.
- nds32/traps: symbol addresses are printed with the same log level
  as backtrace headers.
- lockdep: ip for locking issues is printed with the same log level
  as other part of the warning.
- sched: ip where preemption was disabled is printed as error like
  the rest part of the message.
- ftrace: bug reports are now consistent in the log level being used.

Signed-off-by: Dmitry Safonov <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Acked-by: Steven Rostedt (VMware) <[email protected]>
Cc: Albert Ou <[email protected]>
Cc: Ben Segall <[email protected]>
Cc: Dietmar Eggemann <[email protected]>
Cc: Greentime Hu <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: James Hogan <[email protected]>
Cc: Juri Lelli <[email protected]>
Cc: Mel Gorman <[email protected]>
Cc: Michal Simek <[email protected]>
Cc: Palmer Dabbelt <[email protected]>
Cc: Paul Burton <[email protected]>
Cc: Paul Walmsley <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Ralf Baechle <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Vincent Chen <[email protected]>
Cc: Vincent Guittot <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Dmitry Safonov <[email protected]>
Cc: Dmitry Safonov <[email protected]>
Cc: Jiri Slaby <[email protected]>
Cc: Petr Mladek <[email protected]>
Cc: Sergey Senozhatsky <[email protected]>
Cc: Ivan Kokshaysky <[email protected]>
Cc: Matt Turner <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Vineet Gupta <[email protected]>
Cc: Russell King <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Aurelien Jacquiot <[email protected]>
Cc: Mark Salter <[email protected]>
Cc: Guo Ren <[email protected]>
Cc: Yoshinori Sato <[email protected]>
Cc: Brian Cain <[email protected]>
Cc: Fenghua Yu <[email protected]>
Cc: Tony Luck <[email protected]>
Cc: Geert Uytterhoeven <[email protected]>
Cc: Ley Foon Tan <[email protected]>
Cc: Jonas Bonn <[email protected]>
Cc: Stafford Horne <[email protected]>
Cc: Stefan Kristiansson <[email protected]>
Cc: Helge Deller <[email protected]>
Cc: "James E.J. Bottomley" <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Christian Borntraeger <[email protected]>
Cc: Heiko Carstens <[email protected]>
Cc: Vasily Gorbik <[email protected]>
Cc: Rich Felker <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Anton Ivanov <[email protected]>
Cc: Jeff Dike <[email protected]>
Cc: Richard Weinberger <[email protected]>
Cc: Guan Xuetao <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: Chris Zankel <[email protected]>
Cc: Max Filippov <[email protected]>
Cc: Len Brown <[email protected]>
Cc: Pavel Machek <[email protected]>
Cc: "Rafael J. Wysocki" <[email protected]>
Cc: "Rafael J. Wysocki" <[email protected]>
Cc: Daniel Thompson <[email protected]>
Cc: Douglas Anderson <[email protected]>
Cc: Jason Wessel <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
0x7f454c46 authored and torvalds committed Jun 9, 2020
1 parent abfbb29 commit 2062a4e
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion arch/microblaze/kernel/unwind.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ static void microblaze_unwind_inner(struct task_struct *task,
task->comm);
break;
} else
print_ip_sym(pc);
print_ip_sym(KERN_INFO, pc);
}

/* Stop when we reach anything not part of the kernel */
Expand Down
4 changes: 2 additions & 2 deletions arch/mips/kernel/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static void show_raw_backtrace(unsigned long reg29)
break;
}
if (__kernel_text_address(addr))
print_ip_sym(addr);
print_ip_sym(KERN_DEFAULT, addr);
}
printk("\n");
}
Expand Down Expand Up @@ -155,7 +155,7 @@ static void show_backtrace(struct task_struct *task, const struct pt_regs *regs)
}
printk("Call Trace:\n");
do {
print_ip_sym(pc);
print_ip_sym(KERN_DEFAULT, pc);
pc = unwind_stack(task, &sp, pc, &ra);
} while (pc);
pr_cont("\n");
Expand Down
4 changes: 2 additions & 2 deletions arch/nds32/kernel/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static void __dump(struct task_struct *tsk, unsigned long *base_reg)
if (__kernel_text_address(ret_addr)) {
ret_addr = ftrace_graph_ret_addr(
tsk, &graph, ret_addr, NULL);
print_ip_sym(ret_addr);
print_ip_sym(KERN_EMERG, ret_addr);
}
if (--cnt < 0)
break;
Expand All @@ -124,7 +124,7 @@ static void __dump(struct task_struct *tsk, unsigned long *base_reg)

ret_addr = ftrace_graph_ret_addr(
tsk, &graph, ret_addr, NULL);
print_ip_sym(ret_addr);
print_ip_sym(KERN_EMERG, ret_addr);
}
if (--cnt < 0)
break;
Expand Down
2 changes: 1 addition & 1 deletion arch/riscv/kernel/stacktrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void notrace walk_stackframe(struct task_struct *task,

static bool print_trace_address(unsigned long pc, void *arg)
{
print_ip_sym(pc);
print_ip_sym(KERN_DEFAULT, pc);
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions include/linux/kallsyms.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ static inline int kallsyms_show_value(void)

#endif /*CONFIG_KALLSYMS*/

static inline void print_ip_sym(unsigned long ip)
static inline void print_ip_sym(const char *loglvl, unsigned long ip)
{
printk("[<%px>] %pS\n", (void *) ip, (void *) ip);
printk("%s[<%px>] %pS\n", loglvl, (void *) ip, (void *) ip);
}

#endif /*_LINUX_KALLSYMS_H*/
4 changes: 2 additions & 2 deletions kernel/locking/lockdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -4424,7 +4424,7 @@ static void print_unlock_imbalance_bug(struct task_struct *curr,
curr->comm, task_pid_nr(curr));
print_lockdep_cache(lock);
pr_cont(") at:\n");
print_ip_sym(ip);
print_ip_sym(KERN_WARNING, ip);
pr_warn("but there are no more locks to release!\n");
pr_warn("\nother info that might help us debug this:\n");
lockdep_print_held_locks(curr);
Expand Down Expand Up @@ -5075,7 +5075,7 @@ static void print_lock_contention_bug(struct task_struct *curr,
curr->comm, task_pid_nr(curr));
print_lockdep_cache(lock);
pr_cont(") at:\n");
print_ip_sym(ip);
print_ip_sym(KERN_WARNING, ip);
pr_warn("but there are no locks held!\n");
pr_warn("\nother info that might help us debug this:\n");
lockdep_print_held_locks(curr);
Expand Down
6 changes: 2 additions & 4 deletions kernel/sched/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -3922,8 +3922,7 @@ static noinline void __schedule_bug(struct task_struct *prev)
if (IS_ENABLED(CONFIG_DEBUG_PREEMPT)
&& in_atomic_preempt_off()) {
pr_err("Preemption disabled at:");
print_ip_sym(preempt_disable_ip);
pr_cont("\n");
print_ip_sym(KERN_ERR, preempt_disable_ip);
}
if (panic_on_warn)
panic("scheduling while atomic\n");
Expand Down Expand Up @@ -6871,8 +6870,7 @@ void ___might_sleep(const char *file, int line, int preempt_offset)
if (IS_ENABLED(CONFIG_DEBUG_PREEMPT)
&& !preempt_count_equals(preempt_offset)) {
pr_err("Preemption disabled at:");
print_ip_sym(preempt_disable_ip);
pr_cont("\n");
print_ip_sym(KERN_ERR, preempt_disable_ip);
}
dump_stack();
add_taint(TAINT_WARN, LOCKDEP_STILL_OK);
Expand Down
8 changes: 4 additions & 4 deletions kernel/trace/ftrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -2020,12 +2020,12 @@ void ftrace_bug(int failed, struct dyn_ftrace *rec)
case -EFAULT:
FTRACE_WARN_ON_ONCE(1);
pr_info("ftrace faulted on modifying ");
print_ip_sym(ip);
print_ip_sym(KERN_INFO, ip);
break;
case -EINVAL:
FTRACE_WARN_ON_ONCE(1);
pr_info("ftrace failed to modify ");
print_ip_sym(ip);
print_ip_sym(KERN_INFO, ip);
print_ip_ins(" actual: ", (unsigned char *)ip);
pr_cont("\n");
if (ftrace_expected) {
Expand All @@ -2036,12 +2036,12 @@ void ftrace_bug(int failed, struct dyn_ftrace *rec)
case -EPERM:
FTRACE_WARN_ON_ONCE(1);
pr_info("ftrace faulted on writing ");
print_ip_sym(ip);
print_ip_sym(KERN_INFO, ip);
break;
default:
FTRACE_WARN_ON_ONCE(1);
pr_info("ftrace faulted on unknown error ");
print_ip_sym(ip);
print_ip_sym(KERN_INFO, ip);
}
print_bug_type();
if (rec) {
Expand Down
2 changes: 1 addition & 1 deletion tools/include/linux/kallsyms.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static inline const char *kallsyms_lookup(unsigned long addr,

#include <execinfo.h>
#include <stdlib.h>
static inline void print_ip_sym(unsigned long ip)
static inline void print_ip_sym(const char *loglvl, unsigned long ip)
{
char **name;

Expand Down

0 comments on commit 2062a4e

Please sign in to comment.