Skip to content

Commit

Permalink
unicore32: add loglvl to c_backtrace()
Browse files Browse the repository at this point in the history
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.

Add log level parameter to c_backtrace() as a preparation for introducing
show_stack_loglvl()

[1]: https://lore.kernel.org/lkml/[email protected]/T/#u

Signed-off-by: Dmitry Safonov <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Cc: Guan Xuetao <[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 ee1e990 commit de985dd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion arch/unicore32/kernel/setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extern void kernel_thread_helper(void);
extern void __init early_signal_init(void);

extern asmlinkage void __backtrace(void);
extern asmlinkage void c_backtrace(unsigned long fp);
extern asmlinkage void c_backtrace(unsigned long fp, const char *loglvl);

extern void __show_regs(struct pt_regs *);

Expand Down
2 changes: 1 addition & 1 deletion arch/unicore32/kernel/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ static void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk)
printk("\n");

if (ok)
c_backtrace(fp);
c_backtrace(fp, KERN_DEFAULT);
}

void show_stack(struct task_struct *tsk, unsigned long *sp)
Expand Down
24 changes: 16 additions & 8 deletions arch/unicore32/lib/backtrace.S
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define sv_fp v5
#define sv_pc v6
#define offset v8
#define loglvl v9

ENTRY(__backtrace)
mov r0, fp
Expand All @@ -27,10 +28,11 @@ ENTRY(c_backtrace)
ENDPROC(__backtrace)
ENDPROC(c_backtrace)
#else
stm.w (v4 - v8, lr), [sp-] @ Save an extra register
stm.w (v4 - v10, lr), [sp-] @ Save an extra register
@ so we have a location...
mov.a frame, r0 @ if frame pointer is zero
beq no_frame @ we have no stack frames
mov loglvl, r1

1: stm.w (pc), [sp-] @ calculate offset of PC stored
ldw.w r0, [sp]+, #4 @ by stmfd for this CPU
Expand Down Expand Up @@ -95,9 +97,10 @@ for_each_frame:
bua for_each_frame

1006: adr r0, .Lbad
mov r1, frame
mov r1, loglvl
mov r2, frame
b.l printk
no_frame: ldm.w (v4 - v8, pc), [sp]+
no_frame: ldm.w (v4 - v10, pc), [sp]+
ENDPROC(__backtrace)
ENDPROC(c_backtrace)

Expand Down Expand Up @@ -128,8 +131,11 @@ ENDPROC(c_backtrace)
add v7, v7, #1
cxor.a v7, #6
cmoveq v7, #1
cmoveq r1, #'\n'
cmovne r1, #' '
bne 201f
adr r0, .Lcr
mov r1, loglvl
b.l printk
201:
ldw.w r3, [stack]+, #-4
mov r2, reg
csub.a r2, #8
Expand All @@ -141,18 +147,20 @@ ENDPROC(c_backtrace)
add r2, r2, #0x10 @ so r2 need add 16
201:
adr r0, .Lfp
mov r1, loglvl
b.l printk
2: sub.a reg, reg, #1
bns 1b
cxor.a v7, #0
beq 201f
adr r0, .Lcr
mov r1, loglvl
b.l printk
201: ldm.w (instr, reg, stack, v7, pc), [sp]+

.Lfp: .asciz "%cr%d:%08x"
.Lcr: .asciz "\n"
.Lbad: .asciz "Backtrace aborted due to bad frame pointer <%p>\n"
.Lfp: .asciz "%sr%d:%08x "
.Lcr: .asciz "%s\n"
.Lbad: .asciz "%sBacktrace aborted due to bad frame pointer <%p>\n"
.align
.Ldsi: .word 0x92eec000 >> 14 @ stm.w sp, (... fp, ip, lr, pc)
.word 0x92e10000 >> 14 @ stm.w sp, ()
Expand Down

0 comments on commit de985dd

Please sign in to comment.