Skip to content

Commit c4a0ebf

Browse files
Chengming Zhouctmarinas
authored andcommitted
arm64/ftrace: Make function graph use ftrace directly
As we do in commit 0c0593b ("x86/ftrace: Make function graph use ftrace directly"), we don't need special hook for graph tracer, but instead we use graph_ops:func function to install return_hooker. Since commit 3b23e49 ("arm64: implement ftrace with regs") add implementation for FTRACE_WITH_REGS on arm64, we can easily adopt the same cleanup on arm64. And this cleanup only changes the FTRACE_WITH_REGS implementation, so the mcount-based implementation is unaffected. While in theory it would be possible to make a similar cleanup for !FTRACE_WITH_REGS, this will require rework of the core code, and so for now we only change the FTRACE_WITH_REGS implementation. Tested-by: Mark Rutland <[email protected]> Reviewed-by: Mark Rutland <[email protected]> Signed-off-by: Chengming Zhou <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent e999995 commit c4a0ebf

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

arch/arm64/include/asm/ftrace.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,15 @@ static inline unsigned long ftrace_call_adjust(unsigned long addr)
8080

8181
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
8282
struct dyn_ftrace;
83+
struct ftrace_ops;
84+
struct ftrace_regs;
85+
8386
int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec);
8487
#define ftrace_init_nop ftrace_init_nop
88+
89+
void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
90+
struct ftrace_ops *op, struct ftrace_regs *fregs);
91+
#define ftrace_graph_func ftrace_graph_func
8592
#endif
8693

8794
#define ftrace_return_address(n) return_address(n)

arch/arm64/kernel/entry-ftrace.S

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,6 @@ SYM_CODE_START(ftrace_common)
9797
SYM_INNER_LABEL(ftrace_call, SYM_L_GLOBAL)
9898
bl ftrace_stub
9999

100-
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
101-
SYM_INNER_LABEL(ftrace_graph_call, SYM_L_GLOBAL) // ftrace_graph_caller();
102-
nop // If enabled, this will be replaced
103-
// "b ftrace_graph_caller"
104-
#endif
105-
106100
/*
107101
* At the callsite x0-x8 and x19-x30 were live. Any C code will have preserved
108102
* x19-x29 per the AAPCS, and we created frame records upon entry, so we need
@@ -127,17 +121,6 @@ ftrace_common_return:
127121
ret x9
128122
SYM_CODE_END(ftrace_common)
129123

130-
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
131-
SYM_CODE_START(ftrace_graph_caller)
132-
ldr x0, [sp, #S_PC]
133-
sub x0, x0, #AARCH64_INSN_SIZE // ip (callsite's BL insn)
134-
add x1, sp, #S_LR // parent_ip (callsite's LR)
135-
ldr x2, [sp, #PT_REGS_SIZE] // parent fp (callsite's FP)
136-
bl prepare_ftrace_return
137-
b ftrace_common_return
138-
SYM_CODE_END(ftrace_graph_caller)
139-
#endif
140-
141124
#else /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */
142125

143126
/*

arch/arm64/kernel/ftrace.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,22 @@ void prepare_ftrace_return(unsigned long self_addr, unsigned long *parent,
268268
}
269269

270270
#ifdef CONFIG_DYNAMIC_FTRACE
271+
272+
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
273+
void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
274+
struct ftrace_ops *op, struct ftrace_regs *fregs)
275+
{
276+
/*
277+
* When DYNAMIC_FTRACE_WITH_REGS is selected, `fregs` can never be NULL
278+
* and arch_ftrace_get_regs(fregs) will always give a non-NULL pt_regs
279+
* in which we can safely modify the LR.
280+
*/
281+
struct pt_regs *regs = arch_ftrace_get_regs(fregs);
282+
unsigned long *parent = (unsigned long *)&procedure_link_pointer(regs);
283+
284+
prepare_ftrace_return(ip, parent, frame_pointer(regs));
285+
}
286+
#else
271287
/*
272288
* Turn on/off the call to ftrace_graph_caller() in ftrace_caller()
273289
* depending on @enable.
@@ -297,5 +313,6 @@ int ftrace_disable_ftrace_graph_caller(void)
297313
{
298314
return ftrace_modify_graph_caller(false);
299315
}
316+
#endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */
300317
#endif /* CONFIG_DYNAMIC_FTRACE */
301318
#endif /* CONFIG_FUNCTION_GRAPH_TRACER */

0 commit comments

Comments
 (0)