fork: Implement partial VMAP stack allocation
When CONFIG_ARCH_HAS_VARIABLE_STACK_SIZE is enabled, architectures can
allocate a VMAP stack that is smaller than the full THREAD_SIZE.
This introduces a weak abstraction vm_stack_pages() which defaults to
THREAD_SIZE / PAGE_SIZE. During stack allocation, the kernel will map
only the requested number of pages at the top of the THREAD_SIZE virtual
area (as the stack grows down), leaving the bottom unmapped. This saves
memory while retaining the same virtual alignment and guard page overflow
detection characteristics.
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
[Rebased, used vm_area->nr_pages directly in one instance]
[Depends on !PREEMPT_RT]
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
[Fix races around accounting]
[Use GFP_ATOMIC when executing in the scheduler]
[Depend on INIT_STACK_ALL_* config]
[Fix bugs in some error paths and edge cases]
[Don't cache partially faulted stacks]
[Added out-var to tell if address is on target stack]
Signed-off-by: David Stevens <stevensd@google.com>
[Remove dynamic stack related code, and update commit message]
[Fix memory leak in error path of alloc_vmap_stack()]
[Reset kasan tag for the stack vaddr when mapping it]
Signed-off-by: Mostafa Saleh <smostafa@google.com>
1 file changed