Skip to content

Commit f3dcbe6

Browse files
Dave Martinwilldeacon
authored andcommitted
arm64: stacktrace: Factor out backtrace initialisation
Some common code is required by each stacktrace user to initialise struct stackframe before the first call to unwind_frame(). In preparation for adding to the common code, this patch factors it out into a separate function start_backtrace(), and modifies the stacktrace callers appropriately. No functional change. Signed-off-by: Dave Martin <dave.martin@arm.com> [Mark: drop tsk argument, update more callsites] Signed-off-by: Mark Rutland <mark.rutland@arm.com> Reviewed-by: James Morse <james.morse@arm.com> Acked-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Will Deacon <will@kernel.org>
1 parent 8caa6e2 commit f3dcbe6

7 files changed

Lines changed: 30 additions & 42 deletions

File tree

‎arch/arm64/include/asm/stacktrace.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,14 @@ static inline bool on_accessible_stack(const struct task_struct *tsk,
131131
return false;
132132
}
133133

134+
static inline void start_backtrace(struct stackframe *frame,
135+
unsigned long fp, unsigned long pc)
136+
{
137+
frame->fp = fp;
138+
frame->pc = pc;
139+
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
140+
frame->graph = 0;
141+
#endif
142+
}
143+
134144
#endif /* __ASM_STACKTRACE_H */

‎arch/arm64/kernel/perf_callchain.c‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,7 @@ void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry,
154154
return;
155155
}
156156

157-
frame.fp = regs->regs[29];
158-
frame.pc = regs->pc;
159-
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
160-
frame.graph = 0;
161-
#endif
162-
157+
start_backtrace(&frame, regs->regs[29], regs->pc);
163158
walk_stackframe(current, &frame, callchain_trace, entry);
164159
}
165160

‎arch/arm64/kernel/process.c‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -498,11 +498,8 @@ unsigned long get_wchan(struct task_struct *p)
498498
if (!stack_page)
499499
return 0;
500500

501-
frame.fp = thread_saved_fp(p);
502-
frame.pc = thread_saved_pc(p);
503-
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
504-
frame.graph = 0;
505-
#endif
501+
start_backtrace(&frame, thread_saved_fp(p), thread_saved_pc(p));
502+
506503
do {
507504
if (unwind_frame(p, &frame))
508505
goto out;

‎arch/arm64/kernel/return_address.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,9 @@ void *return_address(unsigned int level)
3838
data.level = level + 2;
3939
data.addr = NULL;
4040

41-
frame.fp = (unsigned long)__builtin_frame_address(0);
42-
frame.pc = (unsigned long)return_address; /* dummy */
43-
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
44-
frame.graph = 0;
45-
#endif
46-
41+
start_backtrace(&frame,
42+
(unsigned long)__builtin_frame_address(0),
43+
(unsigned long)return_address);
4744
walk_stackframe(current, &frame, save_return_addr, &data);
4845

4946
if (!data.level)

‎arch/arm64/kernel/stacktrace.c‎

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,7 @@ void save_stack_trace_regs(struct pt_regs *regs, struct stack_trace *trace)
122122
data.skip = trace->skip;
123123
data.no_sched_functions = 0;
124124

125-
frame.fp = regs->regs[29];
126-
frame.pc = regs->pc;
127-
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
128-
frame.graph = 0;
129-
#endif
130-
125+
start_backtrace(&frame, regs->regs[29], regs->pc);
131126
walk_stackframe(current, &frame, save_trace, &data);
132127
}
133128
EXPORT_SYMBOL_GPL(save_stack_trace_regs);
@@ -146,17 +141,15 @@ static noinline void __save_stack_trace(struct task_struct *tsk,
146141
data.no_sched_functions = nosched;
147142

148143
if (tsk != current) {
149-
frame.fp = thread_saved_fp(tsk);
150-
frame.pc = thread_saved_pc(tsk);
144+
start_backtrace(&frame, thread_saved_fp(tsk),
145+
thread_saved_pc(tsk));
151146
} else {
152147
/* We don't want this function nor the caller */
153148
data.skip += 2;
154-
frame.fp = (unsigned long)__builtin_frame_address(0);
155-
frame.pc = (unsigned long)__save_stack_trace;
149+
start_backtrace(&frame,
150+
(unsigned long)__builtin_frame_address(0),
151+
(unsigned long)__save_stack_trace);
156152
}
157-
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
158-
frame.graph = 0;
159-
#endif
160153

161154
walk_stackframe(tsk, &frame, save_trace, &data);
162155

‎arch/arm64/kernel/time.c‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,8 @@ unsigned long profile_pc(struct pt_regs *regs)
3838
if (!in_lock_functions(regs->pc))
3939
return regs->pc;
4040

41-
frame.fp = regs->regs[29];
42-
frame.pc = regs->pc;
43-
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
44-
frame.graph = 0;
45-
#endif
41+
start_backtrace(&frame, regs->regs[29], regs->pc);
42+
4643
do {
4744
int ret = unwind_frame(NULL, &frame);
4845
if (ret < 0)

‎arch/arm64/kernel/traps.c‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,17 @@ void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk)
100100
return;
101101

102102
if (tsk == current) {
103-
frame.fp = (unsigned long)__builtin_frame_address(0);
104-
frame.pc = (unsigned long)dump_backtrace;
103+
start_backtrace(&frame,
104+
(unsigned long)__builtin_frame_address(0),
105+
(unsigned long)dump_backtrace);
105106
} else {
106107
/*
107108
* task blocked in __switch_to
108109
*/
109-
frame.fp = thread_saved_fp(tsk);
110-
frame.pc = thread_saved_pc(tsk);
110+
start_backtrace(&frame,
111+
thread_saved_fp(tsk),
112+
thread_saved_pc(tsk));
111113
}
112-
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
113-
frame.graph = 0;
114-
#endif
115114

116115
printk("Call trace:\n");
117116
do {

0 commit comments

Comments
 (0)