| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2008 ARM Limited |
|---|
| 3 | 4 | * Copyright (C) 2014 Regents of the University of California |
|---|
| 4 | | - * |
|---|
| 5 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 6 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 7 | | - * published by the Free Software Foundation. |
|---|
| 8 | | - * |
|---|
| 9 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 10 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 12 | | - * GNU General Public License for more details. |
|---|
| 13 | 5 | */ |
|---|
| 14 | 6 | |
|---|
| 15 | 7 | #include <linux/export.h> |
|---|
| .. | .. |
|---|
| 20 | 12 | #include <linux/stacktrace.h> |
|---|
| 21 | 13 | #include <linux/ftrace.h> |
|---|
| 22 | 14 | |
|---|
| 15 | +register unsigned long sp_in_global __asm__("sp"); |
|---|
| 16 | + |
|---|
| 23 | 17 | #ifdef CONFIG_FRAME_POINTER |
|---|
| 24 | 18 | |
|---|
| 25 | 19 | struct stackframe { |
|---|
| .. | .. |
|---|
| 27 | 21 | unsigned long ra; |
|---|
| 28 | 22 | }; |
|---|
| 29 | 23 | |
|---|
| 30 | | -static void notrace walk_stackframe(struct task_struct *task, |
|---|
| 31 | | - struct pt_regs *regs, bool (*fn)(unsigned long, void *), void *arg) |
|---|
| 24 | +void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs, |
|---|
| 25 | + bool (*fn)(unsigned long, void *), void *arg) |
|---|
| 32 | 26 | { |
|---|
| 33 | 27 | unsigned long fp, sp, pc; |
|---|
| 34 | 28 | |
|---|
| 35 | 29 | if (regs) { |
|---|
| 36 | | - fp = GET_FP(regs); |
|---|
| 37 | | - sp = GET_USP(regs); |
|---|
| 38 | | - pc = GET_IP(regs); |
|---|
| 30 | + fp = frame_pointer(regs); |
|---|
| 31 | + sp = user_stack_pointer(regs); |
|---|
| 32 | + pc = instruction_pointer(regs); |
|---|
| 39 | 33 | } else if (task == NULL || task == current) { |
|---|
| 40 | | - const register unsigned long current_sp __asm__ ("sp"); |
|---|
| 34 | + const register unsigned long current_sp = sp_in_global; |
|---|
| 41 | 35 | fp = (unsigned long)__builtin_frame_address(0); |
|---|
| 42 | 36 | sp = current_sp; |
|---|
| 43 | 37 | pc = (unsigned long)walk_stackframe; |
|---|
| .. | .. |
|---|
| 64 | 58 | frame = (struct stackframe *)fp - 1; |
|---|
| 65 | 59 | sp = fp; |
|---|
| 66 | 60 | fp = frame->fp; |
|---|
| 67 | | -#ifdef HAVE_FUNCTION_GRAPH_RET_ADDR_PTR |
|---|
| 68 | 61 | pc = ftrace_graph_ret_addr(current, NULL, frame->ra, |
|---|
| 69 | 62 | (unsigned long *)(fp - 8)); |
|---|
| 70 | | -#else |
|---|
| 71 | | - pc = frame->ra - 0x4; |
|---|
| 72 | | -#endif |
|---|
| 73 | 63 | } |
|---|
| 74 | 64 | } |
|---|
| 75 | 65 | |
|---|
| .. | .. |
|---|
| 82 | 72 | unsigned long *ksp; |
|---|
| 83 | 73 | |
|---|
| 84 | 74 | if (regs) { |
|---|
| 85 | | - sp = GET_USP(regs); |
|---|
| 86 | | - pc = GET_IP(regs); |
|---|
| 75 | + sp = user_stack_pointer(regs); |
|---|
| 76 | + pc = instruction_pointer(regs); |
|---|
| 87 | 77 | } else if (task == NULL || task == current) { |
|---|
| 88 | | - const register unsigned long current_sp __asm__ ("sp"); |
|---|
| 89 | | - sp = current_sp; |
|---|
| 78 | + sp = sp_in_global; |
|---|
| 90 | 79 | pc = (unsigned long)walk_stackframe; |
|---|
| 91 | 80 | } else { |
|---|
| 92 | 81 | /* task blocked in __switch_to */ |
|---|
| .. | .. |
|---|
| 110 | 99 | |
|---|
| 111 | 100 | static bool print_trace_address(unsigned long pc, void *arg) |
|---|
| 112 | 101 | { |
|---|
| 113 | | - print_ip_sym(pc); |
|---|
| 102 | + const char *loglvl = arg; |
|---|
| 103 | + |
|---|
| 104 | + print_ip_sym(loglvl, pc); |
|---|
| 114 | 105 | return false; |
|---|
| 115 | 106 | } |
|---|
| 116 | 107 | |
|---|
| 117 | | -void show_stack(struct task_struct *task, unsigned long *sp) |
|---|
| 108 | +void show_stack(struct task_struct *task, unsigned long *sp, const char *loglvl) |
|---|
| 118 | 109 | { |
|---|
| 119 | 110 | pr_cont("Call Trace:\n"); |
|---|
| 120 | | - walk_stackframe(task, NULL, print_trace_address, NULL); |
|---|
| 111 | + walk_stackframe(task, NULL, print_trace_address, (void *)loglvl); |
|---|
| 121 | 112 | } |
|---|
| 122 | | - |
|---|
| 123 | 113 | |
|---|
| 124 | 114 | static bool save_wchan(unsigned long pc, void *arg) |
|---|
| 125 | 115 | { |
|---|
| .. | .. |
|---|
| 169 | 159 | void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace) |
|---|
| 170 | 160 | { |
|---|
| 171 | 161 | walk_stackframe(tsk, NULL, save_trace, trace); |
|---|
| 172 | | - if (trace->nr_entries < trace->max_entries) |
|---|
| 173 | | - trace->entries[trace->nr_entries++] = ULONG_MAX; |
|---|
| 174 | 162 | } |
|---|
| 175 | 163 | EXPORT_SYMBOL_GPL(save_stack_trace_tsk); |
|---|
| 176 | 164 | |
|---|