Skip to content

Commit 71d6b3b

Browse files
committed
KVM: SVM: Revert IRTE to legacy mode if IOMMU doesn't provide IR metadata
Revert the IRTE back to remapping mode if the AMD IOMMU driver mucks up and doesn't provide the necessary metadata. Returning an error up the stack without actually handling the error is useless and confusing. Link: https://lore.kernel.org/r/20250611224604.313496-39-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent cc8b131 commit 71d6b3b

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

arch/x86/kvm/svm/avic.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -770,16 +770,13 @@ static void svm_ir_list_del(struct kvm_kernel_irqfd *irqfd)
770770
spin_unlock_irqrestore(&to_svm(vcpu)->ir_list_lock, flags);
771771
}
772772

773-
static int svm_ir_list_add(struct vcpu_svm *svm,
774-
struct kvm_kernel_irqfd *irqfd,
775-
struct amd_iommu_pi_data *pi)
773+
static void svm_ir_list_add(struct vcpu_svm *svm,
774+
struct kvm_kernel_irqfd *irqfd,
775+
struct amd_iommu_pi_data *pi)
776776
{
777777
unsigned long flags;
778778
u64 entry;
779779

780-
if (WARN_ON_ONCE(!pi->ir_data))
781-
return -EINVAL;
782-
783780
irqfd->irq_bypass_data = pi->ir_data;
784781

785782
spin_lock_irqsave(&svm->ir_list_lock, flags);
@@ -797,7 +794,6 @@ static int svm_ir_list_add(struct vcpu_svm *svm,
797794

798795
list_add(&irqfd->vcpu_list, &svm->ir_list);
799796
spin_unlock_irqrestore(&svm->ir_list_lock, flags);
800-
return 0;
801797
}
802798

803799
int avic_pi_update_irte(struct kvm_kernel_irqfd *irqfd, struct kvm *kvm,
@@ -834,14 +830,25 @@ int avic_pi_update_irte(struct kvm_kernel_irqfd *irqfd, struct kvm *kvm,
834830
if (ret)
835831
return ret;
836832

833+
/*
834+
* Revert to legacy mode if the IOMMU didn't provide metadata
835+
* for the IRTE, which KVM needs to keep the IRTE up-to-date,
836+
* e.g. if the vCPU is migrated or AVIC is disabled.
837+
*/
838+
if (WARN_ON_ONCE(!pi_data.ir_data)) {
839+
irq_set_vcpu_affinity(host_irq, NULL);
840+
return -EIO;
841+
}
842+
837843
/**
838844
* Here, we successfully setting up vcpu affinity in
839845
* IOMMU guest mode. Now, we need to store the posted
840846
* interrupt information in a per-vcpu ir_list so that
841847
* we can reference to them directly when we update vcpu
842848
* scheduling information in IOMMU irte.
843849
*/
844-
return svm_ir_list_add(to_svm(vcpu), irqfd, &pi_data);
850+
svm_ir_list_add(to_svm(vcpu), irqfd, &pi_data);
851+
return 0;
845852
}
846853
return irq_set_vcpu_affinity(host_irq, NULL);
847854
}

0 commit comments

Comments
 (0)