Skip to content

Commit 77072f0

Browse files
tehcasterIngo Molnar
authored andcommitted
x86/stacktrace: Avoid recording save_stack_trace() wrappers
The save_stack_trace() and save_stack_trace_tsk() wrappers of __save_stack_trace() add themselves to the call stack, and thus appear in the recorded stacktraces. This is redundant and wasteful when we have limited space to record the useful part of the backtrace with e.g. page_owner functionality. Fix this by making sure __save_stack_trace() is noinline (which matches the current gcc decision) and bumping the skip in the wrappers (save_stack_trace_tsk() only when called for the current task). This is similar to what was done for arm in 3683f44 ("ARM: stacktrace: avoid listing stacktrace functions in stacktrace") and is pending for arm64. Also make sure that __save_stack_trace_reliable() doesn't get this problem in the future by marking it __always_inline (which matches current gcc decision), per Josh Poimboeuf. Signed-off-by: Vlastimil Babka <vbabka@suse.cz> Acked-by: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Miroslav Benes <mbenes@suse.cz> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/20170929092335.2744-1-vbabka@suse.cz Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 770b782 commit 77072f0

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

arch/x86/kernel/stacktrace.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static int save_stack_address(struct stack_trace *trace, unsigned long addr,
3030
return 0;
3131
}
3232

33-
static void __save_stack_trace(struct stack_trace *trace,
33+
static void noinline __save_stack_trace(struct stack_trace *trace,
3434
struct task_struct *task, struct pt_regs *regs,
3535
bool nosched)
3636
{
@@ -56,6 +56,7 @@ static void __save_stack_trace(struct stack_trace *trace,
5656
*/
5757
void save_stack_trace(struct stack_trace *trace)
5858
{
59+
trace->skip++;
5960
__save_stack_trace(trace, current, NULL, false);
6061
}
6162
EXPORT_SYMBOL_GPL(save_stack_trace);
@@ -70,6 +71,8 @@ void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
7071
if (!try_get_task_stack(tsk))
7172
return;
7273

74+
if (tsk == current)
75+
trace->skip++;
7376
__save_stack_trace(trace, tsk, NULL, true);
7477

7578
put_task_stack(tsk);
@@ -88,8 +91,9 @@ EXPORT_SYMBOL_GPL(save_stack_trace_tsk);
8891
} \
8992
})
9093

91-
static int __save_stack_trace_reliable(struct stack_trace *trace,
92-
struct task_struct *task)
94+
static int __always_inline
95+
__save_stack_trace_reliable(struct stack_trace *trace,
96+
struct task_struct *task)
9397
{
9498
struct unwind_state state;
9599
struct pt_regs *regs;

0 commit comments

Comments
 (0)