Skip to contentSkip to conversation

mips/ftrace: Fix function tracing return address to match

PATCH In review David Daney 4 participants 7 messages Jul 15, 2013 – Jul 19, 2013 MIPS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mips/ftrace: Fix function tracing return address to match

From: Corey Minyard <[email protected]>

Dynamic function tracing was not working on MIPS. When doing dynamic tracing, the tracer attempts to match up the passed in address with the one the compiler creates in the mcount tables. The MIPS code was passing in the return address from the tracing function call, but the compiler tables were the address of the function call. So they wouldn't match.

Just subtracting 8 from the return address will give the address of the function call. Easy enough.

[[email protected]: Adjusted code comment and patch Subject.]
---
 arch/mips/kernel/mcount.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/kernel/mcount.S +1 -1
index a03e93c..539b629 100644
@@ -83,7 +83,7 @@ _mcount:
 	PTR_S	MCOUNT_RA_ADDRESS_REG, PT_R12(sp)
 #endif
 
-	move	a0, ra		/* arg1: self return address */
+	PTR_SUBU a0, ra, 8	/* arg1: self address */
 	.globl ftrace_call
 ftrace_call:
 	nop	/* a placeholder for the call to a real tracing function */
Signature · 1 line
1.7.11.7
#1 lore raw
Quoted 24 lines · David Daney

From: Corey Minyard <[email protected]>

Dynamic function tracing was not working on MIPS. When doing dynamic tracing, the tracer attempts to match up the passed in address with the one the compiler creates in the mcount tables. The MIPS code was passing in the return address from the tracing function call, but the compiler tables were the address of the function call. So they wouldn't match.

Just subtracting 8 from the return address will give the address of the function call. Easy enough.

[[email protected]: Adjusted code comment and patch Subject.]
---
 arch/mips/kernel/mcount.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/kernel/mcount.S +0 -0
index a03e93c..539b629 100644

arch/mips/kernel/mcount.S _mcount: · line 89

Quoted 8 lines
arch/mips/kernel/mcount.S +1 -1
@@ -83,7 +83,7 @@ _mcount:
 	PTR_S	MCOUNT_RA_ADDRESS_REG, PT_R12(sp)
 #endif
 
-	move	a0, ra		/* arg1: self return address */
+	PTR_SUBU a0, ra, 8	/* arg1: self address */
 	.globl ftrace_call
 ftrace_call:
 	nop	/* a placeholder for the call to a real tracing function */

I applied this patch to my Yeeloong Lemote laptop and it causes the system to crash. Not sure why. I'll try to investigate.

-- Steve

#2 lore raw
Quoted 28 lines · Steven Rostedt
Quoted 27 lines · David Daney

From: Corey Minyard <[email protected]>

Dynamic function tracing was not working on MIPS. When doing dynamic tracing, the tracer attempts to match up the passed in address with the one the compiler creates in the mcount tables. The MIPS code was passing in the return address from the tracing function call, but the compiler tables were the address of the function call. So they wouldn't match.

Just subtracting 8 from the return address will give the address of the function call. Easy enough.

[[email protected]: Adjusted code comment and patch Subject.]
---
  arch/mips/kernel/mcount.S | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/kernel/mcount.S +0 -0
index a03e93c..539b629 100644
@@ -83,7 +83,7 @@ _mcount:
  	PTR_S	MCOUNT_RA_ADDRESS_REG, PT_R12(sp)
  #endif
 
Quoted 9 lines

arch/mips/kernel/mcount.S _mcount: · line 89

Quoted 5 lines
arch/mips/kernel/mcount.S +1 -1
-	move	a0, ra		/* arg1: self return address */
+	PTR_SUBU a0, ra, 8	/* arg1: self address */
  	.globl ftrace_call
  ftrace_call:
  	nop	/* a placeholder for the call to a real tracing function */

I applied this patch to my Yeeloong Lemote laptop and it causes the system to crash. Not sure why. I'll try to investigate.

There is an mcount ABI difference based on which GCC version you are using, although I wouldn't think it would effect this bit.

We are using GCC-4.7 FWIW.

David Daney

Quoted 5 lines

-- Steve

#5 lore raw
In reply to Steven Rostedt
Quoted 11 lines · Steven Rostedt
Quoted 6 lines · David Daney

There is an mcount ABI difference based on which GCC version you are using, although I wouldn't think it would effect this bit.

We are using GCC-4.7 FWIW.

David Daney

I'm using 4.6.3 which I downloaded from
https://www.kernel.org/pub/tools/crosstool/files/bin/x86_64/4.6.3/

I would expect that version to be fine too. The option in question is -mmcount-ra-address, which I added to GCC-4.5

Quoted 7 lines

I can down load the 4.7 version and see if that makes a difference.

-- Steve

#6 lore raw
In reply to Steven Rostedt
Quoted 36 lines · Steven Rostedt
Quoted 24 lines · David Daney

From: Corey Minyard <[email protected]>

Dynamic function tracing was not working on MIPS. When doing dynamic tracing, the tracer attempts to match up the passed in address with the one the compiler creates in the mcount tables. The MIPS code was passing in the return address from the tracing function call, but the compiler tables were the address of the function call. So they wouldn't match.

Just subtracting 8 from the return address will give the address of the function call. Easy enough.

[[email protected]: Adjusted code comment and patch Subject.]
---
  arch/mips/kernel/mcount.S | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/kernel/mcount.S +0 -0
index a03e93c..539b629 100644

arch/mips/kernel/mcount.S _mcount: · line 89

Quoted 8 lines
arch/mips/kernel/mcount.S +1 -1
@@ -83,7 +83,7 @@ _mcount:
  	PTR_S	MCOUNT_RA_ADDRESS_REG, PT_R12(sp)
  #endif
 
-	move	a0, ra		/* arg1: self return address */
+	PTR_SUBU a0, ra, 8	/* arg1: self address */
  	.globl ftrace_call
  ftrace_call:
  	nop	/* a placeholder for the call to a real tracing function */

I applied this patch to my Yeeloong Lemote laptop and it causes the system to crash. Not sure why. I'll try to investigate.

Quoted 3 lines

-- Steve

That is bizarre. That value should just be used for comparisons, it isn't dereferenced or anything like that. What tracing do you have enabled?

-corey