Re: [PATCH v6 5/7] x86/sev: Register Alternate Injection protocol during OVMF boot

From: Borislav Petkov

Date: Fri Nov 20 2026 - 22:31:22 EST


On Fri, Nov 06, 2026 at 01:25:31AM +0000, Melody Wang wrote:
> The SVSM provides the SVSM_APIC_CONFIG_EMULATION protocol to register
> and deregister Alternate Injection. This configuration must be completed

Unknown word [deregister] in commit message. Use "unregister".

But you said that the spec calls it "deregister". Oh well...

> before ExitBootServices() is called. Therefore, OVMF needs to invoke
> this protocol early to set up Alternate Injection for SEV-SNP guests.
>
> Implement this registration by default for guests that have SEV-SNP
> Alternate Injection enabled.
>
> Signed-off-by: Melody Wang <huibo.wang@xxxxxxx>
> ---
> drivers/firmware/efi/libstub/efistub.h | 11 ++++++++
> drivers/firmware/efi/libstub/x86-stub.c | 36 ++++++++++++++++++++++++-
> include/linux/efi.h | 2 ++
> 3 files changed, 48 insertions(+), 1 deletion(-)

...

> diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c
> index a2f193da9bde..878f61cd6fab 100644
> --- a/drivers/firmware/efi/libstub/x86-stub.c
> +++ b/drivers/firmware/efi/libstub/x86-stub.c
> @@ -786,6 +786,39 @@ static efi_status_t exit_boot(struct boot_params *boot_params, void *handle)
> return EFI_SUCCESS;
> }
>
> +/*
> + * When the guest is running at VMPL2 with Alternate Injection enabled,
> + * register Alternate Injection before ExitBootServices().
> + *
> + * Return true in the first conditional to mean that this is not an Alternate
> + * Injection guest and boot can continue. If it is an Alternate Injection guest,
> + * both failure to locate the protocol and to register it, means fail the boot.
> + */

So since we have a CONFIG_AMD_ALTERNATE_INJ config symbol, the intent is to
put all that functionality behind it so you can do something like this:

> +static bool svsm_register_alt_inj(void)
> +{
> + efi_guid_t alt_inj_proto = OVMF_SEV_ALT_INJ_REGISTER_PROTOCOL_GUID;
> + sev_alt_inj_register_protocol_t *proto;
> + efi_status_t status;

if (!IS_ENABLED(CONFIG_AMD_ALTERNATE_INJ))
return true;

> +
> + if (!early_is_sevsnp_guest() || !snp_vmpl ||
> + !(sev_get_status() & MSR_AMD64_SNP_ALTERNATE_INJ))
> + return true;
> +
> + status = efi_bs_call(locate_protocol, &alt_inj_proto, NULL, (void **)&proto);
> + if (status != EFI_SUCCESS) {
> + efi_err("Alternate Injection registration protocol not exist\n");
> + return false;
> + }
> +
> + status = efi_call_proto(proto, sev_register_alt_inj);
> + if (status != EFI_SUCCESS) {
> + efi_err("Alternate Injection registration protocol failed\n");
> + return false;
> + }
> +
> + return true;
> +}

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette