* [PATCH v7 00/10] Alternate Injection: Secure Interrupt Delivery for SEV-SNP Guests - Guest Support
@ 2026-12-06 5:13 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
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: Melody Wang @ 2026-12-06 5:13 UTC (permalink / raw)
To: x86; +Cc: LKML, Tom Lendacky, ardb, Melody Wang
Hi all,
This revision addresses all review comments from version 6.
1. Added three pre-patches to fix the problem that a nested SVSM call on the same
CPU clobbers the arguments of the call it interrupted.
2. Changed some commit messages for better understanding.
3. Some minor code fixes from the review comments of Tom and Boris.
Thanks,
Melody
Changelog:
v6
--
This revision addresses all version 5 review comments from Sashiko.
Key Changes
1. svsm_apic driver cleanups: Removed the read-only MSR from the SVSM APIC
filter in svsm_apic_msr_write(), and the write-only MSR from
svsm_apic_msr_read().
2. Clarified and updated the commit message for patch 5 to improve readability
and context.
v5
--
This revision addresses all review comments from version 4.
1. As Ard suggested, used a bool as return value for svsm_register_alt_inj()
instead of int. Adjusted code with it.
2. Added more comments here for better understanding.
v4
--
This revision addresses all review comments from version 3.
1. As Ard suggested, handed over the registeration of kernel guest for
Alternate Injection with the SVSM to the OVMF insteading of calling the
SVSM for registration from kernel guest before ExitBootsService().
2. Added a common function for SVSM APIC ICR read and write.
3. Added a common function for sev_apic_ghcb_msr_read/write.
4. Changed some comments for better understanding.
5. Patch "Make-SVSM-calls-preemption-safe.patch" was merged to the tip tree.
v3
--
This revision addresses all review comments from version 2.
The changes include:
1. Moved sev_prepare() from decompressor to EFI stub.
2. Changed "Register Alternate Injection" and "configure all interrupt
vectors" as two APIs located in compressed/sev.c since they are
self-contained, avoiding exporting functions.
3. Added more comments for better understanding.
v2
--
This revision fixes all the review comments from version 1.
The changes include:
1. Changed a few comments for better understanding, deleted some unnecessary
code, corrected some typos, and some minor code fixes from the review
comments by Sashiko and Boris.
2. Unified sev_apic_ghcb_msr_write() and sev_apic_ghcb_msr_read().
3. Move x2apic_svsm.o after x2apic_savic.o so that the secure AVIC gets
preferred on machines supporting it.
4. Reworked svsm_apic_probe() as Boris suggested.
5. Updated tools with renamed MSR_AMD64_SNP_ALTERNATE_INJ_BIT and
MSR_AMD64_SNP_ALT_INJ for completeness' sake.
6. Changed svsm_apic_send_IPI_self() with writing to the dedicated
APIC_SELF_IPI instead of writing to APIC_ICR.
v1
--
The revision fixes all of the review comments from version 0.
The changes include:
1. Changed a few commit messages, new file names, variables name and order,
function names and more comments for better understanding.
2. Added a pre-patch to fix the problem that in two functions in the the SVSM
vTPM guest implementation do not disable preemption when fetching CAA. It
is moving the CAA fetching operation inside svsm_perform_call_protocol().
This series relies on this fix too.
3. Removed svsm_do_call() helper function and some intermediary layer
functions in SVSM APIC driver.
4. Removed the Secure AVIC check in SVSM APIC driver since it will never be
touched.
5. Terminate boot when Alternate Injection is enabled in vmpl0.
6. Added a common function for SVSM APIC read and write.
7. Added a new SEV_TERM_SET_LINUX value for Alternate Injection and APIC ghcb
msr read/write.
8. Reworked sev_prepare() to reflect the error conditions correctly.
9. Moved allowing all of interrupts right after registering the SVSM APIC
protocol.
v0
--
Alternate Injection is a method to provide secure interrupt delivery for
SEV-SNP guests against malicious injection attacks. By handing over the
control of the interrupt injection to the guest itself, the security is
applied. Alternate Injection use Secure VM Service Module (SVSM), and APIC
emulation in the SVSM to secure interrupt delivery.
This is the guest side patches. The patch set includes the following:
1. Add support for enabling Alternate Injection.
2. Add support for the SVSM APIC protocol which uses a subset of the
X2APIC MSRs.
3. Add support to allow the guest OS to request Alternate
Injection.
Melody Wang (10):
x86/sev: Add per-CPU CA runtime data and CA get/put helpers
x86/sev: Switch the CA from per-CPU variables to the per-CPU runtime
data
x86/sev: Implement backup CA
x86/sev: Add a config option for Alternate Injection
x86/apic: Add an SVSM APIC driver
x86/sev: Route unsupported APIC register accesses to the hypervisor
APIC emulation
x86/sev: Add a function to contain all SEV-specific setup operations
x86/sev: Register Alternate Injection protocol during OVMF boot
x86/sev: Allow the guest to configure interrupt vectors for the
hypervisor
x86/sev: Indicate that Alternate Injection is supported in the guest
arch/x86/Kconfig | 14 ++
arch/x86/boot/compressed/sev.c | 11 +-
arch/x86/boot/startup/sev-startup.c | 20 ++
arch/x86/boot/startup/sme.c | 3 +
arch/x86/coco/core.c | 3 +
arch/x86/coco/sev/core.c | 96 +++++-----
arch/x86/coco/sev/internal.h | 74 +++++--
arch/x86/coco/sev/noinstr.c | 76 ++++++++
arch/x86/coco/sev/svsm.c | 17 +-
arch/x86/coco/sev/vc-handle.c | 4 +-
arch/x86/include/asm/msr-index.h | 4 +-
arch/x86/include/asm/sev-common.h | 2 +
arch/x86/include/asm/sev.h | 26 ++-
arch/x86/kernel/apic/Makefile | 1 +
arch/x86/kernel/apic/x2apic_savic.c | 8 +-
arch/x86/kernel/apic/x2apic_svsm.c | 245 ++++++++++++++++++++++++
drivers/firmware/efi/libstub/efistub.h | 11 ++
drivers/firmware/efi/libstub/x86-stub.c | 45 ++++-
include/linux/cc_platform.h | 8 +
include/linux/efi.h | 2 +
tools/arch/x86/include/asm/msr-index.h | 4 +-
21 files changed, 591 insertions(+), 83 deletions(-)
create mode 100644 arch/x86/kernel/apic/x2apic_svsm.c
--
2.43.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v7 01/10] x86/sev: Add per-CPU CA runtime data and CA get/put helpers
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 ` 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
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Melody Wang @ 2026-12-06 5:13 UTC (permalink / raw)
To: x86; +Cc: LKML, Tom Lendacky, ardb, Melody Wang
SVSM calls pass their arguments through a Calling Area (CA). The CA is
per-CPU, so a nested SVSM call on the same CPU clobbers the arguments of
the call it interrupted.
This can happen in the SVSM CALL -> NMI -> SVSM CALL case: the NMI hits
while the interrupted context is using the CA, and the NMI handler
itself raises a second SVSM call which overwrites the CA contents the
first call still needs. Interrupts are already disabled around SVSM
calls, but that does not keep NMIs out.
The GHCB has the same problem and solves it with a per-CPU backup page
plus an in-use flag. Do the same for the CA.
No functional change for guests running without an SVSM.
Signed-off-by: Melody Wang <huibo.wang@amd.com>
---
arch/x86/coco/sev/internal.h | 39 ++++++++++++++++++++++++
arch/x86/coco/sev/noinstr.c | 57 ++++++++++++++++++++++++++++++++++++
2 files changed, 96 insertions(+)
diff --git a/arch/x86/coco/sev/internal.h b/arch/x86/coco/sev/internal.h
index 2e2ff48a7aae..96e89977fc2a 100644
--- a/arch/x86/coco/sev/internal.h
+++ b/arch/x86/coco/sev/internal.h
@@ -7,6 +7,36 @@
extern u64 sev_hv_features;
extern u64 sev_secrets_pa;
+struct svsm_ca_runtime_data {
+ /*
+ * The CA registered with the SVSM for this CPU: the boot CA for the
+ * BSP, registered via SVSM_CORE_REMAP_CA during early boot, and the
+ * CA for each AP via SVSM_CORE_CREATE_VCPU.
+ *
+ * Unlike the GHCB, whose GPA is handed to the hypervisor on every
+ * VMGEXIT, the CA GPA is registered state inside the SVSM. It cannot
+ * be swapped for another page on the fly, only its contents can be
+ * saved and restored.
+ */
+ struct svsm_ca *ca_page;
+ u64 caa_pa;
+
+ /*
+ * Mark the per-cpu CAs as in-use to detect a nested SVSM call.
+ * There is no need for it to be atomic, because nothing is written to
+ * the CA between the read and the write of ca_active. So it is safe
+ * to use it when a nested SVSM call happens before the write.
+ *
+ * This is necessary for example in the SVSM CALL->NMI->SVSM CALL case
+ * when the NMI happens while the first SVSM call uses the CA. When the
+ * NMI code raises a second SVSM call it might overwrite the contents of
+ * the CA written by the first SVSM call. To avoid this the content of
+ * the CA is saved and restored when the CA is detected to be in use
+ * already.
+ */
+ bool ca_active;
+};
+
/* #VC handler runtime per-CPU data */
struct sev_es_runtime_data {
struct ghcb ghcb_page;
@@ -42,12 +72,18 @@ struct sev_es_runtime_data {
* is currently unsupported in SEV-ES guests.
*/
unsigned long dr7;
+
+ struct svsm_ca_runtime_data *ca_runtime_data;
};
struct ghcb_state {
struct ghcb *ghcb;
};
+struct caa_state {
+ struct svsm_ca *caa;
+};
+
extern struct svsm_ca boot_svsm_ca_page;
struct ghcb *__sev_get_ghcb(struct ghcb_state *state);
@@ -105,6 +141,9 @@ static inline u64 svsm_get_caa_pa(void)
return boot_svsm_caa_pa;
}
+struct svsm_ca *__svsm_get_caa(struct caa_state *state);
+void __svsm_put_caa(struct caa_state *state);
+
static inline void __pval_terminate(u64 pfn, bool action, unsigned int page_size,
int ret, u64 svsm_ret)
{
diff --git a/arch/x86/coco/sev/noinstr.c b/arch/x86/coco/sev/noinstr.c
index 8ff556d28780..fb178ee1e60a 100644
--- a/arch/x86/coco/sev/noinstr.c
+++ b/arch/x86/coco/sev/noinstr.c
@@ -190,3 +190,60 @@ noinstr void __sev_put_ghcb(struct ghcb_state *state)
data->ghcb_active = false;
}
}
+
+/*
+ * Nothing shall interrupt this code path while holding the per-CPU
+ * CA. The backup CA is only for NMIs interrupting this path.
+ *
+ * Callers must disable interrupts around it.
+ */
+noinstr struct svsm_ca *__svsm_get_caa(struct caa_state *state)
+{
+ struct svsm_ca_runtime_data *data;
+ struct svsm_ca *caa;
+
+ WARN_ON(!irqs_disabled());
+
+ if (!sev_cfg.use_cas) {
+ state->caa = NULL;
+
+ return rip_rel_ptr(&boot_svsm_ca_page);
+ }
+
+ data = this_cpu_read(runtime_data)->ca_runtime_data;
+ caa = data->ca_page;
+
+ if (unlikely(data->ca_active)) {
+ /* CA is already in use - save its contents */
+ /* Backup CAA content */
+ *state->caa = *caa;
+ } else {
+ state->caa = NULL;
+ data->ca_active = true;
+ }
+
+ return caa;
+}
+
+noinstr void __svsm_put_caa(struct caa_state *state)
+{
+ struct svsm_ca_runtime_data *data;
+ struct svsm_ca *caa;
+
+ WARN_ON(!irqs_disabled());
+
+ if (!sev_cfg.use_cas)
+ return;
+
+ data = this_cpu_read(runtime_data)->ca_runtime_data;
+ caa = data->ca_page;
+
+ if (state->caa) {
+ /* Restore CAA from backup */
+ *caa = *state->caa;
+
+ state->caa = NULL;
+ } else {
+ data->ca_active = false;
+ }
+}
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v7 02/10] x86/sev: Switch the CA from per-CPU variables to the per-CPU runtime data
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 ` Melody Wang
2026-12-06 5:13 ` [PATCH v7 03/10] x86/sev: Implement backup CA Melody Wang
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Melody Wang @ 2026-12-06 5:13 UTC (permalink / raw)
To: x86; +Cc: LKML, Tom Lendacky, ardb, Melody Wang
Nested-call detection needs the SVSM Calling Area's in-use state to be
reachable from the same noinstr code that fetches the CA. Today the CA
is tracked in standalone per-CPU variables (svsm_caa, svsm_caa_pa),
separate from the rest of the per-CPU #VC state in struct
sev_es_runtime_data.
Move the CA state into the runtime data so it lives in one place with
the other #VC state, allowing the in-use flag to be accessed safely from
noinstr context alongside the CA pointer.
No functional change intended.
Signed-off-by: Melody Wang <huibo.wang@amd.com>
---
arch/x86/coco/sev/core.c | 46 ++++++++++++++++++++++++-----------
arch/x86/coco/sev/internal.h | 25 +++++++++----------
arch/x86/coco/sev/svsm.c | 17 ++++++++-----
arch/x86/coco/sev/vc-handle.c | 4 +--
4 files changed, 57 insertions(+), 35 deletions(-)
diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c
index 6a13af13ca59..d4cd7a0d469f 100644
--- a/arch/x86/coco/sev/core.c
+++ b/arch/x86/coco/sev/core.c
@@ -386,14 +386,18 @@ static unsigned long __set_pages_state(struct snp_psc_desc *data, unsigned long
static void set_pages_state(unsigned long vaddr, unsigned long npages, int op)
{
+ struct caa_state ca_state;
struct snp_psc_desc desc;
unsigned long vaddr_end;
/* Use the MSR protocol when a GHCB is not available. */
if (!boot_ghcb) {
- struct psc_desc d = { op, svsm_get_caa(), svsm_get_caa_pa() };
+ struct psc_desc d = { op, __svsm_get_caa(&ca_state), svsm_get_caa_pa() };
- return early_set_pages_state(vaddr, __pa(vaddr), npages, &d);
+ early_set_pages_state(vaddr, __pa(vaddr), npages, &d);
+
+ __svsm_put_caa(&ca_state);
+ return;
}
vaddr = vaddr & PAGE_MASK;
@@ -472,8 +476,9 @@ static int vmgexit_ap_control(u64 event, struct sev_es_save_area *vmsa, u32 apic
return ret;
}
-static int snp_set_vmsa(void *va, void *caa, int apic_id, bool make_vmsa)
+static int snp_set_vmsa(void *va, u64 caa_pa, int apic_id, bool make_vmsa)
{
+ struct caa_state ca_state;
int ret;
if (snp_vmpl) {
@@ -482,13 +487,13 @@ static int snp_set_vmsa(void *va, void *caa, int apic_id, bool make_vmsa)
local_irq_save(flags);
- call.caa = this_cpu_read(svsm_caa);
+ call.caa = __svsm_get_caa(&ca_state);
call.rcx = __pa(va);
if (make_vmsa) {
/* Protocol 0, Call ID 2 */
call.rax = SVSM_CORE_CALL(SVSM_CORE_CREATE_VCPU);
- call.rdx = __pa(caa);
+ call.rdx = caa_pa;
call.r8 = apic_id;
} else {
/* Protocol 0, Call ID 3 */
@@ -497,6 +502,7 @@ static int snp_set_vmsa(void *va, void *caa, int apic_id, bool make_vmsa)
ret = svsm_perform_call_protocol(&call);
+ __svsm_put_caa(&ca_state);
local_irq_restore(flags);
} else {
/*
@@ -521,7 +527,7 @@ static void snp_cleanup_vmsa(struct sev_es_save_area *vmsa, int apic_id)
{
int err;
- err = snp_set_vmsa(vmsa, NULL, apic_id, false);
+ err = snp_set_vmsa(vmsa, 0, apic_id, false);
if (err)
pr_err("clear VMSA page failed (%u), leaking page\n", err);
else
@@ -757,8 +763,8 @@ static void *snp_alloc_vmsa_page(int cpu)
static int wakeup_cpu_via_vmgexit(u32 apic_id, unsigned long start_ip, unsigned int cpu)
{
struct sev_es_save_area *cur_vmsa, *vmsa;
- struct svsm_ca *caa;
u8 sipi_vector;
+ u64 caa_pa;
int ret;
u64 cr4;
@@ -794,7 +800,7 @@ static int wakeup_cpu_via_vmgexit(u32 apic_id, unsigned long start_ip, unsigned
return -ENOMEM;
/* If an SVSM is present, the SVSM per-CPU CAA will be !NULL */
- caa = per_cpu(svsm_caa, cpu);
+ caa_pa = svsm_get_cpu_caa_pa(cpu);
/* CR4 should maintain the MCE value */
cr4 = native_read_cr4() & X86_CR4_MCE;
@@ -856,7 +862,7 @@ static int wakeup_cpu_via_vmgexit(u32 apic_id, unsigned long start_ip, unsigned
}
/* Switch the page over to a VMSA page now that it is initialized */
- ret = snp_set_vmsa(vmsa, caa, apic_id, true);
+ ret = snp_set_vmsa(vmsa, caa_pa, apic_id, true);
if (ret) {
pr_err("set VMSA page failed (%u)\n", ret);
free_page((unsigned long)vmsa);
@@ -959,7 +965,7 @@ int __init sev_es_efi_map_ghcbs_cas(pgd_t *pgd)
return 1;
if (snp_vmpl) {
- address = per_cpu(svsm_caa_pa, cpu);
+ address = svsm_get_cpu_caa_pa(cpu);
if (!address)
return 1;
@@ -1194,18 +1200,27 @@ static void __init alloc_runtime_data(int cpu)
per_cpu(runtime_data, cpu) = data;
if (snp_vmpl) {
+ struct svsm_ca_runtime_data *svsm_data;
struct svsm_ca *caa;
/* Allocate the SVSM CA page if an SVSM is present */
caa = cpu ? memblock_alloc_or_panic(sizeof(*caa), PAGE_SIZE)
: &boot_svsm_ca_page;
- per_cpu(svsm_caa, cpu) = caa;
- per_cpu(svsm_caa_pa, cpu) = __pa(caa);
+
+ svsm_data = memblock_alloc_node(sizeof(*svsm_data), PAGE_SIZE, cpu_to_node(cpu));
+
+ if (!svsm_data)
+ panic("Can't allocate SVSM CA runtime data");
+
+ svsm_data->ca_page = caa;
+ svsm_data->caa_pa = __pa(caa);
+
+ data->ca_runtime_data = svsm_data;
}
}
-static void __init init_ghcb(int cpu)
+static void __init init_ghcb_and_ca(int cpu)
{
struct sev_es_runtime_data *data;
int err;
@@ -1221,6 +1236,9 @@ static void __init init_ghcb(int cpu)
data->ghcb_active = false;
data->backup_ghcb_active = false;
+
+ if (snp_vmpl)
+ data->ca_runtime_data->ca_active = false;
}
void __init sev_es_init_vc_handling(void)
@@ -1249,7 +1267,7 @@ void __init sev_es_init_vc_handling(void)
/* Initialize per-cpu GHCB pages */
for_each_possible_cpu(cpu) {
alloc_runtime_data(cpu);
- init_ghcb(cpu);
+ init_ghcb_and_ca(cpu);
}
if (snp_vmpl)
diff --git a/arch/x86/coco/sev/internal.h b/arch/x86/coco/sev/internal.h
index 96e89977fc2a..540b1a2b1946 100644
--- a/arch/x86/coco/sev/internal.h
+++ b/arch/x86/coco/sev/internal.h
@@ -95,9 +95,6 @@ DECLARE_PER_CPU(struct sev_es_save_area *, sev_vmsa);
void early_set_pages_state(unsigned long vaddr, unsigned long paddr,
unsigned long npages, const struct psc_desc *desc);
-DECLARE_PER_CPU(struct svsm_ca *, svsm_caa);
-DECLARE_PER_CPU(u64, svsm_caa_pa);
-
extern u64 boot_svsm_caa_pa;
enum es_result verify_exception_info(struct ghcb *ghcb, struct es_em_ctxt *ctxt);
@@ -125,20 +122,22 @@ u64 get_hv_features(void);
const struct snp_cpuid_table *snp_cpuid_get_table(void);
-static inline struct svsm_ca *svsm_get_caa(void)
+static inline u64 svsm_get_caa_pa(void)
{
- if (sev_cfg.use_cas)
- return this_cpu_read(svsm_caa);
- else
- return rip_rel_ptr(&boot_svsm_ca_page);
+ if (!sev_cfg.use_cas)
+ return boot_svsm_caa_pa;
+
+ return this_cpu_read(runtime_data)->ca_runtime_data->caa_pa;
}
-static inline u64 svsm_get_caa_pa(void)
+static inline u64 svsm_get_cpu_caa_pa(int cpu)
{
- if (sev_cfg.use_cas)
- return this_cpu_read(svsm_caa_pa);
- else
- return boot_svsm_caa_pa;
+ struct sev_es_runtime_data *data = per_cpu(runtime_data, cpu);
+
+ if (!data || !data->ca_runtime_data)
+ return 0;
+
+ return data->ca_runtime_data->caa_pa;
}
struct svsm_ca *__svsm_get_caa(struct caa_state *state);
diff --git a/arch/x86/coco/sev/svsm.c b/arch/x86/coco/sev/svsm.c
index 2d493d55ff2e..cd38c6a03a53 100644
--- a/arch/x86/coco/sev/svsm.c
+++ b/arch/x86/coco/sev/svsm.c
@@ -24,9 +24,6 @@ SYM_PIC_ALIAS(boot_svsm_ca_page);
u64 boot_svsm_caa_pa __ro_after_init;
SYM_PIC_ALIAS(boot_svsm_caa_pa);
-DEFINE_PER_CPU(struct svsm_ca *, svsm_caa);
-DEFINE_PER_CPU(u64, svsm_caa_pa);
-
static int svsm_perform_ghcb_protocol(struct ghcb *ghcb, struct svsm_call *call)
{
struct es_em_ctxt ctxt;
@@ -67,6 +64,7 @@ static int svsm_perform_ghcb_protocol(struct ghcb *ghcb, struct svsm_call *call)
int svsm_perform_call_protocol(struct svsm_call *call)
{
+ struct caa_state ca_state;
struct ghcb_state state;
unsigned long flags;
struct ghcb *ghcb;
@@ -80,7 +78,7 @@ int svsm_perform_call_protocol(struct svsm_call *call)
* is fetched, always fetch 'caa' and then issue the SVSM call with
* interrupts disabled. This ensures the correct 'caa' is used.
*/
- call->caa = svsm_get_caa();
+ call->caa = __svsm_get_caa(&ca_state);
ghcb = __sev_get_ghcb(&state);
@@ -90,6 +88,7 @@ int svsm_perform_call_protocol(struct svsm_call *call)
} while (ret == -EAGAIN);
__sev_put_ghcb(&state);
+ __svsm_put_caa(&ca_state);
native_local_irq_restore(flags);
@@ -176,6 +175,7 @@ void svsm_pval_pages(struct snp_psc_desc *desc)
unsigned int i, pv_4k_count = 0;
struct svsm_pvalidate_call *pc;
struct svsm_call call = {};
+ struct caa_state ca_state;
unsigned long flags;
bool action;
u64 pc_pa;
@@ -194,11 +194,13 @@ void svsm_pval_pages(struct snp_psc_desc *desc)
* the SVSM is invoked. This repeats until all entries in the descriptor
* are processed.
*/
- call.caa = svsm_get_caa();
+ call.caa = __svsm_get_caa(&ca_state);
pc = (struct svsm_pvalidate_call *)call.caa->svsm_buffer;
pc_pa = svsm_get_caa_pa() + offsetof(struct svsm_ca, svsm_buffer);
+ __svsm_put_caa(&ca_state);
+
/* Protocol 0, Call ID 1 */
call.rax = SVSM_CORE_CALL(SVSM_CORE_PVALIDATE);
call.rcx = pc_pa;
@@ -272,6 +274,7 @@ int snp_issue_svsm_attest_req(u64 call_id, struct svsm_call *call,
struct svsm_attest_call *input)
{
struct svsm_attest_call *ac;
+ struct caa_state ca_state;
unsigned long flags;
u64 attest_call_pa;
int ret;
@@ -281,13 +284,15 @@ int snp_issue_svsm_attest_req(u64 call_id, struct svsm_call *call,
local_irq_save(flags);
- call->caa = svsm_get_caa();
+ call->caa = __svsm_get_caa(&ca_state);
ac = (struct svsm_attest_call *)call->caa->svsm_buffer;
attest_call_pa = svsm_get_caa_pa() + offsetof(struct svsm_ca, svsm_buffer);
*ac = *input;
+ __svsm_put_caa(&ca_state);
+
/*
* Set input registers for the request and set RDX and R8 to known
* values in order to detect length values being returned in them.
diff --git a/arch/x86/coco/sev/vc-handle.c b/arch/x86/coco/sev/vc-handle.c
index a233ea5c867e..080b7760aa06 100644
--- a/arch/x86/coco/sev/vc-handle.c
+++ b/arch/x86/coco/sev/vc-handle.c
@@ -345,8 +345,8 @@ static enum es_result __vc_handle_msr_caa(struct pt_regs *regs, bool write)
if (write)
return ES_OK;
- regs->ax = lower_32_bits(this_cpu_read(svsm_caa_pa));
- regs->dx = upper_32_bits(this_cpu_read(svsm_caa_pa));
+ regs->ax = lower_32_bits(svsm_get_caa_pa());
+ regs->dx = upper_32_bits(svsm_get_caa_pa());
return ES_OK;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v7 03/10] x86/sev: Implement backup CA
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 ` Melody Wang
2026-12-06 5:13 ` [PATCH v7 04/10] x86/sev: Add a config option for Alternate Injection Melody Wang
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Melody Wang @ 2026-12-06 5:13 UTC (permalink / raw)
To: x86; +Cc: LKML, Tom Lendacky, ardb, Melody Wang
Give each CPU a backup CA so an interrupting call can save and restore
the in-use CA around its own call. If both CAs are already in use there
is no safe way to proceed, so panic, as the GHCB code does.
No functional change for guests running without an SVSM.
Signed-off-by: Melody Wang <huibo.wang@amd.com>
---
arch/x86/coco/sev/core.c | 4 +++-
arch/x86/coco/sev/internal.h | 10 ++++++++++
arch/x86/coco/sev/noinstr.c | 19 +++++++++++++++++++
3 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c
index d4cd7a0d469f..91a3ff5b1f27 100644
--- a/arch/x86/coco/sev/core.c
+++ b/arch/x86/coco/sev/core.c
@@ -1237,8 +1237,10 @@ static void __init init_ghcb_and_ca(int cpu)
data->ghcb_active = false;
data->backup_ghcb_active = false;
- if (snp_vmpl)
+ if (snp_vmpl) {
data->ca_runtime_data->ca_active = false;
+ data->ca_runtime_data->backup_ca_active = false;
+ }
}
void __init sev_es_init_vc_handling(void)
diff --git a/arch/x86/coco/sev/internal.h b/arch/x86/coco/sev/internal.h
index 540b1a2b1946..8f5dd898b244 100644
--- a/arch/x86/coco/sev/internal.h
+++ b/arch/x86/coco/sev/internal.h
@@ -21,6 +21,15 @@ struct svsm_ca_runtime_data {
struct svsm_ca *ca_page;
u64 caa_pa;
+ /*
+ * Reserve one page per CPU as backup storage for CA.
+ * It is needed when an NMI happens while the SVSM call uses the real
+ * CA, and the NMI handler itself is causing another SVSM call. In
+ * that case the CA content of the first SVSM call needs to be backed up
+ * and restored.
+ */
+ struct svsm_ca backup_ca;
+
/*
* Mark the per-cpu CAs as in-use to detect a nested SVSM call.
* There is no need for it to be atomic, because nothing is written to
@@ -35,6 +44,7 @@ struct svsm_ca_runtime_data {
* already.
*/
bool ca_active;
+ bool backup_ca_active;
};
/* #VC handler runtime per-CPU data */
diff --git a/arch/x86/coco/sev/noinstr.c b/arch/x86/coco/sev/noinstr.c
index fb178ee1e60a..9e85f64f07ac 100644
--- a/arch/x86/coco/sev/noinstr.c
+++ b/arch/x86/coco/sev/noinstr.c
@@ -215,6 +215,24 @@ noinstr struct svsm_ca *__svsm_get_caa(struct caa_state *state)
if (unlikely(data->ca_active)) {
/* CA is already in use - save its contents */
+ if (unlikely(data->backup_ca_active)) {
+ /*
+ * Backup-CA is also already in use. There is no way
+ * to continue here so just kill the machine.
+ */
+ data->ca_active = false;
+ data->backup_ca_active = false;
+
+ instrumentation_begin();
+ panic("CA and backup CA already in use. Giving up");
+ instrumentation_end();
+ }
+
+ /* Mark backup_ca active before writing to it */
+ data->backup_ca_active = true;
+
+ state->caa = &data->backup_ca;
+
/* Backup CAA content */
*state->caa = *caa;
} else {
@@ -242,6 +260,7 @@ noinstr void __svsm_put_caa(struct caa_state *state)
/* Restore CAA from backup */
*caa = *state->caa;
+ data->backup_ca_active = false;
state->caa = NULL;
} else {
data->ca_active = false;
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v7 04/10] x86/sev: Add a config option for Alternate Injection
2026-12-06 5:13 [PATCH v7 00/10] Alternate Injection: Secure Interrupt Delivery for SEV-SNP Guests - Guest Support Melody Wang
` (2 preceding siblings ...)
2026-12-06 5:13 ` [PATCH v7 03/10] x86/sev: Implement backup CA Melody Wang
@ 2026-12-06 5:13 ` Melody Wang
2026-12-06 5:13 ` [PATCH v7 05/10] x86/apic: Add an SVSM APIC driver Melody Wang
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Melody Wang @ 2026-12-06 5:13 UTC (permalink / raw)
To: x86; +Cc: LKML, Tom Lendacky, ardb, Melody Wang
Alternate Injection is a method to protect a SNP guest from malicious
injection attacks by allowing the guest to control the injection.
When this feature is enabled, interrupts are injected with the help of
an agent called a Secure VM Service Module (SVSM) which executes in the
security realm of the guest and uses Restricted Injection as the sole
method to receive interrupts from the hypervisor.
Signed-off-by: Melody Wang <huibo.wang@amd.com>
---
arch/x86/Kconfig | 14 ++++++++++++++
arch/x86/boot/compressed/sev.c | 2 +-
arch/x86/coco/core.c | 3 +++
arch/x86/coco/sev/core.c | 2 +-
arch/x86/include/asm/msr-index.h | 4 ++--
include/linux/cc_platform.h | 8 ++++++++
tools/arch/x86/include/asm/msr-index.h | 4 ++--
7 files changed, 31 insertions(+), 6 deletions(-)
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index ff90a8fef0f2..50da07983f56 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -494,6 +494,20 @@ config AMD_SECURE_AVIC
If you don't know what to do here, say N.
+config AMD_ALTERNATE_INJ
+ bool "Support Alternate Injection"
+ depends on X86_X2APIC && AMD_MEM_ENCRYPT
+ help
+ Enable AMD Alternate Injection support for SNP guests.
+
+ The Alternate Injection feature of SEV-SNP enhances the security of
+ a confidential VM by preventing the untrusted host from presenting
+ unexpected interrupts or exceptions, while still preserving the
+ standard interrupt dispatch semantics inherent to the x86
+ architecture.
+
+ If you don't know what to do here, say N.
+
config X86_POSTED_MSI
bool "Enable MSI and MSI-x delivery by posted interrupts"
depends on X86_64 && IRQ_REMAP
diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c
index c6512f2ea31e..fc2029746c50 100644
--- a/arch/x86/boot/compressed/sev.c
+++ b/arch/x86/boot/compressed/sev.c
@@ -179,7 +179,7 @@ bool sev_es_check_ghcb_fault(unsigned long address)
#define SNP_FEATURES_IMPL_REQ (MSR_AMD64_SNP_VTOM | \
MSR_AMD64_SNP_REFLECT_VC | \
MSR_AMD64_SNP_RESTRICTED_INJ | \
- MSR_AMD64_SNP_ALT_INJ | \
+ MSR_AMD64_SNP_ALTERNATE_INJ | \
MSR_AMD64_SNP_DEBUG_SWAP | \
MSR_AMD64_SNP_VMPL_SSS | \
MSR_AMD64_SNP_SECURE_TSC | \
diff --git a/arch/x86/coco/core.c b/arch/x86/coco/core.c
index 989ca9f72ba3..aabda3ddc0e2 100644
--- a/arch/x86/coco/core.c
+++ b/arch/x86/coco/core.c
@@ -107,6 +107,9 @@ static bool noinstr amd_cc_platform_has(enum cc_attr attr)
case CC_ATTR_SNP_SECURE_AVIC:
return sev_status & MSR_AMD64_SNP_SECURE_AVIC;
+ case CC_ATTR_SNP_ALTERNATE_INJECTION:
+ return sev_status & MSR_AMD64_SNP_ALTERNATE_INJ;
+
default:
return false;
}
diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c
index 91a3ff5b1f27..6d2691170a95 100644
--- a/arch/x86/coco/sev/core.c
+++ b/arch/x86/coco/sev/core.c
@@ -78,7 +78,7 @@ static const char * const sev_status_feat_names[] = {
[MSR_AMD64_SNP_VTOM_BIT] = "vTom",
[MSR_AMD64_SNP_REFLECT_VC_BIT] = "ReflectVC",
[MSR_AMD64_SNP_RESTRICTED_INJ_BIT] = "RI",
- [MSR_AMD64_SNP_ALT_INJ_BIT] = "AI",
+ [MSR_AMD64_SNP_ALTERNATE_INJ_BIT] = "AI",
[MSR_AMD64_SNP_DEBUG_SWAP_BIT] = "DebugSwap",
[MSR_AMD64_SNP_PREVENT_HOST_IBS_BIT] = "NoHostIBS",
[MSR_AMD64_SNP_BTB_ISOLATION_BIT] = "BTBIsol",
diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h
index 1c7b5d29556e..86926fb73d61 100644
--- a/arch/x86/include/asm/msr-index.h
+++ b/arch/x86/include/asm/msr-index.h
@@ -730,8 +730,8 @@
#define MSR_AMD64_SNP_REFLECT_VC BIT_ULL(MSR_AMD64_SNP_REFLECT_VC_BIT)
#define MSR_AMD64_SNP_RESTRICTED_INJ_BIT 5
#define MSR_AMD64_SNP_RESTRICTED_INJ BIT_ULL(MSR_AMD64_SNP_RESTRICTED_INJ_BIT)
-#define MSR_AMD64_SNP_ALT_INJ_BIT 6
-#define MSR_AMD64_SNP_ALT_INJ BIT_ULL(MSR_AMD64_SNP_ALT_INJ_BIT)
+#define MSR_AMD64_SNP_ALTERNATE_INJ_BIT 6
+#define MSR_AMD64_SNP_ALTERNATE_INJ BIT_ULL(MSR_AMD64_SNP_ALTERNATE_INJ_BIT)
#define MSR_AMD64_SNP_DEBUG_SWAP_BIT 7
#define MSR_AMD64_SNP_DEBUG_SWAP BIT_ULL(MSR_AMD64_SNP_DEBUG_SWAP_BIT)
#define MSR_AMD64_SNP_PREVENT_HOST_IBS_BIT 8
diff --git a/include/linux/cc_platform.h b/include/linux/cc_platform.h
index 559353ad64ac..80d9f1de2ae8 100644
--- a/include/linux/cc_platform.h
+++ b/include/linux/cc_platform.h
@@ -104,6 +104,14 @@ enum cc_attr {
* to run SEV-SNP guests with full Secure AVIC capabilities.
*/
CC_ATTR_SNP_SECURE_AVIC,
+
+ /**
+ * @CC_ATTR_SNP_ALTERNATE_INJECTION: AMD Alternate Injection enabled.
+ *
+ * A Secure VM Service Module (SVSM) has started the guest with
+ * Alternate Injection enabled.
+ */
+ CC_ATTR_SNP_ALTERNATE_INJECTION,
};
#ifdef CONFIG_ARCH_HAS_CC_PLATFORM
diff --git a/tools/arch/x86/include/asm/msr-index.h b/tools/arch/x86/include/asm/msr-index.h
index 1c7b5d29556e..86926fb73d61 100644
--- a/tools/arch/x86/include/asm/msr-index.h
+++ b/tools/arch/x86/include/asm/msr-index.h
@@ -730,8 +730,8 @@
#define MSR_AMD64_SNP_REFLECT_VC BIT_ULL(MSR_AMD64_SNP_REFLECT_VC_BIT)
#define MSR_AMD64_SNP_RESTRICTED_INJ_BIT 5
#define MSR_AMD64_SNP_RESTRICTED_INJ BIT_ULL(MSR_AMD64_SNP_RESTRICTED_INJ_BIT)
-#define MSR_AMD64_SNP_ALT_INJ_BIT 6
-#define MSR_AMD64_SNP_ALT_INJ BIT_ULL(MSR_AMD64_SNP_ALT_INJ_BIT)
+#define MSR_AMD64_SNP_ALTERNATE_INJ_BIT 6
+#define MSR_AMD64_SNP_ALTERNATE_INJ BIT_ULL(MSR_AMD64_SNP_ALTERNATE_INJ_BIT)
#define MSR_AMD64_SNP_DEBUG_SWAP_BIT 7
#define MSR_AMD64_SNP_DEBUG_SWAP BIT_ULL(MSR_AMD64_SNP_DEBUG_SWAP_BIT)
#define MSR_AMD64_SNP_PREVENT_HOST_IBS_BIT 8
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v7 05/10] x86/apic: Add an SVSM APIC driver
2026-12-06 5:13 [PATCH v7 00/10] Alternate Injection: Secure Interrupt Delivery for SEV-SNP Guests - Guest Support Melody Wang
` (3 preceding siblings ...)
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 ` 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
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Melody Wang @ 2026-12-06 5:13 UTC (permalink / raw)
To: x86; +Cc: LKML, Tom Lendacky, ardb, Melody Wang
Alternate Injection replaces hypervisor-based interrupt queuing and
event injection in favor of guest-controlled queuing and injection. In
order to complish that, an SVSM is used to update the guest VMSA to
perform the required actions.
The guest uses the SVSM APIC protocol to communicate with the SVSM to
perform selected APIC related operations instead of using standard APIC
MSR access.
Add such a SVSM APIC driver (which implements a subset of an X2APIC),
for the APIC emulation supported by the SVSM.
Signed-off-by: Melody Wang <huibo.wang@amd.com>
---
arch/x86/include/asm/sev-common.h | 1 +
arch/x86/include/asm/sev.h | 9 ++
arch/x86/kernel/apic/Makefile | 1 +
arch/x86/kernel/apic/x2apic_svsm.c | 244 +++++++++++++++++++++++++++++
4 files changed, 255 insertions(+)
create mode 100644 arch/x86/kernel/apic/x2apic_svsm.c
diff --git a/arch/x86/include/asm/sev-common.h b/arch/x86/include/asm/sev-common.h
index b0a64a49875c..ef9761a945f0 100644
--- a/arch/x86/include/asm/sev-common.h
+++ b/arch/x86/include/asm/sev-common.h
@@ -210,6 +210,7 @@ struct snp_psc_desc {
#define GHCB_TERM_SVSM_CA_REMAP_FAIL 11 /* SVSM is present but CA could not be remapped */
#define GHCB_TERM_SAVIC_FAIL 12 /* Secure AVIC-specific failure */
#define GHCB_TERM_VC_NO_GHCB 13 /* #VC that can't be handled without a GHCB */
+#define GHCB_TERM_ALT_INJ_FAIL 14 /* Alternate Injection-specific failure */
#define GHCB_RESP_CODE(v) ((v) & GHCB_MSR_INFO_MASK)
diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h
index c7ea9845351e..6496b376452f 100644
--- a/arch/x86/include/asm/sev.h
+++ b/arch/x86/include/asm/sev.h
@@ -435,6 +435,13 @@ struct svsm_call {
#define SVSM_VTPM_QUERY 0
#define SVSM_VTPM_CMD 1
+#define SVSM_APIC_CALL(x) ((3ULL << 32) | (x))
+#define SVSM_APIC_QUERY_FEATURES 0
+#define SVSM_APIC_CONFIG_EMULATION 1
+#define SVSM_APIC_READ_REGISTER 2
+#define SVSM_APIC_WRITE_REGISTER 3
+#define SVSM_APIC_CONFIG_VECTOR 4
+
#ifdef CONFIG_AMD_MEM_ENCRYPT
extern u8 snp_vmpl;
@@ -529,6 +536,7 @@ void snp_msg_free(struct snp_msg_desc *mdesc);
int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req);
int snp_svsm_vtpm_send_command(u8 *buffer);
+int svsm_perform_call_protocol(struct svsm_call *call);
void __init snp_secure_tsc_prepare(void);
void __init snp_secure_tsc_init(void);
@@ -638,6 +646,7 @@ static inline void snp_msg_free(struct snp_msg_desc *mdesc) { }
static inline int snp_send_guest_request(struct snp_msg_desc *mdesc,
struct snp_guest_req *req) { return -ENODEV; }
static inline int snp_svsm_vtpm_send_command(u8 *buffer) { return -ENODEV; }
+static inline int svsm_perform_call_protocol(struct svsm_call *call) { return -ENODEV; }
static inline void __init snp_secure_tsc_prepare(void) { }
static inline void __init snp_secure_tsc_init(void) { }
static inline void sev_evict_cache(void *va, int npages) {}
diff --git a/arch/x86/kernel/apic/Makefile b/arch/x86/kernel/apic/Makefile
index 581db89477f9..fef51024025b 100644
--- a/arch/x86/kernel/apic/Makefile
+++ b/arch/x86/kernel/apic/Makefile
@@ -19,6 +19,7 @@ ifeq ($(CONFIG_X86_64),y)
obj-$(CONFIG_X86_NUMACHIP) += apic_numachip.o
obj-$(CONFIG_X86_UV) += x2apic_uv_x.o
obj-$(CONFIG_AMD_SECURE_AVIC) += x2apic_savic.o
+obj-$(CONFIG_AMD_ALTERNATE_INJ) += x2apic_svsm.o
obj-$(CONFIG_X86_X2APIC) += x2apic_phys.o
obj-$(CONFIG_X86_X2APIC) += x2apic_cluster.o
obj-y += apic_flat_64.o
diff --git a/arch/x86/kernel/apic/x2apic_svsm.c b/arch/x86/kernel/apic/x2apic_svsm.c
new file mode 100644
index 000000000000..29ee7065e6f4
--- /dev/null
+++ b/arch/x86/kernel/apic/x2apic_svsm.c
@@ -0,0 +1,244 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * AMD Alternate Injection Support (SEV-SNP Guests)
+ *
+ * Copyright (C) 2026 Advanced Micro Devices, Inc.
+ *
+ * Author: Melody Wang <huibo.wang@amd.com>
+ */
+
+#include <linux/cpumask.h>
+#include <linux/cc_platform.h>
+
+#include <asm/apic.h>
+#include <asm/sev.h>
+
+#include "local.h"
+
+static int svsm_apic_probe(void)
+{
+ if (!cc_platform_has(CC_ATTR_SNP_ALTERNATE_INJECTION))
+ return 0;
+
+ if (!snp_vmpl) {
+ pr_err("Alternate Injection in VMPL0 impossible. Terminating.\n");
+ goto terminate;
+ }
+
+ if (!x2apic_mode) {
+ pr_err("Alternate Injection in non x2APIC mode impossible. Terminating.\n");
+ goto terminate;
+ }
+
+ pr_info("Alternate Injection SVSM APIC enabled\n");
+
+ return 1;
+
+terminate:
+ sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_ALT_INJ_FAIL);
+ return -EINVAL;
+
+}
+
+static int svsm_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
+{
+ return x2apic_enabled() && cc_platform_has(CC_ATTR_SNP_ALTERNATE_INJECTION) && snp_vmpl;
+}
+
+static void svsm_apic_msr_write(u32 reg, u32 v)
+{
+ u32 msr = APIC_BASE_MSR + (reg >> 4);
+ struct svsm_call call = {};
+ int ret;
+
+ if (reg == APIC_DFR || reg == APIC_ID || reg == APIC_LDR ||
+ reg == APIC_LVR)
+ return;
+
+ switch (reg) {
+ case APIC_TASKPRI:
+ case APIC_EOI:
+ case APIC_ICR:
+ case APIC_SELF_IPI:
+ call.rax = SVSM_APIC_CALL(SVSM_APIC_WRITE_REGISTER);
+ call.rcx = msr;
+ call.rdx = v;
+
+ ret = svsm_perform_call_protocol(&call);
+ if (ret) {
+ pr_err("SVSM_APIC_WRITE_REGISTER: 0x%x, error: %d\n", reg, ret);
+ sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_ALT_INJ_FAIL);
+ }
+ break;
+ default:
+ pr_err("SVSM_APIC_WRITE_REGISTER 0x%x not supported\n", reg);
+ break;
+ }
+}
+
+static u32 svsm_apic_msr_read(u32 reg)
+{
+ u32 msr = APIC_BASE_MSR + (reg >> 4);
+ struct svsm_call call = {};
+ int ret;
+
+ if (reg == APIC_DFR)
+ return -1;
+
+ switch (reg) {
+ case APIC_ID:
+ case APIC_TASKPRI:
+ case APIC_PROCPRI:
+ case APIC_ICR:
+ case APIC_ISR ... APIC_ISR + 0x70:
+ case APIC_TMR ... APIC_TMR + 0x70:
+ case APIC_IRR ... APIC_IRR + 0x70:
+ if (WARN_ONCE(!IS_ALIGNED(reg, 16),
+ "SVSM APIC register read offset 0x%x not aligned at 16 bytes", reg))
+ return 0;
+ call.rax = SVSM_APIC_CALL(SVSM_APIC_READ_REGISTER);
+ call.rcx = msr;
+
+ ret = svsm_perform_call_protocol(&call);
+ if (ret) {
+ pr_err("SVSM_APIC_READ_REGISTER: 0x%x, error: %d\n", reg, ret);
+ sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_ALT_INJ_FAIL);
+ }
+ break;
+ default:
+ pr_err("SVSM_APIC_READ_REGISTER: 0x%x not supported\n", reg);
+ return 0;
+ }
+
+ return call.rdx_out;
+}
+
+static inline void svsm_apic_msr_eoi(void)
+{
+ svsm_apic_msr_write(APIC_EOI, APIC_EOI_ACK);
+}
+
+static u64 __svsm_apic_icr_rw(u32 low, u32 id, bool write)
+{
+ struct svsm_call call = {};
+ const char *call_reg_str;
+ u32 reg;
+ int ret;
+
+ reg = APIC_ICR;
+
+ call_reg_str = write ? "SVSM_APIC_WRITE_REGISTER"
+ : "SVSM_APIC_READ_REGISTER";
+
+ call.rax = write ? SVSM_APIC_CALL(SVSM_APIC_WRITE_REGISTER)
+ : SVSM_APIC_CALL(SVSM_APIC_READ_REGISTER);
+ call.rcx = APIC_BASE_MSR + (reg >> 4);
+ call.rdx = ((u64)id) << 32 | low;
+
+ ret = svsm_perform_call_protocol(&call);
+ if (ret) {
+ pr_err("%s: 0x%x, error: %d\n", call_reg_str, reg, ret);
+ sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_ALT_INJ_FAIL);
+ }
+
+ return call.rdx_out;
+}
+
+
+static inline u64 svsm_apic_icr_read(void)
+{
+ return __svsm_apic_icr_rw(0, 0, false);
+}
+
+static void svsm_apic_icr_write(u32 low, u32 id)
+{
+ __svsm_apic_icr_rw(low, id, true);
+
+}
+
+static void svsm_apic_send_IPI(int cpu, int vector)
+{
+ u32 dest = per_cpu(x86_cpu_to_apicid, cpu);
+
+ svsm_apic_icr_write(__prepare_ICR(0, vector, APIC_DEST_PHYSICAL), dest);
+}
+
+static void __svsm_apic_send_IPI_mask(const struct cpumask *mask, int vector, int apic_dest)
+{
+ unsigned long query_cpu, this_cpu;
+
+ guard(irqsave)();
+
+ this_cpu = smp_processor_id();
+ for_each_cpu(query_cpu, mask) {
+ if (apic_dest == APIC_DEST_ALLBUT && this_cpu == query_cpu)
+ continue;
+
+ svsm_apic_send_IPI(query_cpu, vector);
+ }
+}
+
+static void svsm_apic_send_IPI_mask(const struct cpumask *mask, int vector)
+{
+ __svsm_apic_send_IPI_mask(mask, vector, APIC_DEST_ALLINC);
+}
+
+static void svsm_apic_send_IPI_mask_allbutself(const struct cpumask *mask, int vector)
+{
+ __svsm_apic_send_IPI_mask(mask, vector, APIC_DEST_ALLBUT);
+}
+
+static void __svsm_apic_send_IPI_shorthand(int vector, u32 which)
+{
+ svsm_apic_icr_write(__prepare_ICR(which, vector, 0), 0);
+}
+
+static void svsm_apic_send_IPI_allbutself(int vector)
+{
+ __svsm_apic_send_IPI_shorthand(vector, APIC_DEST_ALLBUT);
+}
+
+static void svsm_apic_send_IPI_all(int vector)
+{
+ __svsm_apic_send_IPI_shorthand(vector, APIC_DEST_ALLINC);
+}
+
+static void svsm_apic_send_IPI_self(int vector)
+{
+ svsm_apic_msr_write(APIC_SELF_IPI, vector);
+}
+
+static struct apic svsm_apic __ro_after_init = {
+
+ .name = "svsm apic",
+ .probe = svsm_apic_probe,
+ .acpi_madt_oem_check = svsm_acpi_madt_oem_check,
+
+ .dest_mode_logical = false,
+
+ .disable_esr = 0,
+
+ .cpu_present_to_apicid = default_cpu_present_to_apicid,
+
+ .max_apic_id = UINT_MAX,
+ .x2apic_set_max_apicid = true,
+ .get_apic_id = x2apic_get_apic_id,
+
+ .calc_dest_apicid = apic_default_calc_apicid,
+
+ .send_IPI = svsm_apic_send_IPI,
+ .send_IPI_mask = svsm_apic_send_IPI_mask,
+ .send_IPI_mask_allbutself = svsm_apic_send_IPI_mask_allbutself,
+ .send_IPI_allbutself = svsm_apic_send_IPI_allbutself,
+ .send_IPI_all = svsm_apic_send_IPI_all,
+ .send_IPI_self = svsm_apic_send_IPI_self,
+ .nmi_to_offline_cpu = true,
+
+ .read = svsm_apic_msr_read,
+ .write = svsm_apic_msr_write,
+ .eoi = svsm_apic_msr_eoi,
+ .icr_read = svsm_apic_icr_read,
+ .icr_write = svsm_apic_icr_write,
+
+};
+apic_driver(svsm_apic);
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v7 06/10] x86/sev: Route unsupported APIC register accesses to the hypervisor APIC emulation
2026-12-06 5:13 [PATCH v7 00/10] Alternate Injection: Secure Interrupt Delivery for SEV-SNP Guests - Guest Support Melody Wang
` (4 preceding siblings ...)
2026-12-06 5:13 ` [PATCH v7 05/10] x86/apic: Add an SVSM APIC driver Melody Wang
@ 2026-12-06 5:13 ` 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
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Melody Wang @ 2026-12-06 5:13 UTC (permalink / raw)
To: x86; +Cc: LKML, Tom Lendacky, ardb, Melody Wang
The SVSM APIC emulation supports only a subset of the X2APIC MSRs.
Right now only basic APIC functionality related to interrupt delivery is
supported. Therefore, route the unsupported ones to the hypervisor's
X2APIC emulation.
Signed-off-by: Melody Wang <huibo.wang@amd.com>
---
arch/x86/coco/sev/core.c | 46 +++++++++++------------------
arch/x86/include/asm/sev-common.h | 1 +
arch/x86/include/asm/sev.h | 8 ++---
arch/x86/kernel/apic/x2apic_savic.c | 8 ++---
arch/x86/kernel/apic/x2apic_svsm.c | 9 +++---
5 files changed, 31 insertions(+), 41 deletions(-)
diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c
index 6d2691170a95..c410aa42609e 100644
--- a/arch/x86/coco/sev/core.c
+++ b/arch/x86/coco/sev/core.c
@@ -978,7 +978,7 @@ int __init sev_es_efi_map_ghcbs_cas(pgd_t *pgd)
return 0;
}
-u64 savic_ghcb_msr_read(u32 reg)
+static u64 __sev_apic_ghcb_msr_rw(u32 reg, u64 value, bool write)
{
u64 msr = APIC_BASE_MSR + (reg >> 4);
struct pt_regs regs = { .cx = msr };
@@ -987,49 +987,37 @@ u64 savic_ghcb_msr_read(u32 reg)
enum es_result res;
struct ghcb *ghcb;
+ if (write) {
+ regs.ax = lower_32_bits(value);
+ regs.dx = upper_32_bits(value);
+ }
+
guard(irqsave)();
ghcb = __sev_get_ghcb(&state);
vc_ghcb_invalidate(ghcb);
- res = __vc_handle_msr(ghcb, &ctxt, false);
+ res = __vc_handle_msr(ghcb, &ctxt, write);
if (res != ES_OK) {
- pr_err("Secure AVIC MSR (0x%llx) read returned error (%d)\n", msr, res);
- /* MSR read failures are treated as fatal errors */
- sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_SAVIC_FAIL);
+ pr_err("APIC GHCB %s MSR 0x%llx: error %d\n", write ? "write" : "read", msr, res);
+ /* MSR read/write failures are treated as fatal errors */
+ sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_APIC_MSR_FAIL);
}
__sev_put_ghcb(&state);
+ /* The return value will be ignored by the caller for a write */
return regs.ax | regs.dx << 32;
}
-void savic_ghcb_msr_write(u32 reg, u64 value)
+u64 sev_apic_ghcb_msr_read(u32 reg)
{
- u64 msr = APIC_BASE_MSR + (reg >> 4);
- struct pt_regs regs = {
- .cx = msr,
- .ax = lower_32_bits(value),
- .dx = upper_32_bits(value)
- };
- struct es_em_ctxt ctxt = { .regs = ®s };
- struct ghcb_state state;
- enum es_result res;
- struct ghcb *ghcb;
-
- guard(irqsave)();
-
- ghcb = __sev_get_ghcb(&state);
- vc_ghcb_invalidate(ghcb);
-
- res = __vc_handle_msr(ghcb, &ctxt, true);
- if (res != ES_OK) {
- pr_err("Secure AVIC MSR (0x%llx) write returned error (%d)\n", msr, res);
- /* MSR writes should never fail. Any failure is fatal error for SNP guest */
- sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_SAVIC_FAIL);
- }
+ return __sev_apic_ghcb_msr_rw(reg, 0, false);
+}
- __sev_put_ghcb(&state);
+void sev_apic_ghcb_msr_write(u32 reg, u64 value)
+{
+ __sev_apic_ghcb_msr_rw(reg, value, true);
}
enum es_result savic_register_gpa(u64 gpa)
diff --git a/arch/x86/include/asm/sev-common.h b/arch/x86/include/asm/sev-common.h
index ef9761a945f0..b53b05e2caaa 100644
--- a/arch/x86/include/asm/sev-common.h
+++ b/arch/x86/include/asm/sev-common.h
@@ -211,6 +211,7 @@ struct snp_psc_desc {
#define GHCB_TERM_SAVIC_FAIL 12 /* Secure AVIC-specific failure */
#define GHCB_TERM_VC_NO_GHCB 13 /* #VC that can't be handled without a GHCB */
#define GHCB_TERM_ALT_INJ_FAIL 14 /* Alternate Injection-specific failure */
+#define GHCB_TERM_APIC_MSR_FAIL 15 /* APIC MSR failure */
#define GHCB_RESP_CODE(v) ((v) & GHCB_MSR_INFO_MASK)
diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h
index 6496b376452f..d916a5dcd6af 100644
--- a/arch/x86/include/asm/sev.h
+++ b/arch/x86/include/asm/sev.h
@@ -542,8 +542,8 @@ void __init snp_secure_tsc_prepare(void);
void __init snp_secure_tsc_init(void);
enum es_result savic_register_gpa(u64 gpa);
enum es_result savic_unregister_gpa(u64 *gpa);
-u64 savic_ghcb_msr_read(u32 reg);
-void savic_ghcb_msr_write(u32 reg, u64 value);
+u64 sev_apic_ghcb_msr_read(u32 reg);
+void sev_apic_ghcb_msr_write(u32 reg, u64 value);
static __always_inline void vc_ghcb_invalidate(struct ghcb *ghcb)
{
@@ -652,8 +652,8 @@ static inline void __init snp_secure_tsc_init(void) { }
static inline void sev_evict_cache(void *va, int npages) {}
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 savic_ghcb_msr_write(u32 reg, u64 value) { }
-static inline u64 savic_ghcb_msr_read(u32 reg) { return 0; }
+static inline void sev_apic_ghcb_msr_write(u32 reg, u64 value) { }
+static inline u64 sev_apic_ghcb_msr_read(u32 reg) { return 0; }
#endif /* CONFIG_AMD_MEM_ENCRYPT */
diff --git a/arch/x86/kernel/apic/x2apic_savic.c b/arch/x86/kernel/apic/x2apic_savic.c
index 4bc6d7e018a5..990e4a379e07 100644
--- a/arch/x86/kernel/apic/x2apic_savic.c
+++ b/arch/x86/kernel/apic/x2apic_savic.c
@@ -72,7 +72,7 @@ static u32 savic_read(u32 reg)
case APIC_LVT0:
case APIC_LVT1:
case APIC_LVTERR:
- return savic_ghcb_msr_read(reg);
+ return sev_apic_ghcb_msr_read(reg);
case APIC_ID:
case APIC_LVR:
case APIC_TASKPRI:
@@ -193,7 +193,7 @@ static void savic_icr_write(u32 icr_low, u32 icr_high)
icr_data = ((u64)icr_high) << 32 | icr_low;
if (dsh != APIC_DEST_SELF)
- savic_ghcb_msr_write(APIC_ICR, icr_data);
+ sev_apic_ghcb_msr_write(APIC_ICR, icr_data);
apic_set_reg64(this_cpu_ptr(savic_page), APIC_ICR, icr_data);
}
@@ -210,7 +210,7 @@ static void savic_write(u32 reg, u32 data)
case APIC_LVTTHMR:
case APIC_LVTPC:
case APIC_LVTERR:
- savic_ghcb_msr_write(reg, data);
+ sev_apic_ghcb_msr_write(reg, data);
break;
case APIC_TASKPRI:
case APIC_EOI:
@@ -316,7 +316,7 @@ static void savic_eoi(void)
* interrupts. Return to the guest from GHCB protocol event takes
* care of re-evaluating interrupt state.
*/
- savic_ghcb_msr_write(APIC_EOI, 0);
+ sev_apic_ghcb_msr_write(APIC_EOI, 0);
} else {
/*
* Hardware clears APIC_ISR and re-evaluates the interrupt state
diff --git a/arch/x86/kernel/apic/x2apic_svsm.c b/arch/x86/kernel/apic/x2apic_svsm.c
index 29ee7065e6f4..d22b60c78e24 100644
--- a/arch/x86/kernel/apic/x2apic_svsm.c
+++ b/arch/x86/kernel/apic/x2apic_svsm.c
@@ -71,7 +71,7 @@ static void svsm_apic_msr_write(u32 reg, u32 v)
}
break;
default:
- pr_err("SVSM_APIC_WRITE_REGISTER 0x%x not supported\n", reg);
+ sev_apic_ghcb_msr_write(reg, v);
break;
}
}
@@ -80,6 +80,7 @@ static u32 svsm_apic_msr_read(u32 reg)
{
u32 msr = APIC_BASE_MSR + (reg >> 4);
struct svsm_call call = {};
+ u64 val;
int ret;
if (reg == APIC_DFR)
@@ -104,13 +105,13 @@ static u32 svsm_apic_msr_read(u32 reg)
pr_err("SVSM_APIC_READ_REGISTER: 0x%x, error: %d\n", reg, ret);
sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_ALT_INJ_FAIL);
}
+ val = call.rdx_out;
break;
default:
- pr_err("SVSM_APIC_READ_REGISTER: 0x%x not supported\n", reg);
- return 0;
+ val = sev_apic_ghcb_msr_read(reg);
}
- return call.rdx_out;
+ return val;
}
static inline void svsm_apic_msr_eoi(void)
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v7 07/10] x86/sev: Add a function to contain all SEV-specific setup operations
2026-12-06 5:13 [PATCH v7 00/10] Alternate Injection: Secure Interrupt Delivery for SEV-SNP Guests - Guest Support Melody Wang
` (5 preceding siblings ...)
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 ` Melody Wang
2026-12-06 5:13 ` [PATCH v7 08/10] x86/sev: Register Alternate Injection protocol during OVMF boot Melody Wang
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Melody Wang @ 2026-12-06 5:13 UTC (permalink / raw)
To: x86; +Cc: LKML, Tom Lendacky, ardb, Melody Wang
To make the code clean in the boot phase, add a sev_prepare() wrapper
which contains early SEV-specific checks in order to have all that code
in a single place.
No functional changes.
Signed-off-by: Melody Wang <huibo.wang@amd.com>
---
drivers/firmware/efi/libstub/x86-stub.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c
index 42a0ce40260a..3c3259739d69 100644
--- a/drivers/firmware/efi/libstub/x86-stub.c
+++ b/drivers/firmware/efi/libstub/x86-stub.c
@@ -786,7 +786,7 @@ static efi_status_t exit_boot(struct boot_params *boot_params, void *handle)
return EFI_SUCCESS;
}
-static bool have_unsupported_snp_features(void)
+static bool sev_prepare(void)
{
u64 unsupported;
@@ -794,9 +794,9 @@ static bool have_unsupported_snp_features(void)
if (unsupported) {
efi_err("Unsupported SEV-SNP features detected: 0x%llx\n",
unsupported);
- return true;
+ return false;
}
- return false;
+ return true;
}
static void efi_get_seed(void *seed, int size)
@@ -937,7 +937,7 @@ void __noreturn efi_stub_entry(efi_handle_t handle,
hdr = &boot_params->hdr;
- if (have_unsupported_snp_features())
+ if (!sev_prepare())
efi_exit(handle, EFI_UNSUPPORTED);
if (IS_ENABLED(CONFIG_EFI_DXE_MEM_ATTRIBUTES)) {
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v7 08/10] x86/sev: Register Alternate Injection protocol during OVMF boot
2026-12-06 5:13 [PATCH v7 00/10] Alternate Injection: Secure Interrupt Delivery for SEV-SNP Guests - Guest Support Melody Wang
` (6 preceding siblings ...)
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
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
9 siblings, 0 replies; 11+ messages in thread
From: Melody Wang @ 2026-12-06 5:13 UTC (permalink / raw)
To: x86; +Cc: LKML, Tom Lendacky, ardb, Melody Wang
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
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v7 09/10] x86/sev: Allow the guest to configure interrupt vectors for the hypervisor
2026-12-06 5:13 [PATCH v7 00/10] Alternate Injection: Secure Interrupt Delivery for SEV-SNP Guests - Guest Support Melody Wang
` (7 preceding siblings ...)
2026-12-06 5:13 ` [PATCH v7 08/10] x86/sev: Register Alternate Injection protocol during OVMF boot Melody Wang
@ 2026-12-06 5:13 ` Melody Wang
2026-12-06 5:13 ` [PATCH v7 10/10] x86/sev: Indicate that Alternate Injection is supported in the guest Melody Wang
9 siblings, 0 replies; 11+ messages in thread
From: Melody Wang @ 2026-12-06 5:13 UTC (permalink / raw)
To: x86; +Cc: LKML, Tom Lendacky, ardb, Melody Wang
The SVSM APIC protocol supports 5 API calls. SVSM_APIC_CONFIGURE_VECTOR
(shortened to SVSM_APIC_CONFIG_VECTOR for brevity), call 4, provides for
the guest to designate an interrupt vector permissible or impermissible
for hypervisor to deliver.
Implement this call, and make the default interrupt setting permissive
when detecting an SVSM.
Signed-off-by: Melody Wang <huibo.wang@amd.com>
---
arch/x86/boot/startup/sev-startup.c | 20 ++++++++++++++++++++
arch/x86/boot/startup/sme.c | 3 +++
arch/x86/include/asm/sev.h | 9 +++++++++
3 files changed, 32 insertions(+)
diff --git a/arch/x86/boot/startup/sev-startup.c b/arch/x86/boot/startup/sev-startup.c
index 789e99d38d17..bf11e5420dd2 100644
--- a/arch/x86/boot/startup/sev-startup.c
+++ b/arch/x86/boot/startup/sev-startup.c
@@ -191,6 +191,26 @@ static void __init svsm_setup(struct cc_blob_sev_info *cc_info)
boot_svsm_caa_pa = pa;
}
+/*
+ * Configure all interrupts as permissive by default for Alternate Injection
+ * enabled SNP guest.
+ */
+void __init svsm_config_alt_inj_vectors(void)
+{
+ struct svsm_call call = {};
+ int ret;
+
+ if (sev_status & MSR_AMD64_SNP_ALTERNATE_INJ) {
+ call.caa = rip_rel_ptr(&boot_svsm_ca_page);
+ call.rax = SVSM_APIC_CALL(SVSM_APIC_CONFIG_VECTOR);
+ call.rcx = SVSM_IRQ_ENABLE_ALL << 8;
+
+ ret = svsm_call_msr_protocol(&call);
+ if (ret)
+ sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_ALT_INJ_FAIL);
+ }
+}
+
bool __init snp_init(struct boot_params *bp)
{
struct cc_blob_sev_info *cc_info;
diff --git a/arch/x86/boot/startup/sme.c b/arch/x86/boot/startup/sme.c
index 2d5cb3f7eee6..f11dbf901b09 100644
--- a/arch/x86/boot/startup/sme.c
+++ b/arch/x86/boot/startup/sme.c
@@ -566,6 +566,9 @@ void __init sme_enable(struct boot_params *bp)
physical_mask &= ~me_mask;
cc_vendor = CC_VENDOR_AMD;
cc_set_mask(me_mask);
+
+ if (snp_vmpl && IS_ENABLED(CONFIG_AMD_ALTERNATE_INJ))
+ svsm_config_alt_inj_vectors();
}
#ifdef CONFIG_MITIGATION_PAGE_TABLE_ISOLATION
diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h
index d916a5dcd6af..dec4c6b217f0 100644
--- a/arch/x86/include/asm/sev.h
+++ b/arch/x86/include/asm/sev.h
@@ -34,6 +34,13 @@ enum es_result {
ES_RETRY, /* Retry instruction emulation */
};
+enum svsm_vec_enable {
+ SVSM_IRQ_DISABLE_SINGLE,
+ SVSM_IRQ_ENABLE_SINGLE,
+ SVSM_IRQ_DISABLE_ALL,
+ SVSM_IRQ_ENABLE_ALL,
+};
+
struct es_fault_info {
unsigned long vector;
unsigned long error_code;
@@ -518,6 +525,7 @@ void snp_set_memory_shared(unsigned long vaddr, unsigned long npages);
void snp_set_memory_private(unsigned long vaddr, unsigned long npages);
void snp_set_wakeup_secondary_cpu(void);
bool snp_init(struct boot_params *bp);
+void svsm_config_alt_inj_vectors(void);
void snp_dmi_setup(void);
int snp_issue_svsm_attest_req(u64 call_id, struct svsm_call *call, struct svsm_attest_call *input);
void snp_accept_memory(phys_addr_t start, phys_addr_t end);
@@ -626,6 +634,7 @@ static inline void snp_set_memory_shared(unsigned long vaddr, unsigned long npag
static inline void snp_set_memory_private(unsigned long vaddr, unsigned long npages) { }
static inline void snp_set_wakeup_secondary_cpu(void) { }
static inline bool snp_init(struct boot_params *bp) { return false; }
+static inline void svsm_config_alt_inj_vectors(void) { }
static inline void snp_dmi_setup(void) { }
static inline int snp_issue_svsm_attest_req(u64 call_id, struct svsm_call *call, struct svsm_attest_call *input)
{
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v7 10/10] x86/sev: Indicate that Alternate Injection is supported in the guest
2026-12-06 5:13 [PATCH v7 00/10] Alternate Injection: Secure Interrupt Delivery for SEV-SNP Guests - Guest Support Melody Wang
` (8 preceding siblings ...)
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 ` Melody Wang
9 siblings, 0 replies; 11+ messages in thread
From: Melody Wang @ 2026-12-06 5:13 UTC (permalink / raw)
To: x86; +Cc: LKML, Tom Lendacky, ardb, Melody Wang
Now the Alternate Injection support is complete, add it to the present
SNP features.
Signed-off-by: Melody Wang <huibo.wang@amd.com>
---
arch/x86/boot/compressed/sev.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c
index fc2029746c50..ba42a1aee7e9 100644
--- a/arch/x86/boot/compressed/sev.c
+++ b/arch/x86/boot/compressed/sev.c
@@ -197,6 +197,12 @@ bool sev_es_check_ghcb_fault(unsigned long address)
#define SNP_FEATURE_SECURE_AVIC 0
#endif
+#ifdef CONFIG_AMD_ALTERNATE_INJ
+#define SNP_FEATURE_ALTERNATE_INJ MSR_AMD64_SNP_ALTERNATE_INJ
+#else
+#define SNP_FEATURE_ALTERNATE_INJ 0
+#endif
+
/*
* SNP_FEATURES_IMPL is the mask of SNP features that are implemented
* by the guest kernel. As and when a new feature is implemented in the
@@ -204,7 +210,8 @@ bool sev_es_check_ghcb_fault(unsigned long address)
*/
#define SNP_FEATURES_IMPL (MSR_AMD64_SNP_DEBUG_SWAP | \
MSR_AMD64_SNP_SECURE_TSC | \
- SNP_FEATURE_SECURE_AVIC)
+ SNP_FEATURE_SECURE_AVIC | \
+ SNP_FEATURE_ALTERNATE_INJ)
u64 snp_get_unsupported_features(u64 status)
{
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
end of thread, other threads:[~2026-12-06 5:15 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH v7 08/10] x86/sev: Register Alternate Injection protocol during OVMF boot Melody Wang
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox