s390/stacktrace: use common arch_stack_walk infrastructure
authorVasily Gorbik <gor@linux.ibm.com>
Wed, 14 Aug 2019 12:27:44 +0000 (14:27 +0200)
committerVasily Gorbik <gor@linux.ibm.com>
Wed, 21 Aug 2019 10:58:53 +0000 (12:58 +0200)
Use common arch_stack_walk infrastructure to avoid duplicated code and
avoid taking care of the stack storage and filtering.

Common code also uses try_get_task_stack/put_task_stack when needed which
have been missing in our code, which also solves potential problem for us.

Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
arch/s390/Kconfig
arch/s390/kernel/stacktrace.c

index a4ad2733eedf652d7f215b3091341f1e1d938571..3289cc243d92888300a462bf90e46ecbc2ed021f 100644 (file)
@@ -105,6 +105,7 @@ config S390
        select ARCH_INLINE_WRITE_UNLOCK_IRQRESTORE
        select ARCH_KEEP_MEMBLOCK
        select ARCH_SAVE_PAGE_KEYS if HIBERNATION
+       select ARCH_STACKWALK
        select ARCH_SUPPORTS_ATOMIC_RMW
        select ARCH_SUPPORTS_NUMA_BALANCING
        select ARCH_USE_BUILTIN_BSWAP
index f6a620f854e168b733ee73f7f6eeda0910317f7d..f8fc4f8aef9b1585252a25532d8d19f4498c3984 100644 (file)
@@ -6,57 +6,19 @@
  *  Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>
  */
 
-#include <linux/sched.h>
-#include <linux/sched/debug.h>
 #include <linux/stacktrace.h>
-#include <linux/kallsyms.h>
-#include <linux/export.h>
 #include <asm/stacktrace.h>
 #include <asm/unwind.h>
 
-void save_stack_trace(struct stack_trace *trace)
+void arch_stack_walk(stack_trace_consume_fn consume_entry, void *cookie,
+                    struct task_struct *task, struct pt_regs *regs)
 {
        struct unwind_state state;
+       unsigned long addr;
 
-       unwind_for_each_frame(&state, current, NULL, 0) {
-               if (trace->nr_entries >= trace->max_entries)
+       unwind_for_each_frame(&state, task, regs, 0) {
+               addr = unwind_get_return_address(&state);
+               if (!addr || !consume_entry(cookie, addr, false))
                        break;
-               if (trace->skip > 0)
-                       trace->skip--;
-               else
-                       trace->entries[trace->nr_entries++] = state.ip;
        }
 }
-EXPORT_SYMBOL_GPL(save_stack_trace);
-
-void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
-{
-       struct unwind_state state;
-
-       unwind_for_each_frame(&state, tsk, NULL, 0) {
-               if (trace->nr_entries >= trace->max_entries)
-                       break;
-               if (in_sched_functions(state.ip))
-                       continue;
-               if (trace->skip > 0)
-                       trace->skip--;
-               else
-                       trace->entries[trace->nr_entries++] = state.ip;
-       }
-}
-EXPORT_SYMBOL_GPL(save_stack_trace_tsk);
-
-void save_stack_trace_regs(struct pt_regs *regs, struct stack_trace *trace)
-{
-       struct unwind_state state;
-
-       unwind_for_each_frame(&state, current, regs, 0) {
-               if (trace->nr_entries >= trace->max_entries)
-                       break;
-               if (trace->skip > 0)
-                       trace->skip--;
-               else
-                       trace->entries[trace->nr_entries++] = state.ip;
-       }
-}
-EXPORT_SYMBOL_GPL(save_stack_trace_regs);