linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] lockdep: Quiet gcc about dangerous __builtin_return_address() operations
@ 2016-09-08 16:34 Steven Rostedt
  2016-09-08 18:33 ` Borislav Petkov
  2016-10-06 13:35 ` [tip:locking/urgent] locking/lockdep: Quiet GCC " tip-bot for Steven Rostedt
  0 siblings, 2 replies; 7+ messages in thread
From: Steven Rostedt @ 2016-09-08 16:34 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: LKML, Sebastian Andrzej Siewior, Ingo Molnar, Thomas Gleixner,
	Linus Torvalds, Peter Zijlstra

[
  Boris, does this quiet gcc for you?
  I haven't fully tested this yet, as I still don't have a compiler
  that does the warning.
]

Gcc's new warnings about __builtin_return_address(n) operations with
n > 0 is popping up around the kernel. The operation is dangerous, and
the warning is "good to know". But there's instances that we use
__builtin_return_address(n) with n > 0 and are aware of the issues,
and work around them. And its used mostly for tracing and debugging. In
these cases, the warning becomes a distraction and is not helpful.

To get better lock issue traces, a function like get_lock_parent_ip()
uses __builtin_return_address() to find the caller of the lock, and
skip over the internal callers of the lock itself. Currently it is only
used in the kernel/ directory and only if certain configs are enabled.

Create a new config called CONFIG_USING_GET_LOCK_PARENT_IP that gets
selected when another config relies on get_lock_parent_ip(), and this
will now enable the function get_lock_parent_ip(), otherwise it wont be
defined. It will also disable the frame-address warnings from gcc in
the kernel directory.

Reported-by: Borislav Petkov <bp@alien8.de>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h
index 1e2b316d6693..7862c59ac725 100644
--- a/include/linux/ftrace.h
+++ b/include/linux/ftrace.h
@@ -714,6 +714,7 @@ static inline void __ftrace_enabled_restore(int enabled)
 #define CALLER_ADDR5 ((unsigned long)ftrace_return_address(5))
 #define CALLER_ADDR6 ((unsigned long)ftrace_return_address(6))
 
+#ifdef CONFIG_USING_GET_LOCK_PARENT_IP
 static inline unsigned long get_lock_parent_ip(void)
 {
 	unsigned long addr = CALLER_ADDR0;
@@ -725,6 +726,7 @@ static inline unsigned long get_lock_parent_ip(void)
 		return addr;
 	return CALLER_ADDR2;
 }
+#endif
 
 #ifdef CONFIG_IRQSOFF_TRACER
   extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
diff --git a/kernel/Makefile b/kernel/Makefile
index e2ec54e2b952..bff8214bf5f6 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -11,6 +11,13 @@ obj-y     = fork.o exec_domain.o panic.o \
 	    notifier.o ksysfs.o cred.o reboot.o \
 	    async.o range.o smpboot.o
 
+# Tracing may do some dangerous __builtin_return_address() operations
+# We know they are dangerous, we don't need gcc telling us that.
+ifdef CONFIG_USING_GET_LOCK_PARENT_IP
+FRAME_CFLAGS := $(call cc-disable-warning,frame-address)
+KBUILD_CFLAGS += $(FRAME_CFLAGS)
+endif
+
 obj-$(CONFIG_MULTIUSER) += groups.o
 
 ifdef CONFIG_FUNCTION_TRACER
diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig
index 72c07c2ffd79..f02a02fdc3ed 100644
--- a/kernel/trace/Kconfig
+++ b/kernel/trace/Kconfig
@@ -197,6 +197,7 @@ config PREEMPT_TRACER
 	select RING_BUFFER_ALLOW_SWAP
 	select TRACER_SNAPSHOT
 	select TRACER_SNAPSHOT_PER_CPU_SWAP
+	select USING_GET_LOCK_PARENT_IP
 	help
 	  This option measures the time spent in preemption-off critical
 	  sections, with microsecond accuracy.
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 2307d7c89dac..9a2bd7af64df 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -977,6 +977,7 @@ config TIMER_STATS
 config DEBUG_PREEMPT
 	bool "Debug preemptible kernel"
 	depends on DEBUG_KERNEL && PREEMPT && TRACE_IRQFLAGS_SUPPORT
+	select USING_GET_LOCK_PARENT_IP
 	default y
 	help
 	  If you say Y here then the kernel will use a debug variant of the
@@ -1159,8 +1160,17 @@ config LOCK_TORTURE_TEST
 
 endmenu # lock debugging
 
+config USING_GET_LOCK_PARENT_IP
+        bool
+	help
+	  Enables the use of the function get_lock_parent_ip() that
+	  will use __builtin_return_address(n) with n > 0 causing
+	  some gcc warnings. When this is selected, those warnings
+	  will be suppressed.
+
 config TRACE_IRQFLAGS
 	bool
+	select USING_GET_LOCK_PARENT_IP
 	help
 	  Enables hooks to interrupt enabling and disabling for
 	  either tracing or lock debugging.

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

* Re: [PATCH] lockdep: Quiet gcc about dangerous __builtin_return_address() operations
  2016-09-08 16:34 [PATCH] lockdep: Quiet gcc about dangerous __builtin_return_address() operations Steven Rostedt
@ 2016-09-08 18:33 ` Borislav Petkov
  2016-09-08 18:38   ` Steven Rostedt
  2016-09-15 13:54   ` Steven Rostedt
  2016-10-06 13:35 ` [tip:locking/urgent] locking/lockdep: Quiet GCC " tip-bot for Steven Rostedt
  1 sibling, 2 replies; 7+ messages in thread
From: Borislav Petkov @ 2016-09-08 18:33 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: LKML, Sebastian Andrzej Siewior, Ingo Molnar, Thomas Gleixner,
	Linus Torvalds, Peter Zijlstra

On Thu, Sep 08, 2016 at 12:34:33PM -0400, Steven Rostedt wrote:
> [
>   Boris, does this quiet gcc for you?
>   I haven't fully tested this yet, as I still don't have a compiler
>   that does the warning.

gcc 6.x should be available in your distro...

> Gcc's new warnings about __builtin_return_address(n) operations with
> n > 0 is popping up around the kernel. The operation is dangerous, and
> the warning is "good to know". But there's instances that we use
> __builtin_return_address(n) with n > 0 and are aware of the issues,
> and work around them. And its used mostly for tracing and debugging. In
> these cases, the warning becomes a distraction and is not helpful.
> 
> To get better lock issue traces, a function like get_lock_parent_ip()
> uses __builtin_return_address() to find the caller of the lock, and
> skip over the internal callers of the lock itself. Currently it is only
> used in the kernel/ directory and only if certain configs are enabled.
> 
> Create a new config called CONFIG_USING_GET_LOCK_PARENT_IP that gets
> selected when another config relies on get_lock_parent_ip(), and this
> will now enable the function get_lock_parent_ip(), otherwise it wont be
> defined. It will also disable the frame-address warnings from gcc in
> the kernel directory.
> 
> Reported-by: Borislav Petkov <bp@alien8.de>

	  -and-tested-by: me

> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

Thanks Steve!

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.

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

* Re: [PATCH] lockdep: Quiet gcc about dangerous __builtin_return_address() operations
  2016-09-08 18:33 ` Borislav Petkov
@ 2016-09-08 18:38   ` Steven Rostedt
  2016-09-15 13:54   ` Steven Rostedt
  1 sibling, 0 replies; 7+ messages in thread
From: Steven Rostedt @ 2016-09-08 18:38 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: LKML, Sebastian Andrzej Siewior, Ingo Molnar, Thomas Gleixner,
	Linus Torvalds, Peter Zijlstra

On Thu, 8 Sep 2016 20:33:13 +0200
Borislav Petkov <bp@alien8.de> wrote:

> On Thu, Sep 08, 2016 at 12:34:33PM -0400, Steven Rostedt wrote:
> > [
> >   Boris, does this quiet gcc for you?
> >   I haven't fully tested this yet, as I still don't have a compiler
> >   that does the warning.  
> 
> gcc 6.x should be available in your distro...

But I build kernels with distcc and gcc from the crosstools on
kernel.org, which doesn't seem to be maintained anymore :-/

Also, my distro that I test on is Fedora 20 which still has gcc 4.8.3.

> > 
> > Reported-by: Borislav Petkov <bp@alien8.de>  
> 
> 	  -and-tested-by: me
> 
> > Signed-off-by: Steven Rostedt <rostedt@goodmis.org>  
> 
> Thanks Steve!

Thanks Boris!

-- Steve

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

* Re: [PATCH] lockdep: Quiet gcc about dangerous __builtin_return_address() operations
  2016-09-08 18:33 ` Borislav Petkov
  2016-09-08 18:38   ` Steven Rostedt
@ 2016-09-15 13:54   ` Steven Rostedt
  2016-09-15 14:08     ` Peter Zijlstra
  1 sibling, 1 reply; 7+ messages in thread
From: Steven Rostedt @ 2016-09-15 13:54 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Borislav Petkov, LKML, Sebastian Andrzej Siewior, Ingo Molnar,
	Thomas Gleixner, Linus Torvalds


Peter,

Can you pull this patch in? It probably should go to stable as well.

-- Steve


On Thu, 8 Sep 2016 20:33:13 +0200
Borislav Petkov <bp@alien8.de> wrote:

> On Thu, Sep 08, 2016 at 12:34:33PM -0400, Steven Rostedt wrote:
> > [
> >   Boris, does this quiet gcc for you?
> >   I haven't fully tested this yet, as I still don't have a compiler
> >   that does the warning.  
> 
> gcc 6.x should be available in your distro...
> 
> > Gcc's new warnings about __builtin_return_address(n) operations with
> > n > 0 is popping up around the kernel. The operation is dangerous, and
> > the warning is "good to know". But there's instances that we use
> > __builtin_return_address(n) with n > 0 and are aware of the issues,
> > and work around them. And its used mostly for tracing and debugging. In
> > these cases, the warning becomes a distraction and is not helpful.
> > 
> > To get better lock issue traces, a function like get_lock_parent_ip()
> > uses __builtin_return_address() to find the caller of the lock, and
> > skip over the internal callers of the lock itself. Currently it is only
> > used in the kernel/ directory and only if certain configs are enabled.
> > 
> > Create a new config called CONFIG_USING_GET_LOCK_PARENT_IP that gets
> > selected when another config relies on get_lock_parent_ip(), and this
> > will now enable the function get_lock_parent_ip(), otherwise it wont be
> > defined. It will also disable the frame-address warnings from gcc in
> > the kernel directory.
> > 
> > Reported-by: Borislav Petkov <bp@alien8.de>  
> 
> 	  -and-tested-by: me
> 
> > Signed-off-by: Steven Rostedt <rostedt@goodmis.org>  
> 
> Thanks Steve!
> 

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

* Re: [PATCH] lockdep: Quiet gcc about dangerous __builtin_return_address() operations
  2016-09-15 13:54   ` Steven Rostedt
@ 2016-09-15 14:08     ` Peter Zijlstra
  2016-09-15 15:17       ` Steven Rostedt
  0 siblings, 1 reply; 7+ messages in thread
From: Peter Zijlstra @ 2016-09-15 14:08 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Borislav Petkov, LKML, Sebastian Andrzej Siewior, Ingo Molnar,
	Thomas Gleixner, Linus Torvalds

On Thu, Sep 15, 2016 at 09:54:50AM -0400, Steven Rostedt wrote:
> 
> Peter,
> 
> Can you pull this patch in? It probably should go to stable as well.

I'm not sure how this relates to lockdep, which is why I mostly ignored
the patch.

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

* Re: [PATCH] lockdep: Quiet gcc about dangerous __builtin_return_address() operations
  2016-09-15 14:08     ` Peter Zijlstra
@ 2016-09-15 15:17       ` Steven Rostedt
  0 siblings, 0 replies; 7+ messages in thread
From: Steven Rostedt @ 2016-09-15 15:17 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Borislav Petkov, LKML, Sebastian Andrzej Siewior, Ingo Molnar,
	Thomas Gleixner, Linus Torvalds

On Thu, 15 Sep 2016 16:08:10 +0200
Peter Zijlstra <peterz@infradead.org> wrote:

> On Thu, Sep 15, 2016 at 09:54:50AM -0400, Steven Rostedt wrote:
> > 
> > Peter,
> > 
> > Can you pull this patch in? It probably should go to stable as well.  
> 
> I'm not sure how this relates to lockdep, which is why I mostly ignored
> the patch.

It's basically about get_lock_parent_ip() which is used for backtraces
of locks, and thus for debugging locks, so I really didn't know what to
label it as. Should the subject then just be:

   lock stack traces: ...

??

-- Steve

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

* [tip:locking/urgent] locking/lockdep: Quiet GCC about dangerous __builtin_return_address() operations
  2016-09-08 16:34 [PATCH] lockdep: Quiet gcc about dangerous __builtin_return_address() operations Steven Rostedt
  2016-09-08 18:33 ` Borislav Petkov
@ 2016-10-06 13:35 ` tip-bot for Steven Rostedt
  1 sibling, 0 replies; 7+ messages in thread
From: tip-bot for Steven Rostedt @ 2016-10-06 13:35 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: mingo, torvalds, rostedt, paulmck, bigeasy, hpa, akpm, tglx, bp,
	linux-kernel, peterz

Commit-ID:  9311a4c9f0d2d5404cd7bc2ba913c919418f83e2
Gitweb:     http://git.kernel.org/tip/9311a4c9f0d2d5404cd7bc2ba913c919418f83e2
Author:     Steven Rostedt <rostedt@goodmis.org>
AuthorDate: Thu, 8 Sep 2016 12:34:33 -0400
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Thu, 6 Oct 2016 09:55:07 +0200

locking/lockdep: Quiet GCC about dangerous __builtin_return_address() operations

GCC's new warnings about __builtin_return_address(n) operations with
n > 0 is popping up around the kernel. The operation is dangerous, and
the warning is "good to know". But there's instances that we use
__builtin_return_address(n) with n > 0 and are aware of the issues,
and work around them. And its used mostly for tracing and debugging. In
these cases, the warning becomes a distraction and is not helpful.

To get better lock issue traces, a function like get_lock_parent_ip()
uses __builtin_return_address() to find the caller of the lock, and
skip over the internal callers of the lock itself. Currently it is only
used in the kernel/ directory and only if certain configs are enabled.

Create a new config called CONFIG_USING_GET_LOCK_PARENT_IP that gets
selected when another config relies on get_lock_parent_ip(), and this
will now enable the function get_lock_parent_ip(), otherwise it wont be
defined. It will also disable the frame-address warnings from GCC in
the kernel directory.

Reported-and-tested-by: Borislav Petkov <bp@alien8.de>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/20160908123433.2cf93b96@gandalf.local.home
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 include/linux/ftrace.h |  2 ++
 kernel/Makefile        |  7 +++++++
 kernel/trace/Kconfig   |  1 +
 lib/Kconfig.debug      | 10 ++++++++++
 4 files changed, 20 insertions(+)

diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h
index 6f93ac4..1218b15 100644
--- a/include/linux/ftrace.h
+++ b/include/linux/ftrace.h
@@ -714,6 +714,7 @@ static inline void __ftrace_enabled_restore(int enabled)
 #define CALLER_ADDR5 ((unsigned long)ftrace_return_address(5))
 #define CALLER_ADDR6 ((unsigned long)ftrace_return_address(6))
 
+#ifdef CONFIG_USING_GET_LOCK_PARENT_IP
 static inline unsigned long get_lock_parent_ip(void)
 {
 	unsigned long addr = CALLER_ADDR0;
@@ -725,6 +726,7 @@ static inline unsigned long get_lock_parent_ip(void)
 		return addr;
 	return CALLER_ADDR2;
 }
+#endif
 
 #ifdef CONFIG_IRQSOFF_TRACER
   extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
diff --git a/kernel/Makefile b/kernel/Makefile
index e2ec54e..bff8214 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -11,6 +11,13 @@ obj-y     = fork.o exec_domain.o panic.o \
 	    notifier.o ksysfs.o cred.o reboot.o \
 	    async.o range.o smpboot.o
 
+# Tracing may do some dangerous __builtin_return_address() operations
+# We know they are dangerous, we don't need gcc telling us that.
+ifdef CONFIG_USING_GET_LOCK_PARENT_IP
+FRAME_CFLAGS := $(call cc-disable-warning,frame-address)
+KBUILD_CFLAGS += $(FRAME_CFLAGS)
+endif
+
 obj-$(CONFIG_MULTIUSER) += groups.o
 
 ifdef CONFIG_FUNCTION_TRACER
diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig
index ba33267..ecc0bbc 100644
--- a/kernel/trace/Kconfig
+++ b/kernel/trace/Kconfig
@@ -192,6 +192,7 @@ config PREEMPT_TRACER
 	select RING_BUFFER_ALLOW_SWAP
 	select TRACER_SNAPSHOT
 	select TRACER_SNAPSHOT_PER_CPU_SWAP
+	select USING_GET_LOCK_PARENT_IP
 	help
 	  This option measures the time spent in preemption-off critical
 	  sections, with microsecond accuracy.
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index cab7405..dbc49c4 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -977,6 +977,7 @@ config TIMER_STATS
 config DEBUG_PREEMPT
 	bool "Debug preemptible kernel"
 	depends on DEBUG_KERNEL && PREEMPT && TRACE_IRQFLAGS_SUPPORT
+	select USING_GET_LOCK_PARENT_IP
 	default y
 	help
 	  If you say Y here then the kernel will use a debug variant of the
@@ -1159,8 +1160,17 @@ config LOCK_TORTURE_TEST
 
 endmenu # lock debugging
 
+config USING_GET_LOCK_PARENT_IP
+        bool
+	help
+	  Enables the use of the function get_lock_parent_ip() that
+	  will use __builtin_return_address(n) with n > 0 causing
+	  some gcc warnings. When this is selected, those warnings
+	  will be suppressed.
+
 config TRACE_IRQFLAGS
 	bool
+	select USING_GET_LOCK_PARENT_IP
 	help
 	  Enables hooks to interrupt enabling and disabling for
 	  either tracing or lock debugging.

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

end of thread, other threads:[~2016-10-06 13:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-08 16:34 [PATCH] lockdep: Quiet gcc about dangerous __builtin_return_address() operations Steven Rostedt
2016-09-08 18:33 ` Borislav Petkov
2016-09-08 18:38   ` Steven Rostedt
2016-09-15 13:54   ` Steven Rostedt
2016-09-15 14:08     ` Peter Zijlstra
2016-09-15 15:17       ` Steven Rostedt
2016-10-06 13:35 ` [tip:locking/urgent] locking/lockdep: Quiet GCC " tip-bot for Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).