All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -tip v5 1/2] irq: Introduce CONFIG_IRQENTRY kconfig
@ 2017-07-27 16:18 Masami Hiramatsu
  2017-07-27 16:19 ` [PATCH -tip v5 2/2] [BUGFIX] kprobes/x86: Do not jump-optimize kprobes on irq entry code Masami Hiramatsu
  2017-07-28  6:36 ` [PATCH -tip v5 1/2] irq: Introduce CONFIG_IRQENTRY kconfig Ingo Molnar
  0 siblings, 2 replies; 4+ messages in thread
From: Masami Hiramatsu @ 2017-07-27 16:18 UTC (permalink / raw)
  To: Ingo Molnar, Thomas Gleixner
  Cc: Francis Deslauriers, mathieu.desnoyers, Ingo Molnar,
	H . Peter Anvin, x86, Masami Hiramatsu,
	Ananth N Mavinakayanahalli, Anil S Keshavamurthy,
	David S . Miller, linux-kernel

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@kernel.org>
---
 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.

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

* [PATCH -tip v5 2/2] [BUGFIX] kprobes/x86: Do not jump-optimize kprobes on irq entry code
  2017-07-27 16:18 [PATCH -tip v5 1/2] irq: Introduce CONFIG_IRQENTRY kconfig Masami Hiramatsu
@ 2017-07-27 16:19 ` Masami Hiramatsu
  2017-07-28  6:36 ` [PATCH -tip v5 1/2] irq: Introduce CONFIG_IRQENTRY kconfig Ingo Molnar
  1 sibling, 0 replies; 4+ messages in thread
From: Masami Hiramatsu @ 2017-07-27 16:19 UTC (permalink / raw)
  To: Ingo Molnar, Thomas Gleixner
  Cc: Francis Deslauriers, mathieu.desnoyers, Ingo Molnar,
	H . Peter Anvin, x86, Masami Hiramatsu,
	Ananth N Mavinakayanahalli, Anil S Keshavamurthy,
	David S . Miller, linux-kernel

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.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Reported-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Tested-by: Francis Deslauriers <francis.deslauriers@efficios.com>
---
 Changes in v5:
  - Use CONFIG_IRQENTRY.
---
 arch/Kconfig                  |    1 +
 arch/x86/kernel/kprobes/opt.c |    9 ++++++---
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/arch/Kconfig b/arch/Kconfig
index 21d0089117fe..f006af0d8c9e 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -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
diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
index 69ea0bc1cfa3..c26e7f989c7d 100644
--- a/arch/x86/kernel/kprobes/opt.c
+++ b/arch/x86/kernel/kprobes/opt.c
@@ -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. */

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

* Re: [PATCH -tip v5 1/2] irq: Introduce CONFIG_IRQENTRY kconfig
  2017-07-27 16:18 [PATCH -tip v5 1/2] irq: Introduce CONFIG_IRQENTRY kconfig Masami Hiramatsu
  2017-07-27 16:19 ` [PATCH -tip v5 2/2] [BUGFIX] kprobes/x86: Do not jump-optimize kprobes on irq entry code Masami Hiramatsu
@ 2017-07-28  6:36 ` Ingo Molnar
  2017-07-28  9:07   ` Masami Hiramatsu
  1 sibling, 1 reply; 4+ messages in thread
From: Ingo Molnar @ 2017-07-28  6:36 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Thomas Gleixner, Francis Deslauriers, mathieu.desnoyers,
	Ingo Molnar, H . Peter Anvin, x86, Ananth N Mavinakayanahalli,
	Anil S Keshavamurthy, David S . Miller, linux-kernel


* Masami Hiramatsu <mhiramat@kernel.org> wrote:

> 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.

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

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

* Re: [PATCH -tip v5 1/2] irq: Introduce CONFIG_IRQENTRY kconfig
  2017-07-28  6:36 ` [PATCH -tip v5 1/2] irq: Introduce CONFIG_IRQENTRY kconfig Ingo Molnar
@ 2017-07-28  9:07   ` Masami Hiramatsu
  0 siblings, 0 replies; 4+ messages in thread
From: Masami Hiramatsu @ 2017-07-28  9:07 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Thomas Gleixner, Francis Deslauriers, mathieu.desnoyers,
	Ingo Molnar, H . Peter Anvin, x86, Ananth N Mavinakayanahalli,
	Anil S Keshavamurthy, David S . Miller, linux-kernel

On Fri, 28 Jul 2017 08:36:03 +0200
Ingo Molnar <mingo@kernel.org> wrote:

> 
> * Masami Hiramatsu <mhiramat@kernel.org> wrote:
> 
> > 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.
> 
> 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!

> 
> Thanks,
> 
> 	Ingo


-- 
Masami Hiramatsu <mhiramat@kernel.org>

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

end of thread, other threads:[~2017-07-28  9:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-27 16:18 [PATCH -tip v5 1/2] irq: Introduce CONFIG_IRQENTRY kconfig Masami Hiramatsu
2017-07-27 16:19 ` [PATCH -tip v5 2/2] [BUGFIX] kprobes/x86: Do not jump-optimize kprobes on irq entry code Masami Hiramatsu
2017-07-28  6:36 ` [PATCH -tip v5 1/2] irq: Introduce CONFIG_IRQENTRY kconfig Ingo Molnar
2017-07-28  9:07   ` Masami Hiramatsu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.