[RFC PATCH 7/9] KVM: SVM: Notify the SVSM an intercept happened during interrupt delivery
From: Melody Wang
Date: Tue Nov 10 2026 - 04:26:56 EST
When the guest VMEXITs with EXITINTINFO.V=1 (valid bit) is set, that
means an intercept happened during the interrupt delivery.
When the hypervisor sees the valid bit, it should queue the interrupt so
it does not get lost.
However, with Alternate Injection, the hypervisor can not queue the
interrupt directly but the SVSM needs to do that. Notify the SVSM when
the intercept happened.
Signed-off-by: Melody Wang <huibo.wang@xxxxxxx>
---
arch/x86/kvm/svm/sev.c | 2 +-
arch/x86/kvm/svm/svm.c | 11 ++++++++++-
arch/x86/kvm/svm/svm.h | 2 ++
3 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 40f55e7a78e3..019412173062 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -4618,7 +4618,7 @@ static void sev_get_apic_ids(struct vcpu_svm *svm)
kvfree(desc);
}
-static int __sev_snp_run_vmpl(struct vcpu_svm *svm, unsigned int vmpl)
+int __sev_snp_run_vmpl(struct vcpu_svm *svm, unsigned int vmpl)
{
struct kvm_vcpu *vcpu = &svm->vcpu;
struct kvm_vcpu *target = vcpu->common->vcpus[vmpl];
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 756b11bebb5a..6d3d9debe5e8 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -3663,6 +3663,7 @@ static int svm_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)
{
struct vcpu_svm *svm = to_svm(vcpu);
struct kvm_run *kvm_run = vcpu->run;
+ int ret;
/* SEV-ES guests must use the CR write traps to track CR registers. */
if (!is_sev_es_guest(vcpu)) {
@@ -3698,7 +3699,15 @@ static int svm_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)
if (exit_fastpath != EXIT_FASTPATH_NONE)
return 1;
- return svm_invoke_exit_handler(vcpu, svm->vmcb->control.exit_code);
+ ret = svm_invoke_exit_handler(vcpu, svm->vmcb->control.exit_code);
+
+ if (sev_snp_is_ai_active(vcpu)) {
+ if (svm->vmcb->control.exit_int_info & SVM_EVTINJ_VALID)
+ __sev_snp_run_vmpl(svm, SVM_SEV_VMPL0);
+ }
+
+ return ret;
+
}
static void svm_set_nested_run_soft_int_state(struct kvm_vcpu *vcpu)
diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h
index 1ec0a045b1ea..d5f42fa31565 100644
--- a/arch/x86/kvm/svm/svm.h
+++ b/arch/x86/kvm/svm/svm.h
@@ -1009,6 +1009,7 @@ bool sev_snp_ai_update_doorbell(enum inject_type type, struct kvm_vcpu *vcpu, in
void sev_snp_cancel_ai_injection(struct kvm_vcpu *vcpu);
bool sev_snp_ai_blocked(enum inject_type type, struct kvm_vcpu *vcpu);
bool sev_snp_ai_inject(struct kvm_vcpu *vcpu);
+int __sev_snp_run_vmpl(struct vcpu_svm *svm, unsigned int vmpl);
static inline bool sev_snp_is_rinj_active(struct kvm_vcpu *vcpu)
{
@@ -1082,6 +1083,7 @@ static inline void sev_snp_cancel_ai_injection(struct kvm_vcpu *vcpu) {}
static inline bool sev_snp_ai_blocked(enum inject_type type, struct kvm_vcpu *vcpu) { return false; }
static inline bool sev_snp_ai_inject(struct kvm_vcpu *vcpu) { return false; }
static inline bool sev_snp_is_ai_active(struct kvm_vcpu *vcpu) { return false; }
+static inline int __sev_snp_run_vmpl(struct vcpu_svm *svm, unsigned int vmpl) { return -EINVAL; };
#endif
/* vmenter.S */
--
2.43.0