Skip to content

Commit 9960efe

Browse files
committed
ftrace/x86: Add frames pointers to trampoline as necessary
When CONFIG_FRAME_POINTERS are enabled, it is required that the ftrace_caller and ftrace_regs_caller trampolines set up frame pointers otherwise a stack trace from a function call wont print the functions that called the trampoline. This is due to a check in __save_stack_address(): #ifdef CONFIG_FRAME_POINTER if (!reliable) return; #endif The "reliable" variable is only set if the function address is equal to contents of the address before the address the frame pointer register points to. If the frame pointer is not set up for the ftrace caller then this will fail the reliable test. It will miss the function that called the trampoline. Worse yet, if fentry is used (gcc 4.6 and beyond), it will also miss the parent, as the fentry is called before the stack frame is set up. That means the bp frame pointer points to the stack of just before the parent function was called. Link: http://lkml.kernel.org/r/20141119034829.355440340@goodmis.org Cc: Ingo Molnar <mingo@redhat.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: x86@kernel.org Cc: stable@vger.kernel.org # 3.7+ Acked-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent a9ce7c3 commit 9960efe

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

‎arch/x86/kernel/mcount_64.S‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,51 @@ GLOBAL(\trace_label)
4747
#endif
4848
.endm
4949

50+
#ifdef CONFIG_FRAME_POINTER
51+
/*
52+
* Stack traces will stop at the ftrace trampoline if the frame pointer
53+
* is not set up properly. If fentry is used, we need to save a frame
54+
* pointer for the parent as well as the function traced, because the
55+
* fentry is called before the stack frame is set up, where as mcount
56+
* is called afterward.
57+
*/
58+
.macro create_frame parent rip
59+
#ifdef CC_USING_FENTRY
60+
pushq \parent
61+
pushq %rbp
62+
movq %rsp, %rbp
63+
#endif
64+
pushq \rip
65+
pushq %rbp
66+
movq %rsp, %rbp
67+
.endm
68+
69+
.macro restore_frame
70+
#ifdef CC_USING_FENTRY
71+
addq $16, %rsp
72+
#endif
73+
popq %rbp
74+
addq $8, %rsp
75+
.endm
76+
#else
77+
.macro create_frame parent rip
78+
.endm
79+
.macro restore_frame
80+
.endm
81+
#endif /* CONFIG_FRAME_POINTER */
82+
5083
ENTRY(ftrace_caller)
5184
ftrace_caller_setup ftrace_caller_op_ptr
5285
/* regs go into 4th parameter (but make it NULL) */
5386
movq $0, %rcx
5487

88+
create_frame %rsi, %rdi
89+
5590
GLOBAL(ftrace_call)
5691
call ftrace_stub
5792

93+
restore_frame
94+
5895
MCOUNT_RESTORE_FRAME
5996

6097
/*
@@ -105,9 +142,13 @@ ENTRY(ftrace_regs_caller)
105142
/* regs go into 4th parameter */
106143
leaq (%rsp), %rcx
107144

145+
create_frame %rsi, %rdi
146+
108147
GLOBAL(ftrace_regs_call)
109148
call ftrace_stub
110149

150+
restore_frame
151+
111152
/* Copy flags back to SS, to restore them */
112153
movq EFLAGS(%rsp), %rax
113154
movq %rax, SS(%rsp)

0 commit comments

Comments
 (0)