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 v2 4/5] fork: check charging success before zeroing stack
Date: Wed, 07 May 2025 14:46:30 +0200 [thread overview]
Message-ID: <20250507-fork-fixes-v2-4-82ab1e42cde3@linaro.org> (raw)
In-Reply-To: <20250507-fork-fixes-v2-0-82ab1e42cde3@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
[linus.walleij@linaro.org: Rebased]
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 c60a0ec61a421324e3733b506d99531c5965cbc6..6ac4674fdf04081fbcbf1eb99167a4c990a58506 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -279,6 +279,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);
@@ -287,11 +292,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-07 12:46 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-07 12:46 [PATCH v2 0/5] fork: Page operation cleanups in the fork code Linus Walleij
2025-05-07 12:46 ` [PATCH v2 1/5] fork: Clean-up ifdef logic around stack allocation Linus Walleij
2025-05-13 6:29 ` Mike Rapoport
2025-05-07 12:46 ` [PATCH v2 2/5] fork: Clean-up naming of vm_stack/vm_struct variables in vmap stacks code Linus Walleij
2025-05-13 6:33 ` Mike Rapoport
2025-05-07 12:46 ` [PATCH v2 3/5] fork: Remove assumption that vm_area->nr_pages equals to THREAD_SIZE Linus Walleij
2025-05-07 16:56 ` Mateusz Guzik
2025-05-09 5:44 ` Linus Walleij
2025-05-07 12:46 ` Linus Walleij [this message]
2025-05-13 7:38 ` [PATCH v2 4/5] fork: check charging success before zeroing stack Mike Rapoport
2025-05-07 12:46 ` [PATCH v2 5/5] fork: zero vmap stack using clear_page() instead of memset() Linus Walleij
2025-05-07 16:51 ` Mateusz Guzik
2025-05-09 5:49 ` Linus Walleij
2025-05-07 17:03 ` [PATCH v2 0/5] fork: Page operation cleanups in the fork code Mateusz Guzik
2025-05-09 6:57 ` Linus Walleij
2025-05-09 11:16 ` Mateusz Guzik
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=20250507-fork-fixes-v2-4-82ab1e42cde3@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;
as well as URLs for NNTP newsgroup(s).