Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: x86: Save and reload SSP to/from SMRAM

Save CET SSP to SMRAM on SMI and reload it on RSM. KVM emulates HW arch
behavior when guest enters/leaves SMM mode,i.e., save registers to SMRAM
at the entry of SMM and reload them at the exit to SMM. Per SDM, SSP is
one of such registers on 64-bit Arch, and add the support for SSP.

Suggested-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Yang Weijiang <weijiang.yang@intel.com>
Tested-by: Mathias Krause <minipli@grsecurity.net>
Tested-by: John Allen <john.allen@amd.com>
Tested-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
Signed-off-by: Chao Gao <chao.gao@intel.com>
Reviewed-by: Binbin Wu <binbin.wu@linux.intel.com>
Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
Link: https://lore.kernel.org/r/20250919223258.1604852-16-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>

authored by

Yang Weijiang and committed by
Sean Christopherson
1a61bd0d 8b59d027

+9 -1
+8
arch/x86/kvm/smm.c
··· 269 269 enter_smm_save_seg_64(vcpu, &smram->gs, VCPU_SREG_GS); 270 270 271 271 smram->int_shadow = kvm_x86_call(get_interrupt_shadow)(vcpu); 272 + 273 + if (guest_cpu_cap_has(vcpu, X86_FEATURE_SHSTK) && 274 + kvm_msr_read(vcpu, MSR_KVM_INTERNAL_GUEST_SSP, &smram->ssp)) 275 + kvm_make_request(KVM_REQ_TRIPLE_FAULT, vcpu); 272 276 } 273 277 #endif 274 278 ··· 561 557 562 558 kvm_x86_call(set_interrupt_shadow)(vcpu, 0); 563 559 ctxt->interruptibility = (u8)smstate->int_shadow; 560 + 561 + if (guest_cpu_cap_has(vcpu, X86_FEATURE_SHSTK) && 562 + kvm_msr_write(vcpu, MSR_KVM_INTERNAL_GUEST_SSP, smstate->ssp)) 563 + return X86EMUL_UNHANDLEABLE; 564 564 565 565 return X86EMUL_CONTINUE; 566 566 }
+1 -1
arch/x86/kvm/smm.h
··· 116 116 u32 smbase; 117 117 u32 reserved4[5]; 118 118 119 - /* ssp and svm_* fields below are not implemented by KVM */ 120 119 u64 ssp; 120 + /* svm_* fields below are not implemented by KVM */ 121 121 u64 svm_guest_pat; 122 122 u64 svm_host_efer; 123 123 u64 svm_host_cr4;