Skip to content

Commit 5c08846

Browse files
0x7f454c46torvalds
authored andcommitted
unicore32: 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 nice side-effect - print backtrace in __die() with the same log level as the rest of function. [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: Guan Xuetao <gxt@pku.edu.cn> Link: http://lkml.kernel.org/r/20200418201944.482088-40-dima@arista.com Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent de985dd commit 5c08846

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

‎arch/unicore32/kernel/traps.c‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,13 @@ static void dump_instr(const char *lvl, struct pt_regs *regs)
135135
set_fs(fs);
136136
}
137137

138-
static void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk)
138+
static void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk,
139+
const char *loglvl)
139140
{
140141
unsigned int fp;
141142
int ok = 1;
142143

143-
printk(KERN_DEFAULT "Backtrace: ");
144+
printk("%sBacktrace: ", loglvl);
144145

145146
if (!tsk)
146147
tsk = current;
@@ -153,25 +154,31 @@ static void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk)
153154
asm("mov %0, fp" : "=r" (fp) : : "cc");
154155

155156
if (!fp) {
156-
printk("no frame pointer");
157+
printk("%sno frame pointer", loglvl);
157158
ok = 0;
158159
} else if (verify_stack(fp)) {
159-
printk("invalid frame pointer 0x%08x", fp);
160+
printk("%sinvalid frame pointer 0x%08x", loglvl, fp);
160161
ok = 0;
161162
} else if (fp < (unsigned long)end_of_stack(tsk))
162-
printk("frame pointer underflow");
163-
printk("\n");
163+
printk("%sframe pointer underflow", loglvl);
164+
printk("%s\n", loglvl);
164165

165166
if (ok)
166-
c_backtrace(fp, KERN_DEFAULT);
167+
c_backtrace(fp, loglvl);
167168
}
168169

169-
void show_stack(struct task_struct *tsk, unsigned long *sp)
170+
void show_stack_loglvl(struct task_struct *tsk, unsigned long *sp,
171+
const char *loglvl)
170172
{
171-
dump_backtrace(NULL, tsk);
173+
dump_backtrace(NULL, tsk, loglvl);
172174
barrier();
173175
}
174176

177+
void show_stack(struct task_struct *tsk, unsigned long *sp)
178+
{
179+
show_stack_loglvl(tsk, sp, KERN_DEFAULT)
180+
}
181+
175182
static int __die(const char *str, int err, struct thread_info *thread,
176183
struct pt_regs *regs)
177184
{
@@ -196,7 +203,7 @@ static int __die(const char *str, int err, struct thread_info *thread,
196203
if (!user_mode(regs) || in_interrupt()) {
197204
dump_mem(KERN_EMERG, "Stack: ", regs->UCreg_sp,
198205
THREAD_SIZE + (unsigned long)task_stack_page(tsk));
199-
dump_backtrace(regs, tsk);
206+
dump_backtrace(regs, tsk, KERN_EMERG);
200207
dump_instr(KERN_EMERG, regs);
201208
}
202209

0 commit comments

Comments
 (0)