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 5/5] fork: zero vmap stack using clear_page() instead of memset()
Date: Tue, 06 May 2025 09:57:57 +0200 [thread overview]
Message-ID: <20250506-fork-fixes-v1-5-bd35b63f0f1b@linaro.org> (raw)
In-Reply-To: <20250506-fork-fixes-v1-0-bd35b63f0f1b@linaro.org>
From: Pasha Tatashin <pasha.tatashin@soleen.com>
Do not zero the whole span of the stack, but instead only the
pages that are part of the vm_area.
As several architectures have optimized implementations of
clear_page(), this will give the architecture a clear idea
of what is going on and will speed up the clearing operation.
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Link: https://lore.kernel.org/20240311164638.2015063-7-pasha.tatashin@soleen.com
[Rebased, also skipped intermediary helper variable nr_pages]
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
kernel/fork.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/kernel/fork.c b/kernel/fork.c
index 2350ba55db2a5f5675f810d7214252dd8a1fae98..7710b7ded3000c77e8d0871bb6bb5916d90aa4ec 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -271,7 +271,7 @@ static int alloc_thread_stack_node(struct task_struct *tsk, int node)
{
struct vm_struct *vm_area;
void *stack;
- int i;
+ int i, j;
for (i = 0; i < NR_CACHED_STACKS; i++) {
vm_area = this_cpu_xchg(cached_stacks[i], NULL);
@@ -289,7 +289,8 @@ static int alloc_thread_stack_node(struct task_struct *tsk, int node)
stack = kasan_reset_tag(vm_area->addr);
/* Clear stale pointers from reused stack. */
- memset(stack, 0, THREAD_SIZE);
+ for (j = 0; j < vm_area->nr_pages; j++)
+ clear_page(page_address(vm_area->pages[j]));
tsk->stack_vm_area = vm_area;
tsk->stack = stack;
--
2.49.0
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 ` [PATCH 4/5] fork: check charging success before zeroing stack Linus Walleij
2025-05-06 7:57 ` Linus Walleij [this message]
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-5-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