public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] MIPS: lib: Mark intrinsics notrace
@ 2016-05-25 10:06 Harvey Hunt
  2016-05-29 21:03 ` Ralf Baechle
  0 siblings, 1 reply; 3+ messages in thread
From: Harvey Hunt @ 2016-05-25 10:06 UTC (permalink / raw)
  To: ralf; +Cc: Harvey Hunt, linux-mips, linux-kernel, # 4 . 2 . x-

On certain MIPS32 devices, the ftrace tracer "function_graph" uses
__lshrdi3() during the capturing of trace data. ftrace then attempts to
trace __lshrdi3() which leads to infinite recursion and a stack overflow.
Fix this by marking __lshrdi3() as notrace. Mark the other compiler
intrinsics as notrace in case the compiler decides to use them in the
ftrace path.

Signed-off-by: Harvey Hunt <harvey.hunt@imgtec.com>
Cc: <linux-mips@linux-mips.org>
Cc: <linux-kernel@vger.kernel.org>
Cc: <stable@vger.kernel.org> # 4.2.x-
---
I've only been able to test this patch as far back as 4.2, although
the issue could have existed before then.

 arch/mips/lib/ashldi3.c | 2 +-
 arch/mips/lib/ashrdi3.c | 2 +-
 arch/mips/lib/bswapdi.c | 2 +-
 arch/mips/lib/bswapsi.c | 2 +-
 arch/mips/lib/cmpdi2.c  | 2 +-
 arch/mips/lib/lshrdi3.c | 2 +-
 arch/mips/lib/ucmpdi2.c | 2 +-
 7 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/mips/lib/ashldi3.c b/arch/mips/lib/ashldi3.c
index beb80f31..927dc94 100644
--- a/arch/mips/lib/ashldi3.c
+++ b/arch/mips/lib/ashldi3.c
@@ -2,7 +2,7 @@
 
 #include "libgcc.h"
 
-long long __ashldi3(long long u, word_type b)
+long long notrace __ashldi3(long long u, word_type b)
 {
 	DWunion uu, w;
 	word_type bm;
diff --git a/arch/mips/lib/ashrdi3.c b/arch/mips/lib/ashrdi3.c
index c884a91..9fdf1a5 100644
--- a/arch/mips/lib/ashrdi3.c
+++ b/arch/mips/lib/ashrdi3.c
@@ -2,7 +2,7 @@
 
 #include "libgcc.h"
 
-long long __ashrdi3(long long u, word_type b)
+long long notrace __ashrdi3(long long u, word_type b)
 {
 	DWunion uu, w;
 	word_type bm;
diff --git a/arch/mips/lib/bswapdi.c b/arch/mips/lib/bswapdi.c
index 77e5f9c..e3e77aa 100644
--- a/arch/mips/lib/bswapdi.c
+++ b/arch/mips/lib/bswapdi.c
@@ -1,6 +1,6 @@
 #include <linux/module.h>
 
-unsigned long long __bswapdi2(unsigned long long u)
+unsigned long long notrace __bswapdi2(unsigned long long u)
 {
 	return (((u) & 0xff00000000000000ull) >> 56) |
 	       (((u) & 0x00ff000000000000ull) >> 40) |
diff --git a/arch/mips/lib/bswapsi.c b/arch/mips/lib/bswapsi.c
index 2b302ff..530a8af 100644
--- a/arch/mips/lib/bswapsi.c
+++ b/arch/mips/lib/bswapsi.c
@@ -1,6 +1,6 @@
 #include <linux/module.h>
 
-unsigned int __bswapsi2(unsigned int u)
+unsigned int notrace __bswapsi2(unsigned int u)
 {
 	return (((u) & 0xff000000) >> 24) |
 	       (((u) & 0x00ff0000) >>  8) |
diff --git a/arch/mips/lib/cmpdi2.c b/arch/mips/lib/cmpdi2.c
index 8c13064..06857da 100644
--- a/arch/mips/lib/cmpdi2.c
+++ b/arch/mips/lib/cmpdi2.c
@@ -2,7 +2,7 @@
 
 #include "libgcc.h"
 
-word_type __cmpdi2(long long a, long long b)
+word_type notrace __cmpdi2(long long a, long long b)
 {
 	const DWunion au = {
 		.ll = a
diff --git a/arch/mips/lib/lshrdi3.c b/arch/mips/lib/lshrdi3.c
index dcf8d68..3645474 100644
--- a/arch/mips/lib/lshrdi3.c
+++ b/arch/mips/lib/lshrdi3.c
@@ -2,7 +2,7 @@
 
 #include "libgcc.h"
 
-long long __lshrdi3(long long u, word_type b)
+long long notrace __lshrdi3(long long u, word_type b)
 {
 	DWunion uu, w;
 	word_type bm;
diff --git a/arch/mips/lib/ucmpdi2.c b/arch/mips/lib/ucmpdi2.c
index bb4cb2f..bd599f5 100644
--- a/arch/mips/lib/ucmpdi2.c
+++ b/arch/mips/lib/ucmpdi2.c
@@ -2,7 +2,7 @@
 
 #include "libgcc.h"
 
-word_type __ucmpdi2(unsigned long long a, unsigned long long b)
+word_type notrace __ucmpdi2(unsigned long long a, unsigned long long b)
 {
 	const DWunion au = {.ll = a};
 	const DWunion bu = {.ll = b};
-- 
2.8.3

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] MIPS: lib: Mark intrinsics notrace
  2016-05-25 10:06 [PATCH] MIPS: lib: Mark intrinsics notrace Harvey Hunt
@ 2016-05-29 21:03 ` Ralf Baechle
  2016-05-31 12:18   ` Harvey Hunt
  0 siblings, 1 reply; 3+ messages in thread
From: Ralf Baechle @ 2016-05-29 21:03 UTC (permalink / raw)
  To: Harvey Hunt; +Cc: linux-mips, linux-kernel, # 4 . 2 . x-

On Wed, May 25, 2016 at 11:06:35AM +0100, Harvey Hunt wrote:

> On certain MIPS32 devices, the ftrace tracer "function_graph" uses
> __lshrdi3() during the capturing of trace data. ftrace then attempts to
> trace __lshrdi3() which leads to infinite recursion and a stack overflow.
> Fix this by marking __lshrdi3() as notrace. Mark the other compiler
> intrinsics as notrace in case the compiler decides to use them in the
> ftrace path.

Makes perfect sense - but I'm wondering how you triggered it.  Was this
a build with the GCC option -Os that is CONFIG_CC_OPTIMIZE_FOR_SIZE?
Usually people build with CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE that is -O2
which results in intrinsics being inlined.

  Ralf

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] MIPS: lib: Mark intrinsics notrace
  2016-05-29 21:03 ` Ralf Baechle
@ 2016-05-31 12:18   ` Harvey Hunt
  0 siblings, 0 replies; 3+ messages in thread
From: Harvey Hunt @ 2016-05-31 12:18 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: linux-mips, linux-kernel, # 4 . 2 . x-

Hi Ralf,

On 29/05/16 22:03, Ralf Baechle wrote:
> On Wed, May 25, 2016 at 11:06:35AM +0100, Harvey Hunt wrote:
>
>> On certain MIPS32 devices, the ftrace tracer "function_graph" uses
>> __lshrdi3() during the capturing of trace data. ftrace then attempts to
>> trace __lshrdi3() which leads to infinite recursion and a stack overflow.
>> Fix this by marking __lshrdi3() as notrace. Mark the other compiler
>> intrinsics as notrace in case the compiler decides to use them in the
>> ftrace path.
>
> Makes perfect sense - but I'm wondering how you triggered it.  Was this
> a build with the GCC option -Os that is CONFIG_CC_OPTIMIZE_FOR_SIZE?
> Usually people build with CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE that is -O2
> which results in intrinsics being inlined.

This is triggered by building with CONFIG_CC_OPTIMIZE_FOR_SIZE. This 
explains why I only saw it on certain MIPS32 devices - Malta's 
defconfigs don't have CONFIG_CC_OPTIMIZE_FOR_SIZE enabled, but the 
pistachio and Ci20 defconfigs do.

>
>   Ralf
>

Thanks,

Harvey

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-05-31 12:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-25 10:06 [PATCH] MIPS: lib: Mark intrinsics notrace Harvey Hunt
2016-05-29 21:03 ` Ralf Baechle
2016-05-31 12:18   ` Harvey Hunt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox