drm/i915/gvt: devirtualize ->{get,put}_vfio_device
authorChristoph Hellwig <hch@lst.de>
Mon, 11 Apr 2022 14:13:43 +0000 (16:13 +0200)
committerZhi Wang <zhi.a.wang@intel.com>
Thu, 21 Apr 2022 11:36:56 +0000 (07:36 -0400)
Just open code the calls to the VFIO APIs.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Zhi Wang <zhi.a.wang@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20220411141403.86980-15-hch@lst.de
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Zhi Wang <zhi.a.wang@intel.com>
drivers/gpu/drm/i915/gvt/dmabuf.c
drivers/gpu/drm/i915/gvt/hypercall.h
drivers/gpu/drm/i915/gvt/kvmgt.c
drivers/gpu/drm/i915/gvt/mpt.h

index c95c25d..cc1a9ac 100644 (file)
@@ -29,7 +29,7 @@
  */
 
 #include <linux/dma-buf.h>
-#include <linux/vfio.h>
+#include <linux/mdev.h>
 
 #include <drm/drm_fourcc.h>
 #include <drm/drm_plane.h>
@@ -157,7 +157,7 @@ static void dmabuf_gem_object_free(struct kref *kref)
                        dmabuf_obj = list_entry(pos, struct intel_vgpu_dmabuf_obj, list);
                        if (dmabuf_obj == obj) {
                                list_del(pos);
-                               intel_gvt_hypervisor_put_vfio_device(vgpu);
+                               vfio_device_put(vgpu->vfio_device);
                                idr_remove(&vgpu->object_idr,
                                           dmabuf_obj->dmabuf_id);
                                kfree(dmabuf_obj->info);
@@ -492,9 +492,11 @@ int intel_vgpu_query_plane(struct intel_vgpu *vgpu, void *args)
        kref_init(&dmabuf_obj->kref);
 
        mutex_lock(&vgpu->dmabuf_lock);
-       if (intel_gvt_hypervisor_get_vfio_device(vgpu)) {
-               gvt_vgpu_err("get vfio device failed\n");
+       vgpu->vfio_device = vfio_device_get_from_dev(mdev_dev(vgpu->mdev));
+       if (!vgpu->vfio_device) {
+               gvt_vgpu_err("failed to get vfio device\n");
                mutex_unlock(&vgpu->dmabuf_lock);
+               ret = -ENODEV;
                goto out_free_info;
        }
        mutex_unlock(&vgpu->dmabuf_lock);
@@ -603,7 +605,7 @@ void intel_vgpu_dmabuf_cleanup(struct intel_vgpu *vgpu)
                dmabuf_obj->vgpu = NULL;
 
                idr_remove(&vgpu->object_idr, dmabuf_obj->dmabuf_id);
-               intel_gvt_hypervisor_put_vfio_device(vgpu);
+               vfio_device_put(vgpu->vfio_device);
                list_del(pos);
 
                /* dmabuf_obj might be freed in dmabuf_obj_put */
index 61e493e..fd903d5 100644 (file)
@@ -60,8 +60,6 @@ struct intel_gvt_mpt {
 
        int (*set_opregion)(struct intel_vgpu *vgpu);
        int (*set_edid)(struct intel_vgpu *vgpu, int port_num);
-       int (*get_vfio_device)(struct intel_vgpu *vgpu);
-       void (*put_vfio_device)(struct intel_vgpu *vgpu);
        bool (*is_valid_gfn)(struct intel_vgpu *vgpu, unsigned long gfn);
 };
 
index e4e3d0c..1f70cbd 100644 (file)
@@ -662,18 +662,6 @@ static int intel_vgpu_register_reg(struct intel_vgpu *vgpu,
        return 0;
 }
 
-static int kvmgt_get_vfio_device(struct intel_vgpu *vgpu)
-{
-       vgpu->vfio_device = vfio_device_get_from_dev(
-               mdev_dev(vgpu->mdev));
-       if (!vgpu->vfio_device) {
-               gvt_vgpu_err("failed to get vfio device\n");
-               return -ENODEV;
-       }
-       return 0;
-}
-
-
 static int kvmgt_set_opregion(struct intel_vgpu *vgpu)
 {
        void *base;
@@ -730,14 +718,6 @@ static int kvmgt_set_edid(struct intel_vgpu *vgpu, int port_num)
        return ret;
 }
 
-static void kvmgt_put_vfio_device(struct intel_vgpu *vgpu)
-{
-       if (WARN_ON(!vgpu->vfio_device))
-               return;
-
-       vfio_device_put(vgpu->vfio_device);
-}
-
 static int intel_vgpu_create(struct mdev_device *mdev)
 {
        struct intel_vgpu *vgpu = NULL;
@@ -2052,8 +2032,6 @@ static const struct intel_gvt_mpt kvmgt_mpt = {
        .dma_pin_guest_page = kvmgt_dma_pin_guest_page,
        .set_opregion = kvmgt_set_opregion,
        .set_edid = kvmgt_set_edid,
-       .get_vfio_device = kvmgt_get_vfio_device,
-       .put_vfio_device = kvmgt_put_vfio_device,
        .is_valid_gfn = kvmgt_is_valid_gfn,
 };
 
index 72388ce..2196187 100644 (file)
@@ -243,36 +243,6 @@ static inline int intel_gvt_hypervisor_set_edid(struct intel_vgpu *vgpu,
 }
 
 /**
- * intel_gvt_hypervisor_get_vfio_device - increase vfio device ref count
- * @vgpu: a vGPU
- *
- * Returns:
- * Zero on success, negative error code if failed.
- */
-static inline int intel_gvt_hypervisor_get_vfio_device(struct intel_vgpu *vgpu)
-{
-       if (!intel_gvt_host.mpt->get_vfio_device)
-               return 0;
-
-       return intel_gvt_host.mpt->get_vfio_device(vgpu);
-}
-
-/**
- * intel_gvt_hypervisor_put_vfio_device - decrease vfio device ref count
- * @vgpu: a vGPU
- *
- * Returns:
- * Zero on success, negative error code if failed.
- */
-static inline void intel_gvt_hypervisor_put_vfio_device(struct intel_vgpu *vgpu)
-{
-       if (!intel_gvt_host.mpt->put_vfio_device)
-               return;
-
-       intel_gvt_host.mpt->put_vfio_device(vgpu);
-}
-
-/**
  * intel_gvt_hypervisor_is_valid_gfn - check if a visible gfn
  * @vgpu: a vGPU
  * @gfn: guest PFN