@@ -228,8 +228,6 @@ static void intel_gvt_cleanup_vgpu_type_groups(struct intel_gvt *gvt)
228
228
}
229
229
}
230
230
231
- static void intel_vgpu_release_work (struct work_struct * work );
232
-
233
231
static void gvt_unpin_guest_page (struct intel_vgpu * vgpu , unsigned long gfn ,
234
232
unsigned long size )
235
233
{
@@ -761,23 +759,6 @@ static int intel_vgpu_iommu_notifier(struct notifier_block *nb,
761
759
return NOTIFY_OK ;
762
760
}
763
761
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
-
781
762
static bool __kvmgt_vgpu_exist (struct intel_vgpu * vgpu )
782
763
{
783
764
struct intel_vgpu * itr ;
@@ -789,7 +770,7 @@ static bool __kvmgt_vgpu_exist(struct intel_vgpu *vgpu)
789
770
if (!itr -> attached )
790
771
continue ;
791
772
792
- if (vgpu -> kvm == itr -> kvm ) {
773
+ if (vgpu -> vfio_device . kvm == itr -> vfio_device . kvm ) {
793
774
ret = true;
794
775
goto out ;
795
776
}
@@ -806,7 +787,6 @@ static int intel_vgpu_open_device(struct vfio_device *vfio_dev)
806
787
int ret ;
807
788
808
789
vgpu -> iommu_notifier .notifier_call = intel_vgpu_iommu_notifier ;
809
- vgpu -> group_notifier .notifier_call = intel_vgpu_group_notifier ;
810
790
811
791
events = VFIO_IOMMU_NOTIFY_DMA_UNMAP ;
812
792
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)
817
797
goto out ;
818
798
}
819
799
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
-
829
800
ret = - EEXIST ;
830
801
if (vgpu -> attached )
831
- goto undo_register ;
802
+ goto undo_iommu ;
832
803
833
804
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 ) {
835
807
gvt_vgpu_err ("KVM is required to use Intel vGPU\n" );
836
- goto undo_register ;
808
+ goto undo_iommu ;
837
809
}
838
810
811
+ kvm_get_kvm (vgpu -> vfio_device .kvm );
812
+
839
813
ret = - EEXIST ;
840
814
if (__kvmgt_vgpu_exist (vgpu ))
841
- goto undo_register ;
815
+ goto undo_iommu ;
842
816
843
817
vgpu -> attached = true;
844
- kvm_get_kvm (vgpu -> kvm );
845
818
846
819
kvmgt_protect_table_init (vgpu );
847
820
gvt_cache_init (vgpu );
848
821
849
822
vgpu -> track_node .track_write = kvmgt_page_track_write ;
850
823
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 );
852
826
853
827
debugfs_create_ulong (KVMGT_DEBUGFS_FILENAME , 0444 , vgpu -> debugfs ,
854
828
& vgpu -> nr_cache_entries );
@@ -858,10 +832,6 @@ static int intel_vgpu_open_device(struct vfio_device *vfio_dev)
858
832
atomic_set (& vgpu -> released , 0 );
859
833
return 0 ;
860
834
861
- undo_register :
862
- vfio_unregister_notifier (vfio_dev , VFIO_GROUP_NOTIFY ,
863
- & vgpu -> group_notifier );
864
-
865
835
undo_iommu :
866
836
vfio_unregister_notifier (vfio_dev , VFIO_IOMMU_NOTIFY ,
867
837
& vgpu -> iommu_notifier );
@@ -880,8 +850,9 @@ static void intel_vgpu_release_msi_eventfd_ctx(struct intel_vgpu *vgpu)
880
850
}
881
851
}
882
852
883
- static void __intel_vgpu_release (struct intel_vgpu * vgpu )
853
+ static void intel_vgpu_close_device (struct vfio_device * vfio_dev )
884
854
{
855
+ struct intel_vgpu * vgpu = vfio_dev_to_vgpu (vfio_dev );
885
856
struct drm_i915_private * i915 = vgpu -> gvt -> gt -> i915 ;
886
857
int ret ;
887
858
@@ -898,35 +869,19 @@ static void __intel_vgpu_release(struct intel_vgpu *vgpu)
898
869
drm_WARN (& i915 -> drm , ret ,
899
870
"vfio_unregister_notifier for iommu failed: %d\n" , ret );
900
871
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
-
906
872
debugfs_remove (debugfs_lookup (KVMGT_DEBUGFS_FILENAME , vgpu -> debugfs ));
907
873
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 );
910
876
kvmgt_protect_table_destroy (vgpu );
911
877
gvt_cache_destroy (vgpu );
912
878
913
879
intel_vgpu_release_msi_eventfd_ctx (vgpu );
914
880
915
- vgpu -> kvm = NULL ;
916
881
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 );
928
882
929
- __intel_vgpu_release (vgpu );
883
+ if (vgpu -> vfio_device .kvm )
884
+ kvm_put_kvm (vgpu -> vfio_device .kvm );
930
885
}
931
886
932
887
static 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)
1675
1630
return PTR_ERR (vgpu );
1676
1631
}
1677
1632
1678
- INIT_WORK (& vgpu -> release_work , intel_vgpu_release_work );
1679
1633
vfio_init_group_dev (& vgpu -> vfio_device , & mdev -> dev ,
1680
1634
& intel_vgpu_dev_ops );
1681
1635
@@ -1713,7 +1667,7 @@ static struct mdev_driver intel_vgpu_mdev_driver = {
1713
1667
1714
1668
int intel_gvt_page_track_add (struct intel_vgpu * info , u64 gfn )
1715
1669
{
1716
- struct kvm * kvm = info -> kvm ;
1670
+ struct kvm * kvm = info -> vfio_device . kvm ;
1717
1671
struct kvm_memory_slot * slot ;
1718
1672
int idx ;
1719
1673
@@ -1743,7 +1697,7 @@ int intel_gvt_page_track_add(struct intel_vgpu *info, u64 gfn)
1743
1697
1744
1698
int intel_gvt_page_track_remove (struct intel_vgpu * info , u64 gfn )
1745
1699
{
1746
- struct kvm * kvm = info -> kvm ;
1700
+ struct kvm * kvm = info -> vfio_device . kvm ;
1747
1701
struct kvm_memory_slot * slot ;
1748
1702
int idx ;
1749
1703
0 commit comments