From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S941606AbcIHQeo (ORCPT ); Thu, 8 Sep 2016 12:34:44 -0400 Received: from smtprelay0175.hostedemail.com ([216.40.44.175]:42007 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S941351AbcIHQem (ORCPT ); Thu, 8 Sep 2016 12:34:42 -0400 X-Session-Marker: 726F737465647440676F6F646D69732E6F7267 X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,rostedt@goodmis.org,:::::::::::::,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1437:1515:1516:1518:1534:1544:1593:1594:1711:1730:1747:1777:1792:2393:2553:2559:2562:2693:2904:3138:3139:3140:3141:3142:3167:3355:3865:3866:3867:3868:3870:3871:3872:3873:3874:4321:4398:4605:5007:6119:6120:6261:7901:7903:7904:8660:10004:10848:11026:11473:11658:11914:12043:12114:12296:12438:12555:13148:13161:13221:13229:13230:13255:13439:14096:14097:14181:14394:14659:14721:21080:21324:21434:21451:30054:30090,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:2,LUA_SUMMARY:none X-HE-Tag: swing83_45088e8e3d85c X-Filterd-Recvd-Size: 4957 Date: Thu, 8 Sep 2016 12:34:33 -0400 From: Steven Rostedt To: Borislav Petkov Cc: LKML , Sebastian Andrzej Siewior , Ingo Molnar , Thomas Gleixner , Linus Torvalds , Peter Zijlstra Subject: [PATCH] lockdep: Quiet gcc about dangerous __builtin_return_address() operations Message-ID: <20160908123433.2cf93b96@gandalf.local.home> X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ 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 Signed-off-by: Steven Rostedt --- 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.