Subject: [PATCH] mips/ftrace: Fix function tracing return address to match

From: David Daney <[email-masked]>
Date: Mon, 15 Jul 2013 15:17:17 -0700

From: Corey Minyard <[email-masked]>

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.

Signed-off-by: Corey Minyard <[email-masked]>
[[email-masked]: Adjusted code comment and patch Subject.]
Signed-off-by: David Daney <[email-masked]>
---
 arch/mips/kernel/mcount.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/mips/kernel/mcount.S b/arch/mips/kernel/mcount.S
index a03e93c..539b629 100644
--- a/arch/mips/kernel/mcount.S
+++ b/arch/mips/kernel/mcount.S
@@ -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 */
-- 
1.7.11.7

---

From: Steven Rostedt <[email-masked]>
Date: Thu, 18 Jul 2013 16:11:02 -0400

>  	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

---

From: David Daney <[email-masked]>
Date: Thu, 18 Jul 2013 13:14:52 -0700

> 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

---

From: Steven Rostedt <[email-masked]>
Date: Thu, 18 Jul 2013 16:26:00 -0400

> We are using GCC-4.7 FWIW.

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 can down load the 4.7 version and see if that makes a difference.

-- Steve

---

From: Steven Rostedt <[email-masked]>
Date: Thu, 18 Jul 2013 16:27:01 -0400

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

I guess I can't. There is no 4.7 version for MIPS :-p

https://www.kernel.org/pub/tools/crosstool/files/bin/x86_64/4.7.3/

-- Steve

---

From: David Daney <[email-masked]>
Date: Thu, 18 Jul 2013 13:37:34 -0700

> 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

---

From: Corey Minyard <[email-masked]>
Date: Thu, 18 Jul 2013 19:24:06 -0500

> system to crash. Not sure why. I'll try to investigate.
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