On Fri, Jan 26, 2024 at 11:17:24AM +0800, Chao Gao wrote: >On Tue, Jan 23, 2024 at 06:41:54PM -0800, Yang Weijiang wrote: >>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. Note, >>on 32-bit Arch, SSP is not defined in SMRAM, so fail 32-bit CET guest >>launch. >> >>Suggested-by: Sean Christopherson <seanjc@xxxxxxxxxx> >>Suggested-by: Chao Gao <chao.gao@xxxxxxxxx> >>Signed-off-by: Yang Weijiang <weijiang.yang@xxxxxxxxx> >>Reviewed-by: Maxim Levitsky <mlevitsk@xxxxxxxxxx> >>--- >> arch/x86/kvm/cpuid.c | 11 +++++++++++ >> arch/x86/kvm/smm.c | 8 ++++++++ >> arch/x86/kvm/smm.h | 2 +- >> 3 files changed, 20 insertions(+), 1 deletion(-) >> >>diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c >>index 3ab133530573..95233b0879a3 100644 >>--- a/arch/x86/kvm/cpuid.c >>+++ b/arch/x86/kvm/cpuid.c >>@@ -149,6 +149,17 @@ static int kvm_check_cpuid(struct kvm_vcpu *vcpu, >> if (vaddr_bits != 48 && vaddr_bits != 57 && vaddr_bits != 0) >> return -EINVAL; >> } >>+ /* >>+ * Prevent 32-bit guest launch if shadow stack is exposed as SSP >>+ * state is not defined for 32-bit SMRAM. >>+ */ >>+ best = cpuid_entry2_find(entries, nent, 0x80000001, >>+ KVM_CPUID_INDEX_NOT_SIGNIFICANT); >>+ if (best && !(best->edx & F(LM))) { >>+ best = cpuid_entry2_find(entries, nent, 0x7, 0); >>+ if (best && (best->ecx & F(SHSTK))) > >F(LM) and F(SHSTK) are kernel-defined feature bits; they are not >bit masks defined by the CPU. Oops, my comment is wrong here. Please disregard it.