From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Dave Hansen <dave.hansen@intel.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Yang Weijiang <weijiang.yang@intel.com>,
"Gao, Chao" <chao.gao@intel.com>,
"Edgecombe, Rick P" <rick.p.edgecombe@intel.com>,
Maxim Levitsky <mlevitsk@redhat.com>,
John Allen <john.allen@amd.com>,
LKML <linux-kernel@vger.kernel.org>,
peterz@infradead.org, kvm@vger.kernel.org,
binbin.wu@linux.intel.com, Thomas Gleixner <tglx@linutronix.de>,
"Bae, Chang Seok" <chang.seok.bae@intel.com>,
"Mehta, Sohil" <sohil.mehta@intel.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Subject: Re: Kernel Shadow Stacks Versus XFEATURE_MASK_GUEST_SUPERVISOR
Date: Mon, 26 Oct 2026 17:57:40 +0000 [thread overview]
Message-ID: <40e998b5-3238-4adb-9b8f-1bffa0b48f9f@citrix.com> (raw)
In-Reply-To: <5c74f231-46a7-4f37-8fcd-bff84842a923@intel.com>
On 23/10/2026 10:21 pm, Dave Hansen wrote:
> On 10/23/26 14:00, Paolo Bonzini wrote:
>> On 10/23/26 21:03, Dave Hansen wrote:
>>> Any thoughts on what we should do?
>>>
>>> Actually context switching XFEATURE_CET_KERNEL seems kinda silly in a
>>> lot of ways. PL0_SSP can always be derived _and_ it isn't actually even
>>> needed at context switch time, only when running userspace.
>> True but, just to understand, what is the performance like if you
>> actually use XSAVES/XRSTORS to update SSP0 on context switches instead
>> of WRMSR+cache? Hopefully the microcode does a bunch of optimizations
>> as well.
> First, we can use WRMSRNS for this MSR, so it's faster than usual.
> Second, on kernel=>kernel context switches that don't go out to
> userspace, it doesn't need to be written at all. It's kinda like the
> user FPU state. Third, I'm actually reusing the fred_ssp0 cache, so
> further reduces the incremental cost.
XSTATE_CET_S is a weird thing. It contains MSRs for PL{0..2}_SSP which
are the shstk equivalents of tss->rsp{0..2}.
The Ring1/2 aspects are practically useless; CET-SS was the thing which
finally caused me to put Ring1 PV kernels to rest. All of
tss->rsp{0..2} are switched together, so I suppose PL{0..2}_SSP were
grouped for the same reason, not that 64bit OSes use task switching.
Windows uses %xmm in the main ABI, so already need to XSAVE/XRSTOR when
switching between kernel threads. So it's "simple" to add one extra bit
to RFBM while doing this.
VMMs probably want to use XSTATE_CET_S simply to have the guest state
held together. Even then, it does feel like a waste; PL1/2_SSP are
going to be 0 ~all of the time, while PL0_SSP is nonzero ~all of the
time in a CET-enabled kernel, so you can't even rely on the INIT
optimisation to speed things up.
Linux obviously doesn't want to do an X{SAVE,RSTOR}S between kernel
threads, and isn't using Rings 1/2, so the WRMSRNS approach seems fine.
And I agree that it only needs to be good at the point of returning to
userspace.
> Fourth, it's not _really_
> context-switched. There's never a need to read the register. It can
> always be conjured out of thin air.
The requirements are different, depending on FRED or not.
Without FRED, PL0_SSP must point to a Supervisor Shadow Stack token.
IRET marks the token non-busy (squashing any errors), and IDT delivery
checks it can atomically set the token busy, yielding #CP if not.
With FRED, ERETU checks that SSP == SL0_SSP and yields #CP on a
mismatch. There are no checks on entry.
~Andrew
next prev parent reply other threads:[~2026-10-26 17:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-23 19:03 Dave Hansen
2026-10-23 21:00 ` Paolo Bonzini
2026-10-23 21:21 ` Dave Hansen
2026-10-26 17:57 ` Andrew Cooper [this message]
2026-10-27 14:18 ` Chao Gao
2026-10-27 14:28 ` Dave Hansen
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=40e998b5-3238-4adb-9b8f-1bffa0b48f9f@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=binbin.wu@linux.intel.com \
--cc=chang.seok.bae@intel.com \
--cc=chao.gao@intel.com \
--cc=dave.hansen@intel.com \
--cc=john.allen@amd.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mlevitsk@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=rick.p.edgecombe@intel.com \
--cc=sohil.mehta@intel.com \
--cc=tglx@linutronix.de \
--cc=weijiang.yang@intel.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
all inboxes | Powered by JetHome®