[PATCH v3 2/3] x86/ftrace: cleanup graph tracer

Chengming Zhou zhouchengming at bytedance.com
Thu Feb 24 01:32:50 PST 2022


Put CONFIG_DYNAMIC_FTRACE related code after prepare_ftrace_return(),
in which we define ftrace_graph_func() for graph_ops in
DYNAMIC_FTRACE_WITH_ARGS case, then define ftrace_graph_caller
enable and disable functions in the #else case to override.

Since ftrace_graph_caller enable and disable functions have weak
versions in Ftrace core code, we don't need to override them in the
DYNAMIC_FTRACE_WITH_ARGS case. This patch is just a cleanup,
doesn't have functional changes actually.

Signed-off-by: Chengming Zhou <zhouchengming at bytedance.com>
---
 arch/x86/kernel/ftrace.c | 78 +++++++++++++++++-----------------------
 1 file changed, 32 insertions(+), 46 deletions(-)

diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
index 7cc540e6de0c..e49c9d3e986b 100644
--- a/arch/x86/kernel/ftrace.c
+++ b/arch/x86/kernel/ftrace.c
@@ -583,51 +583,6 @@ void arch_ftrace_trampoline_free(struct ftrace_ops *ops)
 #endif /* CONFIG_DYNAMIC_FTRACE */
 
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
-
-#ifdef CONFIG_DYNAMIC_FTRACE
-
-#ifndef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS
-extern void ftrace_graph_call(void);
-static const char *ftrace_jmp_replace(unsigned long ip, unsigned long addr)
-{
-	return text_gen_insn(JMP32_INSN_OPCODE, (void *)ip, (void *)addr);
-}
-
-static int ftrace_mod_jmp(unsigned long ip, void *func)
-{
-	const char *new;
-
-	new = ftrace_jmp_replace(ip, (unsigned long)func);
-	text_poke_bp((void *)ip, new, MCOUNT_INSN_SIZE, NULL);
-	return 0;
-}
-
-int ftrace_enable_ftrace_graph_caller(void)
-{
-	unsigned long ip = (unsigned long)(&ftrace_graph_call);
-
-	return ftrace_mod_jmp(ip, &ftrace_graph_caller);
-}
-
-int ftrace_disable_ftrace_graph_caller(void)
-{
-	unsigned long ip = (unsigned long)(&ftrace_graph_call);
-
-	return ftrace_mod_jmp(ip, &ftrace_stub);
-}
-#else /* !CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS */
-int ftrace_enable_ftrace_graph_caller(void)
-{
-	return 0;
-}
-
-int ftrace_disable_ftrace_graph_caller(void)
-{
-	return 0;
-}
-#endif /* CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS */
-#endif /* !CONFIG_DYNAMIC_FTRACE */
-
 /*
  * Hook the return address and push it in the stack of return addrs
  * in current thread info.
@@ -666,6 +621,8 @@ void prepare_ftrace_return(unsigned long ip, unsigned long *parent,
 	ftrace_test_recursion_unlock(bit);
 }
 
+#ifdef CONFIG_DYNAMIC_FTRACE
+
 #ifdef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS
 void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
 		       struct ftrace_ops *op, struct ftrace_regs *fregs)
@@ -675,6 +632,35 @@ void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
 
 	prepare_ftrace_return(ip, (unsigned long *)stack, 0);
 }
-#endif
+#else
+extern void ftrace_graph_call(void);
+static const char *ftrace_jmp_replace(unsigned long ip, unsigned long addr)
+{
+	return text_gen_insn(JMP32_INSN_OPCODE, (void *)ip, (void *)addr);
+}
 
+static int ftrace_mod_jmp(unsigned long ip, void *func)
+{
+	const char *new;
+
+	new = ftrace_jmp_replace(ip, (unsigned long)func);
+	text_poke_bp((void *)ip, new, MCOUNT_INSN_SIZE, NULL);
+	return 0;
+}
+
+int ftrace_enable_ftrace_graph_caller(void)
+{
+	unsigned long ip = (unsigned long)(&ftrace_graph_call);
+
+	return ftrace_mod_jmp(ip, &ftrace_graph_caller);
+}
+
+int ftrace_disable_ftrace_graph_caller(void)
+{
+	unsigned long ip = (unsigned long)(&ftrace_graph_call);
+
+	return ftrace_mod_jmp(ip, &ftrace_stub);
+}
+#endif /* CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS */
+#endif /* CONFIG_DYNAMIC_FTRACE */
 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
-- 
2.20.1




More information about the linux-arm-kernel mailing list