[PATCH 0/2] x86/kstack_erase: Faster stack poisoning, plus a startup build fix
From: Usama Arif
Date: Thu Nov 19 2026 - 16:32:06 EST
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 REP STOSQ 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 71 ns -> 46 ns
futex wake/wait ping-pong 5-7% faster
Unix socket sendmsg()/recvmsg() ping-pong 5-8% faster
open+read+close of /proc/self/stat 6-8% faster
getppid() (spans below 512 bytes) within 2%
Usama Arif (2):
x86/boot/startup: Disable kernel stack depth tracking
x86/kstack_erase: Use REP STOSQ for large stack fills
arch/x86/boot/startup/Makefile | 2 +-
arch/x86/include/asm/processor.h | 25 +++++++++++++++++++++++++
2 files changed, 26 insertions(+), 1 deletion(-)
--
2.53.1-Meta