@@ -228,8 +228,6 @@ static void intel_gvt_cleanup_vgpu_type_groups(struct intel_gvt *gvt)
228228 }
229229}
230230
231- static void intel_vgpu_release_work (struct work_struct * work );
232-
233231static void gvt_unpin_guest_page (struct intel_vgpu * vgpu , unsigned long gfn ,
234232 unsigned long size )
235233{
@@ -761,23 +759,6 @@ static int intel_vgpu_iommu_notifier(struct notifier_block *nb,
761759 return NOTIFY_OK ;
762760}
763761
764- static int intel_vgpu_group_notifier (struct notifier_block * nb ,
765- unsigned long action , void * data )
766- {
767- struct intel_vgpu * vgpu =
768- container_of (nb , struct intel_vgpu , group_notifier );
769-
770- /* the only action we care about */
771- if (action == VFIO_GROUP_NOTIFY_SET_KVM ) {
772- vgpu -> kvm = data ;
773-
774- if (!data )
775- schedule_work (& vgpu -> release_work );
776- }
777-
778- return NOTIFY_OK ;
779- }
780-
781762static bool __kvmgt_vgpu_exist (struct intel_vgpu * vgpu )
782763{
783764 struct intel_vgpu * itr ;
@@ -789,7 +770,7 @@ static bool __kvmgt_vgpu_exist(struct intel_vgpu *vgpu)
789770 if (!itr -> attached )
790771 continue ;
791772
792- if (vgpu -> kvm == itr -> kvm ) {
773+ if (vgpu -> vfio_device . kvm == itr -> vfio_device . kvm ) {
793774 ret = true;
794775 goto out ;
795776 }
@@ -806,7 +787,6 @@ static int intel_vgpu_open_device(struct vfio_device *vfio_dev)
806787 int ret ;
807788
808789 vgpu -> iommu_notifier .notifier_call = intel_vgpu_iommu_notifier ;
809- vgpu -> group_notifier .notifier_call = intel_vgpu_group_notifier ;
810790
811791 events = VFIO_IOMMU_NOTIFY_DMA_UNMAP ;
812792 ret = vfio_register_notifier (vfio_dev , VFIO_IOMMU_NOTIFY , & events ,
@@ -817,38 +797,32 @@ static int intel_vgpu_open_device(struct vfio_device *vfio_dev)
817797 goto out ;
818798 }
819799
820- events = VFIO_GROUP_NOTIFY_SET_KVM ;
821- ret = vfio_register_notifier (vfio_dev , VFIO_GROUP_NOTIFY , & events ,
822- & vgpu -> group_notifier );
823- if (ret != 0 ) {
824- gvt_vgpu_err ("vfio_register_notifier for group failed: %d\n" ,
825- ret );
826- goto undo_iommu ;
827- }
828-
829800 ret = - EEXIST ;
830801 if (vgpu -> attached )
831- goto undo_register ;
802+ goto undo_iommu ;
832803
833804 ret = - ESRCH ;
834- if (!vgpu -> kvm || vgpu -> kvm -> mm != current -> mm ) {
805+ if (!vgpu -> vfio_device .kvm ||
806+ vgpu -> vfio_device .kvm -> mm != current -> mm ) {
835807 gvt_vgpu_err ("KVM is required to use Intel vGPU\n" );
836- goto undo_register ;
808+ goto undo_iommu ;
837809 }
838810
811+ kvm_get_kvm (vgpu -> vfio_device .kvm );
812+
839813 ret = - EEXIST ;
840814 if (__kvmgt_vgpu_exist (vgpu ))
841- goto undo_register ;
815+ goto undo_iommu ;
842816
843817 vgpu -> attached = true;
844- kvm_get_kvm (vgpu -> kvm );
845818
846819 kvmgt_protect_table_init (vgpu );
847820 gvt_cache_init (vgpu );
848821
849822 vgpu -> track_node .track_write = kvmgt_page_track_write ;
850823 vgpu -> track_node .track_flush_slot = kvmgt_page_track_flush_slot ;
851- kvm_page_track_register_notifier (vgpu -> kvm , & vgpu -> track_node );
824+ kvm_page_track_register_notifier (vgpu -> vfio_device .kvm ,
825+ & vgpu -> track_node );
852826
853827 debugfs_create_ulong (KVMGT_DEBUGFS_FILENAME , 0444 , vgpu -> debugfs ,
854828 & vgpu -> nr_cache_entries );
@@ -858,10 +832,6 @@ static int intel_vgpu_open_device(struct vfio_device *vfio_dev)
858832 atomic_set (& vgpu -> released , 0 );
859833 return 0 ;
860834
861- undo_register :
862- vfio_unregister_notifier (vfio_dev , VFIO_GROUP_NOTIFY ,
863- & vgpu -> group_notifier );
864-
865835undo_iommu :
866836 vfio_unregister_notifier (vfio_dev , VFIO_IOMMU_NOTIFY ,
867837 & vgpu -> iommu_notifier );
@@ -880,8 +850,9 @@ static void intel_vgpu_release_msi_eventfd_ctx(struct intel_vgpu *vgpu)
880850 }
881851}
882852
883- static void __intel_vgpu_release (struct intel_vgpu * vgpu )
853+ static void intel_vgpu_close_device (struct vfio_device * vfio_dev )
884854{
855+ struct intel_vgpu * vgpu = vfio_dev_to_vgpu (vfio_dev );
885856 struct drm_i915_private * i915 = vgpu -> gvt -> gt -> i915 ;
886857 int ret ;
887858
@@ -898,35 +869,19 @@ static void __intel_vgpu_release(struct intel_vgpu *vgpu)
898869 drm_WARN (& i915 -> drm , ret ,
899870 "vfio_unregister_notifier for iommu failed: %d\n" , ret );
900871
901- ret = vfio_unregister_notifier (& vgpu -> vfio_device , VFIO_GROUP_NOTIFY ,
902- & vgpu -> group_notifier );
903- drm_WARN (& i915 -> drm , ret ,
904- "vfio_unregister_notifier for group failed: %d\n" , ret );
905-
906872 debugfs_remove (debugfs_lookup (KVMGT_DEBUGFS_FILENAME , vgpu -> debugfs ));
907873
908- kvm_page_track_unregister_notifier (vgpu -> kvm , & vgpu -> track_node );
909- kvm_put_kvm ( vgpu -> kvm );
874+ kvm_page_track_unregister_notifier (vgpu -> vfio_device . kvm ,
875+ & vgpu -> track_node );
910876 kvmgt_protect_table_destroy (vgpu );
911877 gvt_cache_destroy (vgpu );
912878
913879 intel_vgpu_release_msi_eventfd_ctx (vgpu );
914880
915- vgpu -> kvm = NULL ;
916881 vgpu -> attached = false;
917- }
918-
919- static void intel_vgpu_close_device (struct vfio_device * vfio_dev )
920- {
921- __intel_vgpu_release (vfio_dev_to_vgpu (vfio_dev ));
922- }
923-
924- static void intel_vgpu_release_work (struct work_struct * work )
925- {
926- struct intel_vgpu * vgpu =
927- container_of (work , struct intel_vgpu , release_work );
928882
929- __intel_vgpu_release (vgpu );
883+ if (vgpu -> vfio_device .kvm )
884+ kvm_put_kvm (vgpu -> vfio_device .kvm );
930885}
931886
932887static u64 intel_vgpu_get_bar_addr (struct intel_vgpu * vgpu , int bar )
@@ -1675,7 +1630,6 @@ static int intel_vgpu_probe(struct mdev_device *mdev)
16751630 return PTR_ERR (vgpu );
16761631 }
16771632
1678- INIT_WORK (& vgpu -> release_work , intel_vgpu_release_work );
16791633 vfio_init_group_dev (& vgpu -> vfio_device , & mdev -> dev ,
16801634 & intel_vgpu_dev_ops );
16811635
@@ -1713,7 +1667,7 @@ static struct mdev_driver intel_vgpu_mdev_driver = {
17131667
17141668int intel_gvt_page_track_add (struct intel_vgpu * info , u64 gfn )
17151669{
1716- struct kvm * kvm = info -> kvm ;
1670+ struct kvm * kvm = info -> vfio_device . kvm ;
17171671 struct kvm_memory_slot * slot ;
17181672 int idx ;
17191673
@@ -1743,7 +1697,7 @@ int intel_gvt_page_track_add(struct intel_vgpu *info, u64 gfn)
17431697
17441698int intel_gvt_page_track_remove (struct intel_vgpu * info , u64 gfn )
17451699{
1746- struct kvm * kvm = info -> kvm ;
1700+ struct kvm * kvm = info -> vfio_device . kvm ;
17471701 struct kvm_memory_slot * slot ;
17481702 int idx ;
17491703
0 commit comments