]> git.baikalelectronics.ru Git - kernel.git/commitdiff
arm64: Move console stack display code to stacktrace.c
authorMark Brown <broonie@kernel.org>
Mon, 21 Sep 2020 12:23:41 +0000 (13:23 +0100)
committerWill Deacon <will@kernel.org>
Mon, 21 Sep 2020 18:43:03 +0000 (19:43 +0100)
Currently the code for displaying a stack trace on the console is located
in traps.c rather than stacktrace.c, using the unwinding code that is in
stacktrace.c. This can be confusing and make the code hard to find since
such output is often referred to as a stack trace which might mislead the
unwary. Due to this and since traps.c doesn't interact with this code
except for via the public interfaces move the code to stacktrace.c to
make it easier to find.

Signed-off-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20200921122341.11280-1-broonie@kernel.org
Signed-off-by: Will Deacon <will@kernel.org>
arch/arm64/kernel/stacktrace.c
arch/arm64/kernel/traps.c

index 804d076b02cb81d356cb6d216fc5cdbac004d163..fa56af1a59c39fd452bd31ec29486067430724e3 100644 (file)
@@ -132,6 +132,71 @@ void notrace walk_stackframe(struct task_struct *tsk, struct stackframe *frame,
 }
 NOKPROBE_SYMBOL(walk_stackframe);
 
+static void dump_backtrace_entry(unsigned long where, const char *loglvl)
+{
+       printk("%s %pS\n", loglvl, (void *)where);
+}
+
+void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk,
+                   const char *loglvl)
+{
+       struct stackframe frame;
+       int skip = 0;
+
+       pr_debug("%s(regs = %p tsk = %p)\n", __func__, regs, tsk);
+
+       if (regs) {
+               if (user_mode(regs))
+                       return;
+               skip = 1;
+       }
+
+       if (!tsk)
+               tsk = current;
+
+       if (!try_get_task_stack(tsk))
+               return;
+
+       if (tsk == current) {
+               start_backtrace(&frame,
+                               (unsigned long)__builtin_frame_address(0),
+                               (unsigned long)dump_backtrace);
+       } else {
+               /*
+                * task blocked in __switch_to
+                */
+               start_backtrace(&frame,
+                               thread_saved_fp(tsk),
+                               thread_saved_pc(tsk));
+       }
+
+       printk("%sCall trace:\n", loglvl);
+       do {
+               /* skip until specified stack frame */
+               if (!skip) {
+                       dump_backtrace_entry(frame.pc, loglvl);
+               } else if (frame.fp == regs->regs[29]) {
+                       skip = 0;
+                       /*
+                        * Mostly, this is the case where this function is
+                        * called in panic/abort. As exception handler's
+                        * stack frame does not contain the corresponding pc
+                        * at which an exception has taken place, use regs->pc
+                        * instead.
+                        */
+                       dump_backtrace_entry(regs->pc, loglvl);
+               }
+       } while (!unwind_frame(tsk, &frame));
+
+       put_task_stack(tsk);
+}
+
+void show_stack(struct task_struct *tsk, unsigned long *sp, const char *loglvl)
+{
+       dump_backtrace(NULL, tsk, loglvl);
+       barrier();
+}
+
 #ifdef CONFIG_STACKTRACE
 
 void arch_stack_walk(stack_trace_consume_fn consume_entry, void *cookie,
index 13ebd5ca20706a0746c3a30b48343772e29171b7..77dc8e7701ed4cb65ae9b66e2dec331933789bd3 100644 (file)
@@ -53,11 +53,6 @@ static const char *handler[]= {
 
 int show_unhandled_signals = 0;
 
-static void dump_backtrace_entry(unsigned long where, const char *loglvl)
-{
-       printk("%s %pS\n", loglvl, (void *)where);
-}
-
 static void dump_kernel_instr(const char *lvl, struct pt_regs *regs)
 {
        unsigned long addr = instruction_pointer(regs);
@@ -83,66 +78,6 @@ static void dump_kernel_instr(const char *lvl, struct pt_regs *regs)
        printk("%sCode: %s\n", lvl, str);
 }
 
-void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk,
-                   const char *loglvl)
-{
-       struct stackframe frame;
-       int skip = 0;
-
-       pr_debug("%s(regs = %p tsk = %p)\n", __func__, regs, tsk);
-
-       if (regs) {
-               if (user_mode(regs))
-                       return;
-               skip = 1;
-       }
-
-       if (!tsk)
-               tsk = current;
-
-       if (!try_get_task_stack(tsk))
-               return;
-
-       if (tsk == current) {
-               start_backtrace(&frame,
-                               (unsigned long)__builtin_frame_address(0),
-                               (unsigned long)dump_backtrace);
-       } else {
-               /*
-                * task blocked in __switch_to
-                */
-               start_backtrace(&frame,
-                               thread_saved_fp(tsk),
-                               thread_saved_pc(tsk));
-       }
-
-       printk("%sCall trace:\n", loglvl);
-       do {
-               /* skip until specified stack frame */
-               if (!skip) {
-                       dump_backtrace_entry(frame.pc, loglvl);
-               } else if (frame.fp == regs->regs[29]) {
-                       skip = 0;
-                       /*
-                        * Mostly, this is the case where this function is
-                        * called in panic/abort. As exception handler's
-                        * stack frame does not contain the corresponding pc
-                        * at which an exception has taken place, use regs->pc
-                        * instead.
-                        */
-                       dump_backtrace_entry(regs->pc, loglvl);
-               }
-       } while (!unwind_frame(tsk, &frame));
-
-       put_task_stack(tsk);
-}
-
-void show_stack(struct task_struct *tsk, unsigned long *sp, const char *loglvl)
-{
-       dump_backtrace(NULL, tsk, loglvl);
-       barrier();
-}
-
 #ifdef CONFIG_PREEMPT
 #define S_PREEMPT " PREEMPT"
 #elif defined(CONFIG_PREEMPT_RT)