Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / kernel_patches / patches / configurable-x86-stack-2.4.21-chaos.patch
1 Index: linux-2.4.21-27.EL/include/asm-i386/hw_irq.h
2 ===================================================================
3 --- linux-2.4.21-27.EL.orig/include/asm-i386/hw_irq.h   2004-12-21 13:51:09.000000000 -0500
4 +++ linux-2.4.21-27.EL/include/asm-i386/hw_irq.h        2005-01-07 10:55:45.367690072 -0500
5 @@ -135,21 +135,17 @@
6         "                                                               \
7         /* load the real stack - keep the offset */                     \
8                                                                         \
9 -       movl $-8192, %ebx;                                              \
10 +       movl $- " STR(THREAD_SIZE) ", %ebx;                             \
11         andl %esp, %ebx;                                                \
12         movl 36(%ebx), %edx;                                            \
13         movl %esp, %ebx;                                                \
14 -       andl $0x1fff, %ebx;                                             \
15 +       andl $( " STR(THREAD_SIZE) "-1), %ebx;                          \
16         orl %ebx, %edx;                                                 \
17         movl %edx, %esp;"
18  
19  #define IRQ_NAME2(nr) nr##_interrupt(void)
20  #define IRQ_NAME(nr) IRQ_NAME2(IRQ##nr)
21  
22 -#define GET_CURRENT \
23 -       "movl %esp, %ebx\n\t" \
24 -       "andl $-8192, %ebx\n\t"
25 -
26  /*
27   *     SMP has a few special interrupts for IPI messages
28   */
29 Index: linux-2.4.21-27.EL/include/asm-i386/processor.h
30 ===================================================================
31 --- linux-2.4.21-27.EL.orig/include/asm-i386/processor.h        2004-12-21 13:51:31.000000000 -0500
32 +++ linux-2.4.21-27.EL/include/asm-i386/processor.h     2005-01-07 10:55:45.376688704 -0500
33 @@ -14,6 +14,7 @@
34  #include <asm/types.h>
35  #include <asm/sigcontext.h>
36  #include <asm/cpufeature.h>
37 +#include <asm/current.h>
38  #include <linux/cache.h>
39  #include <linux/config.h>
40  #include <linux/threads.h>
41 @@ -490,10 +491,6 @@
42  #define KSTK_EIP(tsk)  (((unsigned long *)(4096+(unsigned long)(tsk)))[1019])
43  #define KSTK_ESP(tsk)  (((unsigned long *)(4096+(unsigned long)(tsk)))[1022])
44  
45 -#define THREAD_SIZE (2*PAGE_SIZE)
46 -#define __alloc_task_struct() ((struct task_struct *) __get_free_pages(GFP_KERNEL,1))
47 -#define __free_task_struct(p) do { BUG_ON((p)->state < TASK_ZOMBIE); free_pages((unsigned long) (p), 1); } while (0)
48 -
49  #define init_task      (init_task_union.task)
50  #define init_stack     (init_task_union.stack)
51  
52 Index: linux-2.4.21-27.EL/include/asm-i386/current.h
53 ===================================================================
54 --- linux-2.4.21-27.EL.orig/include/asm-i386/current.h  1998-08-14 19:35:22.000000000 -0400
55 +++ linux-2.4.21-27.EL/include/asm-i386/current.h       2005-01-07 10:55:45.356691744 -0500
56 @@ -1,15 +1,64 @@
57  #ifndef _I386_CURRENT_H
58  #define _I386_CURRENT_H
59 +#include <asm/page.h>
60 +
61 +/*
62 + * Configurable page sizes on i386, mainly for debugging purposes.
63 + * (c) Balbir Singh
64 + */
65 +
66 +/* enumerate the values, include/asm-i386/hw_irq.h in particular needs this */
67 +#if (PAGE_SIZE != 4096)
68 +#error PAGE_SIZE != 4096 unsupported
69 +#endif
70 +
71 +#if (CONFIG_STACK_SIZE_SHIFT == 0)
72 +#define THREAD_SIZE    4096
73 +#elif (CONFIG_STACK_SIZE_SHIFT == 1)
74 +#define THREAD_SIZE    8192
75 +#elif (CONFIG_STACK_SIZE_SHIFT == 2)
76 +#define THREAD_SIZE    16384
77 +#elif (CONFIG_STACK_SIZE_SHIFT == 3)
78 +#define THREAD_SIZE    32768
79 +#elif (CONFIG_STACK_SIZE_SHIFT == 4)
80 +#define THREAD_SIZE    65536
81 +#else
82 +#error CONFIG_STACK_SIZE_SHIFT > 4 unsupported
83 +#endif
84 +
85 +#if (CONFIG_STACK_SIZE_SHIFT != 1) && defined(CONFIG_X86_4G)
86 +#error Large stacks with 4G/4G split unsupported
87 +#endif
88 +
89 +#ifdef __ASSEMBLY__
90 +
91 +#define GET_CURRENT(reg) \
92 +       movl $-THREAD_SIZE, reg; \
93 +       andl %esp, reg
94 +
95 +#else /* __ASSEMBLY__ */
96 +
97 +#define __alloc_task_struct() \
98 +  ((struct task_struct *) __get_free_pages(GFP_KERNEL, CONFIG_STACK_SIZE_SHIFT))
99 +
100 +#define __free_task_struct(p) do { \
101 +  BUG_ON((p)->state < TASK_ZOMBIE); \
102 +  free_pages((unsigned long) (p), CONFIG_STACK_SIZE_SHIFT); \
103 +} while(0)
104 +
105 +#define INIT_TASK_SIZE THREAD_SIZE
106  
107  struct task_struct;
108  
109  static inline struct task_struct * get_current(void)
110  {
111         struct task_struct *current;
112 -       __asm__("andl %%esp,%0; ":"=r" (current) : "0" (~8191UL));
113 +       __asm__("andl %%esp,%0; ":"=r" (current) : "0" (~(THREAD_SIZE - 1)));
114         return current;
115   }
116   
117  #define current get_current()
118  
119 +#endif /* __ASSEMBLY__ */
120 +
121  #endif /* !(_I386_CURRENT_H) */
122 Index: linux-2.4.21-27.EL/include/asm-x86_64/processor.h
123 ===================================================================
124 --- linux-2.4.21-27.EL.orig/include/asm-x86_64/processor.h      2004-12-21 13:51:31.000000000 -0500
125 +++ linux-2.4.21-27.EL/include/asm-x86_64/processor.h   2005-01-07 10:58:24.167548824 -0500
126 @@ -407,8 +407,8 @@
127  /* Note: most of the infrastructure to separate stack and task_struct
128     are already there. When you run out of stack try this first. */
129  
130 -#define __alloc_task_struct() ((struct task_struct *) __get_free_pages(GFP_KERNEL,1))
131 -#define  __free_task_struct(p) free_pages((unsigned long) (p), 1)
132 +#define __alloc_task_struct() ((struct task_struct *) __get_free_pages(GFP_KERNEL, THREAD_ORDER))
133 +#define  __free_task_struct(p) free_pages((unsigned long) (p), THREAD_ORDER)
134    
135  #define init_task      (init_task_union.task)
136  #define init_stack     (init_task_union.stack)
137 Index: linux-2.4.21-27.EL/include/asm-x86_64/page.h
138 ===================================================================
139 --- linux-2.4.21-27.EL.orig/include/asm-x86_64/page.h   2004-12-21 13:51:10.000000000 -0500
140 +++ linux-2.4.21-27.EL/include/asm-x86_64/page.h        2005-01-07 10:55:45.404684448 -0500
141 @@ -27,8 +27,8 @@
142  /* We still hope 8K is enough, but ... */
143  /* Currently it is actually ~6k. This would change when task_struct moves into
144     an own slab. */
145 -#define THREAD_ORDER    1
146 -#define THREAD_SIZE    (2*PAGE_SIZE)
147 +#define THREAD_ORDER   CONFIG_STACK_SIZE_SHIFT 
148 +#define THREAD_SIZE    ((1 << CONFIG_STACK_SIZE_SHIFT) * PAGE_SIZE)
149  
150  #define INIT_TASK_SIZE THREAD_SIZE
151  #define CURRENT_MASK (~(THREAD_SIZE-1))
152 Index: linux-2.4.21-27.EL/include/asm-x86_64/current.h
153 ===================================================================
154 --- linux-2.4.21-27.EL.orig/include/asm-x86_64/current.h        2002-11-28 18:53:15.000000000 -0500
155 +++ linux-2.4.21-27.EL/include/asm-x86_64/current.h     2005-01-07 10:55:45.394685968 -0500
156 @@ -5,6 +5,7 @@
157  struct task_struct;
158  
159  #include <asm/pda.h>
160 +#include <asm/page.h>
161  
162  static inline struct task_struct *get_current(void) 
163  { 
164 Index: linux-2.4.21-27.EL/arch/x86_64/config.in
165 ===================================================================
166 --- linux-2.4.21-27.EL.orig/arch/x86_64/config.in       2004-12-21 13:51:30.000000000 -0500
167 +++ linux-2.4.21-27.EL/arch/x86_64/config.in    2005-01-07 10:55:45.324696608 -0500
168 @@ -90,6 +90,28 @@
169     define_bool CONFIG_NUMA y
170  fi
171  
172 +choice 'Bigger Stack Size Support' \
173 +     "off    CONFIG_NOBIGSTACK \
174 +      16KB   CONFIG_STACK_SIZE_16KB \
175 +      32KB   CONFIG_STACK_SIZE_32KB \
176 +      64KB   CONFIG_STACK_SIZE_64KB" off
177 +
178 +if [ "$CONFIG_NOBIGSTACK" = "y" ]; then
179 +   define_int CONFIG_STACK_SIZE_SHIFT 1
180 +else
181 +  if [ "$CONFIG_STACK_SIZE_16KB" = "y" ]; then
182 +     define_int CONFIG_STACK_SIZE_SHIFT 2
183 +  else
184 +    if [ "$CONFIG_STACK_SIZE_32KB" = "y" ]; then
185 +      define_int CONFIG_STACK_SIZE_SHIFT 3
186 +   else
187 +      if [ "$CONFIG_STACK_SIZE_64KB" = "y" ]; then
188 +        define_int CONFIG_STACK_SIZE_SHIFT 4
189 +      fi
190 +    fi
191 +  fi
192 +fi
193
194  endmenu
195  
196  mainmenu_option next_comment
197 Index: linux-2.4.21-27.EL/arch/x86_64/kernel/smpboot.c
198 ===================================================================
199 --- linux-2.4.21-27.EL.orig/arch/x86_64/kernel/smpboot.c        2004-12-21 13:51:01.000000000 -0500
200 +++ linux-2.4.21-27.EL/arch/x86_64/kernel/smpboot.c     2005-01-07 10:55:45.325696456 -0500
201 @@ -753,7 +753,7 @@
202                         Dprintk("CPU has booted.\n");
203                 } else {
204                         boot_status = 1;
205 -                       if (*((volatile unsigned char *)phys_to_virt(8192))
206 +                       if (*((volatile unsigned char *)phys_to_virt(THREAD_SIZE))
207                                         == 0xA5)
208                                 /* trampoline started but...? */
209                                 printk("Stuck ??\n");
210 @@ -771,7 +771,7 @@
211         }
212  
213         /* mark "stuck" area as not stuck */
214 -       *((volatile unsigned int *)phys_to_virt(8192)) = 0;
215 +       *((volatile unsigned int *)phys_to_virt(THREAD_SIZE)) = 0;
216         
217         return cpu; 
218  }
219 Index: linux-2.4.21-27.EL/arch/x86_64/kernel/traps.c
220 ===================================================================
221 --- linux-2.4.21-27.EL.orig/arch/x86_64/kernel/traps.c  2004-12-21 13:51:15.000000000 -0500
222 +++ linux-2.4.21-27.EL/arch/x86_64/kernel/traps.c       2005-01-07 10:55:45.326696304 -0500
223 @@ -240,7 +240,7 @@
224         unsigned long rsp = tsk->thread.rsp;
225  
226         /* User space on another CPU? */
227 -       if ((rsp ^ (unsigned long)tsk) & (PAGE_MASK<<1))
228 +       if ((rsp ^ (unsigned long)tsk) & ~(THREAD_SIZE - 1))
229                 return;
230         show_trace((unsigned long *)rsp);
231  }
232 Index: linux-2.4.21-27.EL/arch/x86_64/vmlinux.lds
233 ===================================================================
234 --- linux-2.4.21-27.EL.orig/arch/x86_64/vmlinux.lds     2003-06-13 10:51:32.000000000 -0400
235 +++ linux-2.4.21-27.EL/arch/x86_64/vmlinux.lds  2005-01-07 10:55:45.327696152 -0500
236 @@ -72,7 +72,8 @@
237    .vsyscall_1 ADDR(.vsyscall_0) + 1024: AT (LOADADDR(.vsyscall_0) + 1024) { *(.vsyscall_1) }
238    . = LOADADDR(.vsyscall_0) + 4096;
239  
240 -  . = ALIGN(8192);             /* init_task */
241 +/* chose the biggest of the possible stack sizes here? */
242 +  . = ALIGN(65536);            /* init_task */
243    .data.init_task : { *(.data.init_task) }
244  
245    . = ALIGN(4096); 
246 Index: linux-2.4.21-27.EL/arch/i386/config.in
247 ===================================================================
248 --- linux-2.4.21-27.EL.orig/arch/i386/config.in 2004-12-21 13:51:31.000000000 -0500
249 +++ linux-2.4.21-27.EL/arch/i386/config.in      2005-01-07 10:55:45.324696608 -0500
250 @@ -306,6 +306,28 @@
251     fi
252  fi
253  
254 +choice 'Bigger Stack Size Support' \
255 +     "off    CONFIG_NOBIGSTACK \
256 +      16KB   CONFIG_STACK_SIZE_16KB \
257 +      32KB   CONFIG_STACK_SIZE_32KB \
258 +      64KB   CONFIG_STACK_SIZE_64KB" off
259 +
260 +if [ "$CONFIG_NOBIGSTACK" = "y" ]; then
261 +   define_int CONFIG_STACK_SIZE_SHIFT 1
262 +else
263 +  if [ "$CONFIG_STACK_SIZE_16KB" = "y" ]; then
264 +     define_int CONFIG_STACK_SIZE_SHIFT 2
265 +  else
266 +    if [ "$CONFIG_STACK_SIZE_32KB" = "y" ]; then
267 +      define_int CONFIG_STACK_SIZE_SHIFT 3
268 +    else
269 +      if [ "$CONFIG_STACK_SIZE_64KB" = "y" ]; then
270 +        define_int CONFIG_STACK_SIZE_SHIFT 4
271 +      fi
272 +    fi
273 +  fi
274 +fi
275 +
276  if [ "$CONFIG_SMP" = "y" -a "$CONFIG_X86_CMPXCHG" = "y" ]; then
277     define_bool CONFIG_HAVE_DEC_LOCK y
278  fi
279 Index: linux-2.4.21-27.EL/arch/i386/kernel/entry.S
280 ===================================================================
281 --- linux-2.4.21-27.EL.orig/arch/i386/kernel/entry.S    2004-12-21 13:51:31.000000000 -0500
282 +++ linux-2.4.21-27.EL/arch/i386/kernel/entry.S 2005-01-07 10:55:45.271704664 -0500
283 @@ -46,6 +46,7 @@
284  #include <asm/segment.h>
285  #include <asm/page.h>
286  #include <asm/smp.h>
287 +#include <asm/current.h>
288  #include <asm/unistd.h>
289         
290  EBX            = 0x00
291 @@ -94,10 +95,6 @@
292  
293  ENOSYS = 38
294  
295 -#define GET_CURRENT(reg) \
296 -       movl $-8192, reg; \
297 -       andl %esp, reg
298 -
299  #if CONFIG_X86_HIGH_ENTRY
300  
301  #define call_SYMBOL_NAME_ABS(X) movl $X, %ebp; call *%ebp
302 @@ -193,7 +190,7 @@
303         GET_CURRENT(%ebx);                              \
304         movl real_stack(%ebx), %edx;                    \
305         movl %esp, %ebx;                                \
306 -       andl $0x1fff, %ebx;                             \
307 +       andl $(THREAD_SIZE-1), %ebx;                    \
308         orl %ebx, %edx;                                 \
309         movl %edx, %esp;
310  
311 @@ -228,7 +225,7 @@
312  return_path_start_marker:                              \
313         nop;                                            \
314         movl %esp, %ebx;                                \
315 -       andl $0x1fff, %ebx;                             \
316 +       andl $(THREAD_SIZE-1), %ebx;                    \
317         orl %ebx, %edx;                                 \
318         movl %esp, %eax;                                \
319         movl %edx, %esp;                                \
320 Index: linux-2.4.21-27.EL/arch/i386/kernel/irq.c
321 ===================================================================
322 --- linux-2.4.21-27.EL.orig/arch/i386/kernel/irq.c      2004-12-21 13:51:22.000000000 -0500
323 +++ linux-2.4.21-27.EL/arch/i386/kernel/irq.c   2005-01-07 10:55:45.307699192 -0500
324 @@ -45,6 +45,7 @@
325  #include <asm/delay.h>
326  #include <asm/desc.h>
327  #include <asm/irq.h>
328 +#include <asm/current.h>
329  
330  
331  
332 @@ -585,7 +586,7 @@
333         long esp;
334  
335         /* Debugging check for stack overflow: is there less than 1KB free? */
336 -       __asm__ __volatile__("andl %%esp,%0" : "=r" (esp) : "0" (8191));
337 +       __asm__ __volatile__("andl %%esp,%0" : "=r" (esp) : "0" (THREAD_SIZE-1));
338         if (unlikely(esp < (sizeof(struct task_struct) + 1024))) {
339                 extern void show_stack(unsigned long *);
340  
341 Index: linux-2.4.21-27.EL/arch/i386/kernel/smpboot.c
342 ===================================================================
343 --- linux-2.4.21-27.EL.orig/arch/i386/kernel/smpboot.c  2004-12-21 13:51:01.000000000 -0500
344 +++ linux-2.4.21-27.EL/arch/i386/kernel/smpboot.c       2005-01-07 10:55:45.305699496 -0500
345 @@ -814,7 +814,7 @@
346  
347         /* So we see what's up   */
348         printk("Booting processor %d/%d eip %lx\n", cpu, apicid, start_eip);
349 -       stack_start.esp = (void *) (1024 + PAGE_SIZE + (char *)idle);
350 +       stack_start.esp = (void *)idle->thread.esp;
351  
352         /*
353          * This grunge runs the startup process for
354 @@ -887,7 +887,7 @@
355                         Dprintk("CPU has booted.\n");
356                 } else {
357                         boot_error= 1;
358 -                       if (*((volatile unsigned char *)phys_to_virt(8192))
359 +                       if (*((volatile unsigned char *)phys_to_virt(THREAD_SIZE))
360                                         == 0xA5)
361                                 /* trampoline started but...? */
362                                 printk("Stuck ??\n");
363 @@ -910,7 +910,7 @@
364         }
365  
366         /* mark "stuck" area as not stuck */
367 -       *((volatile unsigned long *)phys_to_virt(8192)) = 0;
368 +       *((volatile unsigned long *)phys_to_virt(THREAD_SIZE)) = 0;
369  
370         if(clustered_apic_mode == CLUSTERED_APIC_NUMAQ) {
371                 printk("Restoring NMI vector\n");
372 Index: linux-2.4.21-27.EL/arch/i386/kernel/traps.c
373 ===================================================================
374 --- linux-2.4.21-27.EL.orig/arch/i386/kernel/traps.c    2004-12-21 13:51:15.000000000 -0500
375 +++ linux-2.4.21-27.EL/arch/i386/kernel/traps.c 2005-01-07 10:55:45.306699344 -0500
376 @@ -180,7 +180,7 @@
377         unsigned long esp = tsk->thread.esp;
378  
379         /* User space on another CPU? */
380 -       if ((esp ^ (unsigned long)tsk) & (PAGE_MASK<<1))
381 +       if ((esp ^ (unsigned long)tsk) & ~(THREAD_SIZE - 1))
382                 return;
383         show_trace((unsigned long *)esp);
384  }
385 Index: linux-2.4.21-27.EL/arch/i386/kernel/head.S
386 ===================================================================
387 --- linux-2.4.21-27.EL.orig/arch/i386/kernel/head.S     2004-12-21 13:51:07.000000000 -0500
388 +++ linux-2.4.21-27.EL/arch/i386/kernel/head.S  2005-01-07 10:55:45.307699192 -0500
389 @@ -15,6 +15,7 @@
390  #include <asm/page.h>
391  #include <asm/pgtable.h>
392  #include <asm/desc.h>
393 +#include <asm/current.h>
394  
395  #define OLD_CL_MAGIC_ADDR      0x90020
396  #define OLD_CL_MAGIC           0xA33F
397 @@ -343,7 +344,7 @@
398         ret
399  
400  ENTRY(stack_start)
401 -       .long SYMBOL_NAME(init_task_union)+8192
402 +       .long SYMBOL_NAME(init_task_union)+THREAD_SIZE
403         .long __KERNEL_DS
404  
405  /* This is the default interrupt "handler" :-) */
406 Index: linux-2.4.21-27.EL/arch/i386/lib/getuser.S
407 ===================================================================
408 --- linux-2.4.21-27.EL.orig/arch/i386/lib/getuser.S     1998-01-12 16:42:52.000000000 -0500
409 +++ linux-2.4.21-27.EL/arch/i386/lib/getuser.S  2005-01-07 10:55:45.323696760 -0500
410 @@ -21,6 +21,10 @@
411   * as they get called from within inline assembly.
412   */
413  
414 +/* Duplicated from asm/processor.h */
415 +#include <asm/current.h>
416 +#include <linux/config.h>
417 +
418  addr_limit = 12
419  
420  .text
421 @@ -28,7 +32,7 @@
422  .globl __get_user_1
423  __get_user_1:
424         movl %esp,%edx
425 -       andl $0xffffe000,%edx
426 +       andl $~(THREAD_SIZE - 1),%edx
427         cmpl addr_limit(%edx),%eax
428         jae bad_get_user
429  1:     movzbl (%eax),%edx
430 @@ -41,7 +45,7 @@
431         addl $1,%eax
432         movl %esp,%edx
433         jc bad_get_user
434 -       andl $0xffffe000,%edx
435 +       andl $~(THREAD_SIZE - 1),%edx
436         cmpl addr_limit(%edx),%eax
437         jae bad_get_user
438  2:     movzwl -1(%eax),%edx
439 @@ -54,7 +58,7 @@
440         addl $3,%eax
441         movl %esp,%edx
442         jc bad_get_user
443 -       andl $0xffffe000,%edx
444 +       andl $~(THREAD_SIZE - 1),%edx
445         cmpl addr_limit(%edx),%eax
446         jae bad_get_user
447  3:     movl -3(%eax),%edx
448 Index: linux-2.4.21-27.EL/arch/i386/vmlinux.lds.in
449 ===================================================================
450 --- linux-2.4.21-27.EL.orig/arch/i386/vmlinux.lds.in    2004-12-21 13:51:08.000000000 -0500
451 +++ linux-2.4.21-27.EL/arch/i386/vmlinux.lds.in 2005-01-07 10:55:45.324696608 -0500
452 @@ -1,6 +1,7 @@
453  
454  #define __ASSEMBLY__
455  #include <asm/page.h>
456 +#include <asm/current.h>
457  
458  /* ld script to make i386 Linux kernel
459   * Written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>;
460 @@ -51,7 +52,7 @@
461  
462    _edata = .;                  /* End of data section */
463  
464 -  . = ALIGN(8192);             /* init_task */
465 +  . = ALIGN(THREAD_SIZE);              /* init_task */
466    .data.init_task : { *(.data.init_task) }
467  
468    entry_tramp_start = .;