From: Usama Arif <usama.arif@linux.dev>
To: tglx@kernel.org, mingo@redhat.com, bp@alien8.de,
dave.hansen@linux.intel.com, x86@kernel.org, kees@kernel.org,
peterz@infradead.org
Cc: hpa@zytor.com, gustavoars@kernel.org, ardb@kernel.org,
hca@linux.ibm.com, nathan@kernel.org, ndesaulniers@google.com,
morbo@google.com, justinstitt@google.com,
linux-hardening@vger.kernel.org, llvm@lists.linux.dev,
linux-kernel@vger.kernel.org, riel@surriel.com,
shakeel.butt@linux.dev, kernel-team@meta.com, rkeilty@meta.com,
atish.patra@linux.dev, dgreid@meta.com,
Usama Arif <usama.arif@linux.dev>
Subject: [PATCH v2 0/2] Subject: [PATCH v2 0/2] x86/kstack_erase: Faster stack poisoning, plus a startup build fix
Date: Mon, 23 Nov 2026 09:46:37 -0800 [thread overview]
Message-ID: <20261123174703.133167-1-usama.arif@linux.dev> (raw)
With KSTACK_ERASE, every return to user space poisons the part of the
task stack used since the previous return, one 8-byte store at a time.
On Meta hosts running many small VMs, that loop costs about 1.5% of
non-idle host kernel cycles. Most of it is on the way out of futex,
epoll, procfs and socket syscalls that go 1-2 KiB deep.
Patch 2 makes x86-64 use memset64() for spans above 512 bytes, through
the arch hook that s390 already uses. Shorter spans keep the loop, and
the range and value written do not change.
Patch 1 is an independent build fix I found while testing patch 2 with a
small KSTACK_ERASE_TRACK_MIN_SIZE. The startup code still uses the
pre-rename DISABLE_STACKLEAK_PLUGIN, so with Clang, AMD memory
encryption and a tracking minimum below about 90 bytes, vmlinux fails
to link. It can be applied on its own.
Zen 5c KVM guest, one vCPU, before -> after:
stackleak_erase() per return to user 68 ns -> 47 ns
futex wake/wait ping-pong 6% faster
Unix socket sendmsg()/recvmsg() ping-pong 6% faster
open+read+close of /proc/self/stat 8% faster
getppid() (spans below 512 bytes) within 1%
v1 -> v2: https://lore.kernel.org/r/20261119213147.1094488-1-usama.arif@linux.dev
- Patch 1: add Nick's Reviewed-by.
- Patch 2: use memset64() instead of inline asm and make it
__always_inline (Nick, Peter). KMSAN kernels keep the generic loop,
as memset64() is out of line there.
- Patch 2: keep the word loop up to 512 bytes; this is the v2.1
variant from the v1 thread. Unrolled loops, Duff's device, a 64-byte
aligned REP STOSQ and REP STOSQ for all lengths (Peter, David) all
came within 1 ns per erase of it. Most of the time left is the
search for the poison, not the fill. This current version is the cleanest
one IMO.
Usama Arif (2):
x86/boot/startup: Disable kernel stack depth tracking
x86/kstack_erase: Use memset64() for large stack fills
arch/x86/boot/startup/Makefile | 2 +-
arch/x86/include/asm/processor.h | 21 +++++++++++++++++++++
arch/x86/include/asm/string_64.h | 2 +-
3 files changed, 23 insertions(+), 2 deletions(-)
--
2.53.1-Meta
next reply other threads:[~2026-11-23 17:47 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 17:46 Usama Arif [this message]
2026-11-23 17:46 ` [PATCH v2 1/2] x86/boot/startup: Disable kernel stack depth tracking Usama Arif
2026-11-23 17:46 ` [PATCH v2 2/2] x86/kstack_erase: Use memset64() for large stack fills Usama Arif
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=20261123174703.133167-1-usama.arif@linux.dev \
--to=usama.arif@linux.dev \
--cc=ardb@kernel.org \
--cc=atish.patra@linux.dev \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=dgreid@meta.com \
--cc=gustavoars@kernel.org \
--cc=hca@linux.ibm.com \
--cc=hpa@zytor.com \
--cc=justinstitt@google.com \
--cc=kees@kernel.org \
--cc=kernel-team@meta.com \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=mingo@redhat.com \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=peterz@infradead.org \
--cc=riel@surriel.com \
--cc=rkeilty@meta.com \
--cc=shakeel.butt@linux.dev \
--cc=tglx@kernel.org \
--cc=x86@kernel.org \
/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