lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220224093251.49971-2-zhouchengming@bytedance.com>
Date:   Thu, 24 Feb 2022 17:32:50 +0800
From:   Chengming Zhou <zhouchengming@...edance.com>
To:     rostedt@...dmis.org, mark.rutland@....com, mingo@...hat.com,
        tglx@...utronix.de, catalin.marinas@....com, will@...nel.org,
        dave.hansen@...ux.intel.com, broonie@...nel.org
Cc:     x86@...nel.org, linux-arm-kernel@...ts.infradead.org,
        linux-kernel@...r.kernel.org, songmuchun@...edance.com,
        qirui.001@...edance.com,
        Chengming Zhou <zhouchengming@...edance.com>
Subject: [PATCH v3 2/3] x86/ftrace: cleanup graph tracer

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@...edance.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ