Dumb kernel stacksize question

Anton Blanchard anton at samba.org
Wed Nov 26 06:02:16 EST 2003



Hi,

> Is there a guideline for the largest thing one should alloc on
> a kernel stack?   I want to have a temp buffer for a workspace,
> but doing a __get_free_page(GFP_KERNEL); free_page(); seems like
> a waste of time & resource If I can get a suitably large buffer
> on the stack.  But I fear overflowing the kernel stack, which,
> if I understand correctly, is limited to 2 pages (or something
> like that?)

I tend to attack any function with over 1kB of stack usage. On ppc64 the
kernel stack is actually 4 pages and we really do need that much. Below
is a quick patch that warns whenever the kernel stack usage goes over
8kB, its not too hard to trip.

Anton

===== arch/ppc64/Kconfig 1.31 vs edited =====


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

diff -puN arch/ppc64/Kconfig~debug_stackoverflow arch/ppc64/Kconfig
--- foo/arch/ppc64/Kconfig~debug_stackoverflow	2003-11-17 12:16:49.623357752 -0600
+++ foo-anton/arch/ppc64/Kconfig	2003-11-17 12:16:49.631357801 -0600
@@ -331,6 +331,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_SLAB
 	bool "Debug memory allocations"
 	depends on DEBUG_KERNEL
diff -puN arch/ppc64/kernel/irq.c~debug_stackoverflow arch/ppc64/kernel/irq.c
--- foo/arch/ppc64/kernel/irq.c~debug_stackoverflow	2003-11-17 12:16:49.627357777 -0600
+++ foo-anton/arch/ppc64/kernel/irq.c	2003-11-17 12:16:49.632357807 -0600
@@ -571,6 +571,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
+
 #ifdef CONFIG_PPC_ISERIES
 	lpaca = get_paca();
 #ifdef CONFIG_SMP

_

** Sent via the linuxppc64-dev mail list. See http://lists.linuxppc.org/





More information about the Linuxppc64-dev mailing list