From: Tina Zhang <tina.zhang@intel.com>
To: alex.williamson@redhat.com, kraxel@redhat.com,
chris@chris-wilson.co.uk, joonas.lahtinen@linux.intel.com,
zhenyuw@linux.intel.com, zhiyuan.lv@intel.com,
zhi.a.wang@intel.com, kevin.tian@intel.com, daniel@ffwll.ch,
kwankhede@nvidia.com, hang.yuan@intel.com
Cc: Tina Zhang <tina.zhang@intel.com>,
intel-gfx@lists.freedesktop.org,
intel-gvt-dev@lists.freedesktop.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v19 6/6] drm/i915/gvt: Handle orphan dmabuf_objs
Date: Thu, 23 Nov 2017 16:26:37 +0800 [thread overview]
Message-ID: <1511425598-2437-7-git-send-email-tina.zhang@intel.com> (raw)
In-Reply-To: <1511425598-2437-1-git-send-email-tina.zhang@intel.com>
dmabuf_obj's destruction relys on GEM release operation, which is managed
in i915 driver. And there is a time window between vgpu's destruction and
its dmabuf_objs' destruction. This patch is to free the orphan dmabuf_objs
correctly after the vgpu passes away.
Signed-off-by: Tina Zhang <tina.zhang@intel.com>
Cc: Zhenyu Wang <zhenyuw@linux.intel.com>
---
drivers/gpu/drm/i915/gvt/dmabuf.c | 56 ++++++++++++++++++++++++---------------
1 file changed, 35 insertions(+), 21 deletions(-)
diff --git a/drivers/gpu/drm/i915/gvt/dmabuf.c b/drivers/gpu/drm/i915/gvt/dmabuf.c
index 190710c..50215b2 100644
--- a/drivers/gpu/drm/i915/gvt/dmabuf.c
+++ b/drivers/gpu/drm/i915/gvt/dmabuf.c
@@ -88,19 +88,26 @@ static void dmabuf_gem_object_free(struct kref *kref)
container_of(kref, struct intel_vgpu_dmabuf_obj, kref);
struct intel_vgpu *vgpu = obj->vgpu;
struct list_head *pos;
-
struct intel_vgpu_dmabuf_obj *dmabuf_obj;
- list_for_each(pos, &vgpu->dmabuf_obj_list_head) {
- dmabuf_obj = container_of(pos, struct intel_vgpu_dmabuf_obj,
- list);
- if (dmabuf_obj == obj) {
- idr_remove(&vgpu->object_idr, dmabuf_obj->dmabuf_id);
- kfree(dmabuf_obj->info);
- kfree(dmabuf_obj);
- list_del(pos);
- break;
+ if (vgpu) {
+ list_for_each(pos, &vgpu->dmabuf_obj_list_head) {
+ dmabuf_obj = container_of(pos,
+ struct intel_vgpu_dmabuf_obj, list);
+ if (dmabuf_obj == obj) {
+ intel_gvt_hypervisor_put_vfio_device(vgpu);
+ idr_remove(&vgpu->object_idr,
+ dmabuf_obj->dmabuf_id);
+ kfree(dmabuf_obj->info);
+ kfree(dmabuf_obj);
+ list_del(pos);
+ break;
+ }
}
+ } else {
+ /* Free the orphan dmabuf_objs here */
+ kfree(obj->info);
+ kfree(obj);
}
}
@@ -122,11 +129,16 @@ static void vgpu_gem_release(struct drm_i915_gem_object *gem_obj)
struct intel_vgpu_dmabuf_obj *obj = fb_info->obj;
struct intel_vgpu *vgpu = obj->vgpu;
- mutex_lock(&vgpu->dmabuf_lock);
- gem_obj->base.dma_buf = NULL;
- dmabuf_obj_put(obj);
- intel_gvt_hypervisor_put_vfio_device(vgpu);
- mutex_unlock(&vgpu->dmabuf_lock);
+ if (vgpu) {
+ mutex_lock(&vgpu->dmabuf_lock);
+ gem_obj->base.dma_buf = NULL;
+ dmabuf_obj_put(obj);
+ mutex_unlock(&vgpu->dmabuf_lock);
+ } else {
+ /* vgpu is NULL, as it has been removed already */
+ gem_obj->base.dma_buf = NULL;
+ dmabuf_obj_put(obj);
+ }
}
static const struct drm_i915_gem_object_ops intel_vgpu_gem_ops = {
@@ -471,12 +483,6 @@ int intel_vgpu_get_dmabuf(struct intel_vgpu *vgpu, unsigned int dmabuf_id)
}
dmabuf_fd = ret;
- if (intel_gvt_hypervisor_get_vfio_device(vgpu)) {
- gvt_vgpu_err("get vfio device failed\n");
- put_unused_fd(ret);
- goto out_free_dmabuf;
- }
-
dmabuf_obj_get(dmabuf_obj);
if (dmabuf_obj->initref) {
@@ -518,6 +524,14 @@ void intel_vgpu_dmabuf_cleanup(struct intel_vgpu *vgpu)
dmabuf_obj->initref = false;
dmabuf_obj_put(dmabuf_obj);
}
+
+ idr_remove(&vgpu->object_idr, dmabuf_obj->dmabuf_id);
+
+ if (dmabuf_obj->vgpu)
+ intel_gvt_hypervisor_put_vfio_device(vgpu);
+
+ dmabuf_obj->vgpu = NULL;
+
}
mutex_unlock(&vgpu->dmabuf_lock);
}
--
2.7.4
prev parent reply other threads:[~2017-11-23 8:32 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-23 8:26 [PATCH v19 0/6] drm/i915/gvt: Dma-buf support for GVT-g Tina Zhang
2017-11-23 8:26 ` [PATCH v19 1/6] drm/i915/gvt: Add framebuffer decoder support Tina Zhang
2017-11-23 8:26 ` [PATCH v19 2/6] drm: Introduce RGB 64-bit 16:16:16:16 float format Tina Zhang
2017-11-23 8:26 ` [PATCH v19 3/6] drm/i915/gvt: Add " Tina Zhang
2017-11-23 8:26 ` [PATCH v19 4/6] vfio: ABI for mdev display dma-buf operation Tina Zhang
2017-11-23 8:26 ` [PATCH v19 5/6] drm/i915/gvt: Dmabuf support for GVT-g Tina Zhang
2017-11-23 8:26 ` Tina Zhang [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1511425598-2437-7-git-send-email-tina.zhang@intel.com \
--to=tina.zhang@intel.com \
--cc=alex.williamson@redhat.com \
--cc=chris@chris-wilson.co.uk \
--cc=daniel@ffwll.ch \
--cc=hang.yuan@intel.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=intel-gvt-dev@lists.freedesktop.org \
--cc=joonas.lahtinen@linux.intel.com \
--cc=kevin.tian@intel.com \
--cc=kraxel@redhat.com \
--cc=kwankhede@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=zhenyuw@linux.intel.com \
--cc=zhi.a.wang@intel.com \
--cc=zhiyuan.lv@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®