[PATCH v3 6/8] x86/sev: Register the guest with the SVSM APIC protocol
From: Melody Wang
Date: Sun Sep 20 2026 - 14:20:15 EST
The SVSM APIC protocol supports 5 calls. SVSM_APIC_CONFIGURE_EMULATION
(shortened to SVSM_APIC_CONFIG_EMULATION for brevity), call 1, provides
the controls whether the guest can make use of the SVSM APIC protocol.
Implement this call, and register Alternate Injection for the guest by
default.
Signed-off-by: Melody Wang <huibo.wang@xxxxxxx>
---
arch/x86/boot/compressed/sev.c | 23 +++++++++++++++++++++++
arch/x86/boot/compressed/sev.h | 6 ++++++
arch/x86/include/asm/sev.h | 2 ++
drivers/firmware/efi/libstub/x86-stub.c | 3 +++
4 files changed, 34 insertions(+)
diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c
index fc2029746c50..9f776ba7f123 100644
--- a/arch/x86/boot/compressed/sev.c
+++ b/arch/x86/boot/compressed/sev.c
@@ -511,3 +511,26 @@ bool early_is_sevsnp_guest(void)
}
return true;
}
+
+/*
+ * When the guest is running at VMPL2 with Alternate Injection enabled,
+ * register Alternate Injection before ExitBootServices().
+ */
+void svsm_register_alt_inj(void)
+{
+ if (early_is_sevsnp_guest() && snp_vmpl) {
+ struct svsm_call call = {};
+ int ret;
+
+ if (!(sev_get_status() & MSR_AMD64_SNP_ALTERNATE_INJ))
+ return;
+
+ call.caa = (struct svsm_ca *)boot_svsm_caa_pa;
+ call.rax = SVSM_APIC_CALL(SVSM_APIC_CONFIG_EMULATION);
+ call.rcx = SVSM_AI_REGISTER;
+
+ ret = svsm_call_msr_protocol(&call);
+ if (ret)
+ sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_ALT_INJ_FAIL);
+ }
+}
diff --git a/arch/x86/boot/compressed/sev.h b/arch/x86/boot/compressed/sev.h
index 22637b416b46..dd058af2e7aa 100644
--- a/arch/x86/boot/compressed/sev.h
+++ b/arch/x86/boot/compressed/sev.h
@@ -12,6 +12,12 @@
#include <asm/shared/msr.h>
+enum svsm_ai_ctrl {
+ SVSM_AI_DISABLE,
+ SVSM_AI_DEREGISTER,
+ SVSM_AI_REGISTER,
+};
+
void snp_accept_memory(phys_addr_t start, phys_addr_t end);
u64 sev_get_status(void);
bool early_is_sevsnp_guest(void);
diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h
index 3cb6c5d6a6e0..c1e31fc9c918 100644
--- a/arch/x86/include/asm/sev.h
+++ b/arch/x86/include/asm/sev.h
@@ -543,6 +543,7 @@ enum es_result savic_register_gpa(u64 gpa);
enum es_result savic_unregister_gpa(u64 *gpa);
u64 sev_apic_ghcb_msr_read(u32 reg);
void sev_apic_ghcb_msr_write(u32 reg, u64 value);
+void svsm_register_alt_inj(void);
static __always_inline void vc_ghcb_invalidate(struct ghcb *ghcb)
{
@@ -652,6 +653,7 @@ static inline enum es_result savic_register_gpa(u64 gpa) { return ES_UNSUPPORTED
static inline enum es_result savic_unregister_gpa(u64 *gpa) { return ES_UNSUPPORTED; }
static inline void sev_apic_ghcb_msr_write(u32 reg, u64 value) { }
static inline u64 sev_apic_ghcb_msr_read(u32 reg) { return 0; }
+static inline void svsm_register_alt_inj(void) { }
#endif /* CONFIG_AMD_MEM_ENCRYPT */
diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c
index 49388524a61f..35b8641119b9 100644
--- a/drivers/firmware/efi/libstub/x86-stub.c
+++ b/drivers/firmware/efi/libstub/x86-stub.c
@@ -793,6 +793,9 @@ static bool sev_prepare(void)
unsupported);
return true;
}
+
+ svsm_register_alt_inj();
+
return false;
}
--
2.43.0