Re: [PATCH v16 13/51] KVM: x86: Enable guest SSP read/write interface with new uAPIs

From: Xiaoyao Li

Date: Tue Sep 23 2025 - 05:06:57 EST


On 9/20/2025 6:32 AM, Sean Christopherson wrote:
From: Yang Weijiang<weijiang.yang@xxxxxxxxx>

Add a KVM-defined ONE_REG register, KVM_REG_GUEST_SSP, to let userspace
save and restore the guest's Shadow Stack Pointer (SSP). On both Intel
and AMD, SSP is a hardware register that can only be accessed by software
via dedicated ISA (e.g. RDSSP) or via VMCS/VMCB fields (used by hardware
to context switch SSP at entry/exit). As a result, SSP doesn't fit in
any of KVM's existing interfaces for saving/restoring state.

Internally, treat SSP as a fake/synthetic MSR, as the semantics of writes
to SSP follow that of several other Shadow Stack MSRs, e.g. the PLx_SSP
MSRs. Use a translation layer to hide the KVM-internal MSR index so that
the arbitrary index doesn't become ABI, e.g. so that KVM can rework its
implementation as needed, so long as the ONE_REG ABI is maintained.

Explicitly reject accesses to SSP if the vCPU doesn't have Shadow Stack
support to avoid running afoul of ignore_msrs, which unfortunately applies
to host-initiated accesses (which is a discussion for another day). I.e.
ensure consistent behavior for KVM-defined registers irrespective of
ignore_msrs.

Link:https://lore.kernel.org/all/aca9d389-f11e-4811-90cf-d98e345a5cc2@xxxxxxxxx
Suggested-by: Sean Christopherson<seanjc@xxxxxxxxxx>
Signed-off-by: Yang Weijiang<weijiang.yang@xxxxxxxxx>
Tested-by: Mathias Krause<minipli@xxxxxxxxxxxxxx>
Tested-by: John Allen<john.allen@xxxxxxx>
Tested-by: Rick Edgecombe<rick.p.edgecombe@xxxxxxxxx>
Signed-off-by: Chao Gao<chao.gao@xxxxxxxxx>
Co-developed-by: Sean Christopherson<seanjc@xxxxxxxxxx>
Signed-off-by: Sean Christopherson<seanjc@xxxxxxxxxx>

Reviewed-by: Xiaoyao Li <xiaoyao.li@xxxxxxxxx>