Skip to content

Commit 6df262f

Browse files
committed
iommu/amd: KVM: SVM: Add IRTE metadata to affined vCPU's list if AVIC is inhibited
If an IRQ can be posted to a vCPU, but AVIC is currently inhibited on the vCPU, go through the dance of "affining" the IRTE to the vCPU, but leave the actual IRTE in remapped mode. KVM already handles the case where AVIC is inhibited => uninhibited with posted IRQs (see avic_set_pi_irte_mode()), but doesn't handle the scenario where a postable IRQ comes along while AVIC is inhibited. Link: https://lore.kernel.org/r/20250611224604.313496-45-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent f965255 commit 6df262f

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

arch/x86/kvm/svm/avic.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -781,21 +781,17 @@ int avic_pi_update_irte(struct kvm_kernel_irqfd *irqfd, struct kvm *kvm,
781781
*/
782782
svm_ir_list_del(irqfd);
783783

784-
/**
785-
* Here, we setup with legacy mode in the following cases:
786-
* 1. When cannot target interrupt to a specific vcpu.
787-
* 2. Unsetting posted interrupt.
788-
* 3. APIC virtualization is disabled for the vcpu.
789-
* 4. IRQ has incompatible delivery mode (SMI, INIT, etc)
790-
*/
791-
if (vcpu && kvm_vcpu_apicv_active(vcpu)) {
784+
if (vcpu) {
792785
/*
793-
* Try to enable guest_mode in IRTE.
786+
* Try to enable guest_mode in IRTE, unless AVIC is inhibited,
787+
* in which case configure the IRTE for legacy mode, but track
788+
* the IRTE metadata so that it can be converted to guest mode
789+
* if AVIC is enabled/uninhibited in the future.
794790
*/
795791
struct amd_iommu_pi_data pi_data = {
796792
.ga_tag = AVIC_GATAG(to_kvm_svm(kvm)->avic_vm_id,
797793
vcpu->vcpu_id),
798-
.is_guest_mode = true,
794+
.is_guest_mode = kvm_vcpu_apicv_active(vcpu),
799795
.vapic_addr = avic_get_backing_page_address(to_svm(vcpu)),
800796
.vector = vector,
801797
};

drivers/iommu/amd/iommu.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3939,7 +3939,10 @@ static int amd_ir_set_vcpu_affinity(struct irq_data *data, void *info)
39393939
ir_data->ga_root_ptr = (pi_data->vapic_addr >> 12);
39403940
ir_data->ga_vector = pi_data->vector;
39413941
ir_data->ga_tag = pi_data->ga_tag;
3942-
ret = amd_iommu_activate_guest_mode(ir_data, pi_data->cpu);
3942+
if (pi_data->is_guest_mode)
3943+
ret = amd_iommu_activate_guest_mode(ir_data, pi_data->cpu);
3944+
else
3945+
ret = amd_iommu_deactivate_guest_mode(ir_data);
39433946
} else {
39443947
ret = amd_iommu_deactivate_guest_mode(ir_data);
39453948
}

0 commit comments

Comments
 (0)