]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
fork: check charging success before zeroing stack
authorPasha Tatashin <pasha.tatashin@soleen.com>
Fri, 29 Aug 2025 11:44:40 +0000 (13:44 +0200)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 12 Sep 2025 00:25:27 +0000 (17:25 -0700)
Patch series "mm: task_stack: Stack handling cleanups".

These are some small cleanups for the fork code that was split off from
Pasha:s dynamic stack patch series, they are generally nice on their own
so let's propose them for merging.

This patch (of 2):

No need to do zero cached stack if memcg charge fails, so move the
charging attempt before the memset operation.

Link: https://lkml.kernel.org/r/20250829-fork-cleanups-for-dynstack-v1-0-3bbaadce1f00@linaro.org
Link: https://lkml.kernel.org/r/20250829-fork-cleanups-for-dynstack-v1-1-3bbaadce1f00@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>
Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Ben Segall <bsegall@google.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Kees Cook <kees@kernel.org>
Cc: Mel Gorman <mgorman <mgorman@suse.de>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Valentin Schneider <vschneid@redhat.com>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
kernel/fork.c

index c8a6e1495acf0ded27bfb9a7bd0a9acf929517bd..1b394426ab4a8a72363d2fd09dd37cf1a50c02e7 100644 (file)
@@ -290,6 +290,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);
 
@@ -298,11 +303,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;