@@ -804,60 +804,20 @@ static int svm_ir_list_add(struct vcpu_svm *svm,
804
804
return 0 ;
805
805
}
806
806
807
- /*
808
- * Note:
809
- * The HW cannot support posting multicast/broadcast
810
- * interrupts to a vCPU. So, we still use legacy interrupt
811
- * remapping for these kind of interrupts.
812
- *
813
- * For lowest-priority interrupts, we only support
814
- * those with single CPU as the destination, e.g. user
815
- * configures the interrupts via /proc/irq or uses
816
- * irqbalance to make the interrupts single-CPU.
817
- */
818
- static int
819
- get_pi_vcpu_info (struct kvm * kvm , struct kvm_kernel_irq_routing_entry * e ,
820
- struct vcpu_data * vcpu_info , struct kvm_vcpu * * vcpu )
821
- {
822
- struct kvm_lapic_irq irq ;
823
- * vcpu = NULL ;
824
-
825
- kvm_set_msi_irq (kvm , e , & irq );
826
-
827
- if (!kvm_intr_is_single_vcpu (kvm , & irq , vcpu ) ||
828
- !kvm_irq_is_postable (& irq )) {
829
- pr_debug ("SVM: %s: use legacy intr remap mode for irq %u\n" ,
830
- __func__ , irq .vector );
831
- return -1 ;
832
- }
833
-
834
- pr_debug ("SVM: %s: use GA mode for irq %u\n" , __func__ ,
835
- irq .vector );
836
- vcpu_info -> vector = irq .vector ;
837
-
838
- return 0 ;
839
- }
840
-
841
807
int avic_pi_update_irte (struct kvm_kernel_irqfd * irqfd , struct kvm * kvm ,
842
808
unsigned int host_irq , uint32_t guest_irq ,
843
- struct kvm_kernel_irq_routing_entry * new )
809
+ struct kvm_vcpu * vcpu , u32 vector )
844
810
{
845
- bool enable_remapped_mode = true;
846
- struct vcpu_data vcpu_info ;
847
- struct kvm_vcpu * vcpu = NULL ;
848
811
int ret = 0 ;
849
812
850
- if (!kvm_arch_has_assigned_device (kvm ) || !kvm_arch_has_irq_bypass ())
851
- return 0 ;
852
-
853
813
/*
854
814
* If the IRQ was affined to a different vCPU, remove the IRTE metadata
855
815
* from the *previous* vCPU's list.
856
816
*/
857
817
svm_ir_list_del (irqfd );
858
818
859
819
pr_debug ("SVM: %s: host_irq=%#x, guest_irq=%#x, set=%#x\n" ,
860
- __func__ , host_irq , guest_irq , !!new );
820
+ __func__ , host_irq , guest_irq , !!vcpu );
861
821
862
822
/**
863
823
* Here, we setup with legacy mode in the following cases:
@@ -866,23 +826,23 @@ int avic_pi_update_irte(struct kvm_kernel_irqfd *irqfd, struct kvm *kvm,
866
826
* 3. APIC virtualization is disabled for the vcpu.
867
827
* 4. IRQ has incompatible delivery mode (SMI, INIT, etc)
868
828
*/
869
- if (new && new -> type == KVM_IRQ_ROUTING_MSI &&
870
- !get_pi_vcpu_info (kvm , new , & vcpu_info , & vcpu ) &&
871
- kvm_vcpu_apicv_active (vcpu )) {
872
- struct amd_iommu_pi_data pi ;
873
-
874
- enable_remapped_mode = false;
875
-
876
- vcpu_info .pi_desc_addr = avic_get_backing_page_address (to_svm (vcpu ));
877
-
829
+ if (vcpu && kvm_vcpu_apicv_active (vcpu )) {
878
830
/*
879
831
* Try to enable guest_mode in IRTE. Note, the address
880
832
* of the vCPU's AVIC backing page is passed to the
881
833
* IOMMU via vcpu_info->pi_desc_addr.
882
834
*/
883
- pi .ga_tag = AVIC_GATAG (to_kvm_svm (kvm )-> avic_vm_id , vcpu -> vcpu_id );
884
- pi .is_guest_mode = true;
885
- pi .vcpu_data = & vcpu_info ;
835
+ struct vcpu_data vcpu_info = {
836
+ .pi_desc_addr = avic_get_backing_page_address (to_svm (vcpu )),
837
+ .vector = vector ,
838
+ };
839
+
840
+ struct amd_iommu_pi_data pi = {
841
+ .ga_tag = AVIC_GATAG (to_kvm_svm (kvm )-> avic_vm_id , vcpu -> vcpu_id ),
842
+ .is_guest_mode = true,
843
+ .vcpu_data = & vcpu_info ,
844
+ };
845
+
886
846
ret = irq_set_vcpu_affinity (host_irq , & pi );
887
847
888
848
/**
@@ -894,23 +854,19 @@ int avic_pi_update_irte(struct kvm_kernel_irqfd *irqfd, struct kvm *kvm,
894
854
*/
895
855
if (!ret )
896
856
ret = svm_ir_list_add (to_svm (vcpu ), irqfd , & pi );
897
- }
898
857
899
- if (! ret && vcpu ) {
900
- trace_kvm_pi_irte_update ( host_irq , vcpu -> vcpu_id ,
901
- guest_irq , vcpu_info . vector ,
902
- vcpu_info . pi_desc_addr , !! new );
858
+ trace_kvm_pi_irte_update ( host_irq , vcpu -> vcpu_id , guest_irq ,
859
+ vector , vcpu_info . pi_desc_addr , true);
860
+ } else {
861
+ ret = irq_set_vcpu_affinity ( host_irq , NULL );
903
862
}
904
863
905
864
if (ret < 0 ) {
906
865
pr_err ("%s: failed to update PI IRTE\n" , __func__ );
907
866
goto out ;
908
867
}
909
868
910
- if (enable_remapped_mode )
911
- ret = irq_set_vcpu_affinity (host_irq , NULL );
912
- else
913
- ret = 0 ;
869
+ ret = 0 ;
914
870
out :
915
871
return ret ;
916
872
}
0 commit comments