mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: K Prateek Nayak <kprateek.nayak@amd.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Borislav Petkov <bp@alien8.de>,
	the arch/x86 maintainers <x86@kernel.org>,
	<linux-kernel@vger.kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Rick Edgecombe <rick.p.edgecombe@intel.com>,
	Kees Cook <kees@kernel.org>,
	Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
Subject: Re: [RFC PATCH 00/27] x86/shstk: More shadow stack enablement and path to IDT support
Date: Mon, 30 Nov 2026 08:20:33 +0530	[thread overview]
Message-ID: <9858d06e-d2e8-461f-a124-244eb991eaaf@amd.com> (raw)
In-Reply-To: <a3c9436a-5f4c-40c4-b99c-b148bdc6c6af@citrix.com>

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


  reply	other threads:[~2026-11-30  2:50 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 22:29 K Prateek Nayak
2026-11-29 22:29 ` [RFC PATCH 01/27] x86/entry: Parameterize kernel shadow stack handling at FRED entry K Prateek Nayak
2026-11-29 22:29 ` [RFC PATCH 02/27] x86/perf_regs: Rename pt_regs_offset array to prevent build failure K Prateek Nayak
2026-11-29 22:29 ` [RFC PATCH 03/27] x86/cet: Fix build for KERN_SHADOW_STACK and !USER_SHADOW_STACK K Prateek Nayak
2026-11-29 22:29 ` [RFC PATCH 04/27] x86/cet: Make kernel shadow stack #CP fatal instead of livelocking K Prateek Nayak
2026-11-29 22:29 ` [RFC PATCH 05/27] x86/sync_core: Don't use IRET-to-self with kernel shadow stacks K Prateek Nayak
2026-11-29 22:29 ` [RFC PATCH 06/27] x86/process: Initialize and enable kernel shadow stack at boot K Prateek Nayak
2026-11-29 22:29 ` [RFC PATCH 07/27] x86/entry: Handle int3 text patching with kernel shadow stack K Prateek Nayak
2026-11-29 22:29 ` [RFC PATCH 08/27] x86/retpoline: Handle retpolies and thunks " K Prateek Nayak
2026-11-29 22:29 ` [RFC PATCH 09/27] x86/ftrace: Prepare ftrace trampolines to handle " K Prateek Nayak
2026-11-29 22:29 ` [RFC PATCH 10/27] x86/kprobes: Prepare optprobe trampoline to handle shadow stacks K Prateek Nayak
2026-11-29 22:29 ` [RFC PATCH 11/27] x86/rethook: Prepare the rethook trampoline to handle shadow stack K Prateek Nayak
2026-11-29 22:29 ` [RFC PATCH 12/27] x86/cet: Make regs_set_return_ip() helpers context aware K Prateek Nayak
2026-11-29 22:29 ` [RFC PATCH 13/27] x86/cet: Introduce regs_set_return_trampoline() for rethook trampoline K Prateek Nayak
2026-11-29 22:29 ` [RFC PATCH 14/27] x86/ftrace,livepatch: Use CET helpers for ftrace regs->ip and trampoline redirection K Prateek Nayak
2026-11-29 22:29 ` [RFC PATCH 15/27] x86/rethook: Make the trampoline insert and return shadow stack aware K Prateek Nayak
2026-11-29 22:29 ` [RFC PATCH 16/27] x86/error_inject: Use CET helpers to insert just_return_func trampoline K Prateek Nayak
2026-11-29 22:29 ` [RFC PATCH 17/27] x86/kprobes: Use CET helpers in kprobe core to modify regs->ip K Prateek Nayak
2026-11-29 22:29 ` [RFC PATCH 18/27] x86/bpf: Make BPF JIT aware of CET handling K Prateek Nayak
2026-11-29 22:29 ` [RFC PATCH 19/27] x86/shstk: Remove profiling related dependencies for KERN_SHADOW_STACK K Prateek Nayak
2026-11-29 22:29 ` [RFC PATCH 20/27] x86/shstk: Disable kenrel shadow stack when CPU is offlined K Prateek Nayak
2026-11-29 22:29 ` [RFC PATCH 21/27] x86/shstsk: Allow suspend-resume and hibernation with kernel shadow stack K Prateek Nayak
2026-11-29 22:29 ` [RFC PATCH 22/27] x86/shstk: Save and restore shadow stack pointer during kexec K Prateek Nayak
2026-11-29 22:29 ` [RFC PATCH 23/27] x86/idt: Map MCE shadow stack and populate the INT_SPP table K Prateek Nayak
2026-11-29 22:29 ` [RFC PATCH 24/27] x86/process: Initialize shadow stack for IDT systems K Prateek Nayak
2026-11-29 22:29 ` [RFC PATCH 25/27] x86/entry: Prepare IDT entry for shadow stacks K Prateek Nayak
2026-11-29 22:29 ` [RFC PATCH 26/27] x86/syscall: Toggle shadow stack busy on entry and exit from syscall K Prateek Nayak
2026-11-29 22:29 ` [RFC PATCH 27/27] x86/entry: Handle shadow stack on nested NMI K Prateek Nayak
2026-11-29 23:00 ` [RFC PATCH 00/27] x86/shstk: More shadow stack enablement and path to IDT support Andrew Cooper
2026-11-30  2:50   ` K Prateek Nayak [this message]
2026-11-30  0:32 ` 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=9858d06e-d2e8-461f-a124-244eb991eaaf@amd.com \
    --to=kprateek.nayak@amd.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=pawan.kumar.gupta@linux.intel.com \
    --cc=peterz@infradead.org \
    --cc=rick.p.edgecombe@intel.com \
    --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

all inboxes | Powered by JetHome®