Thread (2 messages) 2 messages, 1 author, 2020-02-13
STALE2326d

[PATCH] ARM: add support for DEBUG_STACKOVERFLOW

From: Uwe Kleine-König <hidden>
Date: 2020-01-08 08:29:43
Subsystem: arm port, the rest · Maintainers: Russell King, Linus Torvalds

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 <redacted>
---
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(+)
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);
 }
 
-- 
2.24.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help