[PATCH 1/4] powerpc: ftrace: Use PPC_NOP_INSTR #define for NOP

Subsystems: function hooks (ftrace), linux for powerpc (32-bit and 64-bit), the rest

STALE6589d

4 messages, 1 author, 2008-07-17 · open the first message on its own page

[PATCH 1/4] powerpc: ftrace: Use PPC_NOP_INSTR #define for NOP

From: Michael Ellerman <hidden>
Date: 2008-07-17 07:21:30

And move ftrace_nop into the only function it's used in.

Signed-off-by: Michael Ellerman <redacted>
---
 arch/powerpc/kernel/ftrace.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/arch/powerpc/kernel/ftrace.c b/arch/powerpc/kernel/ftrace.c
index 3855ceb..78f4423 100644
--- a/arch/powerpc/kernel/ftrace.c
+++ b/arch/powerpc/kernel/ftrace.c
@@ -15,11 +15,10 @@
 #include <linux/list.h>
 
 #include <asm/cacheflush.h>
+#include <asm/code-patching.h>
 #include <asm/ftrace.h>
 
 
-static unsigned int ftrace_nop = 0x60000000;
-
 #ifdef CONFIG_PPC32
 # define GET_ADDR(addr) addr
 #else
@@ -35,6 +34,8 @@ static unsigned int notrace ftrace_calc_offset(long ip, long addr)
 
 notrace unsigned char *ftrace_nop_replace(void)
 {
+	static unsigned int ftrace_nop = PPC_NOP_INSTR;
+
 	return (char *)&ftrace_nop;
 }
 
-- 
1.5.5

[PATCH 2/4] powerpc: ftrace: Use ppc_function_entry() rather than hand-rolled macro

From: Michael Ellerman <hidden>
Date: 2008-07-17 07:21:31

Signed-off-by: Michael Ellerman <redacted>
---
 arch/powerpc/kernel/ftrace.c |   10 +---------
 1 files changed, 1 insertions(+), 9 deletions(-)
diff --git a/arch/powerpc/kernel/ftrace.c b/arch/powerpc/kernel/ftrace.c
index 78f4423..1d6f174 100644
--- a/arch/powerpc/kernel/ftrace.c
+++ b/arch/powerpc/kernel/ftrace.c
@@ -19,14 +19,6 @@
 #include <asm/ftrace.h>
 
 
-#ifdef CONFIG_PPC32
-# define GET_ADDR(addr) addr
-#else
-/* PowerPC64's functions are data that points to the functions */
-# define GET_ADDR(addr) *(unsigned long *)addr
-#endif
-
-
 static unsigned int notrace ftrace_calc_offset(long ip, long addr)
 {
 	return (int)(addr - ip);
@@ -49,7 +41,7 @@ notrace unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr)
 	 * instruction that is going to be modified, without modifying the
 	 * code.
 	 */
-	addr = GET_ADDR(addr);
+	addr = ppc_function_entry((void *)addr);
 
 	/* Set to "bl addr" */
 	op = 0x48000001 | (ftrace_calc_offset(ip, addr) & 0x03fffffc);
-- 
1.5.5

[PATCH 3/4] powerpc: ftrace: Use create_branch() and cope with errors

From: Michael Ellerman <hidden>
Date: 2008-07-17 07:21:32

Use create_branch() rather than doing it by hand. It's possible that
we are unable to create a branch to the address, if it's too far away,
in which case just return a nop. This will break the tracing, but
shouldn't crash the kernel at least.

Signed-off-by: Michael Ellerman <redacted>
---
 arch/powerpc/kernel/ftrace.c |   20 ++++++++------------
 1 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/arch/powerpc/kernel/ftrace.c b/arch/powerpc/kernel/ftrace.c
index 1d6f174..49a2049 100644
--- a/arch/powerpc/kernel/ftrace.c
+++ b/arch/powerpc/kernel/ftrace.c
@@ -19,11 +19,6 @@
 #include <asm/ftrace.h>
 
 
-static unsigned int notrace ftrace_calc_offset(long ip, long addr)
-{
-	return (int)(addr - ip);
-}
-
 notrace unsigned char *ftrace_nop_replace(void)
 {
 	static unsigned int ftrace_nop = PPC_NOP_INSTR;
@@ -35,16 +30,17 @@ notrace unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr)
 {
 	static unsigned int op;
 
-	/*
-	 * It would be nice to just use create_function_call, but that will
-	 * update the code itself. Here we need to just return the
-	 * instruction that is going to be modified, without modifying the
-	 * code.
-	 */
 	addr = ppc_function_entry((void *)addr);
 
 	/* Set to "bl addr" */
-	op = 0x48000001 | (ftrace_calc_offset(ip, addr) & 0x03fffffc);
+	op = create_branch((unsigned int *)ip, addr, BRANCH_SET_LINK);
+
+	/*
+	 * This routine is not allowed to fail, but create_branch() can.
+	 * In that case, just return nop and cross our fingers.
+	 */
+	if (!op)
+		return ftrace_nop_replace();
 
 	/*
 	 * No locking needed, this must be called via kstop_machine
-- 
1.5.5

[PATCH 4/4] powerpc: ftrace: Use PPC_LONG and PPC_LONG_ALIGN asm macros

From: Michael Ellerman <hidden>
Date: 2008-07-17 07:21:33

Signed-off-by: Michael Ellerman <redacted>
---
 arch/powerpc/kernel/ftrace.c |   13 +++----------
 1 files changed, 3 insertions(+), 10 deletions(-)
diff --git a/arch/powerpc/kernel/ftrace.c b/arch/powerpc/kernel/ftrace.c
index 49a2049..0e9fc10 100644
--- a/arch/powerpc/kernel/ftrace.c
+++ b/arch/powerpc/kernel/ftrace.c
@@ -14,6 +14,7 @@
 #include <linux/init.h>
 #include <linux/list.h>
 
+#include <asm/asm-compat.h>
 #include <asm/cacheflush.h>
 #include <asm/code-patching.h>
 #include <asm/ftrace.h>
@@ -49,14 +50,6 @@ notrace unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr)
 	return (unsigned char *)&op;
 }
 
-#ifdef CONFIG_PPC64
-# define _ASM_ALIGN	" .align 3 "
-# define _ASM_PTR	" .llong "
-#else
-# define _ASM_ALIGN	" .align 2 "
-# define _ASM_PTR	" .long "
-#endif
-
 notrace int
 ftrace_modify_code(unsigned long ip, unsigned char *old_code,
 		   unsigned char *new_code)
@@ -85,8 +78,8 @@ ftrace_modify_code(unsigned long ip, unsigned char *old_code,
 		"	b 2b\n"
 		".previous\n"
 		".section __ex_table,\"a\"\n"
-		_ASM_ALIGN "\n"
-		_ASM_PTR "1b, 3b\n"
+		PPC_LONG_ALIGN "\n"
+		PPC_LONG "1b, 3b\n"
 		".previous"
 		: "=r"(faulted), "=r"(replaced)
 		: "r"(ip), "r"(new),
-- 
1.5.5
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help