From: Linus Walleij <linus.walleij@linaro.org>
To: Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, Pasha Tatashin <pasha.tatashin@soleen.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Subject: [PATCH 4/5] fork: check charging success before zeroing stack
Date: Tue, 06 May 2025 09:57:56 +0200 [thread overview]
Message-ID: <20250506-fork-fixes-v1-4-bd35b63f0f1b@linaro.org> (raw)
In-Reply-To: <20250506-fork-fixes-v1-0-bd35b63f0f1b@linaro.org>
From: Pasha Tatashin <pasha.tatashin@soleen.com>
No need to do zero cached stack if memcg charge fails, so move the
charging attempt before the memset operation.
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>
---
kernel/fork.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/kernel/fork.c b/kernel/fork.c
index 02943c14ee3b932db11cd9292051fdf5ce381a38..2350ba55db2a5f5675f810d7214252dd8a1fae98 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -278,6 +278,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);
@@ -286,11 +291,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;
--
2.49.0
next prev parent reply other threads:[~2025-05-06 7:58 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-06 7:57 [PATCH 0/5] fork: Page operation cleanups in the fork code Linus Walleij
2025-05-06 7:57 ` [PATCH 1/5] fork: Clean-up ifdef logic around stack allocation Linus Walleij
2025-05-06 7:57 ` [PATCH 2/5] fork: Clean-up naming of vm_strack/vm_struct variables in vmap stacks code Linus Walleij
2025-05-07 1:51 ` Andrew Morton
2025-05-06 7:57 ` [PATCH 3/5] fork: Remove assumption that vm_area->nr_pages equals to THREAD_SIZE Linus Walleij
2025-05-07 1:53 ` Andrew Morton
2025-05-07 12:38 ` Linus Walleij
2025-05-06 7:57 ` Linus Walleij [this message]
2025-05-06 7:57 ` [PATCH 5/5] fork: zero vmap stack using clear_page() instead of memset() Linus Walleij
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250506-fork-fixes-v1-4-bd35b63f0f1b@linaro.org \
--to=linus.walleij@linaro.org \
--cc=akpm@linux-foundation.org \
--cc=linux-mm@kvack.org \
--cc=pasha.tatashin@soleen.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox