[RFC PATCH 5/9] KVM: SVM: Bypass lapic for VMPL1-3 guest with Alternate Injection enabled

From: Melody Wang

Date: Tue Nov 10 2026 - 04:23:24 EST


The interrupts for VMPL1-3 are handled in the SVSM by its APIC emulation
so bypass the KVM's APIC layer and queue them into the doorbell page.

Signed-off-by: Melody Wang <huibo.wang@xxxxxxx>
---
arch/x86/include/asm/kvm-x86-ops.h | 1 +
arch/x86/include/asm/kvm_host.h | 1 +
arch/x86/kvm/lapic.c | 7 +++++--
arch/x86/kvm/svm/svm.c | 6 ++++++
4 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-x86-ops.h
index 16da6d1678e5..dfd38f9408cc 100644
--- a/arch/x86/include/asm/kvm-x86-ops.h
+++ b/arch/x86/include/asm/kvm-x86-ops.h
@@ -96,6 +96,7 @@ KVM_X86_OP_OPTIONAL_RET0(set_tss_addr)
KVM_X86_OP_OPTIONAL_RET0(set_identity_map_addr)
KVM_X86_OP_OPTIONAL_RET0(get_mt_mask)
KVM_X86_OP_OPTIONAL_RET0(has_interrupt)
+KVM_X86_OP_OPTIONAL_RET0(is_bypass_apic_active)
KVM_X86_OP(load_mmu_pgd)
KVM_X86_OP_OPTIONAL(link_external_spt)
KVM_X86_OP_OPTIONAL(set_external_spte)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 985d7f4d7140..60c102db1003 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1874,6 +1874,7 @@ struct kvm_x86_ops {
void (*patch_hypercall)(struct kvm_vcpu *vcpu,
unsigned char *hypercall_addr);
int (*has_interrupt)(struct kvm_vcpu *vcpu);
+ bool (*is_bypass_apic_active)(struct kvm_vcpu *vcpu);
void (*inject_irq)(struct kvm_vcpu *vcpu, bool reinjected);
void (*inject_nmi)(struct kvm_vcpu *vcpu);
void (*inject_exception)(struct kvm_vcpu *vcpu);
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 9ebae1052f64..952b6cc92ede 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -3189,8 +3189,11 @@ void kvm_apic_ack_interrupt(struct kvm_vcpu *vcpu, int vector)
* a concurrent interrupt injection, but that would have
* triggered KVM_REQ_EVENT already.
*/
- apic_set_isr(vector, apic);
- __apic_update_ppr(apic, &ppr);
+ if (!kvm_x86_call(is_bypass_apic_active)(vcpu)) {
+ apic_set_isr(vector, apic);
+ __apic_update_ppr(apic, &ppr);
+ }
+
}

}
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 7c4b3d05ae88..756b11bebb5a 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -4111,6 +4111,11 @@ static int svm_has_interrupt(struct kvm_vcpu *vcpu)
return ret;
}

+static bool svm_is_bypass_apic_active(struct kvm_vcpu *vcpu)
+{
+ return sev_snp_is_ai_active(vcpu);
+}
+
static void svm_enable_irq_window(struct kvm_vcpu *vcpu)
{
struct vcpu_svm *svm = to_svm(vcpu);
@@ -5446,6 +5451,7 @@ struct kvm_x86_ops svm_x86_ops __initdata = {
.get_interrupt_shadow = svm_get_interrupt_shadow,
.patch_hypercall = svm_patch_hypercall,
.has_interrupt = svm_has_interrupt,
+ .is_bypass_apic_active = svm_is_bypass_apic_active,
.inject_irq = svm_inject_irq,
.inject_nmi = svm_inject_nmi,
.is_vnmi_pending = svm_is_vnmi_pending,
--
2.43.0