Skip to content

Commit 92ad650

Browse files
jallen-amdbp3tk0v
authored andcommitted
x86/sev: Include XSS value in GHCB CPUID request
When a guest issues a CPUID instruction for Fn0000000D_x01, the hypervisor may be intercepting the CPUID instruction and need to access the guest XSS value. For SEV-ES, the XSS value is encrypted and needs to be included in the GHCB to be visible to the hypervisor. Signed-off-by: John Allen <john.allen@amd.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com> Link: https://patch.msgid.link/all/20250924200852.4452-3-john.allen@amd.com/
1 parent 9249bcd commit 92ad650

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

arch/x86/coco/sev/vc-shared.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
// SPDX-License-Identifier: GPL-2.0
22

3+
#ifndef __BOOT_COMPRESSED
4+
#define has_cpuflag(f) boot_cpu_has(f)
5+
#endif
6+
37
static enum es_result vc_check_opcode_bytes(struct es_em_ctxt *ctxt,
48
unsigned long exit_code)
59
{
@@ -546,6 +550,13 @@ static enum es_result vc_handle_cpuid(struct ghcb *ghcb,
546550
/* xgetbv will cause #GP - use reset value for xcr0 */
547551
ghcb_set_xcr0(ghcb, 1);
548552

553+
if (has_cpuflag(X86_FEATURE_SHSTK) && regs->ax == 0xd && regs->cx == 1) {
554+
struct msr m;
555+
556+
raw_rdmsr(MSR_IA32_XSS, &m);
557+
ghcb_set_xss(ghcb, m.q);
558+
}
559+
549560
ret = sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_CPUID, 0, 0);
550561
if (ret != ES_OK)
551562
return ret;

arch/x86/include/asm/svm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,5 +701,6 @@ DEFINE_GHCB_ACCESSORS(sw_exit_info_1)
701701
DEFINE_GHCB_ACCESSORS(sw_exit_info_2)
702702
DEFINE_GHCB_ACCESSORS(sw_scratch)
703703
DEFINE_GHCB_ACCESSORS(xcr0)
704+
DEFINE_GHCB_ACCESSORS(xss)
704705

705706
#endif

0 commit comments

Comments
 (0)