Skip to content

Commit 776d95b

Browse files
yanzhao56zhenyw
authored andcommitted
drm/i915/gvt: hold reference of VFIO group during opening of vgpu
hold reference count of the VFIO group for each vgpu at vgpu opening and release the reference at vgpu releasing. Signed-off-by: Yan Zhao <[email protected]> Reviewed-by: Zhenyu Wang<[email protected]> Signed-off-by: Zhenyu Wang<[email protected]> Link: http://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent bcad588 commit 776d95b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

drivers/gpu/drm/i915/gvt/kvmgt.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ struct kvmgt_vdev {
131131
struct work_struct release_work;
132132
atomic_t released;
133133
struct vfio_device *vfio_device;
134+
struct vfio_group *vfio_group;
134135
};
135136

136137
static inline struct kvmgt_vdev *kvmgt_vdev(struct intel_vgpu *vgpu)
@@ -792,6 +793,7 @@ static int intel_vgpu_open(struct mdev_device *mdev)
792793
struct kvmgt_vdev *vdev = kvmgt_vdev(vgpu);
793794
unsigned long events;
794795
int ret;
796+
struct vfio_group *vfio_group;
795797

796798
vdev->iommu_notifier.notifier_call = intel_vgpu_iommu_notifier;
797799
vdev->group_notifier.notifier_call = intel_vgpu_group_notifier;
@@ -814,6 +816,14 @@ static int intel_vgpu_open(struct mdev_device *mdev)
814816
goto undo_iommu;
815817
}
816818

819+
vfio_group = vfio_group_get_external_user_from_dev(mdev_dev(mdev));
820+
if (IS_ERR_OR_NULL(vfio_group)) {
821+
ret = !vfio_group ? -EFAULT : PTR_ERR(vfio_group);
822+
gvt_vgpu_err("vfio_group_get_external_user_from_dev failed\n");
823+
goto undo_register;
824+
}
825+
vdev->vfio_group = vfio_group;
826+
817827
/* Take a module reference as mdev core doesn't take
818828
* a reference for vendor driver.
819829
*/
@@ -830,6 +840,10 @@ static int intel_vgpu_open(struct mdev_device *mdev)
830840
return ret;
831841

832842
undo_group:
843+
vfio_group_put_external_user(vdev->vfio_group);
844+
vdev->vfio_group = NULL;
845+
846+
undo_register:
833847
vfio_unregister_notifier(mdev_dev(mdev), VFIO_GROUP_NOTIFY,
834848
&vdev->group_notifier);
835849

@@ -884,6 +898,7 @@ static void __intel_vgpu_release(struct intel_vgpu *vgpu)
884898
kvmgt_guest_exit(info);
885899

886900
intel_vgpu_release_msi_eventfd_ctx(vgpu);
901+
vfio_group_put_external_user(vdev->vfio_group);
887902

888903
vdev->kvm = NULL;
889904
vgpu->handle = 0;

0 commit comments

Comments
 (0)