fork: check charging success before zeroing stack
No need to do zero cached stack if memcg charge fails, so move the charging attempt before the memset operation. [linus.walleij@linaro.org: rebased] Link: https://lkml.kernel.org/r/20250509-fork-fixes-v3-3-e6c69dd356f2@linaro.org Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com> Link: https://lore.kernel.org/20240311164638.2015063-6-pasha.tatashin@soleen.com Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
committed by
Andrew Morton
parent
90eb270d8e
commit
d82893c52a
@@ -280,6 +280,11 @@ static int alloc_thread_stack_node(struct task_struct *tsk, int node)
|
||||
if (!vm_area)
|
||||
continue;
|
||||
|
||||
if (memcg_charge_kernel_stack(vm_area)) {
|
||||
vfree(vm_area->addr);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* Reset stack metadata. */
|
||||
kasan_unpoison_range(vm_area->addr, THREAD_SIZE);
|
||||
|
||||
@@ -288,11 +293,6 @@ static int alloc_thread_stack_node(struct task_struct *tsk, int node)
|
||||
/* Clear stale pointers from reused stack. */
|
||||
memset(stack, 0, THREAD_SIZE);
|
||||
|
||||
if (memcg_charge_kernel_stack(vm_area)) {
|
||||
vfree(vm_area->addr);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
tsk->stack_vm_area = vm_area;
|
||||
tsk->stack = stack;
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user