@@ -729,34 +729,25 @@ int intel_gvt_set_edid(struct intel_vgpu *vgpu, int port_num)
729729 return ret ;
730730}
731731
732- static int intel_vgpu_iommu_notifier (struct notifier_block * nb ,
733- unsigned long action , void * data )
732+ static void intel_vgpu_dma_unmap (struct vfio_device * vfio_dev , u64 iova ,
733+ u64 length )
734734{
735- struct intel_vgpu * vgpu =
736- container_of (nb , struct intel_vgpu , iommu_notifier );
737-
738- if (action == VFIO_IOMMU_NOTIFY_DMA_UNMAP ) {
739- struct vfio_iommu_type1_dma_unmap * unmap = data ;
740- struct gvt_dma * entry ;
741- unsigned long iov_pfn , end_iov_pfn ;
735+ struct intel_vgpu * vgpu = vfio_dev_to_vgpu (vfio_dev );
736+ struct gvt_dma * entry ;
737+ u64 iov_pfn = iova >> PAGE_SHIFT ;
738+ u64 end_iov_pfn = iov_pfn + length / PAGE_SIZE ;
742739
743- iov_pfn = unmap -> iova >> PAGE_SHIFT ;
744- end_iov_pfn = iov_pfn + unmap -> size / PAGE_SIZE ;
740+ mutex_lock (& vgpu -> cache_lock );
741+ for (; iov_pfn < end_iov_pfn ; iov_pfn ++ ) {
742+ entry = __gvt_cache_find_gfn (vgpu , iov_pfn );
743+ if (!entry )
744+ continue ;
745745
746- mutex_lock (& vgpu -> cache_lock );
747- for (; iov_pfn < end_iov_pfn ; iov_pfn ++ ) {
748- entry = __gvt_cache_find_gfn (vgpu , iov_pfn );
749- if (!entry )
750- continue ;
751-
752- gvt_dma_unmap_page (vgpu , entry -> gfn , entry -> dma_addr ,
753- entry -> size );
754- __gvt_cache_remove_entry (vgpu , entry );
755- }
756- mutex_unlock (& vgpu -> cache_lock );
746+ gvt_dma_unmap_page (vgpu , entry -> gfn , entry -> dma_addr ,
747+ entry -> size );
748+ __gvt_cache_remove_entry (vgpu , entry );
757749 }
758-
759- return NOTIFY_OK ;
750+ mutex_unlock (& vgpu -> cache_lock );
760751}
761752
762753static bool __kvmgt_vgpu_exist (struct intel_vgpu * vgpu )
@@ -783,36 +774,20 @@ static bool __kvmgt_vgpu_exist(struct intel_vgpu *vgpu)
783774static int intel_vgpu_open_device (struct vfio_device * vfio_dev )
784775{
785776 struct intel_vgpu * vgpu = vfio_dev_to_vgpu (vfio_dev );
786- unsigned long events ;
787- int ret ;
788-
789- vgpu -> iommu_notifier .notifier_call = intel_vgpu_iommu_notifier ;
790777
791- events = VFIO_IOMMU_NOTIFY_DMA_UNMAP ;
792- ret = vfio_register_notifier (vfio_dev , VFIO_IOMMU_NOTIFY , & events ,
793- & vgpu -> iommu_notifier );
794- if (ret != 0 ) {
795- gvt_vgpu_err ("vfio_register_notifier for iommu failed: %d\n" ,
796- ret );
797- goto out ;
798- }
799-
800- ret = - EEXIST ;
801778 if (vgpu -> attached )
802- goto undo_iommu ;
779+ return - EEXIST ;
803780
804- ret = - ESRCH ;
805781 if (!vgpu -> vfio_device .kvm ||
806782 vgpu -> vfio_device .kvm -> mm != current -> mm ) {
807783 gvt_vgpu_err ("KVM is required to use Intel vGPU\n" );
808- goto undo_iommu ;
784+ return - ESRCH ;
809785 }
810786
811787 kvm_get_kvm (vgpu -> vfio_device .kvm );
812788
813- ret = - EEXIST ;
814789 if (__kvmgt_vgpu_exist (vgpu ))
815- goto undo_iommu ;
790+ return - EEXIST ;
816791
817792 vgpu -> attached = true;
818793
@@ -831,12 +806,6 @@ static int intel_vgpu_open_device(struct vfio_device *vfio_dev)
831806
832807 atomic_set (& vgpu -> released , 0 );
833808 return 0 ;
834-
835- undo_iommu :
836- vfio_unregister_notifier (vfio_dev , VFIO_IOMMU_NOTIFY ,
837- & vgpu -> iommu_notifier );
838- out :
839- return ret ;
840809}
841810
842811static void intel_vgpu_release_msi_eventfd_ctx (struct intel_vgpu * vgpu )
@@ -853,8 +822,6 @@ static void intel_vgpu_release_msi_eventfd_ctx(struct intel_vgpu *vgpu)
853822static void intel_vgpu_close_device (struct vfio_device * vfio_dev )
854823{
855824 struct intel_vgpu * vgpu = vfio_dev_to_vgpu (vfio_dev );
856- struct drm_i915_private * i915 = vgpu -> gvt -> gt -> i915 ;
857- int ret ;
858825
859826 if (!vgpu -> attached )
860827 return ;
@@ -864,11 +831,6 @@ static void intel_vgpu_close_device(struct vfio_device *vfio_dev)
864831
865832 intel_gvt_release_vgpu (vgpu );
866833
867- ret = vfio_unregister_notifier (& vgpu -> vfio_device , VFIO_IOMMU_NOTIFY ,
868- & vgpu -> iommu_notifier );
869- drm_WARN (& i915 -> drm , ret ,
870- "vfio_unregister_notifier for iommu failed: %d\n" , ret );
871-
872834 debugfs_remove (debugfs_lookup (KVMGT_DEBUGFS_FILENAME , vgpu -> debugfs ));
873835
874836 kvm_page_track_unregister_notifier (vgpu -> vfio_device .kvm ,
@@ -1610,6 +1572,7 @@ static const struct vfio_device_ops intel_vgpu_dev_ops = {
16101572 .write = intel_vgpu_write ,
16111573 .mmap = intel_vgpu_mmap ,
16121574 .ioctl = intel_vgpu_ioctl ,
1575+ .dma_unmap = intel_vgpu_dma_unmap ,
16131576};
16141577
16151578static int intel_vgpu_probe (struct mdev_device * mdev )
0 commit comments