irq: Introduce CONFIG_IRQENTRY kconfig
Subsystems (9)
Masami Hiramatsu
maintainerPATCH v5 1/2 irq: Introduce CONFIG_IRQENTRY kconfig
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.
--- 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(-)
arch/arm/include/asm/traps.h +1 -1
@@ -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[];
arch/arm64/include/asm/traps.h +1 -1
@@ -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 &&
arch/x86/entry/entry_64.S +1 -1
@@ -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
include/asm-generic/vmlinux.lds.h +2 -2
@@ -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) = .; \
include/linux/interrupt.h +1 -1
@@ -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. */
kernel/irq/Kconfig +4 -0
@@ -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
kernel/trace/Kconfig +1 -0
@@ -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
lib/Kconfig.kasan +1 -0
@@ -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.
Masami Hiramatsu
maintainerPATCH v5 2/2 kprobes/x86: Do not jump-optimize kprobes on irq entry code
Since the kernel segment registers are not prepared at the entry of irq-entry code, if a kprobe on such code is jump-optimized, accessing per-cpu variables may cause kernel panic.
However, if the kprobe is not optimized, it kicks int3 exception and set segment registers correctly.
This checks probe-address and if it is in irq-entry code, it prohibits optimizing such kprobes. This means we can continuously probing such interrupt handlers by kprobes but it is not optimized anymore.
---
Changes in v5:
- Use CONFIG_IRQENTRY.
--- arch/Kconfig | 1 + arch/x86/kernel/kprobes/opt.c | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-)
arch/Kconfig +1 -0
@@ -91,6 +91,7 @@ config OPTPROBES def_bool y depends on KPROBES && HAVE_OPTPROBES depends on !PREEMPT + select IRQENTRY config KPROBES_ON_FTRACE def_bool y
arch/x86/kernel/kprobes/opt.c +6 -3
@@ -29,6 +29,7 @@#include <linux/kallsyms.h> #include <linux/ftrace.h> #include <linux/frame.h> +#include <linux/interrupt.h> #include <asm/text-patching.h> #include <asm/cacheflush.h>
@@ -251,10 +252,12 @@ static int can_optimize(unsigned long paddr)/* * Do not optimize in the entry code due to the unstable -* stack handling. +* stack handling and registers setup. */ -if ((paddr >= (unsigned long )__entry_text_start) && - (paddr < (unsigned long )__entry_text_end)) +if (((paddr >= (unsigned long )__entry_text_start) && + (paddr < (unsigned long )__entry_text_end)) || + ((paddr >= (unsigned long )__irqentry_text_start) && + (paddr < (unsigned long )__irqentry_text_end)))return 0 ;/* Check there is enough space for a relative jump. */
Quoted 7 lines · Masami Hiramatsu
Introduce
CONFIG_IRQENTRYto simplify generating irqentry and softirqentry text sections. Currently generating those sections depends onCONFIG_FUNCTION_GRAPH_TRACERand/orCONFIG_KASAN, in each source code. This moves those #ifdef dependencies intoKconfig, instead of the actual code. This makes it scalable for other user of irqentry section.
Please just make it unconditional. That would remove a number of messy #ifdefs, and extra sections/symbols don't have much if any cost.
Thanks,
Ingo
Masami Hiramatsu
maintainerQuoted 11 lines · On Fri, 28 Jul 2017 08:36:03 +0200 Ingo Molnar <[email protected]> wrote:
Quoted 7 lines · Masami Hiramatsu
Introduce
CONFIG_IRQENTRYto simplify generating irqentry and softirqentry text sections. Currently generating those sections depends onCONFIG_FUNCTION_GRAPH_TRACERand/orCONFIG_KASAN, in each source code. This moves those #ifdef dependencies intoKconfig, instead of the actual code. This makes it scalable for other user of irqentry section.
Quoted 2 lines
Please just make it unconditional. That would remove a number of messy #ifdefs, and extra sections/symbols don't have much if any cost.
OK, I'll fix that and resend soon.
Thanks!
Quoted 4 lines
Thanks,
Ingo
Signature · 1 line
Masami Hiramatsu <[email protected]>