.. | .. |
---|
| 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; |
---|
.. | .. |
---|
63 | 57 | /* Unwind stack frame */ |
---|
64 | 58 | frame = (struct stackframe *)fp - 1; |
---|
65 | 59 | sp = fp; |
---|
66 | | - fp = frame->fp; |
---|
67 | | -#ifdef HAVE_FUNCTION_GRAPH_RET_ADDR_PTR |
---|
68 | | - pc = ftrace_graph_ret_addr(current, NULL, frame->ra, |
---|
69 | | - (unsigned long *)(fp - 8)); |
---|
70 | | -#else |
---|
71 | | - pc = frame->ra - 0x4; |
---|
72 | | -#endif |
---|
| 60 | + if (regs && (regs->epc == pc) && (frame->fp & 0x7)) { |
---|
| 61 | + fp = frame->ra; |
---|
| 62 | + pc = regs->ra; |
---|
| 63 | + } else { |
---|
| 64 | + fp = frame->fp; |
---|
| 65 | + pc = ftrace_graph_ret_addr(current, NULL, frame->ra, |
---|
| 66 | + &frame->ra); |
---|
| 67 | + } |
---|
| 68 | + |
---|
73 | 69 | } |
---|
74 | 70 | } |
---|
75 | 71 | |
---|
.. | .. |
---|
82 | 78 | unsigned long *ksp; |
---|
83 | 79 | |
---|
84 | 80 | if (regs) { |
---|
85 | | - sp = GET_USP(regs); |
---|
86 | | - pc = GET_IP(regs); |
---|
| 81 | + sp = user_stack_pointer(regs); |
---|
| 82 | + pc = instruction_pointer(regs); |
---|
87 | 83 | } else if (task == NULL || task == current) { |
---|
88 | | - const register unsigned long current_sp __asm__ ("sp"); |
---|
89 | | - sp = current_sp; |
---|
| 84 | + sp = sp_in_global; |
---|
90 | 85 | pc = (unsigned long)walk_stackframe; |
---|
91 | 86 | } else { |
---|
92 | 87 | /* task blocked in __switch_to */ |
---|
.. | .. |
---|
101 | 96 | while (!kstack_end(ksp)) { |
---|
102 | 97 | if (__kernel_text_address(pc) && unlikely(fn(pc, arg))) |
---|
103 | 98 | break; |
---|
104 | | - pc = (*ksp++) - 0x4; |
---|
| 99 | + pc = READ_ONCE_NOCHECK(*ksp++) - 0x4; |
---|
105 | 100 | } |
---|
106 | 101 | } |
---|
107 | 102 | |
---|
.. | .. |
---|
110 | 105 | |
---|
111 | 106 | static bool print_trace_address(unsigned long pc, void *arg) |
---|
112 | 107 | { |
---|
113 | | - print_ip_sym(pc); |
---|
| 108 | + const char *loglvl = arg; |
---|
| 109 | + |
---|
| 110 | + print_ip_sym(loglvl, pc); |
---|
114 | 111 | return false; |
---|
115 | 112 | } |
---|
116 | 113 | |
---|
117 | | -void show_stack(struct task_struct *task, unsigned long *sp) |
---|
| 114 | +void show_stack(struct task_struct *task, unsigned long *sp, const char *loglvl) |
---|
118 | 115 | { |
---|
119 | 116 | pr_cont("Call Trace:\n"); |
---|
120 | | - walk_stackframe(task, NULL, print_trace_address, NULL); |
---|
| 117 | + walk_stackframe(task, NULL, print_trace_address, (void *)loglvl); |
---|
121 | 118 | } |
---|
122 | | - |
---|
123 | 119 | |
---|
124 | 120 | static bool save_wchan(unsigned long pc, void *arg) |
---|
125 | 121 | { |
---|
.. | .. |
---|
169 | 165 | void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace) |
---|
170 | 166 | { |
---|
171 | 167 | walk_stackframe(tsk, NULL, save_trace, trace); |
---|
172 | | - if (trace->nr_entries < trace->max_entries) |
---|
173 | | - trace->entries[trace->nr_entries++] = ULONG_MAX; |
---|
174 | 168 | } |
---|
175 | 169 | EXPORT_SYMBOL_GPL(save_stack_trace_tsk); |
---|
176 | 170 | |
---|