Skip to contentSkip to conversation

drm/i915/gvt: Make use of idr_find and idr_for_each_entry in dmabuf

PATCH In review Cai Huoqing 3 participants 3 messages Mar 3, 2023 – Mar 9, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 drm/i915/gvt: Make use of idr_find and idr_for_each_entry in dmabuf

This patch uses the already existing IDR mechanism to simplify and improve the dmabuf code.

Using 'vgpu.object_idr' directly instead of 'dmabuf_obj_list_head' or 'dmabuf.list', because the dmabuf_obj can be found by 'idr_find' or 'idr_for_each_entry'.

---
v1->v2:
1.Use idr_find to get the target one and free it instead of free all dma objs. 2.Revert the original code 'ret' related
3.Add '&& !idr_is_empty()' like the original code '&& !list_empty()'

v1 link:

	https://lore.kernel.org/lkml/[email protected]/
 drivers/gpu/drm/i915/gvt/dmabuf.c | 58 +++++++------------------------
 drivers/gpu/drm/i915/gvt/dmabuf.h |  1 -
 drivers/gpu/drm/i915/gvt/gvt.h    |  1 -
 drivers/gpu/drm/i915/gvt/vgpu.c   |  1 -
 4 files changed, 12 insertions(+), 49 deletions(-)
drivers/gpu/drm/i915/gvt/dmabuf.c +12 -46
index 6834f9fe40cf..cf619b1ed3ad 100644
@@ -133,21 +133,15 @@ static void dmabuf_gem_object_free(struct kref *kref)
 	struct intel_vgpu_dmabuf_obj *obj =
 		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;
 
 	if (vgpu && test_bit(INTEL_VGPU_STATUS_ACTIVE, vgpu->status) &&
-	    !list_empty(&vgpu->dmabuf_obj_list_head)) {
-		list_for_each(pos, &vgpu->dmabuf_obj_list_head) {
-			dmabuf_obj = list_entry(pos, struct intel_vgpu_dmabuf_obj, list);
-			if (dmabuf_obj == obj) {
-				list_del(pos);
-				idr_remove(&vgpu->object_idr,
-					   dmabuf_obj->dmabuf_id);
-				kfree(dmabuf_obj->info);
-				kfree(dmabuf_obj);
-				break;
-			}
+	    !idr_is_empty(&vgpu->object_idr)) {
+		dmabuf_obj = idr_find(&vgpu->object_idr, obj->dmabuf_id);
+		if (dmabuf_obj) {
+			idr_remove(&vgpu->object_idr, obj->dmabuf_id);
+			kfree(dmabuf_obj->info);
+			kfree(dmabuf_obj);
 		}
 	} else {
 		/* Free the orphan dmabuf_objs here */
@@ -340,13 +334,12 @@ static struct intel_vgpu_dmabuf_obj *
 pick_dmabuf_by_info(struct intel_vgpu *vgpu,
 		    struct intel_vgpu_fb_info *latest_info)
 {
-	struct list_head *pos;
 	struct intel_vgpu_fb_info *fb_info;
 	struct intel_vgpu_dmabuf_obj *dmabuf_obj = NULL;
 	struct intel_vgpu_dmabuf_obj *ret = NULL;
+	int id;
 
-	list_for_each(pos, &vgpu->dmabuf_obj_list_head) {
-		dmabuf_obj = list_entry(pos, struct intel_vgpu_dmabuf_obj, list);
+	idr_for_each_entry(&vgpu->object_idr, dmabuf_obj, id) {
 		if (!dmabuf_obj->info)
 			continue;
 
@@ -366,24 +359,6 @@ pick_dmabuf_by_info(struct intel_vgpu *vgpu,
 	return ret;
 }
 
-static struct intel_vgpu_dmabuf_obj *
-pick_dmabuf_by_num(struct intel_vgpu *vgpu, u32 id)
-{
-	struct list_head *pos;
-	struct intel_vgpu_dmabuf_obj *dmabuf_obj = NULL;
-	struct intel_vgpu_dmabuf_obj *ret = NULL;
-
-	list_for_each(pos, &vgpu->dmabuf_obj_list_head) {
-		dmabuf_obj = list_entry(pos, struct intel_vgpu_dmabuf_obj, list);
-		if (dmabuf_obj->dmabuf_id == id) {
-			ret = dmabuf_obj;
-			break;
-		}
-	}
-
-	return ret;
-}
-
 static void update_fb_info(struct vfio_device_gfx_plane_info *gvt_dmabuf,
 		      struct intel_vgpu_fb_info *fb_info)
 {
@@ -477,11 +452,6 @@ int intel_vgpu_query_plane(struct intel_vgpu *vgpu, void *args)
 
 	update_fb_info(gfx_plane_info, &fb_info);
 
-	INIT_LIST_HEAD(&dmabuf_obj->list);
-	mutex_lock(&vgpu->dmabuf_lock);
-	list_add_tail(&dmabuf_obj->list, &vgpu->dmabuf_obj_list_head);
-	mutex_unlock(&vgpu->dmabuf_lock);
-
 	gvt_dbg_dpy("vgpu%d: %s new dmabuf_obj ref %d, id %d\n", vgpu->id,
 		    __func__, kref_read(&dmabuf_obj->kref), ret);
 
@@ -508,7 +478,7 @@ int intel_vgpu_get_dmabuf(struct intel_vgpu *vgpu, unsigned int dmabuf_id)
 
 	mutex_lock(&vgpu->dmabuf_lock);
 
-	dmabuf_obj = pick_dmabuf_by_num(vgpu, dmabuf_id);
+	dmabuf_obj = idr_find(&vgpu->object_idr, dmabuf_id);
 	if (dmabuf_obj == NULL) {
 		gvt_vgpu_err("invalid dmabuf id:%d\n", dmabuf_id);
 		ret = -EINVAL;
@@ -570,23 +540,19 @@ int intel_vgpu_get_dmabuf(struct intel_vgpu *vgpu, unsigned int dmabuf_id)
 
 void intel_vgpu_dmabuf_cleanup(struct intel_vgpu *vgpu)
 {
-	struct list_head *pos, *n;
 	struct intel_vgpu_dmabuf_obj *dmabuf_obj;
+	int id;
 
 	mutex_lock(&vgpu->dmabuf_lock);
-	list_for_each_safe(pos, n, &vgpu->dmabuf_obj_list_head) {
-		dmabuf_obj = list_entry(pos, struct intel_vgpu_dmabuf_obj, list);
+	idr_for_each_entry(&vgpu->object_idr, dmabuf_obj, id) {
 		dmabuf_obj->vgpu = NULL;
 
-		idr_remove(&vgpu->object_idr, dmabuf_obj->dmabuf_id);
-		list_del(pos);
-
+		idr_remove(&vgpu->object_idr, id);
 		/* dmabuf_obj might be freed in dmabuf_obj_put */
 		if (dmabuf_obj->initref) {
 			dmabuf_obj->initref = false;
 			dmabuf_obj_put(dmabuf_obj);
 		}
-
 	}
 	mutex_unlock(&vgpu->dmabuf_lock);
 }
drivers/gpu/drm/i915/gvt/dmabuf.h +0 -1
index 3dcdb6570eda..93c0e00bdab9 100644
@@ -57,7 +57,6 @@ struct intel_vgpu_dmabuf_obj {
 	__u32 dmabuf_id;
 	struct kref kref;
 	bool initref;
-	struct list_head list;
 };
 
 int intel_vgpu_query_plane(struct intel_vgpu *vgpu, void *args);
drivers/gpu/drm/i915/gvt/gvt.h +0 -1
index 2d65800d8e93..1100c789f207 100644
@@ -211,7 +211,6 @@ struct intel_vgpu {
 
 	struct dentry *debugfs;
 
-	struct list_head dmabuf_obj_list_head;
 	struct mutex dmabuf_lock;
 	struct idr object_idr;
 	struct intel_vgpu_vblank_timer vblank_timer;
drivers/gpu/drm/i915/gvt/vgpu.c +0 -1
index 08ad1bd651f1..0a511cfef067 100644
@@ -329,7 +329,6 @@ int intel_gvt_create_vgpu(struct intel_vgpu *vgpu,
 	vgpu->sched_ctl.weight = conf->weight;
 	mutex_init(&vgpu->vgpu_lock);
 	mutex_init(&vgpu->dmabuf_lock);
-	INIT_LIST_HEAD(&vgpu->dmabuf_obj_list_head);
 	INIT_RADIX_TREE(&vgpu->page_track_tree, GFP_KERNEL);
 	idr_init_base(&vgpu->object_idr, 1);
 	intel_vgpu_init_cfg_space(vgpu, 1);
Signature · 1 line
2.34.1
#1 lore raw

[Intel-gfx] ✗ Fi.CI.BAT: failure for drm/i915/gvt: Make use of idr_find and idr_for_each_entry in dmabuf (rev2)

== Series Details ==

== Series Details ==

Series: drm/i915/gvt: Make use of idr_find and idr_for_each_entry in dmabuf (rev2)
URL : https://patchwork.freedesktop.org/series/114717/
State : failure

== Summary ==

CI Bug Log - changes from CI_DRM_12818 -> Patchwork_114717v2
====================================================

Summary
-------

**FAILURE**

Serious unknown changes coming with Patchwork_114717v2 absolutely need to be verified manually.

If you think the reported changes have nothing to do with the changes introduced in Patchwork_114717v2, please notify your bug team to allow them to document this new failure mode, which will reduce false positives in CI.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_114717v2/index.html

Participating hosts (35 -> 33)
------------------------------

Missing (2): bat-atsm-1 fi-snb-2520m

Possible new issues
-------------------

Here are the unknown changes that may have been introduced in Patchwork_114717v2:

### IGT changes ###

#### Possible regressions ####

* igt@dmabuf@all-tests@dma_fence:
- bat-jsl-3: [PASS][1] -> [DMESG-FAIL][2]
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12818/bat-jsl-3/igt@dmabuf@all-tests@dma_fence.html
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_114717v2/bat-jsl-3/igt@dmabuf@all-tests@dma_fence.html

* igt@dmabuf@all-tests@sanitycheck:
- bat-jsl-3: [PASS][3] -> [ABORT][4]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12818/bat-jsl-3/igt@dmabuf@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_114717v2/bat-jsl-3/igt@dmabuf@[email protected]

Known issues
------------

Here are the changes found in Patchwork_114717v2 that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@i915_selftest@live@execlists:
- fi-bsw-nick: [PASS][5] -> [ABORT][6] ([i915#7911] / [i915#7913])
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12818/fi-bsw-nick/igt@i915_selftest@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_114717v2/fi-bsw-nick/igt@i915_selftest@[email protected]

* igt@i915_selftest@live@gt_heartbeat:
- fi-apl-guc: [PASS][7] -> [DMESG-FAIL][8] ([i915#5334])
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12818/fi-apl-guc/igt@i915_selftest@live@gt_heartbeat.html
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_114717v2/fi-apl-guc/igt@i915_selftest@live@gt_heartbeat.html

* igt@i915_selftest@live@migrate:
- bat-rplp-1: [PASS][9] -> [DMESG-FAIL][10] ([i915#7699])
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12818/bat-rplp-1/igt@i915_selftest@[email protected]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_114717v2/bat-rplp-1/igt@i915_selftest@[email protected]

* igt@i915_selftest@live@reset:
- bat-rpls-2: [PASS][11] -> [ABORT][12] ([i915#4983] / [i915#7913])
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12818/bat-rpls-2/igt@i915_selftest@[email protected]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_114717v2/bat-rpls-2/igt@i915_selftest@[email protected]
- bat-rpls-1: NOTRUN -> [ABORT][13] ([i915#4983])
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_114717v2/bat-rpls-1/igt@i915_selftest@[email protected]

#### Possible fixes ####

* igt@i915_selftest@live@requests:
- bat-rpls-1: [ABORT][14] ([i915#7694] / [i915#7911] / [i915#7982]) -> [PASS][15]
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12818/bat-rpls-1/igt@i915_selftest@[email protected]
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_114717v2/bat-rpls-1/igt@i915_selftest@[email protected]

[i915#4983]: https://gitlab.freedesktop.org/drm/intel/issues/4983
[i915#5334]: https://gitlab.freedesktop.org/drm/intel/issues/5334
[i915#7694]: https://gitlab.freedesktop.org/drm/intel/issues/7694
[i915#7699]: https://gitlab.freedesktop.org/drm/intel/issues/7699
[i915#7911]: https://gitlab.freedesktop.org/drm/intel/issues/7911
[i915#7913]: https://gitlab.freedesktop.org/drm/intel/issues/7913
[i915#7982]: https://gitlab.freedesktop.org/drm/intel/issues/7982

Build changes
-------------

* Linux: CI_DRM_12818 -> Patchwork_114717v2

CI-20190529: 20190529
CI_DRM_12818: fe02c0851ac36ad0d4e8c2a66a4dc2f45e49b91e @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_7181: f44a24fe9f1948a117daf3162db53df7820f9923 @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git
Patchwork_114717v2: fe02c0851ac36ad0d4e8c2a66a4dc2f45e49b91e @ git://anongit.freedesktop.org/gfx-ci/linux

### Linux commits

bc9f38d73850 drm/i915/gvt: Make use of idr_find and idr_for_each_entry in dmabuf

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_114717v2/index.html

Reviewed-by on v2 1/1
#2 lore raw
In reply to Cai Huoqing
Quoted 7 lines · Cai Huoqing

This patch uses the already existing IDR mechanism to simplify and improve the dmabuf code.

Using 'vgpu.object_idr' directly instead of 'dmabuf_obj_list_head' or 'dmabuf.list', because the dmabuf_obj can be found by 'idr_find' or 'idr_for_each_entry'.

Quoted 6 lines

---
v1->v2:
1.Use idr_find to get the target one and free it instead of free all dma objs. 2.Revert the original code 'ret' related
3.Add '&& !idr_is_empty()' like the original code '&& !list_empty()'

Looks good to me. I'll send it for some regression test before upstream.

Thanks!

Quoted 170 lines

v1 link:

	https://lore.kernel.org/lkml/[email protected]/
 drivers/gpu/drm/i915/gvt/dmabuf.c | 58 +++++++------------------------
 drivers/gpu/drm/i915/gvt/dmabuf.h |  1 -
 drivers/gpu/drm/i915/gvt/gvt.h    |  1 -
 drivers/gpu/drm/i915/gvt/vgpu.c   |  1 -
 4 files changed, 12 insertions(+), 49 deletions(-)
drivers/gpu/drm/i915/gvt/dmabuf.c +12 -46
index 6834f9fe40cf..cf619b1ed3ad 100644
@@ -133,21 +133,15 @@ static void dmabuf_gem_object_free(struct kref *kref)
 	struct intel_vgpu_dmabuf_obj *obj =
 		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;
 
 	if (vgpu && test_bit(INTEL_VGPU_STATUS_ACTIVE, vgpu->status) &&
-	    !list_empty(&vgpu->dmabuf_obj_list_head)) {
-		list_for_each(pos, &vgpu->dmabuf_obj_list_head) {
-			dmabuf_obj = list_entry(pos, struct intel_vgpu_dmabuf_obj, list);
-			if (dmabuf_obj == obj) {
-				list_del(pos);
-				idr_remove(&vgpu->object_idr,
-					   dmabuf_obj->dmabuf_id);
-				kfree(dmabuf_obj->info);
-				kfree(dmabuf_obj);
-				break;
-			}
+	    !idr_is_empty(&vgpu->object_idr)) {
+		dmabuf_obj = idr_find(&vgpu->object_idr, obj->dmabuf_id);
+		if (dmabuf_obj) {
+			idr_remove(&vgpu->object_idr, obj->dmabuf_id);
+			kfree(dmabuf_obj->info);
+			kfree(dmabuf_obj);
 		}
 	} else {
 		/* Free the orphan dmabuf_objs here */
@@ -340,13 +334,12 @@ static struct intel_vgpu_dmabuf_obj *
 pick_dmabuf_by_info(struct intel_vgpu *vgpu,
 		    struct intel_vgpu_fb_info *latest_info)
 {
-	struct list_head *pos;
 	struct intel_vgpu_fb_info *fb_info;
 	struct intel_vgpu_dmabuf_obj *dmabuf_obj = NULL;
 	struct intel_vgpu_dmabuf_obj *ret = NULL;
+	int id;
 
-	list_for_each(pos, &vgpu->dmabuf_obj_list_head) {
-		dmabuf_obj = list_entry(pos, struct intel_vgpu_dmabuf_obj, list);
+	idr_for_each_entry(&vgpu->object_idr, dmabuf_obj, id) {
 		if (!dmabuf_obj->info)
 			continue;
 
@@ -366,24 +359,6 @@ pick_dmabuf_by_info(struct intel_vgpu *vgpu,
 	return ret;
 }
 
-static struct intel_vgpu_dmabuf_obj *
-pick_dmabuf_by_num(struct intel_vgpu *vgpu, u32 id)
-{
-	struct list_head *pos;
-	struct intel_vgpu_dmabuf_obj *dmabuf_obj = NULL;
-	struct intel_vgpu_dmabuf_obj *ret = NULL;
-
-	list_for_each(pos, &vgpu->dmabuf_obj_list_head) {
-		dmabuf_obj = list_entry(pos, struct intel_vgpu_dmabuf_obj, list);
-		if (dmabuf_obj->dmabuf_id == id) {
-			ret = dmabuf_obj;
-			break;
-		}
-	}
-
-	return ret;
-}
-
 static void update_fb_info(struct vfio_device_gfx_plane_info *gvt_dmabuf,
 		      struct intel_vgpu_fb_info *fb_info)
 {
@@ -477,11 +452,6 @@ int intel_vgpu_query_plane(struct intel_vgpu *vgpu, void *args)
 
 	update_fb_info(gfx_plane_info, &fb_info);
 
-	INIT_LIST_HEAD(&dmabuf_obj->list);
-	mutex_lock(&vgpu->dmabuf_lock);
-	list_add_tail(&dmabuf_obj->list, &vgpu->dmabuf_obj_list_head);
-	mutex_unlock(&vgpu->dmabuf_lock);
-
 	gvt_dbg_dpy("vgpu%d: %s new dmabuf_obj ref %d, id %d\n", vgpu->id,
 		    __func__, kref_read(&dmabuf_obj->kref), ret);
 
@@ -508,7 +478,7 @@ int intel_vgpu_get_dmabuf(struct intel_vgpu *vgpu, unsigned int dmabuf_id)
 
 	mutex_lock(&vgpu->dmabuf_lock);
 
-	dmabuf_obj = pick_dmabuf_by_num(vgpu, dmabuf_id);
+	dmabuf_obj = idr_find(&vgpu->object_idr, dmabuf_id);
 	if (dmabuf_obj == NULL) {
 		gvt_vgpu_err("invalid dmabuf id:%d\n", dmabuf_id);
 		ret = -EINVAL;
@@ -570,23 +540,19 @@ int intel_vgpu_get_dmabuf(struct intel_vgpu *vgpu, unsigned int dmabuf_id)
 
 void intel_vgpu_dmabuf_cleanup(struct intel_vgpu *vgpu)
 {
-	struct list_head *pos, *n;
 	struct intel_vgpu_dmabuf_obj *dmabuf_obj;
+	int id;
 
 	mutex_lock(&vgpu->dmabuf_lock);
-	list_for_each_safe(pos, n, &vgpu->dmabuf_obj_list_head) {
-		dmabuf_obj = list_entry(pos, struct intel_vgpu_dmabuf_obj, list);
+	idr_for_each_entry(&vgpu->object_idr, dmabuf_obj, id) {
 		dmabuf_obj->vgpu = NULL;
 
-		idr_remove(&vgpu->object_idr, dmabuf_obj->dmabuf_id);
-		list_del(pos);
-
+		idr_remove(&vgpu->object_idr, id);
 		/* dmabuf_obj might be freed in dmabuf_obj_put */
 		if (dmabuf_obj->initref) {
 			dmabuf_obj->initref = false;
 			dmabuf_obj_put(dmabuf_obj);
 		}
-
 	}
 	mutex_unlock(&vgpu->dmabuf_lock);
 }
drivers/gpu/drm/i915/gvt/dmabuf.h +0 -1
index 3dcdb6570eda..93c0e00bdab9 100644
@@ -57,7 +57,6 @@ struct intel_vgpu_dmabuf_obj {
 	__u32 dmabuf_id;
 	struct kref kref;
 	bool initref;
-	struct list_head list;
 };
 
 int intel_vgpu_query_plane(struct intel_vgpu *vgpu, void *args);
drivers/gpu/drm/i915/gvt/gvt.h +0 -1
index 2d65800d8e93..1100c789f207 100644
@@ -211,7 +211,6 @@ struct intel_vgpu {
 
 	struct dentry *debugfs;
 
-	struct list_head dmabuf_obj_list_head;
 	struct mutex dmabuf_lock;
 	struct idr object_idr;
 	struct intel_vgpu_vblank_timer vblank_timer;
drivers/gpu/drm/i915/gvt/vgpu.c +0 -1
index 08ad1bd651f1..0a511cfef067 100644
@@ -329,7 +329,6 @@ int intel_gvt_create_vgpu(struct intel_vgpu *vgpu,
 	vgpu->sched_ctl.weight = conf->weight;
 	mutex_init(&vgpu->vgpu_lock);
 	mutex_init(&vgpu->dmabuf_lock);
-	INIT_LIST_HEAD(&vgpu->dmabuf_obj_list_head);
 	INIT_RADIX_TREE(&vgpu->page_track_tree, GFP_KERNEL);
 	idr_init_base(&vgpu->object_idr, 1);
 	intel_vgpu_init_cfg_space(vgpu, 1);
Signature · 1 line
2.34.1