Browse Source

ftrace/fgraph/x86: Have prepare_ftrace_return() take ip as first parameter

The function graph helper function prepare_ftrace_return() which does the work
to hijack the parent pointer has that parent pointer as its first parameter.
Instead, if we make it the second parameter and have ip as the first parameter
(self_addr), then it can use the %rdi from save_mcount_regs that loads it
already.

Link: http://lkml.kernel.org/r/alpine.DEB.2.11.1411262304010.3961@nanos

Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Steven Rostedt (Red Hat) 10 years ago
parent
commit
6a06bdbf7f
2 changed files with 6 additions and 9 deletions
  1. 2 2
      arch/x86/kernel/ftrace.c
  2. 4 7
      arch/x86/kernel/mcount_64.S

+ 2 - 2
arch/x86/kernel/ftrace.c

@@ -871,7 +871,7 @@ static void *addr_from_call(void *ptr)
 	return ptr + MCOUNT_INSN_SIZE + calc.offset;
 	return ptr + MCOUNT_INSN_SIZE + calc.offset;
 }
 }
 
 
-void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr,
+void prepare_ftrace_return(unsigned long self_addr, unsigned long *parent,
 			   unsigned long frame_pointer);
 			   unsigned long frame_pointer);
 
 
 /*
 /*
@@ -964,7 +964,7 @@ int ftrace_disable_ftrace_graph_caller(void)
  * Hook the return address and push it in the stack of return addrs
  * Hook the return address and push it in the stack of return addrs
  * in current thread info.
  * in current thread info.
  */
  */
-void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr,
+void prepare_ftrace_return(unsigned long self_addr, unsigned long *parent,
 			   unsigned long frame_pointer)
 			   unsigned long frame_pointer)
 {
 {
 	unsigned long old;
 	unsigned long old;

+ 4 - 7
arch/x86/kernel/mcount_64.S

@@ -124,7 +124,7 @@
 	/*
 	/*
 	 * Now %rdi (the first parameter) has the return address of
 	 * Now %rdi (the first parameter) has the return address of
 	 * where ftrace_call returns. But the callbacks expect the
 	 * where ftrace_call returns. But the callbacks expect the
-	 * the address of the call itself.
+	 * address of the call itself.
 	 */
 	 */
 	subq $MCOUNT_INSN_SIZE, %rdi
 	subq $MCOUNT_INSN_SIZE, %rdi
 	.endm
 	.endm
@@ -289,21 +289,18 @@ END(function_hook)
 
 
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
 ENTRY(ftrace_graph_caller)
 ENTRY(ftrace_graph_caller)
-	/* Saves rbp into %rdx */
+	/* Saves rbp into %rdx and fills first parameter  */
 	save_mcount_regs
 	save_mcount_regs
 
 
 #ifdef CC_USING_FENTRY
 #ifdef CC_USING_FENTRY
-	leaq MCOUNT_REG_SIZE+8(%rsp), %rdi
+	leaq MCOUNT_REG_SIZE+8(%rsp), %rsi
 	movq $0, %rdx	/* No framepointers needed */
 	movq $0, %rdx	/* No framepointers needed */
 #else
 #else
 	/* Save address of the return address of traced function */
 	/* Save address of the return address of traced function */
-	leaq 8(%rdx), %rdi
+	leaq 8(%rdx), %rsi
 	/* ftrace does sanity checks against frame pointers */
 	/* ftrace does sanity checks against frame pointers */
 	movq (%rdx), %rdx
 	movq (%rdx), %rdx
 #endif
 #endif
-	movq RIP(%rsp), %rsi
-	subq $MCOUNT_INSN_SIZE, %rsi
-
 	call	prepare_ftrace_return
 	call	prepare_ftrace_return
 
 
 	restore_mcount_regs
 	restore_mcount_regs