All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -tip v9 0/5] kprobes related bugfix
@ 2017-08-03  2:33 ` Masami Hiramatsu
  0 siblings, 0 replies; 15+ messages in thread
From: Masami Hiramatsu @ 2017-08-03  2:33 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, Yoshinori Sato, Chris Zankel,
	Max Filippov, Mikael Starvik, Jesper Nilsson, linux-cris-kernel,
	linux-arch

Hi,

Here are the 9th version of the series to fix kprobes not
to optimize on the functions in irqentry text ([5/5]).
To check the irqentry text always, [4/5] makes irqentry
text section unconditional.

This involves some other cleanups on h8300, xtensa, and
cris ports, because those sources declare section 
start/end symbol as single characters, but generic
sections.h declares it as character arrays. So it leads
build errors if we apply [4/5].

Changes in v9
 - Add cris cleanup patch (3/5).

BTW, in this series I just give a minimum fix for
arch dependent code, since this is a series to fix
a bug in x86 optprobe. However, IMHO, we should
revisit these "local _stext/_etext references" and
replace it with just including asm/sections.h.
And also, I would like to expose is_kernel_text()
as a generic routine for arch dependent code
so that they can use it.

Thank you,

---

Masami Hiramatsu (5):
      h8300: mark _stext and _etext as char-arrays, not single char
      xtensa: mark _stext and _end as char-arrays, not single char
      cris: mark _stext and _end as char-arrays, not single char
      irq: Make irqentry text section unconditional
      [BUGFIX] kprobes/x86: Do not jump-optimize kprobes on irq entry code


 arch/arm/include/asm/traps.h         |    7 -------
 arch/arm64/include/asm/traps.h       |    7 -------
 arch/cris/arch-v32/mach-a3/arbiter.c |    4 ++--
 arch/cris/arch-v32/mach-fs/arbiter.c |    4 ++--
 arch/cris/kernel/traps.c             |    6 +++---
 arch/h8300/include/asm/traps.h       |    6 +++---
 arch/x86/entry/entry_64.S            |    9 ++-------
 arch/x86/kernel/kprobes/opt.c        |    9 ++++++---
 arch/x86/kernel/unwind_frame.c       |    2 --
 arch/xtensa/kernel/setup.c           |    6 +++---
 include/asm-generic/sections.h       |    4 ++++
 include/asm-generic/vmlinux.lds.h    |    8 --------
 include/linux/interrupt.h            |   14 +-------------
 13 files changed, 26 insertions(+), 60 deletions(-)

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

* [PATCH -tip v9 0/5] kprobes related bugfix
@ 2017-08-03  2:33 ` Masami Hiramatsu
  0 siblings, 0 replies; 15+ messages in thread
From: Masami Hiramatsu @ 2017-08-03  2:33 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, Yoshinori Sato, Chris Zankel,
	Max Filippov, Mikael Starvik, Jesper Nilsson, linux-cris-kernel,
	linux-arch

Hi,

Here are the 9th version of the series to fix kprobes not
to optimize on the functions in irqentry text ([5/5]).
To check the irqentry text always, [4/5] makes irqentry
text section unconditional.

This involves some other cleanups on h8300, xtensa, and
cris ports, because those sources declare section 
start/end symbol as single characters, but generic
sections.h declares it as character arrays. So it leads
build errors if we apply [4/5].

Changes in v9
 - Add cris cleanup patch (3/5).

BTW, in this series I just give a minimum fix for
arch dependent code, since this is a series to fix
a bug in x86 optprobe. However, IMHO, we should
revisit these "local _stext/_etext references" and
replace it with just including asm/sections.h.
And also, I would like to expose is_kernel_text()
as a generic routine for arch dependent code
so that they can use it.

Thank you,

---

Masami Hiramatsu (5):
      h8300: mark _stext and _etext as char-arrays, not single char
      xtensa: mark _stext and _end as char-arrays, not single char
      cris: mark _stext and _end as char-arrays, not single char
      irq: Make irqentry text section unconditional
      [BUGFIX] kprobes/x86: Do not jump-optimize kprobes on irq entry code


 arch/arm/include/asm/traps.h         |    7 -------
 arch/arm64/include/asm/traps.h       |    7 -------
 arch/cris/arch-v32/mach-a3/arbiter.c |    4 ++--
 arch/cris/arch-v32/mach-fs/arbiter.c |    4 ++--
 arch/cris/kernel/traps.c             |    6 +++---
 arch/h8300/include/asm/traps.h       |    6 +++---
 arch/x86/entry/entry_64.S            |    9 ++-------
 arch/x86/kernel/kprobes/opt.c        |    9 ++++++---
 arch/x86/kernel/unwind_frame.c       |    2 --
 arch/xtensa/kernel/setup.c           |    6 +++---
 include/asm-generic/sections.h       |    4 ++++
 include/asm-generic/vmlinux.lds.h    |    8 --------
 include/linux/interrupt.h            |   14 +-------------
 13 files changed, 26 insertions(+), 60 deletions(-)

--
Masami Hiramatsu

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

* [PATCH -tip v9 1/5] h8300: mark _stext and _etext as char-arrays, not single char
  2017-08-03  2:33 ` Masami Hiramatsu
  (?)
@ 2017-08-03  2:35 ` Masami Hiramatsu
  2017-08-10 16:35   ` [tip:perf/core] h8300: Mark _stext and _etext as char-arrays, not single char variables tip-bot for Masami Hiramatsu
  -1 siblings, 1 reply; 15+ messages in thread
From: Masami Hiramatsu @ 2017-08-03  2:35 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, Yoshinori Sato, Chris Zankel,
	Max Filippov, Mikael Starvik, Jesper Nilsson, linux-cris-kernel,
	linux-arch

Mark _stext and _etext as character arrays instead of
single character, as same as include/asm-generic/sections.h
does.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 arch/h8300/include/asm/traps.h |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/h8300/include/asm/traps.h b/arch/h8300/include/asm/traps.h
index 15e701130b27..1c5a30ec2df8 100644
--- a/arch/h8300/include/asm/traps.h
+++ b/arch/h8300/include/asm/traps.h
@@ -33,9 +33,9 @@ extern unsigned long *_interrupt_redirect_table;
 #define TRAP2_VEC 10
 #define TRAP3_VEC 11
 
-extern char _start, _etext;
+extern char _start[], _etext[];
 #define check_kernel_text(addr) \
-	((addr >= (unsigned long)(&_start)) && \
-	 (addr <  (unsigned long)(&_etext)) && !(addr & 1))
+	((addr >= (unsigned long)(_start)) && \
+	 (addr <  (unsigned long)(_etext)) && !(addr & 1))
 
 #endif /* _H8300_TRAPS_H */

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

* [PATCH -tip v9 2/5] xtensa: mark _stext and _end as char-arrays, not single char
  2017-08-03  2:33 ` Masami Hiramatsu
  (?)
  (?)
@ 2017-08-03  2:36 ` Masami Hiramatsu
  2017-08-10 16:35   ` [tip:perf/core] xtensa: Mark _stext and _end as char-arrays, not single char variables tip-bot for Masami Hiramatsu
  -1 siblings, 1 reply; 15+ messages in thread
From: Masami Hiramatsu @ 2017-08-03  2:36 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, Yoshinori Sato, Chris Zankel,
	Max Filippov, Mikael Starvik, Jesper Nilsson, linux-cris-kernel,
	linux-arch

Mark _stext and _end as character arrays instead of single
character, as same as include/asm-generic/sections.h does.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 arch/xtensa/kernel/setup.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/xtensa/kernel/setup.c b/arch/xtensa/kernel/setup.c
index 33bfa5270d95..08175df7a69e 100644
--- a/arch/xtensa/kernel/setup.c
+++ b/arch/xtensa/kernel/setup.c
@@ -273,8 +273,8 @@ void __init init_arch(bp_tag_t *bp_start)
  * Initialize system. Setup memory and reserve regions.
  */
 
-extern char _end;
-extern char _stext;
+extern char _end[];
+extern char _stext[];
 extern char _WindowVectors_text_start;
 extern char _WindowVectors_text_end;
 extern char _DebugInterruptVector_literal_start;
@@ -333,7 +333,7 @@ void __init setup_arch(char **cmdline_p)
 	}
 #endif
 
-	mem_reserve(__pa(&_stext), __pa(&_end));
+	mem_reserve(__pa(_stext), __pa(_end));
 
 #ifdef CONFIG_VECTORS_OFFSET
 	mem_reserve(__pa(&_WindowVectors_text_start),

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

* [PATCH -tip v9 3/5] cris: mark _stext and _end as char-arrays, not single char
  2017-08-03  2:33 ` Masami Hiramatsu
                   ` (2 preceding siblings ...)
  (?)
@ 2017-08-03  2:37 ` Masami Hiramatsu
  2017-08-10 16:36   ` [tip:perf/core] cris: Mark _stext and _end as char-arrays, not single char variables tip-bot for Masami Hiramatsu
                     ` (2 more replies)
  -1 siblings, 3 replies; 15+ messages in thread
From: Masami Hiramatsu @ 2017-08-03  2:37 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, Yoshinori Sato, Chris Zankel,
	Max Filippov, Mikael Starvik, Jesper Nilsson, linux-cris-kernel,
	linux-arch

Mark _stext and _end as character arrays instead of single
character, as same as include/asm-generic/sections.h does.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 arch/cris/arch-v32/mach-a3/arbiter.c |    4 ++--
 arch/cris/arch-v32/mach-fs/arbiter.c |    4 ++--
 arch/cris/kernel/traps.c             |    6 +++---
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/cris/arch-v32/mach-a3/arbiter.c b/arch/cris/arch-v32/mach-a3/arbiter.c
index ab5c421a4de8..735a9b0abdb8 100644
--- a/arch/cris/arch-v32/mach-a3/arbiter.c
+++ b/arch/cris/arch-v32/mach-a3/arbiter.c
@@ -227,7 +227,7 @@ static void crisv32_arbiter_config(int arbiter, int region, int unused_slots)
 	}
 }
 
-extern char _stext, _etext;
+extern char _stext[], _etext[];
 
 static void crisv32_arbiter_init(void)
 {
@@ -265,7 +265,7 @@ static void crisv32_arbiter_init(void)
 
 #ifndef CONFIG_ETRAX_KGDB
 	/* Global watch for writes to kernel text segment. */
-	crisv32_arbiter_watch(virt_to_phys(&_stext), &_etext - &_stext,
+	crisv32_arbiter_watch(virt_to_phys(_stext), _etext - _stext,
 		MARB_CLIENTS(arbiter_all_clients, arbiter_bar_all_clients),
 			      arbiter_all_write, NULL);
 #endif
diff --git a/arch/cris/arch-v32/mach-fs/arbiter.c b/arch/cris/arch-v32/mach-fs/arbiter.c
index c97f4d8120f9..047c70bdbb23 100644
--- a/arch/cris/arch-v32/mach-fs/arbiter.c
+++ b/arch/cris/arch-v32/mach-fs/arbiter.c
@@ -158,7 +158,7 @@ static void crisv32_arbiter_config(int region, int unused_slots)
 	}
 }
 
-extern char _stext, _etext;
+extern char _stext[], _etext[];
 
 static void crisv32_arbiter_init(void)
 {
@@ -190,7 +190,7 @@ static void crisv32_arbiter_init(void)
 
 #ifndef CONFIG_ETRAX_KGDB
 	/* Global watch for writes to kernel text segment. */
-	crisv32_arbiter_watch(virt_to_phys(&_stext), &_etext - &_stext,
+	crisv32_arbiter_watch(virt_to_phys(_stext), _etext - _stext,
 			      arbiter_all_clients, arbiter_all_write, NULL);
 #endif
 }
diff --git a/arch/cris/kernel/traps.c b/arch/cris/kernel/traps.c
index a01636a12a6e..d98131c45bb5 100644
--- a/arch/cris/kernel/traps.c
+++ b/arch/cris/kernel/traps.c
@@ -42,7 +42,7 @@ void (*nmi_handler)(struct pt_regs *);
 void show_trace(unsigned long *stack)
 {
 	unsigned long addr, module_start, module_end;
-	extern char _stext, _etext;
+	extern char _stext[], _etext[];
 	int i;
 
 	pr_err("\nCall Trace: ");
@@ -69,8 +69,8 @@ void show_trace(unsigned long *stack)
 		 * down the cause of the crash will be able to figure
 		 * out the call path that was taken.
 		 */
-		if (((addr >= (unsigned long)&_stext) &&
-		     (addr <= (unsigned long)&_etext)) ||
+		if (((addr >= (unsigned long)_stext) &&
+		     (addr <= (unsigned long)_etext)) ||
 		    ((addr >= module_start) && (addr <= module_end))) {
 #ifdef CONFIG_KALLSYMS
 			print_ip_sym(addr);

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

* [PATCH -tip v9 4/5] irq: Make irqentry text section unconditional
  2017-08-03  2:33 ` Masami Hiramatsu
                   ` (3 preceding siblings ...)
  (?)
@ 2017-08-03  2:38 ` Masami Hiramatsu
  2017-08-10 16:36   ` [tip:perf/core] irq: Make the " tip-bot for Masami Hiramatsu
  -1 siblings, 1 reply; 15+ messages in thread
From: Masami Hiramatsu @ 2017-08-03  2:38 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, Yoshinori Sato, Chris Zankel,
	Max Filippov, Mikael Starvik, Jesper Nilsson, linux-cris-kernel,
	linux-arch

Generate irqentry and softirqentry text sections without
any configs. This will add above extra sections, but
no performace impact.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Suggested-by: Ingo Molnar <mingo@kernel.org>
---
 arch/arm/include/asm/traps.h      |    7 -------
 arch/arm64/include/asm/traps.h    |    7 -------
 arch/x86/entry/entry_64.S         |    9 ++-------
 arch/x86/kernel/unwind_frame.c    |    2 --
 include/asm-generic/sections.h    |    4 ++++
 include/asm-generic/vmlinux.lds.h |    8 --------
 include/linux/interrupt.h         |   14 +-------------
 7 files changed, 7 insertions(+), 44 deletions(-)

diff --git a/arch/arm/include/asm/traps.h b/arch/arm/include/asm/traps.h
index f555bb3664dc..683d9230984a 100644
--- a/arch/arm/include/asm/traps.h
+++ b/arch/arm/include/asm/traps.h
@@ -18,7 +18,6 @@ struct undef_hook {
 void register_undef_hook(struct undef_hook *hook);
 void unregister_undef_hook(struct undef_hook *hook);
 
-#ifdef CONFIG_FUNCTION_GRAPH_TRACER
 static inline int __in_irqentry_text(unsigned long ptr)
 {
 	extern char __irqentry_text_start[];
@@ -27,12 +26,6 @@ static inline int __in_irqentry_text(unsigned long ptr)
 	return ptr >= (unsigned long)&__irqentry_text_start &&
 	       ptr < (unsigned long)&__irqentry_text_end;
 }
-#else
-static inline int __in_irqentry_text(unsigned long ptr)
-{
-	return 0;
-}
-#endif
 
 static inline int in_exception_text(unsigned long ptr)
 {
diff --git a/arch/arm64/include/asm/traps.h b/arch/arm64/include/asm/traps.h
index 02e9035b0685..47a9066f7c86 100644
--- a/arch/arm64/include/asm/traps.h
+++ b/arch/arm64/include/asm/traps.h
@@ -37,18 +37,11 @@ void unregister_undef_hook(struct undef_hook *hook);
 
 void arm64_notify_segfault(struct pt_regs *regs, unsigned long addr);
 
-#ifdef CONFIG_FUNCTION_GRAPH_TRACER
 static inline int __in_irqentry_text(unsigned long ptr)
 {
 	return ptr >= (unsigned long)&__irqentry_text_start &&
 	       ptr < (unsigned long)&__irqentry_text_end;
 }
-#else
-static inline int __in_irqentry_text(unsigned long ptr)
-{
-	return 0;
-}
-#endif
 
 static inline int in_exception_text(unsigned long ptr)
 {
diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
index aa58155187c5..5e41396efbbf 100644
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -766,13 +766,8 @@ 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)
-# define PUSH_SECTION_IRQENTRY	.pushsection .irqentry.text, "ax"
-# define POP_SECTION_IRQENTRY	.popsection
-#else
-# define PUSH_SECTION_IRQENTRY
-# define POP_SECTION_IRQENTRY
-#endif
+#define PUSH_SECTION_IRQENTRY	.pushsection .irqentry.text, "ax"
+#define POP_SECTION_IRQENTRY	.popsection
 
 .macro apicinterrupt num sym do_sym
 PUSH_SECTION_IRQENTRY
diff --git a/arch/x86/kernel/unwind_frame.c b/arch/x86/kernel/unwind_frame.c
index 7574ef5f16ec..d145a0b1f529 100644
--- a/arch/x86/kernel/unwind_frame.c
+++ b/arch/x86/kernel/unwind_frame.c
@@ -84,10 +84,8 @@ static bool in_entry_code(unsigned long ip)
 	if (addr >= __entry_text_start && addr < __entry_text_end)
 		return true;
 
-#if defined(CONFIG_FUNCTION_GRAPH_TRACER) || defined(CONFIG_KASAN)
 	if (addr >= __irqentry_text_start && addr < __irqentry_text_end)
 		return true;
-#endif
 
 	return false;
 }
diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index 532372c6cf15..e5da44eddd2f 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -27,6 +27,8 @@
  *	__kprobes_text_start, __kprobes_text_end
  *	__entry_text_start, __entry_text_end
  *	__ctors_start, __ctors_end
+ *	__irqentry_text_start, __irqentry_text_end
+ *	__softirqentry_text_start, __softirqentry_text_end
  */
 extern char _text[], _stext[], _etext[];
 extern char _data[], _sdata[], _edata[];
@@ -39,6 +41,8 @@ extern char __per_cpu_load[], __per_cpu_start[], __per_cpu_end[];
 extern char __kprobes_text_start[], __kprobes_text_end[];
 extern char __entry_text_start[], __entry_text_end[];
 extern char __start_rodata[], __end_rodata[];
+extern char __irqentry_text_start[], __irqentry_text_end[];
+extern char __softirqentry_text_start[], __softirqentry_text_end[];
 
 /* Start and end of .ctors section - used for constructor calls. */
 extern char __ctors_start[], __ctors_end[];
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index fffc9bdae025..438b014c192f 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -483,25 +483,17 @@
 		*(.entry.text)						\
 		VMLINUX_SYMBOL(__entry_text_end) = .;
 
-#if defined(CONFIG_FUNCTION_GRAPH_TRACER) || defined(CONFIG_KASAN)
 #define IRQENTRY_TEXT							\
 		ALIGN_FUNCTION();					\
 		VMLINUX_SYMBOL(__irqentry_text_start) = .;		\
 		*(.irqentry.text)					\
 		VMLINUX_SYMBOL(__irqentry_text_end) = .;
-#else
-#define IRQENTRY_TEXT
-#endif
 
-#if defined(CONFIG_FUNCTION_GRAPH_TRACER) || defined(CONFIG_KASAN)
 #define SOFTIRQENTRY_TEXT						\
 		ALIGN_FUNCTION();					\
 		VMLINUX_SYMBOL(__softirqentry_text_start) = .;		\
 		*(.softirqentry.text)					\
 		VMLINUX_SYMBOL(__softirqentry_text_end) = .;
-#else
-#define SOFTIRQENTRY_TEXT
-#endif
 
 /* Section used for early init (in .S files) */
 #define HEAD_TEXT  *(.head.text)
diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
index a2fddddb0d60..59ba11661b6e 100644
--- a/include/linux/interrupt.h
+++ b/include/linux/interrupt.h
@@ -18,6 +18,7 @@
 #include <linux/atomic.h>
 #include <asm/ptrace.h>
 #include <asm/irq.h>
+#include <asm/sections.h>
 
 /*
  * These correspond to the IORESOURCE_IRQ_* defines in
@@ -726,7 +727,6 @@ 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)
 /*
  * We want to know which function is an entrypoint of a hardirq or a softirq.
  */
@@ -734,16 +734,4 @@ extern int arch_early_irq_init(void);
 #define __softirq_entry  \
 	__attribute__((__section__(".softirqentry.text")))
 
-/* Limits of hardirq entrypoints */
-extern char __irqentry_text_start[];
-extern char __irqentry_text_end[];
-/* Limits of softirq entrypoints */
-extern char __softirqentry_text_start[];
-extern char __softirqentry_text_end[];
-
-#else
-#define __irq_entry
-#define __softirq_entry
-#endif
-
 #endif

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

* [PATCH -tip v9 5/5] [BUGFIX] kprobes/x86: Do not jump-optimize kprobes on irq entry code
  2017-08-03  2:33 ` Masami Hiramatsu
                   ` (4 preceding siblings ...)
  (?)
@ 2017-08-03  2:39 ` Masami Hiramatsu
  2017-08-10 16:36   ` [tip:perf/core] " tip-bot for Masami Hiramatsu
  -1 siblings, 1 reply; 15+ messages in thread
From: Masami Hiramatsu @ 2017-08-03  2:39 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, Yoshinori Sato, Chris Zankel,
	Max Filippov, Mikael Starvik, Jesper Nilsson, linux-cris-kernel,
	linux-arch

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>
---
 arch/x86/kernel/kprobes/opt.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
index 69ea0bc1cfa3..4f98aad38237 100644
--- a/arch/x86/kernel/kprobes/opt.c
+++ b/arch/x86/kernel/kprobes/opt.c
@@ -39,6 +39,7 @@
 #include <asm/insn.h>
 #include <asm/debugreg.h>
 #include <asm/set_memory.h>
+#include <asm/sections.h>
 
 #include "common.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] 15+ messages in thread

* [tip:perf/core] h8300: Mark _stext and _etext as char-arrays, not single char variables
  2017-08-03  2:35 ` [PATCH -tip v9 1/5] h8300: mark _stext and _etext as char-arrays, not single char Masami Hiramatsu
@ 2017-08-10 16:35   ` tip-bot for Masami Hiramatsu
  0 siblings, 0 replies; 15+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2017-08-10 16:35 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: davem, torvalds, mhiramat, mingo, chris, hpa, ysato, linux-kernel,
	jesper.nilsson, francis.deslauriers, anil.s.keshavamurthy, peterz,
	ananth, tglx, starvik, jcmvbkbc

Commit-ID:  b4464bf977004832f63f31c015751c049bc47dde
Gitweb:     http://git.kernel.org/tip/b4464bf977004832f63f31c015751c049bc47dde
Author:     Masami Hiramatsu <mhiramat@kernel.org>
AuthorDate: Thu, 3 Aug 2017 11:35:04 +0900
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Thu, 10 Aug 2017 16:28:52 +0200

h8300: Mark _stext and _etext as char-arrays, not single char variables

Mark _stext and _etext as character arrays instead of
single character variables, like include/asm-generic/sections.h
does.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
Cc: Chris Zankel <chris@zankel.net>
Cc: David S . Miller <davem@davemloft.net>
Cc: Francis Deslauriers <francis.deslauriers@efficios.com>
Cc: Jesper Nilsson <jesper.nilsson@axis.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: Mikael Starvik <starvik@axis.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: linux-arch@vger.kernel.org
Cc: linux-cris-kernel@axis.com
Cc: mathieu.desnoyers@efficios.com
Link: http://lkml.kernel.org/r/150172769415.27216.12021110228384155707.stgit@devbox
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/h8300/include/asm/traps.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/h8300/include/asm/traps.h b/arch/h8300/include/asm/traps.h
index 15e70113..1c5a30e 100644
--- a/arch/h8300/include/asm/traps.h
+++ b/arch/h8300/include/asm/traps.h
@@ -33,9 +33,9 @@ extern unsigned long *_interrupt_redirect_table;
 #define TRAP2_VEC 10
 #define TRAP3_VEC 11
 
-extern char _start, _etext;
+extern char _start[], _etext[];
 #define check_kernel_text(addr) \
-	((addr >= (unsigned long)(&_start)) && \
-	 (addr <  (unsigned long)(&_etext)) && !(addr & 1))
+	((addr >= (unsigned long)(_start)) && \
+	 (addr <  (unsigned long)(_etext)) && !(addr & 1))
 
 #endif /* _H8300_TRAPS_H */

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

* [tip:perf/core] xtensa: Mark _stext and _end as char-arrays, not single char variables
  2017-08-03  2:36 ` [PATCH -tip v9 2/5] xtensa: mark _stext and _end as char-arrays, not single char Masami Hiramatsu
@ 2017-08-10 16:35   ` tip-bot for Masami Hiramatsu
  0 siblings, 0 replies; 15+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2017-08-10 16:35 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: mingo, starvik, chris, jcmvbkbc, peterz, hpa, ysato, tglx,
	torvalds, ananth, mhiramat, anil.s.keshavamurthy, davem,
	jesper.nilsson, linux-kernel, francis.deslauriers

Commit-ID:  1824436262b2f43a46051a4958e2dd58a9d9aadf
Gitweb:     http://git.kernel.org/tip/1824436262b2f43a46051a4958e2dd58a9d9aadf
Author:     Masami Hiramatsu <mhiramat@kernel.org>
AuthorDate: Thu, 3 Aug 2017 11:36:09 +0900
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Thu, 10 Aug 2017 16:28:52 +0200

xtensa: Mark _stext and _end as char-arrays, not single char variables

Mark _stext and _end as character arrays instead of single
character variables, like include/asm-generic/sections.h does.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
Cc: Chris Zankel <chris@zankel.net>
Cc: David S . Miller <davem@davemloft.net>
Cc: Francis Deslauriers <francis.deslauriers@efficios.com>
Cc: Jesper Nilsson <jesper.nilsson@axis.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: Mikael Starvik <starvik@axis.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: linux-arch@vger.kernel.org
Cc: linux-cris-kernel@axis.com
Cc: mathieu.desnoyers@efficios.com
Link: http://lkml.kernel.org/r/150172775958.27216.12951305461398200544.stgit@devbox
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/xtensa/kernel/setup.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/xtensa/kernel/setup.c b/arch/xtensa/kernel/setup.c
index 33bfa52..08175df 100644
--- a/arch/xtensa/kernel/setup.c
+++ b/arch/xtensa/kernel/setup.c
@@ -273,8 +273,8 @@ void __init init_arch(bp_tag_t *bp_start)
  * Initialize system. Setup memory and reserve regions.
  */
 
-extern char _end;
-extern char _stext;
+extern char _end[];
+extern char _stext[];
 extern char _WindowVectors_text_start;
 extern char _WindowVectors_text_end;
 extern char _DebugInterruptVector_literal_start;
@@ -333,7 +333,7 @@ void __init setup_arch(char **cmdline_p)
 	}
 #endif
 
-	mem_reserve(__pa(&_stext), __pa(&_end));
+	mem_reserve(__pa(_stext), __pa(_end));
 
 #ifdef CONFIG_VECTORS_OFFSET
 	mem_reserve(__pa(&_WindowVectors_text_start),

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

* [tip:perf/core] cris: Mark _stext and _end as char-arrays, not single char variables
  2017-08-03  2:37 ` [PATCH -tip v9 3/5] cris: mark _stext and _end as char-arrays, not single char Masami Hiramatsu
@ 2017-08-10 16:36   ` tip-bot for Masami Hiramatsu
  2017-08-16 11:01   ` [PATCH -tip v9 3/5] cris: mark _stext and _end as char-arrays, not single char Masami Hiramatsu
  2017-08-18 18:38   ` Jesper Nilsson
  2 siblings, 0 replies; 15+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2017-08-10 16:36 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: anil.s.keshavamurthy, ananth, francis.deslauriers, davem,
	jcmvbkbc, starvik, peterz, tglx, torvalds, jesper.nilsson, ysato,
	mhiramat, mingo, chris, linux-kernel, hpa

Commit-ID:  c2579fee22483b0f156099abd9996d900634562c
Gitweb:     http://git.kernel.org/tip/c2579fee22483b0f156099abd9996d900634562c
Author:     Masami Hiramatsu <mhiramat@kernel.org>
AuthorDate: Thu, 3 Aug 2017 11:37:15 +0900
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Thu, 10 Aug 2017 16:28:53 +0200

cris: Mark _stext and _end as char-arrays, not single char variables

Mark _stext and _end as character arrays instead of single
character variable, like include/asm-generic/sections.h does.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
Cc: Chris Zankel <chris@zankel.net>
Cc: David S . Miller <davem@davemloft.net>
Cc: Francis Deslauriers <francis.deslauriers@efficios.com>
Cc: Jesper Nilsson <jesper.nilsson@axis.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: Mikael Starvik <starvik@axis.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: linux-arch@vger.kernel.org
Cc: linux-cris-kernel@axis.com
Cc: mathieu.desnoyers@efficios.com
Link: http://lkml.kernel.org/r/150172782555.27216.2805751327900543374.stgit@devbox
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/cris/arch-v32/mach-a3/arbiter.c | 4 ++--
 arch/cris/arch-v32/mach-fs/arbiter.c | 4 ++--
 arch/cris/kernel/traps.c             | 6 +++---
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/cris/arch-v32/mach-a3/arbiter.c b/arch/cris/arch-v32/mach-a3/arbiter.c
index ab5c421..735a9b0 100644
--- a/arch/cris/arch-v32/mach-a3/arbiter.c
+++ b/arch/cris/arch-v32/mach-a3/arbiter.c
@@ -227,7 +227,7 @@ static void crisv32_arbiter_config(int arbiter, int region, int unused_slots)
 	}
 }
 
-extern char _stext, _etext;
+extern char _stext[], _etext[];
 
 static void crisv32_arbiter_init(void)
 {
@@ -265,7 +265,7 @@ static void crisv32_arbiter_init(void)
 
 #ifndef CONFIG_ETRAX_KGDB
 	/* Global watch for writes to kernel text segment. */
-	crisv32_arbiter_watch(virt_to_phys(&_stext), &_etext - &_stext,
+	crisv32_arbiter_watch(virt_to_phys(_stext), _etext - _stext,
 		MARB_CLIENTS(arbiter_all_clients, arbiter_bar_all_clients),
 			      arbiter_all_write, NULL);
 #endif
diff --git a/arch/cris/arch-v32/mach-fs/arbiter.c b/arch/cris/arch-v32/mach-fs/arbiter.c
index c97f4d8..047c70b 100644
--- a/arch/cris/arch-v32/mach-fs/arbiter.c
+++ b/arch/cris/arch-v32/mach-fs/arbiter.c
@@ -158,7 +158,7 @@ static void crisv32_arbiter_config(int region, int unused_slots)
 	}
 }
 
-extern char _stext, _etext;
+extern char _stext[], _etext[];
 
 static void crisv32_arbiter_init(void)
 {
@@ -190,7 +190,7 @@ static void crisv32_arbiter_init(void)
 
 #ifndef CONFIG_ETRAX_KGDB
 	/* Global watch for writes to kernel text segment. */
-	crisv32_arbiter_watch(virt_to_phys(&_stext), &_etext - &_stext,
+	crisv32_arbiter_watch(virt_to_phys(_stext), _etext - _stext,
 			      arbiter_all_clients, arbiter_all_write, NULL);
 #endif
 }
diff --git a/arch/cris/kernel/traps.c b/arch/cris/kernel/traps.c
index a01636a..d98131c 100644
--- a/arch/cris/kernel/traps.c
+++ b/arch/cris/kernel/traps.c
@@ -42,7 +42,7 @@ void (*nmi_handler)(struct pt_regs *);
 void show_trace(unsigned long *stack)
 {
 	unsigned long addr, module_start, module_end;
-	extern char _stext, _etext;
+	extern char _stext[], _etext[];
 	int i;
 
 	pr_err("\nCall Trace: ");
@@ -69,8 +69,8 @@ void show_trace(unsigned long *stack)
 		 * down the cause of the crash will be able to figure
 		 * out the call path that was taken.
 		 */
-		if (((addr >= (unsigned long)&_stext) &&
-		     (addr <= (unsigned long)&_etext)) ||
+		if (((addr >= (unsigned long)_stext) &&
+		     (addr <= (unsigned long)_etext)) ||
 		    ((addr >= module_start) && (addr <= module_end))) {
 #ifdef CONFIG_KALLSYMS
 			print_ip_sym(addr);

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

* [tip:perf/core] irq: Make the irqentry text section unconditional
  2017-08-03  2:38 ` [PATCH -tip v9 4/5] irq: Make irqentry text section unconditional Masami Hiramatsu
@ 2017-08-10 16:36   ` tip-bot for Masami Hiramatsu
  0 siblings, 0 replies; 15+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2017-08-10 16:36 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: torvalds, jcmvbkbc, francis.deslauriers, hpa, mingo, starvik,
	tglx, ananth, jesper.nilsson, anil.s.keshavamurthy, linux-kernel,
	chris, davem, peterz, ysato, mhiramat

Commit-ID:  229a71860547ec856b156179a9c6bef2de426f66
Gitweb:     http://git.kernel.org/tip/229a71860547ec856b156179a9c6bef2de426f66
Author:     Masami Hiramatsu <mhiramat@kernel.org>
AuthorDate: Thu, 3 Aug 2017 11:38:21 +0900
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Thu, 10 Aug 2017 16:28:53 +0200

irq: Make the irqentry text section unconditional

Generate irqentry and softirqentry text sections without
any Kconfig dependencies. This will add extra sections, but
there should be no performace impact.

Suggested-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
Cc: Chris Zankel <chris@zankel.net>
Cc: David S . Miller <davem@davemloft.net>
Cc: Francis Deslauriers <francis.deslauriers@efficios.com>
Cc: Jesper Nilsson <jesper.nilsson@axis.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: Mikael Starvik <starvik@axis.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: linux-arch@vger.kernel.org
Cc: linux-cris-kernel@axis.com
Cc: mathieu.desnoyers@efficios.com
Link: http://lkml.kernel.org/r/150172789110.27216.3955739126693102122.stgit@devbox
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/arm/include/asm/traps.h      |  7 -------
 arch/arm64/include/asm/traps.h    |  7 -------
 arch/x86/entry/entry_64.S         |  9 ++-------
 arch/x86/kernel/unwind_frame.c    |  2 --
 include/asm-generic/sections.h    |  4 ++++
 include/asm-generic/vmlinux.lds.h |  8 --------
 include/linux/interrupt.h         | 14 +-------------
 7 files changed, 7 insertions(+), 44 deletions(-)

diff --git a/arch/arm/include/asm/traps.h b/arch/arm/include/asm/traps.h
index f555bb3..683d923 100644
--- a/arch/arm/include/asm/traps.h
+++ b/arch/arm/include/asm/traps.h
@@ -18,7 +18,6 @@ struct undef_hook {
 void register_undef_hook(struct undef_hook *hook);
 void unregister_undef_hook(struct undef_hook *hook);
 
-#ifdef CONFIG_FUNCTION_GRAPH_TRACER
 static inline int __in_irqentry_text(unsigned long ptr)
 {
 	extern char __irqentry_text_start[];
@@ -27,12 +26,6 @@ static inline int __in_irqentry_text(unsigned long ptr)
 	return ptr >= (unsigned long)&__irqentry_text_start &&
 	       ptr < (unsigned long)&__irqentry_text_end;
 }
-#else
-static inline int __in_irqentry_text(unsigned long ptr)
-{
-	return 0;
-}
-#endif
 
 static inline int in_exception_text(unsigned long ptr)
 {
diff --git a/arch/arm64/include/asm/traps.h b/arch/arm64/include/asm/traps.h
index 02e9035..47a9066 100644
--- a/arch/arm64/include/asm/traps.h
+++ b/arch/arm64/include/asm/traps.h
@@ -37,18 +37,11 @@ void unregister_undef_hook(struct undef_hook *hook);
 
 void arm64_notify_segfault(struct pt_regs *regs, unsigned long addr);
 
-#ifdef CONFIG_FUNCTION_GRAPH_TRACER
 static inline int __in_irqentry_text(unsigned long ptr)
 {
 	return ptr >= (unsigned long)&__irqentry_text_start &&
 	       ptr < (unsigned long)&__irqentry_text_end;
 }
-#else
-static inline int __in_irqentry_text(unsigned long ptr)
-{
-	return 0;
-}
-#endif
 
 static inline int in_exception_text(unsigned long ptr)
 {
diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
index d271fb7..3e3da29 100644
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -675,13 +675,8 @@ 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)
-# define PUSH_SECTION_IRQENTRY	.pushsection .irqentry.text, "ax"
-# define POP_SECTION_IRQENTRY	.popsection
-#else
-# define PUSH_SECTION_IRQENTRY
-# define POP_SECTION_IRQENTRY
-#endif
+#define PUSH_SECTION_IRQENTRY	.pushsection .irqentry.text, "ax"
+#define POP_SECTION_IRQENTRY	.popsection
 
 .macro apicinterrupt num sym do_sym
 PUSH_SECTION_IRQENTRY
diff --git a/arch/x86/kernel/unwind_frame.c b/arch/x86/kernel/unwind_frame.c
index b9389d7..c29e5bc 100644
--- a/arch/x86/kernel/unwind_frame.c
+++ b/arch/x86/kernel/unwind_frame.c
@@ -91,10 +91,8 @@ static bool in_entry_code(unsigned long ip)
 	if (addr >= __entry_text_start && addr < __entry_text_end)
 		return true;
 
-#if defined(CONFIG_FUNCTION_GRAPH_TRACER) || defined(CONFIG_KASAN)
 	if (addr >= __irqentry_text_start && addr < __irqentry_text_end)
 		return true;
-#endif
 
 	return false;
 }
diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index 532372c..e5da44e 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -27,6 +27,8 @@
  *	__kprobes_text_start, __kprobes_text_end
  *	__entry_text_start, __entry_text_end
  *	__ctors_start, __ctors_end
+ *	__irqentry_text_start, __irqentry_text_end
+ *	__softirqentry_text_start, __softirqentry_text_end
  */
 extern char _text[], _stext[], _etext[];
 extern char _data[], _sdata[], _edata[];
@@ -39,6 +41,8 @@ extern char __per_cpu_load[], __per_cpu_start[], __per_cpu_end[];
 extern char __kprobes_text_start[], __kprobes_text_end[];
 extern char __entry_text_start[], __entry_text_end[];
 extern char __start_rodata[], __end_rodata[];
+extern char __irqentry_text_start[], __irqentry_text_end[];
+extern char __softirqentry_text_start[], __softirqentry_text_end[];
 
 /* Start and end of .ctors section - used for constructor calls. */
 extern char __ctors_start[], __ctors_end[];
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index da0be9a..62e2395 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -483,25 +483,17 @@
 		*(.entry.text)						\
 		VMLINUX_SYMBOL(__entry_text_end) = .;
 
-#if defined(CONFIG_FUNCTION_GRAPH_TRACER) || defined(CONFIG_KASAN)
 #define IRQENTRY_TEXT							\
 		ALIGN_FUNCTION();					\
 		VMLINUX_SYMBOL(__irqentry_text_start) = .;		\
 		*(.irqentry.text)					\
 		VMLINUX_SYMBOL(__irqentry_text_end) = .;
-#else
-#define IRQENTRY_TEXT
-#endif
 
-#if defined(CONFIG_FUNCTION_GRAPH_TRACER) || defined(CONFIG_KASAN)
 #define SOFTIRQENTRY_TEXT						\
 		ALIGN_FUNCTION();					\
 		VMLINUX_SYMBOL(__softirqentry_text_start) = .;		\
 		*(.softirqentry.text)					\
 		VMLINUX_SYMBOL(__softirqentry_text_end) = .;
-#else
-#define SOFTIRQENTRY_TEXT
-#endif
 
 /* Section used for early init (in .S files) */
 #define HEAD_TEXT  *(.head.text)
diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
index a2fdddd..59ba116 100644
--- a/include/linux/interrupt.h
+++ b/include/linux/interrupt.h
@@ -18,6 +18,7 @@
 #include <linux/atomic.h>
 #include <asm/ptrace.h>
 #include <asm/irq.h>
+#include <asm/sections.h>
 
 /*
  * These correspond to the IORESOURCE_IRQ_* defines in
@@ -726,7 +727,6 @@ 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)
 /*
  * We want to know which function is an entrypoint of a hardirq or a softirq.
  */
@@ -734,16 +734,4 @@ extern int arch_early_irq_init(void);
 #define __softirq_entry  \
 	__attribute__((__section__(".softirqentry.text")))
 
-/* Limits of hardirq entrypoints */
-extern char __irqentry_text_start[];
-extern char __irqentry_text_end[];
-/* Limits of softirq entrypoints */
-extern char __softirqentry_text_start[];
-extern char __softirqentry_text_end[];
-
-#else
-#define __irq_entry
-#define __softirq_entry
-#endif
-
 #endif

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

* [tip:perf/core] kprobes/x86: Do not jump-optimize kprobes on irq entry code
  2017-08-03  2:39 ` [PATCH -tip v9 5/5] [BUGFIX] kprobes/x86: Do not jump-optimize kprobes on irq entry code Masami Hiramatsu
@ 2017-08-10 16:36   ` tip-bot for Masami Hiramatsu
  0 siblings, 0 replies; 15+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2017-08-10 16:36 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, mhiramat, tglx, davem, jcmvbkbc, hpa, starvik,
	torvalds, anil.s.keshavamurthy, jesper.nilsson, ananth,
	francis.deslauriers, mingo, peterz, chris, ysato

Commit-ID:  d9f5f32a7d17f4906a21ad59589853639a1328a0
Gitweb:     http://git.kernel.org/tip/d9f5f32a7d17f4906a21ad59589853639a1328a0
Author:     Masami Hiramatsu <mhiramat@kernel.org>
AuthorDate: Thu, 3 Aug 2017 11:39:26 +0900
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Thu, 10 Aug 2017 16:28:53 +0200

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 a
kernel panic.

However, if the kprobe is not optimized, it triggers an int3
exception and sets segment registers correctly.

With this patch we check the probe-address and if it is in the
irq-entry code, it prohibits optimizing such kprobes.

This means we can continue probing such interrupt handlers by kprobes
but it is not optimized anymore.

Reported-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Tested-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
Cc: Chris Zankel <chris@zankel.net>
Cc: David S . Miller <davem@davemloft.net>
Cc: Jesper Nilsson <jesper.nilsson@axis.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: Mikael Starvik <starvik@axis.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: linux-arch@vger.kernel.org
Cc: linux-cris-kernel@axis.com
Cc: mathieu.desnoyers@efficios.com
Link: http://lkml.kernel.org/r/150172795654.27216.9824039077047777477.stgit@devbox
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/kernel/kprobes/opt.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
index 69ea0bc..4f98aad 100644
--- a/arch/x86/kernel/kprobes/opt.c
+++ b/arch/x86/kernel/kprobes/opt.c
@@ -39,6 +39,7 @@
 #include <asm/insn.h>
 #include <asm/debugreg.h>
 #include <asm/set_memory.h>
+#include <asm/sections.h>
 
 #include "common.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] 15+ messages in thread

* Re: [PATCH -tip v9 3/5] cris: mark _stext and _end as char-arrays, not single char
  2017-08-03  2:37 ` [PATCH -tip v9 3/5] cris: mark _stext and _end as char-arrays, not single char Masami Hiramatsu
  2017-08-10 16:36   ` [tip:perf/core] cris: Mark _stext and _end as char-arrays, not single char variables tip-bot for Masami Hiramatsu
@ 2017-08-16 11:01   ` Masami Hiramatsu
  2017-08-18 18:38     ` Jesper Nilsson
  2017-08-18 18:38   ` Jesper Nilsson
  2 siblings, 1 reply; 15+ messages in thread
From: Masami Hiramatsu @ 2017-08-16 11:01 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Ingo Molnar, Thomas Gleixner, Francis Deslauriers,
	mathieu.desnoyers, Ingo Molnar, H . Peter Anvin, x86,
	Ananth N Mavinakayanahalli, Anil S Keshavamurthy,
	David S . Miller, linux-kernel, Yoshinori Sato, Chris Zankel,
	Max Filippov, Mikael Starvik, Jesper Nilsson, linux-cris-kernel,
	linux-arch

On Thu,  3 Aug 2017 11:37:15 +0900
Masami Hiramatsu <mhiramat@kernel.org> wrote:

> diff --git a/arch/cris/kernel/traps.c b/arch/cris/kernel/traps.c
> index a01636a12a6e..d98131c45bb5 100644
> --- a/arch/cris/kernel/traps.c
> +++ b/arch/cris/kernel/traps.c
> @@ -42,7 +42,7 @@ void (*nmi_handler)(struct pt_regs *);
>  void show_trace(unsigned long *stack)
>  {
>  	unsigned long addr, module_start, module_end;
> -	extern char _stext, _etext;
> +	extern char _stext[], _etext[];
>  	int i;
>  
>  	pr_err("\nCall Trace: ");
> @@ -69,8 +69,8 @@ void show_trace(unsigned long *stack)
>  		 * down the cause of the crash will be able to figure
>  		 * out the call path that was taken.
>  		 */
> -		if (((addr >= (unsigned long)&_stext) &&
> -		     (addr <= (unsigned long)&_etext)) ||
> +		if (((addr >= (unsigned long)_stext) &&
> +		     (addr <= (unsigned long)_etext)) ||
>  		    ((addr >= module_start) && (addr <= module_end))) {

BTW, I would like to ask cris people, this seems to check over 1 byte,
since _etext and module_end will be placed at the next byte of the real
address area.
As same as other arch, Should it be 

(addr < (unsigned long)_etext)

or are there any other reason?

Thank you,


>  #ifdef CONFIG_KALLSYMS
>  			print_ip_sym(addr);
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

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

* Re: [PATCH -tip v9 3/5] cris: mark _stext and _end as char-arrays, not single char
  2017-08-03  2:37 ` [PATCH -tip v9 3/5] cris: mark _stext and _end as char-arrays, not single char Masami Hiramatsu
  2017-08-10 16:36   ` [tip:perf/core] cris: Mark _stext and _end as char-arrays, not single char variables tip-bot for Masami Hiramatsu
  2017-08-16 11:01   ` [PATCH -tip v9 3/5] cris: mark _stext and _end as char-arrays, not single char Masami Hiramatsu
@ 2017-08-18 18:38   ` Jesper Nilsson
  2 siblings, 0 replies; 15+ messages in thread
From: Jesper Nilsson @ 2017-08-18 18:38 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Ingo Molnar, Thomas Gleixner, Francis Deslauriers,
	mathieu.desnoyers, Ingo Molnar, H . Peter Anvin, x86,
	Ananth N Mavinakayanahalli, Anil S Keshavamurthy,
	David S . Miller, linux-kernel, Yoshinori Sato, Chris Zankel,
	Max Filippov, Mikael Starvik, Jesper Nilsson, linux-cris-kernel,
	linux-arch


On Thu, Aug 03, 2017 at 11:37:15AM +0900, Masami Hiramatsu wrote:
> Mark _stext and _end as character arrays instead of single
> character, as same as include/asm-generic/sections.h does.

Looks good.

Acked-by: Jesper Nilsson <jesper.nilsson@axis.com>

> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> ---
>  arch/cris/arch-v32/mach-a3/arbiter.c |    4 ++--
>  arch/cris/arch-v32/mach-fs/arbiter.c |    4 ++--
>  arch/cris/kernel/traps.c             |    6 +++---
>  3 files changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/cris/arch-v32/mach-a3/arbiter.c b/arch/cris/arch-v32/mach-a3/arbiter.c
> index ab5c421a4de8..735a9b0abdb8 100644
> --- a/arch/cris/arch-v32/mach-a3/arbiter.c
> +++ b/arch/cris/arch-v32/mach-a3/arbiter.c
> @@ -227,7 +227,7 @@ static void crisv32_arbiter_config(int arbiter, int region, int unused_slots)
>  	}
>  }
>  
> -extern char _stext, _etext;
> +extern char _stext[], _etext[];
>  
>  static void crisv32_arbiter_init(void)
>  {
> @@ -265,7 +265,7 @@ static void crisv32_arbiter_init(void)
>  
>  #ifndef CONFIG_ETRAX_KGDB
>  	/* Global watch for writes to kernel text segment. */
> -	crisv32_arbiter_watch(virt_to_phys(&_stext), &_etext - &_stext,
> +	crisv32_arbiter_watch(virt_to_phys(_stext), _etext - _stext,
>  		MARB_CLIENTS(arbiter_all_clients, arbiter_bar_all_clients),
>  			      arbiter_all_write, NULL);
>  #endif
> diff --git a/arch/cris/arch-v32/mach-fs/arbiter.c b/arch/cris/arch-v32/mach-fs/arbiter.c
> index c97f4d8120f9..047c70bdbb23 100644
> --- a/arch/cris/arch-v32/mach-fs/arbiter.c
> +++ b/arch/cris/arch-v32/mach-fs/arbiter.c
> @@ -158,7 +158,7 @@ static void crisv32_arbiter_config(int region, int unused_slots)
>  	}
>  }
>  
> -extern char _stext, _etext;
> +extern char _stext[], _etext[];
>  
>  static void crisv32_arbiter_init(void)
>  {
> @@ -190,7 +190,7 @@ static void crisv32_arbiter_init(void)
>  
>  #ifndef CONFIG_ETRAX_KGDB
>  	/* Global watch for writes to kernel text segment. */
> -	crisv32_arbiter_watch(virt_to_phys(&_stext), &_etext - &_stext,
> +	crisv32_arbiter_watch(virt_to_phys(_stext), _etext - _stext,
>  			      arbiter_all_clients, arbiter_all_write, NULL);
>  #endif
>  }
> diff --git a/arch/cris/kernel/traps.c b/arch/cris/kernel/traps.c
> index a01636a12a6e..d98131c45bb5 100644
> --- a/arch/cris/kernel/traps.c
> +++ b/arch/cris/kernel/traps.c
> @@ -42,7 +42,7 @@ void (*nmi_handler)(struct pt_regs *);
>  void show_trace(unsigned long *stack)
>  {
>  	unsigned long addr, module_start, module_end;
> -	extern char _stext, _etext;
> +	extern char _stext[], _etext[];
>  	int i;
>  
>  	pr_err("\nCall Trace: ");
> @@ -69,8 +69,8 @@ void show_trace(unsigned long *stack)
>  		 * down the cause of the crash will be able to figure
>  		 * out the call path that was taken.
>  		 */
> -		if (((addr >= (unsigned long)&_stext) &&
> -		     (addr <= (unsigned long)&_etext)) ||
> +		if (((addr >= (unsigned long)_stext) &&
> +		     (addr <= (unsigned long)_etext)) ||
>  		    ((addr >= module_start) && (addr <= module_end))) {
>  #ifdef CONFIG_KALLSYMS
>  			print_ip_sym(addr);

/^JN - Jesper Nilsson
-- 
               Jesper Nilsson -- jesper.nilsson@axis.com

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

* Re: [PATCH -tip v9 3/5] cris: mark _stext and _end as char-arrays, not single char
  2017-08-16 11:01   ` [PATCH -tip v9 3/5] cris: mark _stext and _end as char-arrays, not single char Masami Hiramatsu
@ 2017-08-18 18:38     ` Jesper Nilsson
  0 siblings, 0 replies; 15+ messages in thread
From: Jesper Nilsson @ 2017-08-18 18:38 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Ingo Molnar, Thomas Gleixner, Francis Deslauriers,
	mathieu.desnoyers, Ingo Molnar, H . Peter Anvin, x86,
	Ananth N Mavinakayanahalli, Anil S Keshavamurthy,
	David S . Miller, linux-kernel, Yoshinori Sato, Chris Zankel,
	Max Filippov, Mikael Starvik, Jesper Nilsson, linux-cris-kernel,
	linux-arch

On Wed, Aug 16, 2017 at 08:01:33PM +0900, Masami Hiramatsu wrote:
> On Thu,  3 Aug 2017 11:37:15 +0900
> Masami Hiramatsu <mhiramat@kernel.org> wrote:
> 
> > diff --git a/arch/cris/kernel/traps.c b/arch/cris/kernel/traps.c
> > index a01636a12a6e..d98131c45bb5 100644
> > --- a/arch/cris/kernel/traps.c
> > +++ b/arch/cris/kernel/traps.c
> > @@ -42,7 +42,7 @@ void (*nmi_handler)(struct pt_regs *);
> >  void show_trace(unsigned long *stack)
> >  {
> >  	unsigned long addr, module_start, module_end;
> > -	extern char _stext, _etext;
> > +	extern char _stext[], _etext[];
> >  	int i;
> >  
> >  	pr_err("\nCall Trace: ");
> > @@ -69,8 +69,8 @@ void show_trace(unsigned long *stack)
> >  		 * down the cause of the crash will be able to figure
> >  		 * out the call path that was taken.
> >  		 */
> > -		if (((addr >= (unsigned long)&_stext) &&
> > -		     (addr <= (unsigned long)&_etext)) ||
> > +		if (((addr >= (unsigned long)_stext) &&
> > +		     (addr <= (unsigned long)_etext)) ||
> >  		    ((addr >= module_start) && (addr <= module_end))) {
> 
> BTW, I would like to ask cris people, this seems to check over 1 byte,
> since _etext and module_end will be placed at the next byte of the real
> address area.
> As same as other arch, Should it be 
> 
> (addr < (unsigned long)_etext)
> 
> or are there any other reason?

As far as I can tell, this is non-intentional.

> Thank you,

> Masami Hiramatsu <mhiramat@kernel.org>

/^JN - Jesper Nilsson
-- 
               Jesper Nilsson -- jesper.nilsson@axis.com

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

end of thread, other threads:[~2017-08-18 18:38 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-03  2:33 [PATCH -tip v9 0/5] kprobes related bugfix Masami Hiramatsu
2017-08-03  2:33 ` Masami Hiramatsu
2017-08-03  2:35 ` [PATCH -tip v9 1/5] h8300: mark _stext and _etext as char-arrays, not single char Masami Hiramatsu
2017-08-10 16:35   ` [tip:perf/core] h8300: Mark _stext and _etext as char-arrays, not single char variables tip-bot for Masami Hiramatsu
2017-08-03  2:36 ` [PATCH -tip v9 2/5] xtensa: mark _stext and _end as char-arrays, not single char Masami Hiramatsu
2017-08-10 16:35   ` [tip:perf/core] xtensa: Mark _stext and _end as char-arrays, not single char variables tip-bot for Masami Hiramatsu
2017-08-03  2:37 ` [PATCH -tip v9 3/5] cris: mark _stext and _end as char-arrays, not single char Masami Hiramatsu
2017-08-10 16:36   ` [tip:perf/core] cris: Mark _stext and _end as char-arrays, not single char variables tip-bot for Masami Hiramatsu
2017-08-16 11:01   ` [PATCH -tip v9 3/5] cris: mark _stext and _end as char-arrays, not single char Masami Hiramatsu
2017-08-18 18:38     ` Jesper Nilsson
2017-08-18 18:38   ` Jesper Nilsson
2017-08-03  2:38 ` [PATCH -tip v9 4/5] irq: Make irqentry text section unconditional Masami Hiramatsu
2017-08-10 16:36   ` [tip:perf/core] irq: Make the " tip-bot for Masami Hiramatsu
2017-08-03  2:39 ` [PATCH -tip v9 5/5] [BUGFIX] kprobes/x86: Do not jump-optimize kprobes on irq entry code Masami Hiramatsu
2017-08-10 16:36   ` [tip:perf/core] " tip-bot for 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.