[RFC 07/14] fork: use the first page in stack to store vm_stack in cached_stacks

From: Pasha Tatashin
Date: Mon Mar 11 2024 - 12:48:08 EST


vmap stack are stored in a per-cpu cache_stacks in order to reduce
number of allocations and free calls. However, the stacks ared stored
using the buttom address of the stack. Since stacks normally grow down,
this is a problem with dynamic stacks, as the lower pages might not
even be allocated. Instead of the first available page from vm_area.

Signed-off-by: Pasha Tatashin <pasha.tatashin@xxxxxxxxxx>
---
kernel/fork.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/fork.c b/kernel/fork.c
index 41e0baee79d2..3004e6ce6c65 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -217,9 +217,10 @@ static void thread_stack_free_rcu(struct rcu_head *rh)

static void thread_stack_delayed_free(struct task_struct *tsk)
{
- struct vm_stack *vm_stack = tsk->stack;
+ struct vm_struct *vm_area = tsk->stack_vm_area;
+ struct vm_stack *vm_stack = page_address(vm_area->pages[0]);

- vm_stack->stack_vm_area = tsk->stack_vm_area;
+ vm_stack->stack_vm_area = vm_area;
call_rcu(&vm_stack->rcu, thread_stack_free_rcu);
}

--
2.44.0.278.ge034bb2e1d-goog