[PATCH -tip v5 1/2] irq: Introduce CONFIG_IRQENTRY kconfig

From: Masami Hiramatsu
Date: Thu Jul 27 2017 - 12:19:46 EST


Introduce CONFIG_IRQENTRY to simplify generating
irqentry and softirqentry text sections.
Currently generating those sections depends on
CONFIG_FUNCTION_GRAPH_TRACER and/or CONFIG_KASAN, in
each source code. This moves those #ifdef dependencies
into Kconfig, instead of the actual code. This makes
it scalable for other user of irqentry section.

Signed-off-by: Masami Hiramatsu <mhiramat@xxxxxxxxxx>
---
arch/arm/include/asm/traps.h | 2 +-
arch/arm64/include/asm/traps.h | 2 +-
arch/x86/entry/entry_64.S | 2 +-
include/asm-generic/vmlinux.lds.h | 4 ++--
include/linux/interrupt.h | 2 +-
kernel/irq/Kconfig | 4 ++++
kernel/trace/Kconfig | 1 +
lib/Kconfig.kasan | 1 +
8 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/arch/arm/include/asm/traps.h b/arch/arm/include/asm/traps.h
index f555bb3664dc..6a768d61d15e 100644
--- a/arch/arm/include/asm/traps.h
+++ b/arch/arm/include/asm/traps.h
@@ -18,7 +18,7 @@ struct undef_hook {
void register_undef_hook(struct undef_hook *hook);
void unregister_undef_hook(struct undef_hook *hook);

-#ifdef CONFIG_FUNCTION_GRAPH_TRACER
+#ifdef CONFIG_IRQENTRY
static inline int __in_irqentry_text(unsigned long ptr)
{
extern char __irqentry_text_start[];
diff --git a/arch/arm64/include/asm/traps.h b/arch/arm64/include/asm/traps.h
index 02e9035b0685..24eafb139902 100644
--- a/arch/arm64/include/asm/traps.h
+++ b/arch/arm64/include/asm/traps.h
@@ -37,7 +37,7 @@ void unregister_undef_hook(struct undef_hook *hook);

void arm64_notify_segfault(struct pt_regs *regs, unsigned long addr);

-#ifdef CONFIG_FUNCTION_GRAPH_TRACER
+#ifdef CONFIG_IRQENTRY
static inline int __in_irqentry_text(unsigned long ptr)
{
return ptr >= (unsigned long)&__irqentry_text_start &&
diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
index aa58155187c5..5300372fadc9 100644
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -766,7 +766,7 @@ apicinterrupt3 \num trace(\sym) smp_trace(\sym)
#endif

/* Make sure APIC interrupt handlers end up in the irqentry section: */
-#if defined(CONFIG_FUNCTION_GRAPH_TRACER) || defined(CONFIG_KASAN)
+#ifdef CONFIG_IRQENTRY
# define PUSH_SECTION_IRQENTRY .pushsection .irqentry.text, "ax"
# define POP_SECTION_IRQENTRY .popsection
#else
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index fffc9bdae025..a45712768f97 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -483,7 +483,7 @@
*(.entry.text) \
VMLINUX_SYMBOL(__entry_text_end) = .;

-#if defined(CONFIG_FUNCTION_GRAPH_TRACER) || defined(CONFIG_KASAN)
+#ifdef CONFIG_IRQENTRY
#define IRQENTRY_TEXT \
ALIGN_FUNCTION(); \
VMLINUX_SYMBOL(__irqentry_text_start) = .; \
@@ -493,7 +493,7 @@
#define IRQENTRY_TEXT
#endif

-#if defined(CONFIG_FUNCTION_GRAPH_TRACER) || defined(CONFIG_KASAN)
+#ifdef CONFIG_IRQENTRY
#define SOFTIRQENTRY_TEXT \
ALIGN_FUNCTION(); \
VMLINUX_SYMBOL(__softirqentry_text_start) = .; \
diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
index a2fddddb0d60..6adad995d8fd 100644
--- a/include/linux/interrupt.h
+++ b/include/linux/interrupt.h
@@ -726,7 +726,7 @@ extern int early_irq_init(void);
extern int arch_probe_nr_irqs(void);
extern int arch_early_irq_init(void);

-#if defined(CONFIG_FUNCTION_GRAPH_TRACER) || defined(CONFIG_KASAN)
+#ifdef CONFIG_IRQENTRY
/*
* We want to know which function is an entrypoint of a hardirq or a softirq.
*/
diff --git a/kernel/irq/Kconfig b/kernel/irq/Kconfig
index 27c4e774071c..fd4a69c28700 100644
--- a/kernel/irq/Kconfig
+++ b/kernel/irq/Kconfig
@@ -126,4 +126,8 @@ config GENERIC_IRQ_DEBUGFS

If you don't know what to do here, say N.

+# Generate irqentry and softirqentry text sections
+config IRQENTRY
+ bool
+
endmenu
diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig
index 434c840e2d82..2556a7ca8cdc 100644
--- a/kernel/trace/Kconfig
+++ b/kernel/trace/Kconfig
@@ -150,6 +150,7 @@ config FUNCTION_GRAPH_TRACER
depends on HAVE_FUNCTION_GRAPH_TRACER
depends on FUNCTION_TRACER
depends on !X86_32 || !CC_OPTIMIZE_FOR_SIZE
+ select IRQENTRY
default y
help
Enable the kernel to trace a function at both its return
diff --git a/lib/Kconfig.kasan b/lib/Kconfig.kasan
index bd38aab05929..09daa0d505e6 100644
--- a/lib/Kconfig.kasan
+++ b/lib/Kconfig.kasan
@@ -8,6 +8,7 @@ config KASAN
depends on SLUB || (SLAB && !DEBUG_SLAB)
select CONSTRUCTORS
select STACKDEPOT
+ select IRQENTRY
help
Enables kernel address sanitizer - runtime memory debugger,
designed to find out-of-bounds accesses and use-after-free bugs.