[PATCH] drm/i195/gvt: Use debugobjects to track dmabuf_obj life time

Tina Zhang tina.zhang at intel.com
Wed Nov 29 06:18:07 UTC 2017


This patch uses debugobjects to track dmabuf_obj life time.

Signed-off-by: Tina Zhang <tina.zhang at intel.com>
---
 drivers/gpu/drm/i915/gvt/dmabuf.c | 120 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 120 insertions(+)

diff --git a/drivers/gpu/drm/i915/gvt/dmabuf.c b/drivers/gpu/drm/i915/gvt/dmabuf.c
index 9c40a67..459499f 100644
--- a/drivers/gpu/drm/i915/gvt/dmabuf.c
+++ b/drivers/gpu/drm/i915/gvt/dmabuf.c
@@ -37,6 +37,114 @@
 
 #define GEN8_DECODE_PTE(pte) (pte & GENMASK_ULL(63, 12))
 
+#define DEBUG_DMABUF_OBJ
+
+#ifdef DEBUG_DMABUF_OBJ
+
+static void *vgpu_dmabuf_debug_hint(void *addr)
+{
+	unsigned long ref =
+		kref_read(&((struct intel_vgpu_dmabuf_obj *)addr)->kref);
+
+	return (void *)(ref);
+}
+
+static struct debug_obj_descr vgpu_debug_descr = {
+	.name = "vgpu_dmabuf",
+	.debug_hint = vgpu_dmabuf_debug_hint,
+};
+
+static inline void debug_dmabuf_init(
+	struct intel_vgpu_dmabuf_obj *dmabuf_obj)
+{
+	debug_object_init(dmabuf_obj, &vgpu_debug_descr);
+}
+
+static inline void debug_dmabuf_init_onstack(
+	struct intel_vgpu_dmabuf_obj *dmabuf_obj)
+{
+	debug_object_init_on_stack(dmabuf_obj, &vgpu_debug_descr);
+}
+
+static inline void debug_dmabuf_activate(
+	struct intel_vgpu_dmabuf_obj *dmabuf_obj)
+{
+	debug_object_activate(dmabuf_obj, &vgpu_debug_descr);
+}
+
+static inline void debug_dmabuf_set_state(
+	struct intel_vgpu_dmabuf_obj *dmabuf_obj, int old, int new)
+{
+	debug_object_active_state(dmabuf_obj, &vgpu_debug_descr, old, new);
+}
+
+static inline void debug_dmabuf_deactivate(
+	struct intel_vgpu_dmabuf_obj *dmabuf_obj)
+{
+	debug_object_deactivate(dmabuf_obj, &vgpu_debug_descr);
+}
+
+static inline void debug_dmabuf_destroy(
+	struct intel_vgpu_dmabuf_obj *dmabuf_obj)
+{
+	debug_object_destroy(dmabuf_obj, &vgpu_debug_descr);
+}
+
+static inline void debug_dmabuf_free(
+	struct intel_vgpu_dmabuf_obj *dmabuf_obj)
+{
+	debug_object_free(dmabuf_obj, &vgpu_debug_descr);
+}
+
+static inline void debug_dmabuf_assert(
+	struct intel_vgpu_dmabuf_obj *dmabuf_obj)
+{
+	debug_object_assert_init(dmabuf_obj, &vgpu_debug_descr);
+}
+
+#else
+
+static inline void debug_dmabuf_init(
+	struct intel_vgpu_dmabuf_obj *dmabuf_obj)
+{
+}
+
+static inline void debug_dmabuf_init_onstack(
+	struct intel_vgpu_dmabuf_obj *dmabuf_obj)
+{
+}
+
+static inline void debug_dmabuf_activate(
+	struct intel_vgpu_dmabuf_obj *dmabuf_obj)
+{
+}
+
+static inline void debug_dmabuf_set_state(
+	struct intel_vgpu_dmabuf_obj *dmabuf_obj, int old, int new)
+{
+}
+
+static inline void debug_dmabuf_deactivate(
+	struct intel_vgpu_dmabuf_obj *dmabuf_obj)
+{
+}
+
+static inline void debug_dmabuf_destroy(
+	struct intel_vgpu_dmabuf_obj *dmabuf_obj)
+{
+}
+
+static inline void debug_dmabuf_free(
+	struct intel_vgpu_dmabuf_obj *dmabuf_obj)
+{
+}
+
+static inline void debug_dmabuf_assert(
+	struct intel_vgpu_dmabuf_obj *dmabuf_obj)
+{
+}
+#endif
+
 static int vgpu_gem_get_pages(
 		struct drm_i915_gem_object *obj)
 {
@@ -90,6 +198,8 @@ static void dmabuf_gem_object_free(struct kref *kref)
 	struct list_head *pos;
 	struct intel_vgpu_dmabuf_obj *dmabuf_obj;
 
+	debug_dmabuf_destroy(obj);
+
 	if (vgpu && vgpu->active && !list_empty(&vgpu->dmabuf_obj_list_head)) {
 		list_for_each(pos, &vgpu->dmabuf_obj_list_head) {
 			dmabuf_obj = container_of(pos,
@@ -98,6 +208,7 @@ static void dmabuf_gem_object_free(struct kref *kref)
 				intel_gvt_hypervisor_put_vfio_device(vgpu);
 				idr_remove(&vgpu->object_idr,
 					   dmabuf_obj->dmabuf_id);
+				debug_dmabuf_free(obj);
 				kfree(dmabuf_obj->info);
 				kfree(dmabuf_obj);
 				list_del(pos);
@@ -106,6 +217,7 @@ static void dmabuf_gem_object_free(struct kref *kref)
 		}
 	} else {
 		/* Free the orphan dmabuf_objs here */
+		debug_dmabuf_free(obj);
 		kfree(obj->info);
 		kfree(obj);
 	}
@@ -132,6 +244,7 @@ static void vgpu_gem_release(struct drm_i915_gem_object *gem_obj)
 	if (vgpu) {
 		mutex_lock(&vgpu->dmabuf_lock);
 		gem_obj->base.dma_buf = NULL;
+		debug_dmabuf_deactivate(obj);
 		dmabuf_obj_put(obj);
 		mutex_unlock(&vgpu->dmabuf_lock);
 	} else {
@@ -406,6 +519,7 @@ int intel_vgpu_query_plane(struct intel_vgpu *vgpu, void *args)
 	dmabuf_obj->dmabuf_id = ret;
 
 	dmabuf_obj->initref = true;
+	debug_dmabuf_init(dmabuf_obj);
 
 	kref_init(&dmabuf_obj->kref);
 
@@ -457,6 +571,8 @@ int intel_vgpu_get_dmabuf(struct intel_vgpu *vgpu, unsigned int dmabuf_id)
 		goto out;
 	}
 
+	debug_dmabuf_assert(dmabuf_obj);
+
 	obj = vgpu_create_gem(dev, dmabuf_obj->info);
 	if (obj == NULL) {
 		gvt_vgpu_err("create gvt gem obj failed:%d\n", vgpu->id);
@@ -488,6 +604,7 @@ int intel_vgpu_get_dmabuf(struct intel_vgpu *vgpu, unsigned int dmabuf_id)
 	if (dmabuf_obj->initref) {
 		dmabuf_obj->initref = false;
 		dmabuf_obj_put(dmabuf_obj);
+		debug_dmabuf_activate(dmabuf_obj);
 	}
 
 	mutex_unlock(&vgpu->dmabuf_lock);
@@ -524,6 +641,7 @@ void intel_vgpu_dmabuf_cleanup(struct intel_vgpu *vgpu)
 			dmabuf_obj->initref = false;
 			dmabuf_obj_put(dmabuf_obj);
 		}
+		debug_dmabuf_deactivate(dmabuf_obj);
 
 		idr_remove(&vgpu->object_idr, dmabuf_obj->dmabuf_id);
 
@@ -533,6 +651,8 @@ void intel_vgpu_dmabuf_cleanup(struct intel_vgpu *vgpu)
 		list_del(pos);
 		dmabuf_obj->vgpu = NULL;
 
+		debug_dmabuf_destroy(dmabuf_obj);
+
 	}
 	mutex_unlock(&vgpu->dmabuf_lock);
 }
-- 
2.7.4



More information about the intel-gvt-dev mailing list