arm64: stacktrace: avoid listing stacktrace functions in stacktrace

The stacktraces always begin as follows:

[<c00117b4>] save_stack_trace_tsk+0x0/0x98
[<c0011870>] save_stack_trace+0x24/0x28
...

This is because the stack trace code includes the stack frames for
itself. This is incorrect behaviour, and also leads to "skip" doing the
wrong thing (which is the number of stack frames to avoid recording.)

Perversely, it does the right thing when passed a non-current thread.
Fix this by ensuring that we have a known constant number of frames
above the main stack trace function, and always skip these.

This was fixed for arch arm by commit 3683f44c42e9 ("ARM: stacktrace:
avoid listing stacktrace functions in stacktrace")

Link: http://lkml.kernel.org/r/1504078343-28754-1-git-send-email-guptap@codeaurora.org
Signed-off-by: Prakash Gupta <guptap@codeaurora.org>
Cc: Russell King <rmk+kernel@arm.linux.org.uk>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Prakash Gupta and committed by
Linus Torvalds
bb53c820 0ee931c4

+13 -5
+13 -5
arch/arm64/kernel/stacktrace.c
··· 140 trace->entries[trace->nr_entries++] = ULONG_MAX; 141 } 142 143 - void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace) 144 { 145 struct stack_trace_data data; 146 struct stackframe frame; ··· 151 152 data.trace = trace; 153 data.skip = trace->skip; 154 155 if (tsk != current) { 156 - data.no_sched_functions = 1; 157 frame.fp = thread_saved_fp(tsk); 158 frame.pc = thread_saved_pc(tsk); 159 } else { 160 - data.no_sched_functions = 0; 161 frame.fp = (unsigned long)__builtin_frame_address(0); 162 - frame.pc = (unsigned long)save_stack_trace_tsk; 163 } 164 #ifdef CONFIG_FUNCTION_GRAPH_TRACER 165 frame.graph = tsk->curr_ret_stack; ··· 174 } 175 EXPORT_SYMBOL_GPL(save_stack_trace_tsk); 176 177 void save_stack_trace(struct stack_trace *trace) 178 { 179 - save_stack_trace_tsk(current, trace); 180 } 181 EXPORT_SYMBOL_GPL(save_stack_trace); 182 #endif
··· 140 trace->entries[trace->nr_entries++] = ULONG_MAX; 141 } 142 143 + static noinline void __save_stack_trace(struct task_struct *tsk, 144 + struct stack_trace *trace, unsigned int nosched) 145 { 146 struct stack_trace_data data; 147 struct stackframe frame; ··· 150 151 data.trace = trace; 152 data.skip = trace->skip; 153 + data.no_sched_functions = nosched; 154 155 if (tsk != current) { 156 frame.fp = thread_saved_fp(tsk); 157 frame.pc = thread_saved_pc(tsk); 158 } else { 159 + /* We don't want this function nor the caller */ 160 + data.skip += 2; 161 frame.fp = (unsigned long)__builtin_frame_address(0); 162 + frame.pc = (unsigned long)__save_stack_trace; 163 } 164 #ifdef CONFIG_FUNCTION_GRAPH_TRACER 165 frame.graph = tsk->curr_ret_stack; ··· 172 } 173 EXPORT_SYMBOL_GPL(save_stack_trace_tsk); 174 175 + void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace) 176 + { 177 + __save_stack_trace(tsk, trace, 1); 178 + } 179 + 180 void save_stack_trace(struct stack_trace *trace) 181 { 182 + __save_stack_trace(current, trace, 0); 183 } 184 + 185 EXPORT_SYMBOL_GPL(save_stack_trace); 186 #endif