Skip to contentSkip to conversation

ftrace/x86: Load ftrace_ops in parameter not the variable holding it

PATCH In review Steven Rostedt 4 participants 6 messages Nov 13, 2013 – Jan 9, 2014 x86

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ftrace/x86: Load ftrace_ops in parameter not the variable holding it

Function tracing callbacks expect to have the ftrace_ops that registered it passed to them, not the address of the variable that holds the ftrace_ops that registered it.

Use a mov instead of a lea to store the ftrace_ops into the parameter of the function tracing callback.

---
 arch/x86/kernel/entry_32.S | 4 ++--
 arch/x86/kernel/entry_64.S | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/entry_32.S +2 -2
index f0dcb0c..15a569a 100644
@@ -1085,7 +1085,7 @@ ENTRY(ftrace_caller)
 	pushl $0	/* Pass NULL as regs pointer */
 	movl 4*4(%esp), %eax
 	movl 0x4(%ebp), %edx
-	leal function_trace_op, %ecx
+	movl function_trace_op, %ecx
 	subl $MCOUNT_INSN_SIZE, %eax
 
 .globl ftrace_call
@@ -1143,7 +1143,7 @@ ENTRY(ftrace_regs_caller)
 	movl 12*4(%esp), %eax	/* Load ip (1st parameter) */
 	subl $MCOUNT_INSN_SIZE, %eax	/* Adjust ip */
 	movl 0x4(%ebp), %edx	/* Load parent ip (2nd parameter) */
-	leal function_trace_op, %ecx /* Save ftrace_pos in 3rd parameter */
+	movl function_trace_op, %ecx /* Save ftrace_pos in 3rd parameter */
 	pushl %esp		/* Save pt_regs as 4th parameter */
 
 GLOBAL(ftrace_regs_call)
arch/x86/kernel/entry_64.S +1 -1
index b077f4c..9ce2567 100644
@@ -88,7 +88,7 @@ END(function_hook)
 	MCOUNT_SAVE_FRAME \skip
 
 	/* Load the ftrace_ops into the 3rd parameter */
-	leaq function_trace_op, %rdx
+	movq function_trace_op(%rip), %rdx
 
 	/* Load ip into the first parameter */
 	movq RIP(%rsp), %rdi
Signature · 1 line
1.8.1.4
#1 lore raw
Quoted 9 lines · Steven Rostedt

Function tracing callbacks expect to have the ftrace_ops that registered it passed to them, not the address of the variable that holds the ftrace_ops that registered it.

Use a mov instead of a lea to store the ftrace_ops into the parameter of the function tracing callback.

This looks like an urgent fix, am I correct?

-hpa

#2 lore raw
Quoted 6 lines · On Wed, 13 Nov 2013 13:06:33 -0800 "H. Peter Anvin" <[email protected]> wrote:
Quoted 5 lines · Steven Rostedt

Function tracing callbacks expect to have the ftrace_ops that registered it passed to them, not the address of the variable that holds the ftrace_ops that registered it.

Quoted 7 lines
Quoted 4 lines

Use a mov instead of a lea to store the ftrace_ops into the parameter of the function tracing callback.

This looks like an urgent fix, am I correct?

It should go into 3.13 at least. I have code that will depend on this fix, and it would be nice if it makes it into 3.13.

It's been shear luck that this hasn't caused any issues so far. That's because the current callbacks that use its ftrace_ops don't get called directly by assembly. If they did, they would crash due to this bug.

We should probably tag it for stable too. The bug goes back to 3.8.

Fixes 2f5f6ad9390c1 ("ftrace: Pass ftrace_ops as third parameter to

function trace callback")

Thanks,

-- Steve

#3 lore raw
In reply to H. Peter Anvin
Quoted 6 lines · On Wed, 13 Nov 2013 13:06:33 -0800 "H. Peter Anvin" <[email protected]> wrote:
Quoted 5 lines · Steven Rostedt

Function tracing callbacks expect to have the ftrace_ops that registered it passed to them, not the address of the variable that holds the ftrace_ops that registered it.

Quoted 6 lines
Quoted 4 lines

Use a mov instead of a lea to store the ftrace_ops into the parameter of the function tracing callback.

This looks like an urgent fix, am I correct?

Hi Peter, I think this patch got missed somehow. Can you pull it in. You can also add Masami's reviewed-by tag too.

Also add the following tags:

Fixes 2f5f6ad9390c1 ("ftrace: Pass ftrace_ops as third parameter to

function trace callback")

Thanks!

-- Steve

Reviewed-by on v2 1/1
#4 lore raw
In reply to Steven Rostedt
Quoted 7 lines · Steven Rostedt

Function tracing callbacks expect to have the ftrace_ops that registered it passed to them, not the address of the variable that holds the ftrace_ops that registered it.

Use a mov instead of a lea to store the ftrace_ops into the parameter of the function tracing callback.

I see, function_trace_op is just a pointer to an actual ftrace_ops. :) And I have ensured this change doesn't affect ftrace-kprobes since it doesn't use this parameter.

Quoted 1 line

Thank you,

Quoted 41 lines
---
 arch/x86/kernel/entry_32.S | 4 ++--
 arch/x86/kernel/entry_64.S | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/entry_32.S +2 -2
index f0dcb0c..15a569a 100644
@@ -1085,7 +1085,7 @@ ENTRY(ftrace_caller)
 	pushl $0	/* Pass NULL as regs pointer */
 	movl 4*4(%esp), %eax
 	movl 0x4(%ebp), %edx
-	leal function_trace_op, %ecx
+	movl function_trace_op, %ecx
 	subl $MCOUNT_INSN_SIZE, %eax
 
 .globl ftrace_call
@@ -1143,7 +1143,7 @@ ENTRY(ftrace_regs_caller)
 	movl 12*4(%esp), %eax	/* Load ip (1st parameter) */
 	subl $MCOUNT_INSN_SIZE, %eax	/* Adjust ip */
 	movl 0x4(%ebp), %edx	/* Load parent ip (2nd parameter) */
-	leal function_trace_op, %ecx /* Save ftrace_pos in 3rd parameter */
+	movl function_trace_op, %ecx /* Save ftrace_pos in 3rd parameter */
 	pushl %esp		/* Save pt_regs as 4th parameter */
 
 GLOBAL(ftrace_regs_call)
arch/x86/kernel/entry_64.S +1 -1
index b077f4c..9ce2567 100644
@@ -88,7 +88,7 @@ END(function_hook)
 	MCOUNT_SAVE_FRAME \skip
 
 	/* Load the ftrace_ops into the 3rd parameter */
-	leaq function_trace_op, %rdx
+	movq function_trace_op(%rip), %rdx
 
 	/* Load ip into the first parameter */
 	movq RIP(%rsp), %rdi
Signature · 4 lines
Masami HIRAMATSU
IT Management Research Dept. Linux Technology Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: [email protected]
#5 lore raw
In reply to Steven Rostedt
ftrace/x86: Load ftrace_ops in parameter not the variable holding it
Commit-ID:  1739f09e33d8f66bf48ddbc3eca615574da6c4f6
Gitweb:     http://git.kernel.org/tip/1739f09e33d8f66bf48ddbc3eca615574da6c4f6
Author:     Steven Rostedt <[email protected]>
AuthorDate: Wed, 13 Nov 2013 15:20:04 -0500
Committer:  H. Peter Anvin <[email protected]>
CommitDate: Thu, 9 Jan 2014 13:24:29 -0800

ftrace/x86: Load ftrace_ops in parameter not the variable holding it

Function tracing callbacks expect to have the ftrace_ops that registered it passed to them, not the address of the variable that holds the ftrace_ops that registered it.

Use a mov instead of a lea to store the ftrace_ops into the parameter of the function tracing callback.

---
 arch/x86/kernel/entry_32.S | 4 ++--
 arch/x86/kernel/entry_64.S | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/entry_32.S +2 -2
index 51e2988..a2a4f46 100644
@@ -1082,7 +1082,7 @@ ENTRY(ftrace_caller)
 	pushl $0	/* Pass NULL as regs pointer */
 	movl 4*4(%esp), %eax
 	movl 0x4(%ebp), %edx
-	leal function_trace_op, %ecx
+	movl function_trace_op, %ecx
 	subl $MCOUNT_INSN_SIZE, %eax
 
 .globl ftrace_call
@@ -1140,7 +1140,7 @@ ENTRY(ftrace_regs_caller)
 	movl 12*4(%esp), %eax	/* Load ip (1st parameter) */
 	subl $MCOUNT_INSN_SIZE, %eax	/* Adjust ip */
 	movl 0x4(%ebp), %edx	/* Load parent ip (2nd parameter) */
-	leal function_trace_op, %ecx /* Save ftrace_pos in 3rd parameter */
+	movl function_trace_op, %ecx /* Save ftrace_pos in 3rd parameter */
 	pushl %esp		/* Save pt_regs as 4th parameter */
 
 GLOBAL(ftrace_regs_call)
arch/x86/kernel/entry_64.S +1 -1
index e21b078..1e96c36 100644
@@ -88,7 +88,7 @@ END(function_hook)
 	MCOUNT_SAVE_FRAME \skip
 
 	/* Load the ftrace_ops into the 3rd parameter */
-	leaq function_trace_op, %rdx
+	movq function_trace_op(%rip), %rdx
 
 	/* Load ip into the first parameter */
 	movq RIP(%rsp), %rdi