Re: [RFC PATCH 00/27] x86/shstk: More shadow stack enablement and path to IDT support

From: K Prateek Nayak

Date: Sun Nov 29 2026 - 21:50:52 EST


Hello Andrew,

On 11/30/2026 4:30 AM, Andrew Cooper wrote:
> On 29/11/2026 10:29 pm, K Prateek Nayak wrote:
>> Write-to-CR2 for serialization
>> ==============================
>>
>> CPUs that don't have SERIALIZE and have X86_FEATURE_KERN_SHSTK will
>> default to using write-to-CR2 as serializing step. write-to-CR2 is
>> available widely and although the comment in sync_core() suggests XEN
>> may have some issues here, CONFIG_X86_KERE_SHADOW_STACK cannot be
>> compiled with XEN yet so we'll consider write-to-CR2 as a temporary
>> measure.
>
> There is no legitimate dependency CONFIG_X86_KERNEL_SHADOW_STACK and
> XEN; it's bogus and needs dropping.
>
> Xen PV guests will never see CET (SS or IBT) and never enter the
> CONFIG_X86_KERNEL_SHADOW_STACK paths. Xen HVM guests will, and they
> will work as per native, just like KVM guests/etc.

Ack! Thank you for clarifying. I only thought they won't see FRED
but now that I look at your comment on Deve's thread, I see you mention
CET_SS as a whole. Sorry for getting that mixed up.

> The change you've made in sync core is fine. IRET is used because for
> both XenPV and for UML, it will serialise without trapping; it's a
> performance concern only.

Ack! And since you say CET_SS will not be visible, the guests will
continue to user the IRET-to-self path and there should be no concern.

>
>> CALL emulation
>> ==============
>>
>> Call emulation requires a RET frame to be inserted below the FRED entry
>> frame. FRED frame is a { CS, LIP, SSP } pushed onto the shadow stack.
>>
>> To make our lives easy, we push a corresponding metadata frame onto the
>> regula stack on top of pt_regs to make the following container:
>>
>> struct {
>> u64 metadata; /* Context */
>> u64 ssp; /* SSP at FRED_ENTRY */
>> pt_rega *regs;
>> }
>>
>> For CALL emulation, regs_emulate_call() helper will use the SSP from
>> this context to overwrite the CS in the FRED frame with the return IP.
>> The original CS and LIP are moved one slot up to make:
>>
>> ... ...
>> +-----+ +-----+
>> | CS | | RET |
>> | LIP | -> +-----+
>> | SSP | | CS |
>> +-----+ | LIP | <- Jump to CALL site
>> +-----+ <- Top of stack
>>
>> Text patching events always occur at same FRED level and SSP always
>> points to address 3 slots down. regs_emulate_call() will then notify
>> FRED_EXIT of the patching by setting a flag in the metadata.
>>
>> FRED_EXIT will see this flag and do a dummy call, fixup stack, and
>> overwrite the top of shadow stack with a SSP of three slots down to
>> complete the FRED frame which matches for ERETS. After an ERETS, the
>> fist RET will mismatch but rest of the RETs are balanced in RSB.
>>
>> This is also the same method of doing a direct call via ORIG_RAX in
>> ftrace_regs_caller and has been adopted here.
>
> MSR_FRED_CONFIG.SSP (bit 3) exists exclusively for this purpose.
>
> There was a reasonable amount of spirited debate required to get that
> into the FRED spec. It would be a shame not to use it.
Ooo! That should do well too and save a few WRSS for CALL handling on
the FRED path.

--
Thanks and Regards,
Prateek