Re: [PATCH v2 6/8] x86/sev: Register the guest with the SVSM APIC protocol

From: Melody Wang

Date: Wed Sep 16 2026 - 15:20:42 EST


Hi Ard,

On 9/15/26 12:44 AM, Ard Biesheuvel wrote:
So please add it to the EFI stub, and code it against the boot services
(efi_err() for error messages, efi_exit() when aborting and returning to
the firmware, etc). Implementing this in a hybrid manner seems entirely
unnecessary.

I moved sev_prepare() into the EFI stub, and I wrote a wrapper for registering Alternate Injection in the EFI stub but kept the code in compressed, otherwise I have to export early_is_sevsnp_guest(), boot_svsm_caa_pa, and svsm_call_msr_protocol() so that it builds.

How about this below:

This is in the stub:

static bool sev_prepare(void)
{
u64 unsupported;

unsupported = snp_get_unsupported_features(sev_get_status());
if (unsupported) {
efi_err("Unsupported SEV-SNP features detected: 0x%llx\n",
unsupported);
return true;
}

register_alternate_injection();

return false;
}

and the stub calls this function:

+void register_alternate_injection(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);
+ }
+}

which is kept in sev.c to avoid cross-dependencies.

I can send it as patches too if it is easier to review this way.

--
Thanks,
Melody