
From: Anton Blanchard <anton@samba.org>

This adds stack overflow debugging much like x86. Its pretty agressive
and checks if > 8kB out of 16kB of stack is used.


---

 arch/ppc64/Kconfig      |    4 ++++
 arch/ppc64/kernel/irq.c |   15 +++++++++++++++
 2 files changed, 19 insertions(+)

diff -puN arch/ppc64/Kconfig~ppc64-stackoverflow arch/ppc64/Kconfig
--- 25/arch/ppc64/Kconfig~ppc64-stackoverflow	2004-02-21 20:58:26.000000000 -0800
+++ 25-akpm/arch/ppc64/Kconfig	2004-02-21 20:58:26.000000000 -0800
@@ -316,6 +316,10 @@ config DEBUG_KERNEL
 	  Say Y here if you are developing drivers or trying to debug and
 	  identify kernel problems.
 
+config DEBUG_STACKOVERFLOW
+	bool "Check for stack overflows"
+	depends on DEBUG_KERNEL
+
 config DEBUG_STACK_USAGE
 	bool "Stack utilization instrumentation"
 	depends on DEBUG_KERNEL
diff -puN arch/ppc64/kernel/irq.c~ppc64-stackoverflow arch/ppc64/kernel/irq.c
--- 25/arch/ppc64/kernel/irq.c~ppc64-stackoverflow	2004-02-21 20:58:26.000000000 -0800
+++ 25-akpm/arch/ppc64/kernel/irq.c	2004-02-21 20:58:26.000000000 -0800
@@ -568,6 +568,21 @@ int do_IRQ(struct pt_regs *regs)
 
 	irq_enter();
 
+#ifdef CONFIG_DEBUG_STACKOVERFLOW
+	/* Debugging check for stack overflow: is there less than 8KB free? */
+	{
+		long sp;
+
+		sp = (unsigned long)_get_SP() & (THREAD_SIZE-1);
+
+		if (unlikely(sp < (sizeof(struct thread_info) + 8192))) {
+			printk("do_IRQ: stack overflow: %ld\n",
+				sp - sizeof(struct thread_info));
+			dump_stack();
+		}
+	}
+#endif
+
 	lpaca = get_paca();
 #ifdef CONFIG_SMP
 	if (lpaca->xLpPaca.xIntDword.xFields.xIpiCnt) {

_
