From: Melody Wang <huibo.wang@amd.com>
To: <x86@kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
Tom Lendacky <thomas.lendacky@amd.com>, <ardb@kernel.org>,
Melody Wang <huibo.wang@amd.com>
Subject: [PATCH v7 08/10] x86/sev: Register Alternate Injection protocol during OVMF boot
Date: Sun, 6 Dec 2026 05:13:10 +0000 [thread overview]
Message-ID: <2892342f07b920fc4a73dd9ebc65924e4ad4b677.1796524449.git.huibo.wang@amd.com> (raw)
In-Reply-To: <cover.1796524449.git.huibo.wang@amd.com>
The SVSM provides the SVSM_APIC_CONFIG_EMULATION protocol to register
and deregister Alternate Injection. This configuration must be completed
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@amd.com>
---
drivers/firmware/efi/libstub/efistub.h | 11 +++++++
drivers/firmware/efi/libstub/x86-stub.c | 39 ++++++++++++++++++++++++-
include/linux/efi.h | 2 ++
3 files changed, 51 insertions(+), 1 deletion(-)
diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h
index a3b589c7d81c..062c9806c5d4 100644
--- a/drivers/firmware/efi/libstub/efistub.h
+++ b/drivers/firmware/efi/libstub/efistub.h
@@ -177,6 +177,17 @@ void efi_set_u64_split(u64 data, u32 *lo, u32 *hi)
*/
#define EFI_MMAP_NR_SLACK_SLOTS 32
+typedef union sev_alt_inj_register_protocol sev_alt_inj_register_protocol_t;
+union sev_alt_inj_register_protocol {
+ struct {
+ efi_status_t (__efiapi * sev_register_alt_inj)
+ (sev_alt_inj_register_protocol_t *);
+ };
+ struct {
+ u32 sev_register_alt_inj;
+ } mixed_mode;
+};
+
typedef struct efi_generic_dev_path efi_device_path_protocol_t;
union efi_device_path_to_text_protocol {
diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c
index 3c3259739d69..07a4aeec1ba7 100644
--- a/drivers/firmware/efi/libstub/x86-stub.c
+++ b/drivers/firmware/efi/libstub/x86-stub.c
@@ -786,6 +786,42 @@ 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.
+ */
+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;
+}
+
static bool sev_prepare(void)
{
u64 unsupported;
@@ -796,7 +832,8 @@ static bool sev_prepare(void)
unsupported);
return false;
}
- return true;
+
+ return svsm_register_alt_inj();
}
static void efi_get_seed(void *seed, int size)
diff --git a/include/linux/efi.h b/include/linux/efi.h
index 1bdb4639acef..3ceefc0066e2 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -444,6 +444,8 @@ void efi_native_runtime_setup(void);
#define OVMF_SEV_MEMORY_ACCEPTANCE_PROTOCOL_GUID EFI_GUID(0xc5a010fe, 0x38a7, 0x4531, 0x8a, 0x4a, 0x05, 0x00, 0xd2, 0xfd, 0x16, 0x49)
#define OVMF_MEMORY_LOG_TABLE_GUID EFI_GUID(0x95305139, 0xb20f, 0x4723, 0x84, 0x25, 0x62, 0x7c, 0x88, 0x8f, 0xf1, 0x21)
+#define OVMF_SEV_ALT_INJ_REGISTER_PROTOCOL_GUID EFI_GUID(0x3cf00587, 0x2329, 0x4c44, 0xb1, 0x84, 0x8f, 0xd9, 0x87, 0x00, 0x42, 0xe0)
+
typedef struct {
efi_guid_t guid;
u64 table;
--
2.43.0
next prev parent reply other threads:[~2026-12-06 5:15 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-06 5:13 [PATCH v7 00/10] Alternate Injection: Secure Interrupt Delivery for SEV-SNP Guests - Guest Support Melody Wang
2026-12-06 5:13 ` [PATCH v7 01/10] x86/sev: Add per-CPU CA runtime data and CA get/put helpers Melody Wang
2026-12-06 5:13 ` [PATCH v7 02/10] x86/sev: Switch the CA from per-CPU variables to the per-CPU runtime data Melody Wang
2026-12-06 5:13 ` [PATCH v7 03/10] x86/sev: Implement backup CA Melody Wang
2026-12-06 5:13 ` [PATCH v7 04/10] x86/sev: Add a config option for Alternate Injection Melody Wang
2026-12-06 5:13 ` [PATCH v7 05/10] x86/apic: Add an SVSM APIC driver Melody Wang
2026-12-06 5:13 ` [PATCH v7 06/10] x86/sev: Route unsupported APIC register accesses to the hypervisor APIC emulation Melody Wang
2026-12-06 5:13 ` [PATCH v7 07/10] x86/sev: Add a function to contain all SEV-specific setup operations Melody Wang
2026-12-06 5:13 ` Melody Wang [this message]
2026-12-06 5:13 ` [PATCH v7 09/10] x86/sev: Allow the guest to configure interrupt vectors for the hypervisor Melody Wang
2026-12-06 5:13 ` [PATCH v7 10/10] x86/sev: Indicate that Alternate Injection is supported in the guest Melody Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2892342f07b920fc4a73dd9ebc65924e4ad4b677.1796524449.git.huibo.wang@amd.com \
--to=huibo.wang@amd.com \
--cc=ardb@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=thomas.lendacky@amd.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®