diff mbox series

ARM: add support for DEBUG_STACKOVERFLOW

Message ID 20200108082913.29710-1-u.kleine-koenig@pengutronix.de (mailing list archive)
State New, archived
Headers show
Series ARM: add support for DEBUG_STACKOVERFLOW | expand

Commit Message

Uwe Kleine-König Jan. 8, 2020, 8:29 a.m. UTC
This is similar to the checks done for mips that were introduced in
334c86c494b9 ("MIPS: IRQ: Add stackoverflow detection") and helps
detecting stack overflows in combination with interrupts.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
Hello,

this is for now only lightly tested (it compiles and doesn't trigger on
my test machine).

Best regards
Uwe

 arch/arm/Kconfig      |  1 +
 arch/arm/kernel/irq.c | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+)

Comments

Uwe Kleine-König Feb. 13, 2020, 10:32 a.m. UTC | #1
Hello,

On Wed, Jan 08, 2020 at 09:29:13AM +0100, Uwe Kleine-König wrote:
> This is similar to the checks done for mips that were introduced in
> 334c86c494b9 ("MIPS: IRQ: Add stackoverflow detection") and helps
> detecting stack overflows in combination with interrupts.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

I didn't get any feedback on this one. Does someone feel responsible to
give feedback or apply this patch?

Best regards
Uwe
diff mbox series

Patch

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index ba75e3661a41..f6c534f41914 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -74,6 +74,7 @@  config ARM
 	select HAVE_CONTEXT_TRACKING
 	select HAVE_C_RECORDMCOUNT
 	select HAVE_DEBUG_KMEMLEAK
+	select HAVE_DEBUG_STACKOVERFLOW
 	select HAVE_DMA_CONTIGUOUS if MMU
 	select HAVE_DYNAMIC_FTRACE if !XIP_KERNEL && !CPU_ENDIAN_BE32 && MMU
 	select HAVE_DYNAMIC_FTRACE_WITH_REGS if HAVE_DYNAMIC_FTRACE
diff --git a/arch/arm/kernel/irq.c b/arch/arm/kernel/irq.c
index ee514034c0a1..dfd5fdc0e565 100644
--- a/arch/arm/kernel/irq.c
+++ b/arch/arm/kernel/irq.c
@@ -41,6 +41,7 @@ 
 #include <asm/mach/arch.h>
 #include <asm/mach/irq.h>
 #include <asm/mach/time.h>
+#include <asm/thread_info.h>
 
 unsigned long irq_err_count;
 
@@ -56,6 +57,23 @@  int arch_show_interrupts(struct seq_file *p, int prec)
 	return 0;
 }
 
+#ifdef CONFIG_DEBUG_STACKOVERFLOW
+#define STACK_WARN	(THREAD_SIZE / 8)
+static inline void check_stack_overflow(void)
+{
+	unsigned long remaining_stack =
+		current_stack_pointer & (THREAD_SIZE - 1);
+
+	if (remaining_stack < sizeof(struct thread_info) + STACK_WARN) {
+		pr_err("handle_IRQ: stack overflow: %ld\n",
+		       remaining_stack - sizeof(struct thread_info));
+		dump_stack();
+	}
+}
+#else
+static inline void check_stack_overflow(void) {}
+#endif
+
 /*
  * handle_IRQ handles all hardware IRQ's.  Decoded IRQs should
  * not come via this function.  Instead, they should provide their
@@ -64,6 +82,7 @@  int arch_show_interrupts(struct seq_file *p, int prec)
  */
 void handle_IRQ(unsigned int irq, struct pt_regs *regs)
 {
+	check_stack_overflow();
 	__handle_domain_irq(NULL, irq, false, regs);
 }