Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

parisc,metag: Do not hardcode maximum userspace stack size

This patch affects only architectures where the stack grows upwards
(currently parisc and metag only). On those do not hardcode the maximum
initial stack size to 1GB for 32-bit processes, but make it configurable
via a config option.

The main problem with the hardcoded stack size is, that we have two
memory regions which grow upwards: stack and heap. To keep most of the
memory available for heap in a flexmap memory layout, it makes no sense
to hard allocate up to 1GB of the memory for stack which can't be used
as heap then.

This patch makes the stack size for 32-bit processes configurable and
uses 80MB as default value which has been in use during the last few
years on parisc and which hasn't showed any problems yet.

Signed-off-by: Helge Deller <deller@gmx.de>
Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: "James E.J. Bottomley" <jejb@parisc-linux.org>
Cc: linux-parisc@vger.kernel.org
Cc: linux-metag@vger.kernel.org
Cc: John David Anglin <dave.anglin@bell.net>

authored by

Helge Deller and committed by
James Hogan
042d27ac d71f290b

+23 -5
+1 -1
arch/metag/include/asm/processor.h
··· 23 23 #define STACK_TOP (TASK_SIZE - PAGE_SIZE) 24 24 #define STACK_TOP_MAX STACK_TOP 25 25 /* Maximum virtual space for stack */ 26 - #define STACK_SIZE_MAX (1 << 28) /* 256 MB */ 26 + #define STACK_SIZE_MAX (CONFIG_MAX_STACK_SIZE_MB*1024*1024) 27 27 28 28 /* This decides where the kernel will search for a free chunk of vm 29 29 * space during mmap's.
+4 -1
arch/parisc/include/asm/processor.h
··· 55 55 #define STACK_TOP TASK_SIZE 56 56 #define STACK_TOP_MAX DEFAULT_TASK_SIZE 57 57 58 - #define STACK_SIZE_MAX (1 << 30) /* 1 GB */ 58 + /* Allow bigger stacks for 64-bit processes */ 59 + #define STACK_SIZE_MAX (USER_WIDE_MODE \ 60 + ? (1 << 30) /* 1 GB */ \ 61 + : (CONFIG_MAX_STACK_SIZE_MB*1024*1024)) 59 62 60 63 #endif 61 64
+3 -3
arch/parisc/kernel/sys_parisc.c
··· 72 72 { 73 73 unsigned long stack_base; 74 74 75 - /* Limit stack size to 1GB - see setup_arg_pages() in fs/exec.c */ 75 + /* Limit stack size - see setup_arg_pages() in fs/exec.c */ 76 76 stack_base = rlimit_max(RLIMIT_STACK); 77 - if (stack_base > (1 << 30)) 78 - stack_base = 1 << 30; 77 + if (stack_base > STACK_SIZE_MAX) 78 + stack_base = STACK_SIZE_MAX; 79 79 80 80 return PAGE_ALIGN(STACK_TOP - stack_base); 81 81 }
+15
mm/Kconfig
··· 581 581 582 582 config GENERIC_EARLY_IOREMAP 583 583 bool 584 + 585 + config MAX_STACK_SIZE_MB 586 + int "Maximum user stack size for 32-bit processes (MB)" 587 + default 80 588 + range 8 256 if METAG 589 + range 8 2048 590 + depends on STACK_GROWSUP && (!64BIT || COMPAT) 591 + help 592 + This is the maximum stack size in Megabytes in the VM layout of 32-bit 593 + user processes when the stack grows upwards (currently only on parisc 594 + and metag arch). The stack will be located at the highest memory 595 + address minus the given value, unless the RLIMIT_STACK hard limit is 596 + changed to a smaller value in which case that is used. 597 + 598 + A sane initial value is 80 MB.