* Re: [patch] larger kernel stack (8k->16k) per task (fwd)
@ 2002-02-08 18:40 Balbir Singh
2002-02-08 19:01 ` Tigran Aivazian
0 siblings, 1 reply; 5+ messages in thread
From: Balbir Singh @ 2002-02-08 18:40 UTC (permalink / raw)
To: tigran; +Cc: linux-kernel, balbir_soni
[-- Attachment #1: Type: text/plain, Size: 12342 bytes --]
Thanks, I managed to come up with a patch of my own.
The patch looks good, some comments
1. We do not really have to change the size of INIT_TASK
since that is architecture independent code in sched.h
PARISC is managing with init_task stack of 8K and
other stacks of 16K.
2. I think you missed getuser.S in arch/i386/kernel/lib.
All the __get_user_x should change to
3. I verified that the instance of GET_CURRENT in hw-irq.h
is not being used by anybody and can safely be removed.
__get_user_1:
movl %esp,%edx
andl $~(THREAD_SIZE - 1),%edx
cmpl addr_limit(%edx),%eax
I have a patch that lets the user select any stack size
from 8K to 64K, it can be configured. And yes, it works
on my system.
I do not have the /proc entry that u have though in
my patch.
Would you like to merge both the patches or would you
like me to do it and send out a new version.
The patch is attached along with this email. It
is againt 2.4.17
I believe that using 8K as stack size is correct.
My patch is to help people debug stack overflows
and if they wanted to experiment or port code from
other OS'es (where the code uses a stack > 8K - sizeof
(struct task_struct)) then they can use this patch.
Comments,
Balbir
>Hi Balbir,
>
>Here is my patch that does what you want but only on i386 architecture. I
>am forwarding it to you in case you are not subscribed to linux-kernel
>list.
>
>Regards
>Tigran
>
>---------- Forwarded message ----------
>Date: Fri, 8 Feb 2002 15:20:19 +0000 (GMT)
>From: Tigran Aivazian <tigran@veritas.com>
>To: linux-kernel@vger.kernel.org
>Cc: Hugh Dickins <hugh@veritas.com>
>Subject: [patch] larger kernel stack (8k->16k) per task
>
>Hi,
>
>In the light of some talks here about increasing kernel stack, here is my
>patch for i386 architecture that some may find useful. It also has a nice
>extra (/proc/stack) implemented by Hugh Dickins which helps to find major
>offenders.
>
>It is against 2.4.9 but should be easy to port in any direction. (One way
>the patch could be improved is by making the size CONFIG_ option instead
>of hardcoding). Oh btw, please don't tell me "but now you'd need _four_
>physically-contiguous pages to create a task instead of two!" because I
>know it (and think it's not too bad).
>
>Regards,
>Tigran
>
>diff -urN 249-vx/arch/i386/kernel/entry.S
>249-vx-bigstack/arch/i386/kernel/entry.S
>--- 249-vx/arch/i386/kernel/entry.S Tue Jun 12 19:47:28 2001
>+++ 249-vx-bigstack/arch/i386/kernel/entry.S Sun Jan 13 00:14:30 2002
>@@ -130,7 +130,7 @@
> .previous
>
> #define GET_CURRENT(reg) \
>- movl $-8192, reg; \
>+ movl $-16384, reg; \
> andl %esp, reg
>
> ENTRY(lcall7)
>@@ -145,7 +145,7 @@
> movl %ecx,CS(%esp) #
> movl %esp,%ebx
> pushl %ebx
>- andl $-8192,%ebx # GET_CURRENT
>+ andl $-16384,%ebx # GET_CURRENT
> movl exec_domain(%ebx),%edx # Get the execution domain
> movl 4(%edx),%edx # Get the lcall7 handler for the domain
> pushl $0x7
>@@ -166,7 +166,7 @@
> movl %ecx,CS(%esp) #
> movl %esp,%ebx
> pushl %ebx
>- andl $-8192,%ebx # GET_CURRENT
>+ andl $-16384,%ebx # GET_CURRENT
> movl exec_domain(%ebx),%edx # Get the execution domain
> movl 4(%edx),%edx # Get the lcall7 handler for the domain
> pushl $0x27
>diff -urN 249-vx/arch/i386/kernel/head.S
>249-vx-bigstack/arch/i386/kernel/head.S
>--- 249-vx/arch/i386/kernel/head.S Wed Jun 20 19:00:53 2001
>+++ 249-vx-bigstack/arch/i386/kernel/head.S Sun Jan 13 00:14:30 2002
>@@ -320,7 +320,7 @@
> ret
>
> ENTRY(stack_start)
>- .long SYMBOL_NAME(init_task_union)+8192
>+ .long SYMBOL_NAME(init_task_union)+16384
> .long __KERNEL_DS
>
> /* This is the default interrupt "handler" :-) */
>diff -urN 249-vx/arch/i386/kernel/process.c
>249-vx-bigstack/arch/i386/kernel/process.c
>--- 249-vx/arch/i386/kernel/process.c Thu Jul 26 02:19:11 2001
>+++ 249-vx-bigstack/arch/i386/kernel/process.c Sun Jan 13 00:14:30 2002
>@@ -757,12 +757,12 @@
> return 0;
> stack_page = (unsigned long)p;
> esp = p->thread.esp;
>- if (!stack_page || esp < stack_page || esp > 8188+stack_page)
>+ if (!stack_page || esp < stack_page || esp > 16380+stack_page)
> return 0;
> /* include/asm-i386/system.h:switch_to() pushes ebp last. */
> ebp = *(unsigned long *) esp;
> do {
>- if (ebp < stack_page || ebp > 8184+stack_page)
>+ if (ebp < stack_page || ebp > 16376+stack_page)
> return 0;
> eip = *(unsigned long *) (ebp+4);
> if (eip < first_sched || eip >= last_sched)
>diff -urN 249-vx/arch/i386/kernel/smpboot.c
>249-vx-bigstack/arch/i386/kernel/smpboot.c
>--- 249-vx/arch/i386/kernel/smpboot.c Tue Feb 13 22:13:43 2001
>+++ 249-vx-bigstack/arch/i386/kernel/smpboot.c Sun Jan 13 00:14:30 2002
>@@ -577,7 +577,7 @@
>
> /* So we see what's up */
> printk("Booting processor %d/%d eip %lx\n", cpu, apicid, start_eip);
>- stack_start.esp = (void *) (1024 + PAGE_SIZE + (char *)idle);
>+ stack_start.esp = (void *) idle->thread.esp;
>
> /*
> * This grunge runs the startup process for
>diff -urN 249-vx/arch/i386/kernel/traps.c
>249-vx-bigstack/arch/i386/kernel/traps.c
>--- 249-vx/arch/i386/kernel/traps.c Sun Aug 12 19:13:59 2001
>+++ 249-vx-bigstack/arch/i386/kernel/traps.c Sun Jan 13 00:14:30 2002
>@@ -160,7 +160,7 @@
> unsigned long esp = tsk->thread.esp;
>
> /* User space on another CPU? */
>- if ((esp ^ (unsigned long)tsk) & (PAGE_MASK<<1))
>+ if ((esp ^ (unsigned long)tsk) & ~(THREAD_SIZE-1))
> return;
> show_trace((unsigned long *)esp);
> }
>diff -urN 249-vx/arch/i386/lib/getuser.S
>249-vx-bigstack/arch/i386/lib/getuser.S
>--- 249-vx/arch/i386/lib/getuser.S Mon Jan 12 21:42:52 1998
>+++ 249-vx-bigstack/arch/i386/lib/getuser.S Sun Jan 13 00:14:30 2002
>@@ -28,7 +28,7 @@
> .globl __get_user_1
> __get_user_1:
> movl %esp,%edx
>- andl $0xffffe000,%edx
>+ andl $-16384,%edx
> cmpl addr_limit(%edx),%eax
> jae bad_get_user
> 1: movzbl (%eax),%edx
>@@ -41,7 +41,7 @@
> addl $1,%eax
> movl %esp,%edx
> jc bad_get_user
>- andl $0xffffe000,%edx
>+ andl $-16384,%edx
> cmpl addr_limit(%edx),%eax
> jae bad_get_user
> 2: movzwl -1(%eax),%edx
>@@ -54,7 +54,7 @@
> addl $3,%eax
> movl %esp,%edx
> jc bad_get_user
>- andl $0xffffe000,%edx
>+ andl $-16384,%edx
> cmpl addr_limit(%edx),%eax
> jae bad_get_user
> 3: movl -3(%eax),%edx
>diff -urN 249-vx/arch/i386/vmlinux.lds
>249-vx-bigstack/arch/i386/vmlinux.lds
>--- 249-vx/arch/i386/vmlinux.lds Sat Jan 12 21:31:54 2002
>+++ 249-vx-bigstack/arch/i386/vmlinux.lds Sun Jan 13 00:14:30 2002
>@@ -36,7 +36,7 @@
>
> _edata = .; /* End of data section */
>
>- . = ALIGN(8192); /* init_task */
>+ . = ALIGN(16384); /* init_task */
> .data.init_task : { *(.data.init_task) }
>
> . = ALIGN(4096); /* Init code and data */
>diff -urN 249-vx/include/asm-i386/current.h
>249-vx-bigstack/include/asm-i386/current.h
>--- 249-vx/include/asm-i386/current.h Sat Aug 15 00:35:22 1998
>+++ 249-vx-bigstack/include/asm-i386/current.h Sun Jan 13 00:14:30 2002
>@@ -6,7 +6,7 @@
> static inline struct task_struct * get_current(void)
> {
> struct task_struct *current;
>- __asm__("andl %%esp,%0; ":"=r" (current) : "0" (~8191UL));
>+ __asm__("andl %%esp,%0; ":"=r" (current) : "0" (~16383UL));
> return current;
> }
>
>diff -urN 249-vx/include/asm-i386/hw_irq.h
>249-vx-bigstack/include/asm-i386/hw_irq.h
>--- 249-vx/include/asm-i386/hw_irq.h Wed Aug 15 22:21:11 2001
>+++ 249-vx-bigstack/include/asm-i386/hw_irq.h Sun Jan 13 00:14:30 2002
>@@ -115,7 +115,7 @@
>
> #define GET_CURRENT \
> "movl %esp, %ebx\n\t" \
>- "andl $-8192, %ebx\n\t"
>+ "andl $-16384, %ebx\n\t"
>
> /*
> * SMP has a few special interrupts for IPI messages
>diff -urN 249-vx/include/asm-i386/processor.h
>249-vx-bigstack/include/asm-i386/processor.h
>--- 249-vx/include/asm-i386/processor.h Wed Aug 15 22:21:11 2001
>+++ 249-vx-bigstack/include/asm-i386/processor.h Sun Jan 13 00:14:30 2002
>@@ -445,13 +445,27 @@
> }
>
> unsigned long get_wchan(struct task_struct *p);
>-#define KSTK_EIP(tsk) (((unsigned long *)(4096+(unsigned
>long)(tsk)))[1019])
>-#define KSTK_ESP(tsk) (((unsigned long *)(4096+(unsigned
>long)(tsk)))[1022])
>
>-#define THREAD_SIZE (2*PAGE_SIZE)
>-#define alloc_task_struct() ((struct task_struct *)
>__get_free_pages(GFP_KERNEL,1))
>-#define free_task_struct(p) free_pages((unsigned long) (p), 1)
>-#define get_task_struct(tsk) atomic_inc(&virt_to_page(tsk)->count)
>+#define THREAD_ORDER 2
>+#define THREAD_SIZE (PAGE_SIZE << THREAD_ORDER)
>+#define THREAD_LONGS (THREAD_SIZE / sizeof(unsigned long))
>+
>+#define KSTK_EIP(tsk) (((unsigned long *)(tsk))[THREAD_LONGS-5])
>+#define KSTK_ESP(tsk) (((unsigned long *)(tsk))[THREAD_LONGS-2])
>+
>+#define alloc_task_struct() \
>+ ({ \
>+ unsigned long tsk = __get_free_pages(GFP_KERNEL, THREAD_ORDER); \
>+ if (tsk != 0) { \
>+ /* Alt-SysRq-T show_task() show if stack went deep */ \
>+ memset((char*)tsk+sizeof(struct task_struct), 0, \
>+ THREAD_SIZE-sizeof(struct task_struct)); \
>+ } \
>+ (struct task_struct *) tsk; \
>+ })
>+
>+#define free_task_struct(tsk) free_pages((unsigned long) (tsk),
>THREAD_ORDER)
>+#define get_task_struct(tsk) atomic_inc(&virt_to_page(tsk)->count)
>
> #define init_task (init_task_union.task)
> #define init_stack (init_task_union.stack)
>diff -urN 249-vx/include/linux/sched.h
>249-vx-bigstack/include/linux/sched.h
>--- 249-vx/include/linux/sched.h Sat Jan 12 23:53:58 2002
>+++ 249-vx-bigstack/include/linux/sched.h Sun Jan 13 00:14:30 2002
>@@ -484,7 +484,7 @@
>
>
> #ifndef INIT_TASK_SIZE
>-# define INIT_TASK_SIZE 2048*sizeof(long)
>+# define INIT_TASK_SIZE 4096*sizeof(long)
> #endif
>
> union task_union {
>diff -urN 249-vx/kernel/exit.c 249-vx-bigstack/kernel/exit.c
>--- 249-vx/kernel/exit.c Sun Aug 12 18:52:29 2001
>+++ 249-vx-bigstack/kernel/exit.c Sun Jan 13 00:14:30 2002
>@@ -11,6 +11,7 @@
> #include <linux/module.h>
> #include <linux/completion.h>
> #include <linux/tty.h>
>+#include <linux/proc_fs.h>
> #ifdef CONFIG_BSD_PROCESS_ACCT
> #include <linux/acct.h>
> #endif
>@@ -24,6 +25,74 @@
>
> int getrusage(struct task_struct *, int, struct rusage *);
>
>+#ifdef CONFIG_PROC_FS
>+static int max_stack_depth;
>+static pid_t max_stack_pid;
>+static struct task_struct *max_stack_task; /* kept for kdb */
>+static spinlock_t max_stack_lock = SPIN_LOCK_UNLOCKED;
>+static void check_stack_depth(struct task_struct *);
>+
>+static int stack_read_proc(char *page, char **start, off_t off,
>+ int count, int *eof, void *data)
>+{
>+ struct task_struct *p;
>+ int len;
>+
>+ read_lock(&tasklist_lock);
>+ for_each_task(p)
>+ check_stack_depth(p);
>+ read_unlock(&tasklist_lock);
>+
>+ spin_lock(&max_stack_lock);
>+ len = sprintf(page,
>+ "Deepest stack is 0x%04x (+ task 0x%04x = 0x%04x) for pid %d %.16s\n",
>+ max_stack_depth, sizeof(*p), sizeof(*p) + max_stack_depth,
>+ max_stack_pid, max_stack_task->comm);
>+ spin_unlock(&max_stack_lock);
>+
>+ *eof = (len <= off + count);
>+ *start = page + off;
>+ len -= off;
>+ if (len > count)
>+ len = count;
>+ if (len < 0)
>+ len = 0;
>+ return len;
>+}
>+
>+static void check_stack_depth(struct task_struct *p)
>+{
>+ int depth;
>+ struct task_struct *old_stack_task;
>+ unsigned long *sp = (unsigned long *)(p + 1);
>+
>+ while (!*sp)
>+ sp++;
>+ depth = (int)p + THREAD_SIZE - (int)sp;
>+ if (depth <= max_stack_depth)
>+ return;
>+
>+ old_stack_task = NULL;
>+ spin_lock(&max_stack_lock);
>+ if (depth > max_stack_depth) {
>+ old_stack_task = max_stack_task;
>+ max_stack_depth = depth;
>+ max_stack_pid = p->pid;
>+ max_stack_task = p;
>+ get_task_struct(p);
>+ }
>+ spin_unlock(&max_stack_lock);
>+
>+ if (old_stack_task)
>+ free_task_struct(old_stack_task);
>+ else
>+ create_proc_read_entry("stack",
>+ 0444, NULL, stack_read_proc, NULL);
>+}
>+#else /* ndef CONFIG_PROC_FS */
>+#define check_stack_depth(p) do { } while (0)
>+#endif /* ndef CONFIG_PROC_FS */
>+
> static void release_task(struct task_struct * p)
> {
> if (p != current) {
>@@ -63,6 +132,7 @@
> current->counter += p->counter;
> if (current->counter >= MAX_COUNTER)
> current->counter = MAX_COUNTER;
>+ check_stack_depth(p);
> p->pid = 0;
> free_task_struct(p);
> } else {
>
>
_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com
[-- Attachment #2: big_stack_patch.diff --]
[-- Type: application/octet-stream, Size: 6595 bytes --]
diff -Naur linux/arch/i386/config.in linux-new/arch/i386/config.in
--- linux/arch/i386/config.in Fri Dec 21 10:41:53 2001
+++ linux-new/arch/i386/config.in Wed Feb 6 19:14:10 2002
@@ -413,6 +413,26 @@
bool ' Magic SysRq key' CONFIG_MAGIC_SYSRQ
bool ' Spinlock debugging' CONFIG_DEBUG_SPINLOCK
bool ' Verbose BUG() reporting (adds 70K)' CONFIG_DEBUG_BUGVERBOSE
-fi
+ choice 'Bigger Stack Size Support' \
+ "off CONFIG_NOBIGSTACK \
+ 16KB CONFIG_STACK_SIZE_16KB \
+ 32KB CONFIG_STACK_SIZE_32KB \
+ 64KB CONFIG_STACK_SIZE_64KB" off
+ if [ "$CONFIG_NOBIGSTACK" = "y" ]; then
+ define_int CONFIG_STACK_SIZE_SHIFT 1
+ else
+ if [ "$CONFIG_STACK_SIZE_16KB" = "y" ]; then
+ define_int CONFIG_STACK_SIZE_SHIFT 2
+ else
+ if [ "$CONFIG_STACK_SIZE_32KB" = "y" ]; then
+ define_int CONFIG_STACK_SIZE_SHIFT 3
+ else
+ if [ "$CONFIG_STACK_SIZE_64KB" = "y" ]; then
+ define_int CONFIG_STACK_SIZE_SHIF 4
+ fi
+ fi
+ fi
+ fi
+fi
endmenu
diff -Naur linux/arch/i386/kernel/entry.S linux-new/arch/i386/kernel/entry.S
--- linux/arch/i386/kernel/entry.S Fri Nov 2 18:18:49 2001
+++ linux-new/arch/i386/kernel/entry.S Wed Feb 6 18:51:55 2002
@@ -45,6 +45,7 @@
#include <linux/linkage.h>
#include <asm/segment.h>
#include <asm/smp.h>
+#include <asm/current.h>
EBX = 0x00
ECX = 0x04
@@ -128,10 +129,6 @@
.long 3b,6b; \
.previous
-#define GET_CURRENT(reg) \
- movl $-8192, reg; \
- andl %esp, reg
-
ENTRY(lcall7)
pushfl # We get a different stack layout with call gates,
pushl %eax # which has to be cleaned up later..
@@ -144,7 +141,7 @@
movl %ecx,CS(%esp) #
movl %esp,%ebx
pushl %ebx
- andl $-8192,%ebx # GET_CURRENT
+ andl $-THREAD_SIZE,%ebx # GET_CURRENT
movl exec_domain(%ebx),%edx # Get the execution domain
movl 4(%edx),%edx # Get the lcall7 handler for the domain
pushl $0x7
@@ -165,7 +162,7 @@
movl %ecx,CS(%esp) #
movl %esp,%ebx
pushl %ebx
- andl $-8192,%ebx # GET_CURRENT
+ andl $-THREAD_SIZE,%ebx # GET_CURRENT
movl exec_domain(%ebx),%edx # Get the execution domain
movl 4(%edx),%edx # Get the lcall7 handler for the domain
pushl $0x27
diff -Naur linux/arch/i386/kernel/init_task.c linux-new/arch/i386/kernel/init_task.c
--- linux/arch/i386/kernel/init_task.c Mon Sep 17 16:29:09 2001
+++ linux-new/arch/i386/kernel/init_task.c Wed Feb 6 16:43:52 2002
@@ -14,7 +14,7 @@
/*
* Initial task structure.
*
- * We need to make sure that this is 8192-byte aligned due to the
+ * We need to make sure that this is 16384-byte aligned due to the
* way process stacks are handled. This is done by having a special
* "init_task" linker map entry..
*/
diff -Naur linux/arch/i386/lib/getuser.S linux-new/arch/i386/lib/getuser.S
--- linux/arch/i386/lib/getuser.S Mon Jan 12 14:42:52 1998
+++ linux-new/arch/i386/lib/getuser.S Fri Feb 8 11:20:26 2002
@@ -21,6 +21,10 @@
* as they get called from within inline assembly.
*/
+/* Duplicated from asm/processor.h */
+#include <asm/current.h>
+#include <linux/config.h>
+
addr_limit = 12
.text
@@ -28,7 +32,7 @@
.globl __get_user_1
__get_user_1:
movl %esp,%edx
- andl $0xffffe000,%edx
+ andl $~(THREAD_SIZE - 1),%edx
cmpl addr_limit(%edx),%eax
jae bad_get_user
1: movzbl (%eax),%edx
@@ -41,7 +45,7 @@
addl $1,%eax
movl %esp,%edx
jc bad_get_user
- andl $0xffffe000,%edx
+ andl $~(THREAD_SIZE - 1),%edx
cmpl addr_limit(%edx),%eax
jae bad_get_user
2: movzwl -1(%eax),%edx
@@ -54,7 +58,7 @@
addl $3,%eax
movl %esp,%edx
jc bad_get_user
- andl $0xffffe000,%edx
+ andl $~(THREAD_SIZE - 1),%edx
cmpl addr_limit(%edx),%eax
jae bad_get_user
3: movl -3(%eax),%edx
diff -Naur linux/include/asm-i386/current.h linux-new/include/asm-i386/current.h
--- linux/include/asm-i386/current.h Fri Aug 14 17:35:22 1998
+++ linux-new/include/asm-i386/current.h Wed Feb 6 20:05:53 2002
@@ -1,15 +1,44 @@
#ifndef _I386_CURRENT_H
#define _I386_CURRENT_H
+#include <asm/page.h>
+
+/*
+ * Configurable page sizes on i386, mainly for debugging purposes.
+ * (c) Balbir Singh
+ */
+
+#ifdef __ASSEMBLY__
+
+#define PAGE_SIZE 4096 /* as cannot handle 1UL << 12 */
+#define THREAD_SIZE ((1 << CONFIG_STACK_SIZE_SHIFT) * PAGE_SIZE)
+
+#else /* __ASSEMBLY__ */
+
+#define THREAD_SIZE ((1 << CONFIG_STACK_SIZE_SHIFT) * PAGE_SIZE)
+#define alloc_task_struct() \
+ ((struct task_struct *) __get_free_pages(GFP_KERNEL,CONFIG_STACK_SIZE_SHIFT))
+
+#define free_task_struct(p) \
+ free_pages((unsigned long) (p), CONFIG_STACK_SIZE_SHIFT)
+
struct task_struct;
static inline struct task_struct * get_current(void)
{
struct task_struct *current;
- __asm__("andl %%esp,%0; ":"=r" (current) : "0" (~8191UL));
+ __asm__("andl %%esp,%0; ":"=r" (current) : "0" (~(THREAD_SIZE - 1)));
return current;
- }
-
+}
+
#define current get_current()
+#endif /* __ASSEMBLY__ */
+
+#define GET_CURRENT(reg) \
+ movl $-THREAD_SIZE, (reg); \
+ andl %esp, (reg)
+
+
#endif /* !(_I386_CURRENT_H) */
+#define THREAD_SIZE ((1 << CONFIG_STACK_SIZE_SHIFT) * PAGE_SIZE)
diff -Naur linux/include/asm-i386/hw_irq.h linux-new/include/asm-i386/hw_irq.h
--- linux/include/asm-i386/hw_irq.h Thu Nov 22 12:46:18 2001
+++ linux-new/include/asm-i386/hw_irq.h Wed Feb 6 20:05:55 2002
@@ -15,6 +15,7 @@
#include <linux/config.h>
#include <asm/atomic.h>
#include <asm/irq.h>
+#include <asm/current.h>
/*
* IDT vectors usable for external interrupt sources start
@@ -113,10 +114,6 @@
#define IRQ_NAME2(nr) nr##_interrupt(void)
#define IRQ_NAME(nr) IRQ_NAME2(IRQ##nr)
-#define GET_CURRENT \
- "movl %esp, %ebx\n\t" \
- "andl $-8192, %ebx\n\t"
-
/*
* SMP has a few special interrupts for IPI messages
*/
diff -Naur linux/include/asm-i386/processor.h linux-new/include/asm-i386/processor.h
--- linux/include/asm-i386/processor.h Thu Nov 22 12:46:19 2001
+++ linux-new/include/asm-i386/processor.h Wed Feb 6 20:05:55 2002
@@ -14,6 +14,7 @@
#include <asm/types.h>
#include <asm/sigcontext.h>
#include <asm/cpufeature.h>
+#include <asm/current.h>
#include <linux/cache.h>
#include <linux/config.h>
#include <linux/threads.h>
@@ -447,9 +448,6 @@
#define KSTK_EIP(tsk) (((unsigned long *)(4096+(unsigned long)(tsk)))[1019])
#define KSTK_ESP(tsk) (((unsigned long *)(4096+(unsigned long)(tsk)))[1022])
-#define THREAD_SIZE (2*PAGE_SIZE)
-#define alloc_task_struct() ((struct task_struct *) __get_free_pages(GFP_KERNEL,1))
-#define free_task_struct(p) free_pages((unsigned long) (p), 1)
#define get_task_struct(tsk) atomic_inc(&virt_to_page(tsk)->count)
#define init_task (init_task_union.task)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch] larger kernel stack (8k->16k) per task (fwd)
2002-02-08 18:40 Balbir Singh
@ 2002-02-08 19:01 ` Tigran Aivazian
0 siblings, 0 replies; 5+ messages in thread
From: Tigran Aivazian @ 2002-02-08 19:01 UTC (permalink / raw)
To: Balbir Singh; +Cc: linux-kernel
Hi Balbir,
On Fri, 8 Feb 2002, Balbir Singh wrote:
> 2. I think you missed getuser.S in arch/i386/kernel/lib.
> All the __get_user_x should change to
no, I didn't miss them. If you read the patch again you will see them.
>
> 3. I verified that the instance of GET_CURRENT in hw-irq.h
> is not being used by anybody and can safely be removed.
yes, I also verified and came to the same conclusion but left the change
in the patch on purpose (so if anyone does start using it, it is already
correct)
>
> __get_user_1:
> movl %esp,%edx
> andl $~(THREAD_SIZE - 1),%edx
> cmpl addr_limit(%edx),%eax
>
> I have a patch that lets the user select any stack size
> from 8K to 64K, it can be configured. And yes, it works
> on my system.
>
> I do not have the /proc entry that u have though in
> my patch.
>
> Would you like to merge both the patches or would you
> like me to do it and send out a new version.
>
>
> The patch is attached along with this email. It
> is againt 2.4.17
The serious problem with your patch is that you missed quite a few places
(e.g. smpboot.c and traps.c). Most importantly, you missed the alignment
in vmlinux.lds so I guess your machine boots by pure luck :) In the early
stages (first hours of writing it) I missed that one too and was puzzled
by random panics on boot...
Actually, the patch I sent is only part of the "complete piece", the other
part being changes to kdb to work correctly with large stack. I can
separate those from kdb patch that I use and send out if there was enough
interest.
Regards,
Tigran
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch] larger kernel stack (8k->16k) per task (fwd)
@ 2002-02-08 19:23 Balbir Singh
0 siblings, 0 replies; 5+ messages in thread
From: Balbir Singh @ 2002-02-08 19:23 UTC (permalink / raw)
To: tigran; +Cc: linux-kernel
Hi Tigran,
>From: Tigran Aivazian <tigran@veritas.com>
>To: Balbir Singh <balbir_soni@hotmail.com>
>CC: <linux-kernel@vger.kernel.org>
>Subject: Re: [patch] larger kernel stack (8k->16k) per task (fwd)
>Date: Fri, 8 Feb 2002 19:01:06 +0000 (GMT)
>
>Hi Balbir,
>
>On Fri, 8 Feb 2002, Balbir Singh wrote:
> > 2. I think you missed getuser.S in arch/i386/kernel/lib.
> > All the __get_user_x should change to
>
>no, I didn't miss them. If you read the patch again you will see them.
>
> >
> > 3. I verified that the instance of GET_CURRENT in hw-irq.h
> > is not being used by anybody and can safely be removed.
>
>yes, I also verified and came to the same conclusion but left the change
>in the patch on purpose (so if anyone does start using it, it is already
>correct)
>
> >
> > __get_user_1:
> > movl %esp,%edx
> > andl $~(THREAD_SIZE - 1),%edx
> > cmpl addr_limit(%edx),%eax
> >
> > I have a patch that lets the user select any stack size
> > from 8K to 64K, it can be configured. And yes, it works
> > on my system.
> >
> > I do not have the /proc entry that u have though in
> > my patch.
> >
> > Would you like to merge both the patches or would you
> > like me to do it and send out a new version.
> >
> >
> > The patch is attached along with this email. It
> > is againt 2.4.17
>
>The serious problem with your patch is that you missed quite a few places
>(e.g. smpboot.c and traps.c). Most importantly, you missed the alignment
>in vmlinux.lds so I guess your machine boots by pure luck :) In the early
>stages (first hours of writing it) I missed that one too and was puzzled
>by random panics on boot...
>
I can explain the vmlinux.lds with the fact that
I think we should not change the size of init_task
in sched.h. It would affect all the architectures.
As I mentioned, I followed the PARISC model.
Yes, I did miss out changes in traps.c and smpboot.c
Thanks for pointing them out.
>Actually, the patch I sent is only part of the "complete piece", the other
>part being changes to kdb to work correctly with large stack. I can
>separate those from kdb patch that I use and send out if there was enough
>interest.
>
>Regards,
>Tigran
>
_________________________________________________________________
MSN Photos is the easiest way to share and print your photos:
http://photos.msn.com/support/worldwide.aspx
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch] larger kernel stack (8k->16k) per task (fwd)
@ 2002-02-08 20:42 Balbir Singh
2002-02-08 21:11 ` William Lee Irwin III
0 siblings, 1 reply; 5+ messages in thread
From: Balbir Singh @ 2002-02-08 20:42 UTC (permalink / raw)
To: tigran; +Cc: linux-kernel, balbir_soni
[-- Attachment #1: Type: text/plain, Size: 2551 bytes --]
Modified the patch to fix smpboot.c and traps.c
vmlinux.lds and sched.h need not be fixed. The
size of INIT_TASK is still 8K, so that other
architectures using 8K stacks are not hurt.
This is a patch specific to i386. Its main use is to debug
kernel code which causes an overflow of the kernel stack.
It is highly recommended to use the existing stack size of
8KB, increasing the stack size to 16KB with an 200
processes running on an average causes 1.5MB of
extra memory to be used.
I have tested this patch on my desktop to my satisfaction.
I do not think that this affects an SMP system. Testing on
an SMP box and reporting Bugs and/or success of the patch
would be highly appreciated.
The patch is included as an attachment along with this
email.
>
>Hi Balbir,
>
>On Fri, 8 Feb 2002, Balbir Singh wrote:
> > 2. I think you missed getuser.S in arch/i386/kernel/lib.
> > All the __get_user_x should change to
>
>no, I didn't miss them. If you read the patch again you will see them.
>
> >
> > 3. I verified that the instance of GET_CURRENT in hw-irq.h
> > is not being used by anybody and can safely be removed.
>
>yes, I also verified and came to the same conclusion but left the change
>in the patch on purpose (so if anyone does start using it, it is already
>correct)
>
> >
> > __get_user_1:
> > movl %esp,%edx
> > andl $~(THREAD_SIZE - 1),%edx
> > cmpl addr_limit(%edx),%eax
> >
> > I have a patch that lets the user select any stack size
> > from 8K to 64K, it can be configured. And yes, it works
> > on my system.
> >
> > I do not have the /proc entry that u have though in
> > my patch.
> >
> > Would you like to merge both the patches or would you
> > like me to do it and send out a new version.
> >
> >
> > The patch is attached along with this email. It
> > is againt 2.4.17
>
>The serious problem with your patch is that you missed quite a few places
>(e.g. smpboot.c and traps.c). Most importantly, you missed the alignment
>in vmlinux.lds so I guess your machine boots by pure luck :) In the early
>stages (first hours of writing it) I missed that one too and was puzzled
>by random panics on boot...
>
>Actually, the patch I sent is only part of the "complete piece", the other
>part being changes to kdb to work correctly with large stack. I can
>separate those from kdb patch that I use and send out if there was enough
>interest.
>
>Regards,
>Tigran
>
_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com
[-- Attachment #2: big_stack_patch.diff.txt --]
[-- Type: text/plain, Size: 7455 bytes --]
diff -Naur linux/arch/i386/config.in linux-new/arch/i386/config.in
--- linux/arch/i386/config.in Fri Dec 21 10:41:53 2001
+++ linux-new/arch/i386/config.in Wed Feb 6 19:14:10 2002
@@ -413,6 +413,26 @@
bool ' Magic SysRq key' CONFIG_MAGIC_SYSRQ
bool ' Spinlock debugging' CONFIG_DEBUG_SPINLOCK
bool ' Verbose BUG() reporting (adds 70K)' CONFIG_DEBUG_BUGVERBOSE
-fi
+ choice 'Bigger Stack Size Support' \
+ "off CONFIG_NOBIGSTACK \
+ 16KB CONFIG_STACK_SIZE_16KB \
+ 32KB CONFIG_STACK_SIZE_32KB \
+ 64KB CONFIG_STACK_SIZE_64KB" off
+ if [ "$CONFIG_NOBIGSTACK" = "y" ]; then
+ define_int CONFIG_STACK_SIZE_SHIFT 1
+ else
+ if [ "$CONFIG_STACK_SIZE_16KB" = "y" ]; then
+ define_int CONFIG_STACK_SIZE_SHIFT 2
+ else
+ if [ "$CONFIG_STACK_SIZE_32KB" = "y" ]; then
+ define_int CONFIG_STACK_SIZE_SHIFT 3
+ else
+ if [ "$CONFIG_STACK_SIZE_64KB" = "y" ]; then
+ define_int CONFIG_STACK_SIZE_SHIF 4
+ fi
+ fi
+ fi
+ fi
+fi
endmenu
diff -Naur linux/arch/i386/kernel/entry.S linux-new/arch/i386/kernel/entry.S
--- linux/arch/i386/kernel/entry.S Fri Nov 2 18:18:49 2001
+++ linux-new/arch/i386/kernel/entry.S Wed Feb 6 18:51:55 2002
@@ -45,6 +45,7 @@
#include <linux/linkage.h>
#include <asm/segment.h>
#include <asm/smp.h>
+#include <asm/current.h>
EBX = 0x00
ECX = 0x04
@@ -128,10 +129,6 @@
.long 3b,6b; \
.previous
-#define GET_CURRENT(reg) \
- movl $-8192, reg; \
- andl %esp, reg
-
ENTRY(lcall7)
pushfl # We get a different stack layout with call gates,
pushl %eax # which has to be cleaned up later..
@@ -144,7 +141,7 @@
movl %ecx,CS(%esp) #
movl %esp,%ebx
pushl %ebx
- andl $-8192,%ebx # GET_CURRENT
+ andl $-THREAD_SIZE,%ebx # GET_CURRENT
movl exec_domain(%ebx),%edx # Get the execution domain
movl 4(%edx),%edx # Get the lcall7 handler for the domain
pushl $0x7
@@ -165,7 +162,7 @@
movl %ecx,CS(%esp) #
movl %esp,%ebx
pushl %ebx
- andl $-8192,%ebx # GET_CURRENT
+ andl $-THREAD_SIZE,%ebx # GET_CURRENT
movl exec_domain(%ebx),%edx # Get the execution domain
movl 4(%edx),%edx # Get the lcall7 handler for the domain
pushl $0x27
diff -Naur linux/arch/i386/kernel/init_task.c
linux-new/arch/i386/kernel/init_task.c
--- linux/arch/i386/kernel/init_task.c Mon Sep 17 16:29:09 2001
+++ linux-new/arch/i386/kernel/init_task.c Wed Feb 6 16:43:52 2002
@@ -14,7 +14,7 @@
/*
* Initial task structure.
*
- * We need to make sure that this is 8192-byte aligned due to the
+ * We need to make sure that this is 16384-byte aligned due to the
* way process stacks are handled. This is done by having a special
* "init_task" linker map entry..
*/
diff -Naur linux/arch/i386/kernel/smpboot.c
linux-new/arch/i386/kernel/smpboot.c
--- linux/arch/i386/kernel/smpboot.c Fri Dec 21 10:41:53 2001
+++ linux-new/arch/i386/kernel/smpboot.c Fri Feb 8 13:23:28 2002
@@ -819,7 +819,7 @@
/* So we see what's up */
printk("Booting processor %d/%d eip %lx\n", cpu, apicid, start_eip);
- stack_start.esp = (void *) (1024 + PAGE_SIZE + (char *)idle);
+ stack_start.esp = (void *)idle->thread.esp;
/*
* This grunge runs the startup process for
diff -Naur linux/arch/i386/kernel/traps.c linux-new/arch/i386/kernel/traps.c
--- linux/arch/i386/kernel/traps.c Sun Sep 30 13:26:08 2001
+++ linux-new/arch/i386/kernel/traps.c Fri Feb 8 13:20:04 2002
@@ -158,7 +158,7 @@
unsigned long esp = tsk->thread.esp;
/* User space on another CPU? */
- if ((esp ^ (unsigned long)tsk) & (PAGE_MASK<<1))
+ if ((esp ^ (unsigned long)tsk) & ~(THREAD_SIZE - 1))
return;
show_trace((unsigned long *)esp);
}
diff -Naur linux/arch/i386/lib/getuser.S linux-new/arch/i386/lib/getuser.S
--- linux/arch/i386/lib/getuser.S Mon Jan 12 14:42:52 1998
+++ linux-new/arch/i386/lib/getuser.S Fri Feb 8 11:20:26 2002
@@ -21,6 +21,10 @@
* as they get called from within inline assembly.
*/
+/* Duplicated from asm/processor.h */
+#include <asm/current.h>
+#include <linux/config.h>
+
addr_limit = 12
.text
@@ -28,7 +32,7 @@
.globl __get_user_1
__get_user_1:
movl %esp,%edx
- andl $0xffffe000,%edx
+ andl $~(THREAD_SIZE - 1),%edx
cmpl addr_limit(%edx),%eax
jae bad_get_user
1: movzbl (%eax),%edx
@@ -41,7 +45,7 @@
addl $1,%eax
movl %esp,%edx
jc bad_get_user
- andl $0xffffe000,%edx
+ andl $~(THREAD_SIZE - 1),%edx
cmpl addr_limit(%edx),%eax
jae bad_get_user
2: movzwl -1(%eax),%edx
@@ -54,7 +58,7 @@
addl $3,%eax
movl %esp,%edx
jc bad_get_user
- andl $0xffffe000,%edx
+ andl $~(THREAD_SIZE - 1),%edx
cmpl addr_limit(%edx),%eax
jae bad_get_user
3: movl -3(%eax),%edx
diff -Naur linux/include/asm-i386/current.h
linux-new/include/asm-i386/current.h
--- linux/include/asm-i386/current.h Fri Aug 14 17:35:22 1998
+++ linux-new/include/asm-i386/current.h Wed Feb 6 20:05:53 2002
@@ -1,15 +1,44 @@
#ifndef _I386_CURRENT_H
#define _I386_CURRENT_H
+#include <asm/page.h>
+
+/*
+ * Configurable page sizes on i386, mainly for debugging purposes.
+ * (c) Balbir Singh
+ */
+
+#ifdef __ASSEMBLY__
+
+#define PAGE_SIZE 4096 /* as cannot handle 1UL << 12 */
+#define THREAD_SIZE ((1 << CONFIG_STACK_SIZE_SHIFT) * PAGE_SIZE)
+
+#else /* __ASSEMBLY__ */
+
+#define THREAD_SIZE ((1 << CONFIG_STACK_SIZE_SHIFT) * PAGE_SIZE)
+#define alloc_task_struct() \
+ ((struct task_struct *)
__get_free_pages(GFP_KERNEL,CONFIG_STACK_SIZE_SHIFT))
+
+#define free_task_struct(p) \
+ free_pages((unsigned long) (p), CONFIG_STACK_SIZE_SHIFT)
+
struct task_struct;
static inline struct task_struct * get_current(void)
{
struct task_struct *current;
- __asm__("andl %%esp,%0; ":"=r" (current) : "0" (~8191UL));
+ __asm__("andl %%esp,%0; ":"=r" (current) : "0" (~(THREAD_SIZE - 1)));
return current;
- }
-
+}
+
#define current get_current()
+#endif /* __ASSEMBLY__ */
+
+#define GET_CURRENT(reg) \
+ movl $-THREAD_SIZE, (reg); \
+ andl %esp, (reg)
+
+
#endif /* !(_I386_CURRENT_H) */
+#define THREAD_SIZE ((1 << CONFIG_STACK_SIZE_SHIFT) * PAGE_SIZE)
diff -Naur linux/include/asm-i386/hw_irq.h
linux-new/include/asm-i386/hw_irq.h
--- linux/include/asm-i386/hw_irq.h Thu Nov 22 12:46:18 2001
+++ linux-new/include/asm-i386/hw_irq.h Wed Feb 6 20:05:55 2002
@@ -15,6 +15,7 @@
#include <linux/config.h>
#include <asm/atomic.h>
#include <asm/irq.h>
+#include <asm/current.h>
/*
* IDT vectors usable for external interrupt sources start
@@ -113,10 +114,6 @@
#define IRQ_NAME2(nr) nr##_interrupt(void)
#define IRQ_NAME(nr) IRQ_NAME2(IRQ##nr)
-#define GET_CURRENT \
- "movl %esp, %ebx\n\t" \
- "andl $-8192, %ebx\n\t"
-
/*
* SMP has a few special interrupts for IPI messages
*/
diff -Naur linux/include/asm-i386/processor.h
linux-new/include/asm-i386/processor.h
--- linux/include/asm-i386/processor.h Thu Nov 22 12:46:19 2001
+++ linux-new/include/asm-i386/processor.h Wed Feb 6 20:05:55 2002
@@ -14,6 +14,7 @@
#include <asm/types.h>
#include <asm/sigcontext.h>
#include <asm/cpufeature.h>
+#include <asm/current.h>
#include <linux/cache.h>
#include <linux/config.h>
#include <linux/threads.h>
@@ -447,9 +448,6 @@
#define KSTK_EIP(tsk) (((unsigned long *)(4096+(unsigned long)(tsk)))[1019])
#define KSTK_ESP(tsk) (((unsigned long *)(4096+(unsigned long)(tsk)))[1022])
-#define THREAD_SIZE (2*PAGE_SIZE)
-#define alloc_task_struct() ((struct task_struct *)
__get_free_pages(GFP_KERNEL,1))
-#define free_task_struct(p) free_pages((unsigned long) (p), 1)
#define get_task_struct(tsk) atomic_inc(&virt_to_page(tsk)->count)
#define init_task (init_task_union.task)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch] larger kernel stack (8k->16k) per task (fwd)
2002-02-08 20:42 [patch] larger kernel stack (8k->16k) per task (fwd) Balbir Singh
@ 2002-02-08 21:11 ` William Lee Irwin III
0 siblings, 0 replies; 5+ messages in thread
From: William Lee Irwin III @ 2002-02-08 21:11 UTC (permalink / raw)
To: Balbir Singh; +Cc: tigran, linux-kernel
On Fri, Feb 08, 2002 at 12:42:02PM -0800, Balbir Singh wrote:
> It is highly recommended to use the existing stack size of
> 8KB, increasing the stack size to 16KB with an 200
> processes running on an average causes 1.5MB of
> extra memory to be used.
This sounds small compared to the costs of struct page.
Of course, I would be concerned regardless if this patch
were for anything but debugging.
Excellent work!
Cheers,
Bill
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2002-02-08 21:12 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-02-08 20:42 [patch] larger kernel stack (8k->16k) per task (fwd) Balbir Singh
2002-02-08 21:11 ` William Lee Irwin III
-- strict thread matches above, loose matches on Subject: below --
2002-02-08 19:23 Balbir Singh
2002-02-08 18:40 Balbir Singh
2002-02-08 19:01 ` Tigran Aivazian
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox