Skip to content

Commit d938ba1

Browse files
Donglin Pengrostedt
authored andcommitted
x86/ftrace: Enable HAVE_FUNCTION_GRAPH_RETVAL
The previous patch ("function_graph: Support recording and printing the return value of function") has laid the groundwork for the for the funcgraph-retval, and this modification makes it available on the x86 platform. We introduce a new structure called fgraph_ret_regs for the x86 platform to hold return registers and the frame pointer. We then fill its content in the return_to_handler and pass its address to the function ftrace_return_to_handler to record the return value. Link: https://lkml.kernel.org/r/53a506f0f18ff4b7aeb0feb762f1c9a5e9b83ee9.1680954589.git.pengdonglin@sangfor.com.cn Signed-off-by: Donglin Peng <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 3646970 commit d938ba1

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

arch/x86/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ config X86
216216
select HAVE_FAST_GUP
217217
select HAVE_FENTRY if X86_64 || DYNAMIC_FTRACE
218218
select HAVE_FTRACE_MCOUNT_RECORD
219+
select HAVE_FUNCTION_GRAPH_RETVAL if HAVE_FUNCTION_GRAPH_TRACER
219220
select HAVE_FUNCTION_GRAPH_TRACER if X86_32 || (X86_64 && DYNAMIC_FTRACE)
220221
select HAVE_FUNCTION_TRACER
221222
select HAVE_GCC_PLUGINS

arch/x86/include/asm/ftrace.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,24 @@ static inline bool arch_trace_is_compat_syscall(struct pt_regs *regs)
147147
#endif /* !COMPILE_OFFSETS */
148148
#endif /* !__ASSEMBLY__ */
149149

150+
#ifndef __ASSEMBLY__
151+
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
152+
struct fgraph_ret_regs {
153+
unsigned long ax;
154+
unsigned long dx;
155+
unsigned long bp;
156+
};
157+
158+
static inline unsigned long fgraph_ret_regs_return_value(struct fgraph_ret_regs *ret_regs)
159+
{
160+
return ret_regs->ax;
161+
}
162+
163+
static inline unsigned long fgraph_ret_regs_frame_pointer(struct fgraph_ret_regs *ret_regs)
164+
{
165+
return ret_regs->bp;
166+
}
167+
#endif /* ifdef CONFIG_FUNCTION_GRAPH_TRACER */
168+
#endif
169+
150170
#endif /* _ASM_X86_FTRACE_H */

arch/x86/kernel/ftrace_32.S

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,14 @@ SYM_CODE_END(ftrace_graph_caller)
187187

188188
.globl return_to_handler
189189
return_to_handler:
190-
pushl %eax
190+
pushl $0
191191
pushl %edx
192-
movl $0, %eax
192+
pushl %eax
193+
movl %esp, %eax
193194
call ftrace_return_to_handler
194195
movl %eax, %ecx
195-
popl %edx
196196
popl %eax
197+
popl %edx
198+
addl $4, %esp # skip ebp
197199
JMP_NOSPEC ecx
198200
#endif

arch/x86/kernel/ftrace_64.S

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,20 +348,21 @@ STACK_FRAME_NON_STANDARD_FP(__fentry__)
348348
SYM_CODE_START(return_to_handler)
349349
UNWIND_HINT_UNDEFINED
350350
ANNOTATE_NOENDBR
351-
subq $16, %rsp
351+
subq $24, %rsp
352352

353353
/* Save the return values */
354354
movq %rax, (%rsp)
355355
movq %rdx, 8(%rsp)
356-
movq %rbp, %rdi
356+
movq %rbp, 16(%rsp)
357+
movq %rsp, %rdi
357358

358359
call ftrace_return_to_handler
359360

360361
movq %rax, %rdi
361362
movq 8(%rsp), %rdx
362363
movq (%rsp), %rax
363364

364-
addq $16, %rsp
365+
addq $24, %rsp
365366
/*
366367
* Jump back to the old return address. This cannot be JMP_NOSPEC rdi
367368
* since IBT would demand that contain ENDBR, which simply isn't so for

0 commit comments

Comments
 (0)