[RFC PATCH 2/9] KVM: SVM: Add support for Alternate Injection for the SEV-SNP #HV doorbell page NAE event

From: Melody Wang

Date: Tue Nov 10 2026 - 04:26:12 EST


To support Alternate Injection, there are three new NAE
events added in the spec:

1. "configure Injection Notification Vector": configures the interrupt
vector that will be used by the hypervisor whenever it needs to
notify the SVSM that the interrupt processing for VMPL1-3 is
required

2. "Specific EOI" - requests the hypervisor to perform an EOI cycle on
level-sensitive interrupt, and

3. "Disable Alternate Injection" - requests the hypervisor to disable
Alternate Injection for a specific VMPL.

Implement the first two.

Signed-off-by: Melody Wang <huibo.wang@xxxxxxx>
---
arch/x86/include/uapi/asm/svm.h | 2 ++
arch/x86/kvm/lapic.c | 3 ++-
arch/x86/kvm/lapic.h | 1 +
arch/x86/kvm/svm/sev.c | 40 +++++++++++++++++++++++++++++++--
arch/x86/kvm/svm/svm.h | 1 +
5 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/arch/x86/include/uapi/asm/svm.h b/arch/x86/include/uapi/asm/svm.h
index 60b7a52f6f7e..786f50f33457 100644
--- a/arch/x86/include/uapi/asm/svm.h
+++ b/arch/x86/include/uapi/asm/svm.h
@@ -127,6 +127,8 @@
#define SVM_VMGEXIT_AP_VMPL_SHIFT 16
#define SVM_VMGEXIT_GET_APIC_IDS 0x80000017ull
#define SVM_VMGEXIT_SNP_RUN_VMPL 0x80000018ull
+#define SVM_VMGEXIT_SNP_CONFIG_INT_INJ 0x8000001bull
+#define SVM_VMGEXIT_SVSM_SPECIFIC_EOI 0x8000001dull
#define SVM_VMGEXIT_SAVIC 0x8000001aull
#define SVM_VMGEXIT_SAVIC_REGISTER_GPA 0
#define SVM_VMGEXIT_SAVIC_UNREGISTER_GPA 1
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index dc7a08831a54..9ebae1052f64 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -1543,7 +1543,7 @@ static bool kvm_ioapic_handles_vector(struct kvm_lapic *apic, int vector)
return test_bit(vector, apic->vcpu->arch.ioapic_handled_vectors);
}

-static void kvm_ioapic_send_eoi(struct kvm_lapic *apic, int vector)
+void kvm_ioapic_send_eoi(struct kvm_lapic *apic, int vector)
{
int __maybe_unused trigger_mode;

@@ -1584,6 +1584,7 @@ static void kvm_ioapic_send_eoi(struct kvm_lapic *apic, int vector)
kvm_ioapic_update_eoi(apic->vcpu, vector, trigger_mode);
#endif
}
+EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_ioapic_send_eoi);

static int apic_set_eoi(struct kvm_lapic *apic)
{
diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h
index a9ede0e145d9..9d202ef3016b 100644
--- a/arch/x86/kvm/lapic.h
+++ b/arch/x86/kvm/lapic.h
@@ -254,6 +254,7 @@ void kvm_lapic_switch_to_hv_timer(struct kvm_vcpu *vcpu);
void kvm_lapic_expired_hv_timer(struct kvm_vcpu *vcpu);
bool kvm_lapic_hv_timer_in_use(struct kvm_vcpu *vcpu);
void kvm_lapic_restart_hv_timer(struct kvm_vcpu *vcpu);
+void kvm_ioapic_send_eoi(struct kvm_lapic *apic, int vector);

static inline enum lapic_mode kvm_apic_mode(u64 apic_base)
{
diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 0736e1c778d9..924c1b968fdc 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -3432,6 +3432,8 @@ static void sev_es_sync_from_ghcb(struct vcpu_svm *svm)
memset(ghcb->save.valid_bitmap, 0, sizeof(ghcb->save.valid_bitmap));
}

+#define SVM_SEV_VMPL_MAX 4
+
static int sev_es_validate_vmgexit(struct vcpu_svm *svm)
{
struct vmcb_control_area *control = &svm->vmcb->control;
@@ -3566,6 +3568,21 @@ static int sev_es_validate_vmgexit(struct vcpu_svm *svm)
if (!sev_snp_guest(vcpu->kvm))
goto vmgexit_err;
break;
+ case SVM_VMGEXIT_SNP_CONFIG_INT_INJ:
+ if (!sev_snp_guest(vcpu->kvm))
+ goto vmgexit_err;
+ break;
+ case SVM_VMGEXIT_SVSM_SPECIFIC_EOI: {
+ u8 vmpl;
+
+ if (!sev_snp_guest(vcpu->kvm))
+ goto vmgexit_err;
+
+ vmpl = (control->exit_info_1 >> 16) & 0xff;
+ if (vmpl >= SVM_SEV_VMPL_MAX)
+ goto vmgexit_err;
+ break;
+ }
default:
reason = GHCB_ERR_INVALID_EVENT;
goto vmgexit_err;
@@ -4217,8 +4234,6 @@ static unsigned int get_ap_creation_apic_id(struct vcpu_svm *svm)
return upper_32_bits(svm->vmcb->control.exit_info_1);
}

-#define SVM_SEV_VMPL_MAX 4
-
static int sev_snp_ap_creation(struct kvm_vcpu *vcpu)
{
struct vcpu_svm *target_svm = NULL, *svm = to_svm(vcpu);
@@ -4953,6 +4968,27 @@ int sev_handle_vmgexit(struct kvm_vcpu *vcpu)
}
ret = 1;
break;
+ case SVM_VMGEXIT_SNP_CONFIG_INT_INJ:
+ svm->sev_es.hvdb_ai_vector = svm->vmcb->control.exit_info_1 & 0xff;
+ ret = 1;
+ break;
+ case SVM_VMGEXIT_SVSM_SPECIFIC_EOI: {
+ struct kvm_plane *target_plane;
+ struct kvm_vcpu *target_vcpu;
+ u8 vmpl = array_index_nospec((control->exit_info_1 >> 16) & 0xff,
+ SVM_SEV_VMPL_MAX);
+ int vector = control->exit_info_1 & 0xff;
+
+ target_plane = vcpu->kvm->planes[vmpl];
+
+ if (target_plane) {
+ target_vcpu = plane_get_vcpu_by_id(target_plane, vcpu->vcpu_id);
+ if (target_vcpu)
+ kvm_ioapic_send_eoi(target_vcpu->arch.apic, vector);
+ }
+ ret = 1;
+ break;
+ }
case SVM_VMGEXIT_GET_APIC_IDS:
sev_get_apic_ids(svm);
ret = 1;
diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h
index 7aba2cceb44d..d2e397542a84 100644
--- a/arch/x86/kvm/svm/svm.h
+++ b/arch/x86/kvm/svm/svm.h
@@ -287,6 +287,7 @@ struct vcpu_sev_es_state {
bool snp_has_guest_vmsa;

gpa_t hvdb_gpa;
+ u8 hvdb_ai_vector;
};

struct vcpu_svm {
--
2.43.0