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