All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/15] drm: Do not use import_attach in drivers
@ 2025-03-17 13:06 Thomas Zimmermann
  2025-03-17 13:06 ` [PATCH 01/15] drm/armada: Test for imported buffers with drm_gem_is_imported() Thomas Zimmermann
                   ` (15 more replies)
  0 siblings, 16 replies; 27+ messages in thread
From: Thomas Zimmermann @ 2025-03-17 13:06 UTC (permalink / raw)
  To: airlied, simona, maarten.lankhorst, mripard; +Cc: dri-devel, Thomas Zimmermann

Avoid struct drm_gem_object.import_attach in many DRM drivers that
use it to get the object's dma-buf or test for an imported buffer.

The helper drm_gem_is_imported() tests if a GEM object's buffer
has been imported into the driver. The corresponding dma-buf is
referenced by the object itself. Both cases avoid import_attach.

The import_attach field in struct drm_gem_object is an artifact of
the import process, but should not be used otherwise. This series
fixes most of the drivers in the DRM misc tree. Other DRM drivers
can be converted when drm_gem_is_imported() becomes available in
their tree.

Thomas Zimmermann (15):
  drm/armada: Test for imported buffers with drm_gem_is_imported()
  drm/etnaviv: Test for imported buffers with drm_gem_is_imported()
  drm/etnaviv: Use dma_buf from GEM object instance
  drm/exynos: Test for imported buffers with drm_gem_is_imported()
  drm/gud: Test for imported buffers with drm_gem_is_imported()
  drm/msm: Test for imported buffers with drm_gem_is_imported()
  drm/omapdrm: Test for imported buffers with drm_gem_is_imported()
  drm/panfrost: Test for imported buffers with drm_gem_is_imported()
  drm/panthor: Test for imported buffers with drm_gem_is_imported()
  drm/rockchip: Test for imported buffers with drm_gem_is_imported()
  drm/vc4: Test for imported buffers with drm_gem_is_imported()
  drm/virtio: Test for imported buffers with drm_gem_is_imported()
  drm/vmwgfx: Test for imported buffers with drm_gem_is_imported()
  drm/vmwgfx: Use dma_buf from GEM object instance
  drm/xen: Test for imported buffers with drm_gem_is_imported()

 drivers/gpu/drm/armada/armada_fb.c          |  2 +-
 drivers/gpu/drm/armada/armada_gem.c         |  2 +-
 drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c |  8 ++++----
 drivers/gpu/drm/exynos/exynos_drm_gem.c     |  4 ++--
 drivers/gpu/drm/gud/gud_pipe.c              |  2 +-
 drivers/gpu/drm/msm/msm_drv.c               |  2 +-
 drivers/gpu/drm/msm/msm_gem.c               |  4 ++--
 drivers/gpu/drm/msm/msm_gem.h               |  2 +-
 drivers/gpu/drm/msm/msm_gem_prime.c         |  4 ++--
 drivers/gpu/drm/omapdrm/omap_gem.c          |  2 +-
 drivers/gpu/drm/panfrost/panfrost_gem.c     |  2 +-
 drivers/gpu/drm/panthor/panthor_gem.c       |  2 +-
 drivers/gpu/drm/panthor/panthor_mmu.c       | 10 +++++-----
 drivers/gpu/drm/rockchip/rockchip_drm_gem.c |  2 +-
 drivers/gpu/drm/vc4/vc4_bo.c                |  2 +-
 drivers/gpu/drm/vc4/vc4_gem.c               |  2 +-
 drivers/gpu/drm/virtio/virtgpu_plane.c      |  8 ++++----
 drivers/gpu/drm/vmwgfx/vmwgfx_blit.c        |  4 ++--
 drivers/gpu/drm/vmwgfx/vmwgfx_gem.c         | 12 ++++++------
 drivers/gpu/drm/xen/xen_drm_front_gem.c     |  2 +-
 20 files changed, 39 insertions(+), 39 deletions(-)

-- 
2.48.1


^ permalink raw reply	[flat|nested] 27+ messages in thread

* [PATCH 01/15] drm/armada: Test for imported buffers with drm_gem_is_imported()
  2025-03-17 13:06 [PATCH 00/15] drm: Do not use import_attach in drivers Thomas Zimmermann
@ 2025-03-17 13:06 ` Thomas Zimmermann
  2025-03-17 13:06 ` [PATCH 02/15] drm/etnaviv: " Thomas Zimmermann
                   ` (14 subsequent siblings)
  15 siblings, 0 replies; 27+ messages in thread
From: Thomas Zimmermann @ 2025-03-17 13:06 UTC (permalink / raw)
  To: airlied, simona, maarten.lankhorst, mripard
  Cc: dri-devel, Thomas Zimmermann, Russell King

Instead of testing import_attach for imported GEM buffers, invoke
drm_gem_is_imported() to do the test. The helper tests the dma_buf
itself while import_attach is just an artifact of the import. Prepares
to make import_attach optional.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Russell King <linux@armlinux.org.uk>
---
 drivers/gpu/drm/armada/armada_fb.c  | 2 +-
 drivers/gpu/drm/armada/armada_gem.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/armada/armada_fb.c b/drivers/gpu/drm/armada/armada_fb.c
index cf2e88218dc0..67af4bd8797f 100644
--- a/drivers/gpu/drm/armada/armada_fb.c
+++ b/drivers/gpu/drm/armada/armada_fb.c
@@ -110,7 +110,7 @@ struct drm_framebuffer *armada_fb_create(struct drm_device *dev,
 		goto err;
 	}
 
-	if (obj->obj.import_attach && !obj->sgt) {
+	if (drm_gem_is_imported(&obj->obj) && !obj->sgt) {
 		ret = armada_gem_map_import(obj);
 		if (ret)
 			goto err_unref;
diff --git a/drivers/gpu/drm/armada/armada_gem.c b/drivers/gpu/drm/armada/armada_gem.c
index 1a1680d71486..bd4209b6a893 100644
--- a/drivers/gpu/drm/armada/armada_gem.c
+++ b/drivers/gpu/drm/armada/armada_gem.c
@@ -63,7 +63,7 @@ void armada_gem_free_object(struct drm_gem_object *obj)
 			iounmap(dobj->addr);
 	}
 
-	if (dobj->obj.import_attach) {
+	if (drm_gem_is_imported(&dobj->obj)) {
 		/* We only ever display imported data */
 		if (dobj->sgt)
 			dma_buf_unmap_attachment_unlocked(dobj->obj.import_attach,
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 02/15] drm/etnaviv: Test for imported buffers with drm_gem_is_imported()
  2025-03-17 13:06 [PATCH 00/15] drm: Do not use import_attach in drivers Thomas Zimmermann
  2025-03-17 13:06 ` [PATCH 01/15] drm/armada: Test for imported buffers with drm_gem_is_imported() Thomas Zimmermann
@ 2025-03-17 13:06 ` Thomas Zimmermann
  2025-03-17 13:06 ` [PATCH 03/15] drm/etnaviv: Use dma_buf from GEM object instance Thomas Zimmermann
                   ` (13 subsequent siblings)
  15 siblings, 0 replies; 27+ messages in thread
From: Thomas Zimmermann @ 2025-03-17 13:06 UTC (permalink / raw)
  To: airlied, simona, maarten.lankhorst, mripard
  Cc: dri-devel, Thomas Zimmermann, Lucas Stach, Russell King,
	Christian Gmeiner, etnaviv

Instead of testing import_attach for imported GEM buffers, invoke
drm_gem_is_imported() to do the test. The helper tests the dma_buf
itself while import_attach is just an artifact of the import. Prepares
to make import_attach optional.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Lucas Stach <l.stach@pengutronix.de>
Cc: Russell King <linux+etnaviv@armlinux.org.uk>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: etnaviv@lists.freedesktop.org
---
 drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c b/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c
index 42e57d142554..40a50c60dfff 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c
@@ -39,7 +39,7 @@ int etnaviv_gem_prime_vmap(struct drm_gem_object *obj, struct iosys_map *map)
 
 int etnaviv_gem_prime_pin(struct drm_gem_object *obj)
 {
-	if (!obj->import_attach) {
+	if (!drm_gem_is_imported(obj)) {
 		struct etnaviv_gem_object *etnaviv_obj = to_etnaviv_bo(obj);
 
 		mutex_lock(&etnaviv_obj->lock);
@@ -51,7 +51,7 @@ int etnaviv_gem_prime_pin(struct drm_gem_object *obj)
 
 void etnaviv_gem_prime_unpin(struct drm_gem_object *obj)
 {
-	if (!obj->import_attach) {
+	if (!drm_gem_is_imported(obj)) {
 		struct etnaviv_gem_object *etnaviv_obj = to_etnaviv_bo(obj);
 
 		mutex_lock(&etnaviv_obj->lock);
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 03/15] drm/etnaviv: Use dma_buf from GEM object instance
  2025-03-17 13:06 [PATCH 00/15] drm: Do not use import_attach in drivers Thomas Zimmermann
  2025-03-17 13:06 ` [PATCH 01/15] drm/armada: Test for imported buffers with drm_gem_is_imported() Thomas Zimmermann
  2025-03-17 13:06 ` [PATCH 02/15] drm/etnaviv: " Thomas Zimmermann
@ 2025-03-17 13:06 ` Thomas Zimmermann
  2025-03-17 14:54   ` Lucas Stach
  2025-03-17 13:06 ` [PATCH 04/15] drm/exynos: Test for imported buffers with drm_gem_is_imported() Thomas Zimmermann
                   ` (12 subsequent siblings)
  15 siblings, 1 reply; 27+ messages in thread
From: Thomas Zimmermann @ 2025-03-17 13:06 UTC (permalink / raw)
  To: airlied, simona, maarten.lankhorst, mripard
  Cc: dri-devel, Thomas Zimmermann, Lucas Stach, Russell King,
	Christian Gmeiner, etnaviv

Avoid dereferencing struct drm_gem_object.import_attach for the
imported dma-buf. The dma_buf field in the GEM object instance refers
to the same buffer. Prepares to make import_attach optional.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Lucas Stach <l.stach@pengutronix.de>
Cc: Russell King <linux+etnaviv@armlinux.org.uk>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: etnaviv@lists.freedesktop.org
---
 drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c b/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c
index 40a50c60dfff..917ad527c961 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c
@@ -65,7 +65,7 @@ static void etnaviv_gem_prime_release(struct etnaviv_gem_object *etnaviv_obj)
 	struct iosys_map map = IOSYS_MAP_INIT_VADDR(etnaviv_obj->vaddr);
 
 	if (etnaviv_obj->vaddr)
-		dma_buf_vunmap_unlocked(etnaviv_obj->base.import_attach->dmabuf, &map);
+		dma_buf_vunmap_unlocked(etnaviv_obj->base.dma_buf, &map);
 
 	/* Don't drop the pages for imported dmabuf, as they are not
 	 * ours, just free the array we allocated:
@@ -82,7 +82,7 @@ static void *etnaviv_gem_prime_vmap_impl(struct etnaviv_gem_object *etnaviv_obj)
 
 	lockdep_assert_held(&etnaviv_obj->lock);
 
-	ret = dma_buf_vmap(etnaviv_obj->base.import_attach->dmabuf, &map);
+	ret = dma_buf_vmap(etnaviv_obj->base.dma_buf, &map);
 	if (ret)
 		return NULL;
 	return map.vaddr;
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 04/15] drm/exynos: Test for imported buffers with drm_gem_is_imported()
  2025-03-17 13:06 [PATCH 00/15] drm: Do not use import_attach in drivers Thomas Zimmermann
                   ` (2 preceding siblings ...)
  2025-03-17 13:06 ` [PATCH 03/15] drm/etnaviv: Use dma_buf from GEM object instance Thomas Zimmermann
@ 2025-03-17 13:06 ` Thomas Zimmermann
  2025-03-17 13:06 ` [PATCH 05/15] drm/gud: " Thomas Zimmermann
                   ` (11 subsequent siblings)
  15 siblings, 0 replies; 27+ messages in thread
From: Thomas Zimmermann @ 2025-03-17 13:06 UTC (permalink / raw)
  To: airlied, simona, maarten.lankhorst, mripard
  Cc: dri-devel, Thomas Zimmermann, Inki Dae, Seung-Woo Kim,
	Kyungmin Park

Instead of testing import_attach for imported GEM buffers, invoke
drm_gem_is_imported() to do the test. The helper tests the dma_buf
itself while import_attach is just an artifact of the import. Prepares
to make import_attach optional.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Inki Dae <inki.dae@samsung.com>
Cc: Seung-Woo Kim <sw0312.kim@samsung.com>
Cc: Kyungmin Park <kyungmin.park@samsung.com>
---
 drivers/gpu/drm/exynos/exynos_drm_gem.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/exynos/exynos_drm_gem.c b/drivers/gpu/drm/exynos/exynos_drm_gem.c
index 4787fee4696f..c549ba5cda5e 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_gem.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_gem.c
@@ -121,7 +121,7 @@ void exynos_drm_gem_destroy(struct exynos_drm_gem *exynos_gem)
 	 * the region will be released by exporter
 	 * once dmabuf's refcount becomes 0.
 	 */
-	if (obj->import_attach)
+	if (drm_gem_is_imported(obj))
 		drm_prime_gem_destroy(obj, exynos_gem->sgt);
 	else
 		exynos_drm_free_buf(exynos_gem);
@@ -365,7 +365,7 @@ static int exynos_drm_gem_mmap(struct drm_gem_object *obj, struct vm_area_struct
 	struct exynos_drm_gem *exynos_gem = to_exynos_gem(obj);
 	int ret;
 
-	if (obj->import_attach)
+	if (drm_gem_is_imported(obj))
 		return dma_buf_mmap(obj->dma_buf, vma, 0);
 
 	vm_flags_set(vma, VM_IO | VM_DONTEXPAND | VM_DONTDUMP);
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 05/15] drm/gud: Test for imported buffers with drm_gem_is_imported()
  2025-03-17 13:06 [PATCH 00/15] drm: Do not use import_attach in drivers Thomas Zimmermann
                   ` (3 preceding siblings ...)
  2025-03-17 13:06 ` [PATCH 04/15] drm/exynos: Test for imported buffers with drm_gem_is_imported() Thomas Zimmermann
@ 2025-03-17 13:06 ` Thomas Zimmermann
  2025-03-17 13:06 ` [PATCH 06/15] drm/msm: " Thomas Zimmermann
                   ` (10 subsequent siblings)
  15 siblings, 0 replies; 27+ messages in thread
From: Thomas Zimmermann @ 2025-03-17 13:06 UTC (permalink / raw)
  To: airlied, simona, maarten.lankhorst, mripard; +Cc: dri-devel, Thomas Zimmermann

Instead of testing import_attach for imported GEM buffers, invoke
drm_gem_is_imported() to do the test. The helper tests the dma_buf
itself while import_attach is just an artifact of the import. Prepares
to make import_attach optional.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/gpu/drm/gud/gud_pipe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/gud/gud_pipe.c b/drivers/gpu/drm/gud/gud_pipe.c
index e163649816d5..99b34158afb3 100644
--- a/drivers/gpu/drm/gud/gud_pipe.c
+++ b/drivers/gpu/drm/gud/gud_pipe.c
@@ -443,7 +443,7 @@ static void gud_fb_handle_damage(struct gud_device *gdrm, struct drm_framebuffer
 	}
 
 	/* Imported buffers are assumed to be WriteCombined with uncached reads */
-	gud_flush_damage(gdrm, fb, src, !fb->obj[0]->import_attach, damage);
+	gud_flush_damage(gdrm, fb, src, !drm_gem_is_imported(fb->obj[0]), damage);
 }
 
 int gud_pipe_check(struct drm_simple_display_pipe *pipe,
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 06/15] drm/msm: Test for imported buffers with drm_gem_is_imported()
  2025-03-17 13:06 [PATCH 00/15] drm: Do not use import_attach in drivers Thomas Zimmermann
                   ` (4 preceding siblings ...)
  2025-03-17 13:06 ` [PATCH 05/15] drm/gud: " Thomas Zimmermann
@ 2025-03-17 13:06 ` Thomas Zimmermann
  2025-03-17 14:10   ` Dmitry Baryshkov
  2025-03-17 13:06 ` [PATCH 07/15] drm/omapdrm: " Thomas Zimmermann
                   ` (9 subsequent siblings)
  15 siblings, 1 reply; 27+ messages in thread
From: Thomas Zimmermann @ 2025-03-17 13:06 UTC (permalink / raw)
  To: airlied, simona, maarten.lankhorst, mripard
  Cc: dri-devel, Thomas Zimmermann, Rob Clark, Abhinav Kumar,
	Dmitry Baryshkov, Sean Paul, Marijn Suijten, linux-arm-msm,
	freedreno

Instead of testing import_attach for imported GEM buffers, invoke
drm_gem_is_imported() to do the test. The helper tests the dma_buf
itself while import_attach is just an artifact of the import. Prepares
to make import_attach optional.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Rob Clark <robdclark@gmail.com>
Cc: Abhinav Kumar <quic_abhinavk@quicinc.com>
Cc: Dmitry Baryshkov <lumag@kernel.org>
Cc: Sean Paul <sean@poorly.run>
Cc: Marijn Suijten <marijn.suijten@somainline.org>
Cc: linux-arm-msm@vger.kernel.org
Cc: freedreno@lists.freedesktop.org
---
 drivers/gpu/drm/msm/msm_drv.c       | 2 +-
 drivers/gpu/drm/msm/msm_gem.c       | 4 ++--
 drivers/gpu/drm/msm/msm_gem.h       | 2 +-
 drivers/gpu/drm/msm/msm_gem_prime.c | 4 ++--
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c
index c3588dc9e537..f316e6776f67 100644
--- a/drivers/gpu/drm/msm/msm_drv.c
+++ b/drivers/gpu/drm/msm/msm_drv.c
@@ -671,7 +671,7 @@ static int msm_ioctl_gem_info(struct drm_device *dev, void *data,
 		ret = msm_ioctl_gem_info_set_iova(dev, file, obj, args->value);
 		break;
 	case MSM_INFO_GET_FLAGS:
-		if (obj->import_attach) {
+		if (drm_gem_is_imported(obj)) {
 			ret = -EINVAL;
 			break;
 		}
diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c
index ebc9ba66efb8..2995e80fec3b 100644
--- a/drivers/gpu/drm/msm/msm_gem.c
+++ b/drivers/gpu/drm/msm/msm_gem.c
@@ -735,7 +735,7 @@ static void *get_vaddr(struct drm_gem_object *obj, unsigned madv)
 
 	msm_gem_assert_locked(obj);
 
-	if (obj->import_attach)
+	if (drm_gem_is_imported(obj))
 		return ERR_PTR(-ENODEV);
 
 	pages = msm_gem_get_pages_locked(obj, madv);
@@ -1074,7 +1074,7 @@ static void msm_gem_free_object(struct drm_gem_object *obj)
 
 	put_iova_spaces(obj, true);
 
-	if (obj->import_attach) {
+	if (drm_gem_is_imported(obj)) {
 		GEM_WARN_ON(msm_obj->vaddr);
 
 		/* Don't drop the pages for imported dmabuf, as they are not
diff --git a/drivers/gpu/drm/msm/msm_gem.h b/drivers/gpu/drm/msm/msm_gem.h
index 85f0257e83da..ba5c4ff76292 100644
--- a/drivers/gpu/drm/msm/msm_gem.h
+++ b/drivers/gpu/drm/msm/msm_gem.h
@@ -224,7 +224,7 @@ msm_gem_assert_locked(struct drm_gem_object *obj)
 /* imported/exported objects are not purgeable: */
 static inline bool is_unpurgeable(struct msm_gem_object *msm_obj)
 {
-	return msm_obj->base.import_attach || msm_obj->pin_count;
+	return drm_gem_is_imported(&msm_obj->base) || msm_obj->pin_count;
 }
 
 static inline bool is_purgeable(struct msm_gem_object *msm_obj)
diff --git a/drivers/gpu/drm/msm/msm_gem_prime.c b/drivers/gpu/drm/msm/msm_gem_prime.c
index ee267490c935..2e37913d5a6a 100644
--- a/drivers/gpu/drm/msm/msm_gem_prime.c
+++ b/drivers/gpu/drm/msm/msm_gem_prime.c
@@ -50,7 +50,7 @@ int msm_gem_prime_pin(struct drm_gem_object *obj)
 	struct page **pages;
 	int ret = 0;
 
-	if (obj->import_attach)
+	if (drm_gem_is_imported(obj))
 		return 0;
 
 	pages = msm_gem_pin_pages_locked(obj);
@@ -62,7 +62,7 @@ int msm_gem_prime_pin(struct drm_gem_object *obj)
 
 void msm_gem_prime_unpin(struct drm_gem_object *obj)
 {
-	if (obj->import_attach)
+	if (drm_gem_is_imported(obj))
 		return;
 
 	msm_gem_unpin_pages_locked(obj);
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 07/15] drm/omapdrm: Test for imported buffers with drm_gem_is_imported()
  2025-03-17 13:06 [PATCH 00/15] drm: Do not use import_attach in drivers Thomas Zimmermann
                   ` (5 preceding siblings ...)
  2025-03-17 13:06 ` [PATCH 06/15] drm/msm: " Thomas Zimmermann
@ 2025-03-17 13:06 ` Thomas Zimmermann
  2025-03-17 13:06 ` [PATCH 08/15] drm/panfrost: " Thomas Zimmermann
                   ` (8 subsequent siblings)
  15 siblings, 0 replies; 27+ messages in thread
From: Thomas Zimmermann @ 2025-03-17 13:06 UTC (permalink / raw)
  To: airlied, simona, maarten.lankhorst, mripard
  Cc: dri-devel, Thomas Zimmermann, Tomi Valkeinen

Instead of testing import_attach for imported GEM buffers, invoke
drm_gem_is_imported() to do the test. The helper tests the dma_buf
itself while import_attach is just an artifact of the import. Prepares
to make import_attach optional.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
 drivers/gpu/drm/omapdrm/omap_gem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/omapdrm/omap_gem.c b/drivers/gpu/drm/omapdrm/omap_gem.c
index b9c67e4ca360..d50bc91437fa 100644
--- a/drivers/gpu/drm/omapdrm/omap_gem.c
+++ b/drivers/gpu/drm/omapdrm/omap_gem.c
@@ -1222,7 +1222,7 @@ static void omap_gem_free_object(struct drm_gem_object *obj)
 			    omap_obj->dma_addr);
 	} else if (omap_obj->vaddr) {
 		vunmap(omap_obj->vaddr);
-	} else if (obj->import_attach) {
+	} else if (drm_gem_is_imported(obj)) {
 		drm_prime_gem_destroy(obj, omap_obj->sgt);
 	}
 
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 08/15] drm/panfrost: Test for imported buffers with drm_gem_is_imported()
  2025-03-17 13:06 [PATCH 00/15] drm: Do not use import_attach in drivers Thomas Zimmermann
                   ` (6 preceding siblings ...)
  2025-03-17 13:06 ` [PATCH 07/15] drm/omapdrm: " Thomas Zimmermann
@ 2025-03-17 13:06 ` Thomas Zimmermann
  2025-03-31  9:02   ` Steven Price
  2025-03-17 13:06 ` [PATCH 09/15] drm/panthor: " Thomas Zimmermann
                   ` (7 subsequent siblings)
  15 siblings, 1 reply; 27+ messages in thread
From: Thomas Zimmermann @ 2025-03-17 13:06 UTC (permalink / raw)
  To: airlied, simona, maarten.lankhorst, mripard
  Cc: dri-devel, Thomas Zimmermann, Boris Brezillon, Rob Herring,
	Steven Price

Instead of testing import_attach for imported GEM buffers, invoke
drm_gem_is_imported() to do the test. The helper tests the dma_buf
itself while import_attach is just an artifact of the import. Prepares
to make import_attach optional.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Boris Brezillon <boris.brezillon@collabora.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Steven Price <steven.price@arm.com>
---
 drivers/gpu/drm/panfrost/panfrost_gem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.c b/drivers/gpu/drm/panfrost/panfrost_gem.c
index 8e0ff3efede7..963f04ba2de6 100644
--- a/drivers/gpu/drm/panfrost/panfrost_gem.c
+++ b/drivers/gpu/drm/panfrost/panfrost_gem.c
@@ -200,7 +200,7 @@ static enum drm_gem_object_status panfrost_gem_status(struct drm_gem_object *obj
 	struct panfrost_gem_object *bo = to_panfrost_bo(obj);
 	enum drm_gem_object_status res = 0;
 
-	if (bo->base.base.import_attach || bo->base.pages)
+	if (drm_gem_is_imported(&bo->base.base) || bo->base.pages)
 		res |= DRM_GEM_OBJECT_RESIDENT;
 
 	if (bo->base.madv == PANFROST_MADV_DONTNEED)
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 09/15] drm/panthor: Test for imported buffers with drm_gem_is_imported()
  2025-03-17 13:06 [PATCH 00/15] drm: Do not use import_attach in drivers Thomas Zimmermann
                   ` (7 preceding siblings ...)
  2025-03-17 13:06 ` [PATCH 08/15] drm/panfrost: " Thomas Zimmermann
@ 2025-03-17 13:06 ` Thomas Zimmermann
  2025-03-17 13:59   ` Liviu Dudau
                     ` (2 more replies)
  2025-03-17 13:06 ` [PATCH 10/15] drm/rockchip: " Thomas Zimmermann
                   ` (6 subsequent siblings)
  15 siblings, 3 replies; 27+ messages in thread
From: Thomas Zimmermann @ 2025-03-17 13:06 UTC (permalink / raw)
  To: airlied, simona, maarten.lankhorst, mripard
  Cc: dri-devel, Thomas Zimmermann, Boris Brezillon, Steven Price,
	Liviu Dudau

Instead of testing import_attach for imported GEM buffers, invoke
drm_gem_is_imported() to do the test. The helper tests the dma_buf
itself while import_attach is just an artifact of the import. Prepares
to make import_attach optional.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Boris Brezillon <boris.brezillon@collabora.com>
Cc: Steven Price <steven.price@arm.com>
Cc: Liviu Dudau <liviu.dudau@arm.com>
---
 drivers/gpu/drm/panthor/panthor_gem.c |  2 +-
 drivers/gpu/drm/panthor/panthor_mmu.c | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/panthor/panthor_gem.c
index 8244a4e6c2a2..fd014ccc3bfc 100644
--- a/drivers/gpu/drm/panthor/panthor_gem.c
+++ b/drivers/gpu/drm/panthor/panthor_gem.c
@@ -155,7 +155,7 @@ static enum drm_gem_object_status panthor_gem_status(struct drm_gem_object *obj)
 	struct panthor_gem_object *bo = to_panthor_bo(obj);
 	enum drm_gem_object_status res = 0;
 
-	if (bo->base.base.import_attach || bo->base.pages)
+	if (drm_gem_is_imported(&bo->base.base) || bo->base.pages)
 		res |= DRM_GEM_OBJECT_RESIDENT;
 
 	return res;
diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
index 12a02e28f50f..3e123159ac10 100644
--- a/drivers/gpu/drm/panthor/panthor_mmu.c
+++ b/drivers/gpu/drm/panthor/panthor_mmu.c
@@ -1103,7 +1103,7 @@ static void panthor_vm_bo_put(struct drm_gpuvm_bo *vm_bo)
 	/* If the vm_bo object was destroyed, release the pin reference that
 	 * was hold by this object.
 	 */
-	if (unpin && !bo->base.base.import_attach)
+	if (unpin && !drm_gem_is_imported(&bo->base.base))
 		drm_gem_shmem_unpin(&bo->base);
 
 	drm_gpuvm_put(vm);
@@ -1234,7 +1234,7 @@ static int panthor_vm_prepare_map_op_ctx(struct panthor_vm_op_ctx *op_ctx,
 	if (ret)
 		goto err_cleanup;
 
-	if (!bo->base.base.import_attach) {
+	if (!drm_gem_is_imported(&bo->base.base)) {
 		/* Pre-reserve the BO pages, so the map operation doesn't have to
 		 * allocate.
 		 */
@@ -1245,7 +1245,7 @@ static int panthor_vm_prepare_map_op_ctx(struct panthor_vm_op_ctx *op_ctx,
 
 	sgt = drm_gem_shmem_get_pages_sgt(&bo->base);
 	if (IS_ERR(sgt)) {
-		if (!bo->base.base.import_attach)
+		if (!drm_gem_is_imported(&bo->base.base))
 			drm_gem_shmem_unpin(&bo->base);
 
 		ret = PTR_ERR(sgt);
@@ -1256,7 +1256,7 @@ static int panthor_vm_prepare_map_op_ctx(struct panthor_vm_op_ctx *op_ctx,
 
 	preallocated_vm_bo = drm_gpuvm_bo_create(&vm->base, &bo->base.base);
 	if (!preallocated_vm_bo) {
-		if (!bo->base.base.import_attach)
+		if (!drm_gem_is_imported(&bo->base.base))
 			drm_gem_shmem_unpin(&bo->base);
 
 		ret = -ENOMEM;
@@ -1282,7 +1282,7 @@ static int panthor_vm_prepare_map_op_ctx(struct panthor_vm_op_ctx *op_ctx,
 	 * which will be released in panthor_vm_bo_put().
 	 */
 	if (preallocated_vm_bo != op_ctx->map.vm_bo &&
-	    !bo->base.base.import_attach)
+	    !drm_gem_is_imported(&bo->base.base))
 		drm_gem_shmem_unpin(&bo->base);
 
 	op_ctx->map.bo_offset = offset;
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 10/15] drm/rockchip: Test for imported buffers with drm_gem_is_imported()
  2025-03-17 13:06 [PATCH 00/15] drm: Do not use import_attach in drivers Thomas Zimmermann
                   ` (8 preceding siblings ...)
  2025-03-17 13:06 ` [PATCH 09/15] drm/panthor: " Thomas Zimmermann
@ 2025-03-17 13:06 ` Thomas Zimmermann
  2025-03-17 13:06 ` [PATCH 11/15] drm/vc4: " Thomas Zimmermann
                   ` (5 subsequent siblings)
  15 siblings, 0 replies; 27+ messages in thread
From: Thomas Zimmermann @ 2025-03-17 13:06 UTC (permalink / raw)
  To: airlied, simona, maarten.lankhorst, mripard
  Cc: dri-devel, Thomas Zimmermann, Sandy Huang, Heiko Stübner,
	Andy Yan

Instead of testing import_attach for imported GEM buffers, invoke
drm_gem_is_imported() to do the test. The helper tests the dma_buf
itself while import_attach is just an artifact of the import. Prepares
to make import_attach optional.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Sandy Huang <hjc@rock-chips.com>
Cc: "Heiko Stübner" <heiko@sntech.de>
Cc: Andy Yan <andy.yan@rock-chips.com>
---
 drivers/gpu/drm/rockchip/rockchip_drm_gem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_gem.c b/drivers/gpu/drm/rockchip/rockchip_drm_gem.c
index 6330b883efc3..e44396d46dc1 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_gem.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_gem.c
@@ -332,7 +332,7 @@ void rockchip_gem_free_object(struct drm_gem_object *obj)
 	struct rockchip_drm_private *private = drm->dev_private;
 	struct rockchip_gem_object *rk_obj = to_rockchip_obj(obj);
 
-	if (obj->import_attach) {
+	if (drm_gem_is_imported(obj)) {
 		if (private->domain) {
 			rockchip_gem_iommu_unmap(rk_obj);
 		} else {
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 11/15] drm/vc4: Test for imported buffers with drm_gem_is_imported()
  2025-03-17 13:06 [PATCH 00/15] drm: Do not use import_attach in drivers Thomas Zimmermann
                   ` (9 preceding siblings ...)
  2025-03-17 13:06 ` [PATCH 10/15] drm/rockchip: " Thomas Zimmermann
@ 2025-03-17 13:06 ` Thomas Zimmermann
  2025-03-17 13:06 ` [PATCH 12/15] drm/virtio: " Thomas Zimmermann
                   ` (4 subsequent siblings)
  15 siblings, 0 replies; 27+ messages in thread
From: Thomas Zimmermann @ 2025-03-17 13:06 UTC (permalink / raw)
  To: airlied, simona, maarten.lankhorst, mripard
  Cc: dri-devel, Thomas Zimmermann, Dave Stevenson, Maíra Canal,
	Raspberry Pi Kernel Maintenance

Instead of testing import_attach for imported GEM buffers, invoke
drm_gem_is_imported() to do the test. The helper tests the dma_buf
itself while import_attach is just an artifact of the import. Prepares
to make import_attach optional.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Dave Stevenson <dave.stevenson@raspberrypi.com>
Cc: "Maíra Canal" <mcanal@igalia.com>
Cc: Raspberry Pi Kernel Maintenance <kernel-list@raspberrypi.com>
---
 drivers/gpu/drm/vc4/vc4_bo.c  | 2 +-
 drivers/gpu/drm/vc4/vc4_gem.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/vc4/vc4_bo.c b/drivers/gpu/drm/vc4/vc4_bo.c
index fb450b6a4d44..0b68e13b70f1 100644
--- a/drivers/gpu/drm/vc4/vc4_bo.c
+++ b/drivers/gpu/drm/vc4/vc4_bo.c
@@ -556,7 +556,7 @@ static void vc4_free_object(struct drm_gem_object *gem_bo)
 	mutex_lock(&vc4->bo_lock);
 	/* If the object references someone else's memory, we can't cache it.
 	 */
-	if (gem_bo->import_attach) {
+	if (drm_gem_is_imported(gem_bo)) {
 		vc4_bo_destroy(bo);
 		goto out;
 	}
diff --git a/drivers/gpu/drm/vc4/vc4_gem.c b/drivers/gpu/drm/vc4/vc4_gem.c
index 8125f87edc60..3e79ad69250a 100644
--- a/drivers/gpu/drm/vc4/vc4_gem.c
+++ b/drivers/gpu/drm/vc4/vc4_gem.c
@@ -1249,7 +1249,7 @@ int vc4_gem_madvise_ioctl(struct drm_device *dev, void *data,
 	/* Not sure it's safe to purge imported BOs. Let's just assume it's
 	 * not until proven otherwise.
 	 */
-	if (gem_obj->import_attach) {
+	if (drm_gem_is_imported(gem_obj)) {
 		DRM_DEBUG("madvise not supported on imported BOs\n");
 		ret = -EINVAL;
 		goto out_put_gem;
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 12/15] drm/virtio: Test for imported buffers with drm_gem_is_imported()
  2025-03-17 13:06 [PATCH 00/15] drm: Do not use import_attach in drivers Thomas Zimmermann
                   ` (10 preceding siblings ...)
  2025-03-17 13:06 ` [PATCH 11/15] drm/vc4: " Thomas Zimmermann
@ 2025-03-17 13:06 ` Thomas Zimmermann
  2025-03-17 13:06 ` [PATCH 13/15] drm/vmwgfx: " Thomas Zimmermann
                   ` (3 subsequent siblings)
  15 siblings, 0 replies; 27+ messages in thread
From: Thomas Zimmermann @ 2025-03-17 13:06 UTC (permalink / raw)
  To: airlied, simona, maarten.lankhorst, mripard
  Cc: dri-devel, Thomas Zimmermann, David Airlie, Gerd Hoffmann,
	Gurchetan Singh, Chia-I Wu, virtualization

Instead of testing import_attach for imported GEM buffers, invoke
drm_gem_is_imported() to do the test. The helper tests the dma_buf
itself while import_attach is just an artifact of the import. Prepares
to make import_attach optional.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Gurchetan Singh <gurchetansingh@chromium.org>
Cc: Chia-I Wu <olvaffe@gmail.com>
Cc: virtualization@lists.linux.dev
---
 drivers/gpu/drm/virtio/virtgpu_plane.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/virtio/virtgpu_plane.c b/drivers/gpu/drm/virtio/virtgpu_plane.c
index a6f5a78f436a..e1dd38e7efe8 100644
--- a/drivers/gpu/drm/virtio/virtgpu_plane.c
+++ b/drivers/gpu/drm/virtio/virtgpu_plane.c
@@ -366,13 +366,13 @@ static int virtio_gpu_plane_prepare_fb(struct drm_plane *plane,
 		return 0;
 
 	obj = new_state->fb->obj[0];
-	if (obj->import_attach) {
+	if (drm_gem_is_imported(obj)) {
 		ret = virtio_gpu_prepare_imported_obj(plane, new_state, obj);
 		if (ret)
 			return ret;
 	}
 
-	if (bo->dumb || obj->import_attach) {
+	if (bo->dumb || drm_gem_is_imported(obj)) {
 		vgplane_st->fence = virtio_gpu_fence_alloc(vgdev,
 						     vgdev->fence_drv.context,
 						     0);
@@ -409,7 +409,7 @@ static void virtio_gpu_plane_cleanup_fb(struct drm_plane *plane,
 	}
 
 	obj = state->fb->obj[0];
-	if (obj->import_attach)
+	if (drm_gem_is_imported(obj))
 		virtio_gpu_cleanup_imported_obj(obj);
 }
 
@@ -501,7 +501,7 @@ static int virtio_drm_get_scanout_buffer(struct drm_plane *plane,
 	bo = gem_to_virtio_gpu_obj(plane->state->fb->obj[0]);
 
 	/* Only support mapped shmem bo */
-	if (virtio_gpu_is_vram(bo) || bo->base.base.import_attach || !bo->base.vaddr)
+	if (virtio_gpu_is_vram(bo) || drm_gem_is_imported(&bo->base.base) || !bo->base.vaddr)
 		return -ENODEV;
 
 	iosys_map_set_vaddr(&sb->map[0], bo->base.vaddr);
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 13/15] drm/vmwgfx: Test for imported buffers with drm_gem_is_imported()
  2025-03-17 13:06 [PATCH 00/15] drm: Do not use import_attach in drivers Thomas Zimmermann
                   ` (11 preceding siblings ...)
  2025-03-17 13:06 ` [PATCH 12/15] drm/virtio: " Thomas Zimmermann
@ 2025-03-17 13:06 ` Thomas Zimmermann
  2025-03-17 16:12   ` Zack Rusin
  2025-03-17 13:06 ` [PATCH 14/15] drm/vmwgfx: Use dma_buf from GEM object instance Thomas Zimmermann
                   ` (2 subsequent siblings)
  15 siblings, 1 reply; 27+ messages in thread
From: Thomas Zimmermann @ 2025-03-17 13:06 UTC (permalink / raw)
  To: airlied, simona, maarten.lankhorst, mripard
  Cc: dri-devel, Thomas Zimmermann, Zack Rusin,
	Broadcom internal kernel review list

Instead of testing import_attach for imported GEM buffers, invoke
drm_gem_is_imported() to do the test. The helper tests the dma_buf
itself while import_attach is just an artifact of the import. Prepares
to make import_attach optional.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Zack Rusin <zack.rusin@broadcom.com>
Cc: Broadcom internal kernel review list <bcm-kernel-feedback-list@broadcom.com>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_blit.c | 4 ++--
 drivers/gpu/drm/vmwgfx/vmwgfx_gem.c  | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c b/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c
index 64bd7d74854e..fa5841fda659 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c
@@ -429,7 +429,7 @@ static void *map_external(struct vmw_bo *bo, struct iosys_map *map)
 	void *ptr = NULL;
 	int ret;
 
-	if (bo->tbo.base.import_attach) {
+	if (drm_gem_is_imported(&bo->tbo.base)) {
 		ret = dma_buf_vmap(bo->tbo.base.dma_buf, map);
 		if (ret) {
 			drm_dbg_driver(&vmw->drm,
@@ -447,7 +447,7 @@ static void *map_external(struct vmw_bo *bo, struct iosys_map *map)
 
 static void unmap_external(struct vmw_bo *bo, struct iosys_map *map)
 {
-	if (bo->tbo.base.import_attach)
+	if (drm_gem_is_imported(&bo->tbo.base))
 		dma_buf_vunmap(bo->tbo.base.dma_buf, map);
 	else
 		vmw_bo_unmap(bo);
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c
index ed5015ced392..200240fecf7d 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c
@@ -84,7 +84,7 @@ static int vmw_gem_vmap(struct drm_gem_object *obj, struct iosys_map *map)
 	struct ttm_buffer_object *bo = drm_gem_ttm_of_gem(obj);
 	int ret;
 
-	if (obj->import_attach) {
+	if (drm_gem_is_imported(obj)) {
 		ret = dma_buf_vmap(obj->import_attach->dmabuf, map);
 		if (!ret) {
 			if (drm_WARN_ON(obj->dev, map->is_iomem)) {
@@ -101,7 +101,7 @@ static int vmw_gem_vmap(struct drm_gem_object *obj, struct iosys_map *map)
 
 static void vmw_gem_vunmap(struct drm_gem_object *obj, struct iosys_map *map)
 {
-	if (obj->import_attach)
+	if (drm_gem_is_imported(obj))
 		dma_buf_vunmap(obj->import_attach->dmabuf, map);
 	else
 		drm_gem_ttm_vunmap(obj, map);
@@ -111,7 +111,7 @@ static int vmw_gem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
 {
 	int ret;
 
-	if (obj->import_attach) {
+	if (drm_gem_is_imported(obj)) {
 		/*
 		 * Reset both vm_ops and vm_private_data, so we don't end up with
 		 * vm_ops pointing to our implementation if the dma-buf backend
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 14/15] drm/vmwgfx: Use dma_buf from GEM object instance
  2025-03-17 13:06 [PATCH 00/15] drm: Do not use import_attach in drivers Thomas Zimmermann
                   ` (12 preceding siblings ...)
  2025-03-17 13:06 ` [PATCH 13/15] drm/vmwgfx: " Thomas Zimmermann
@ 2025-03-17 13:06 ` Thomas Zimmermann
  2025-03-17 16:13   ` Zack Rusin
  2025-03-17 13:06 ` [PATCH 15/15] drm/xen: Test for imported buffers with drm_gem_is_imported() Thomas Zimmermann
  2025-04-10 17:27 ` [PATCH 00/15] drm: Do not use import_attach in drivers Thomas Zimmermann
  15 siblings, 1 reply; 27+ messages in thread
From: Thomas Zimmermann @ 2025-03-17 13:06 UTC (permalink / raw)
  To: airlied, simona, maarten.lankhorst, mripard
  Cc: dri-devel, Thomas Zimmermann, Zack Rusin,
	Broadcom internal kernel review list

Avoid dereferencing struct drm_gem_object.import_attach for the
imported dma-buf. The dma_buf field in the GEM object instance refers
to the same buffer. Prepares to make import_attach optional.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Zack Rusin <zack.rusin@broadcom.com>
Cc: Broadcom internal kernel review list <bcm-kernel-feedback-list@broadcom.com>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_gem.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c
index 200240fecf7d..2a252e1d5e9f 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c
@@ -85,10 +85,10 @@ static int vmw_gem_vmap(struct drm_gem_object *obj, struct iosys_map *map)
 	int ret;
 
 	if (drm_gem_is_imported(obj)) {
-		ret = dma_buf_vmap(obj->import_attach->dmabuf, map);
+		ret = dma_buf_vmap(obj->dma_buf, map);
 		if (!ret) {
 			if (drm_WARN_ON(obj->dev, map->is_iomem)) {
-				dma_buf_vunmap(obj->import_attach->dmabuf, map);
+				dma_buf_vunmap(obj->dma_buf, map);
 				return -EIO;
 			}
 		}
@@ -102,7 +102,7 @@ static int vmw_gem_vmap(struct drm_gem_object *obj, struct iosys_map *map)
 static void vmw_gem_vunmap(struct drm_gem_object *obj, struct iosys_map *map)
 {
 	if (drm_gem_is_imported(obj))
-		dma_buf_vunmap(obj->import_attach->dmabuf, map);
+		dma_buf_vunmap(obj->dma_buf, map);
 	else
 		drm_gem_ttm_vunmap(obj, map);
 }
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* [PATCH 15/15] drm/xen: Test for imported buffers with drm_gem_is_imported()
  2025-03-17 13:06 [PATCH 00/15] drm: Do not use import_attach in drivers Thomas Zimmermann
                   ` (13 preceding siblings ...)
  2025-03-17 13:06 ` [PATCH 14/15] drm/vmwgfx: Use dma_buf from GEM object instance Thomas Zimmermann
@ 2025-03-17 13:06 ` Thomas Zimmermann
  2025-04-10 17:27 ` [PATCH 00/15] drm: Do not use import_attach in drivers Thomas Zimmermann
  15 siblings, 0 replies; 27+ messages in thread
From: Thomas Zimmermann @ 2025-03-17 13:06 UTC (permalink / raw)
  To: airlied, simona, maarten.lankhorst, mripard
  Cc: dri-devel, Thomas Zimmermann, Oleksandr Andrushchenko, xen-devel

Instead of testing import_attach for imported GEM buffers, invoke
drm_gem_is_imported() to do the test. The helper tests the dma_buf
itself while import_attach is just an artifact of the import. Prepares
to make import_attach optional.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Cc: xen-devel@lists.xenproject.org
---
 drivers/gpu/drm/xen/xen_drm_front_gem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/xen/xen_drm_front_gem.c b/drivers/gpu/drm/xen/xen_drm_front_gem.c
index 63112ed975c4..62a83c36fce8 100644
--- a/drivers/gpu/drm/xen/xen_drm_front_gem.c
+++ b/drivers/gpu/drm/xen/xen_drm_front_gem.c
@@ -203,7 +203,7 @@ void xen_drm_front_gem_free_object_unlocked(struct drm_gem_object *gem_obj)
 {
 	struct xen_gem_object *xen_obj = to_xen_gem_obj(gem_obj);
 
-	if (xen_obj->base.import_attach) {
+	if (drm_gem_is_imported(&xen_obj->base)) {
 		drm_prime_gem_destroy(&xen_obj->base, xen_obj->sgt_imported);
 		gem_free_pages_array(xen_obj);
 	} else {
-- 
2.48.1



^ permalink raw reply related	[flat|nested] 27+ messages in thread

* Re: [PATCH 09/15] drm/panthor: Test for imported buffers with drm_gem_is_imported()
  2025-03-17 13:06 ` [PATCH 09/15] drm/panthor: " Thomas Zimmermann
@ 2025-03-17 13:59   ` Liviu Dudau
  2025-03-31  9:02   ` Steven Price
  2025-04-25 13:34   ` Steven Price
  2 siblings, 0 replies; 27+ messages in thread
From: Liviu Dudau @ 2025-03-17 13:59 UTC (permalink / raw)
  To: Thomas Zimmermann
  Cc: airlied, simona, maarten.lankhorst, mripard, dri-devel,
	Boris Brezillon, Steven Price

On Mon, Mar 17, 2025 at 02:06:47PM +0100, Thomas Zimmermann wrote:
> Instead of testing import_attach for imported GEM buffers, invoke
> drm_gem_is_imported() to do the test. The helper tests the dma_buf
> itself while import_attach is just an artifact of the import. Prepares
> to make import_attach optional.
> 
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Boris Brezillon <boris.brezillon@collabora.com>
> Cc: Steven Price <steven.price@arm.com>
> Cc: Liviu Dudau <liviu.dudau@arm.com>

Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>

Best regards,
Liviu

> ---
>  drivers/gpu/drm/panthor/panthor_gem.c |  2 +-
>  drivers/gpu/drm/panthor/panthor_mmu.c | 10 +++++-----
>  2 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/panthor/panthor_gem.c
> index 8244a4e6c2a2..fd014ccc3bfc 100644
> --- a/drivers/gpu/drm/panthor/panthor_gem.c
> +++ b/drivers/gpu/drm/panthor/panthor_gem.c
> @@ -155,7 +155,7 @@ static enum drm_gem_object_status panthor_gem_status(struct drm_gem_object *obj)
>  	struct panthor_gem_object *bo = to_panthor_bo(obj);
>  	enum drm_gem_object_status res = 0;
>  
> -	if (bo->base.base.import_attach || bo->base.pages)
> +	if (drm_gem_is_imported(&bo->base.base) || bo->base.pages)
>  		res |= DRM_GEM_OBJECT_RESIDENT;
>  
>  	return res;
> diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
> index 12a02e28f50f..3e123159ac10 100644
> --- a/drivers/gpu/drm/panthor/panthor_mmu.c
> +++ b/drivers/gpu/drm/panthor/panthor_mmu.c
> @@ -1103,7 +1103,7 @@ static void panthor_vm_bo_put(struct drm_gpuvm_bo *vm_bo)
>  	/* If the vm_bo object was destroyed, release the pin reference that
>  	 * was hold by this object.
>  	 */
> -	if (unpin && !bo->base.base.import_attach)
> +	if (unpin && !drm_gem_is_imported(&bo->base.base))
>  		drm_gem_shmem_unpin(&bo->base);
>  
>  	drm_gpuvm_put(vm);
> @@ -1234,7 +1234,7 @@ static int panthor_vm_prepare_map_op_ctx(struct panthor_vm_op_ctx *op_ctx,
>  	if (ret)
>  		goto err_cleanup;
>  
> -	if (!bo->base.base.import_attach) {
> +	if (!drm_gem_is_imported(&bo->base.base)) {
>  		/* Pre-reserve the BO pages, so the map operation doesn't have to
>  		 * allocate.
>  		 */
> @@ -1245,7 +1245,7 @@ static int panthor_vm_prepare_map_op_ctx(struct panthor_vm_op_ctx *op_ctx,
>  
>  	sgt = drm_gem_shmem_get_pages_sgt(&bo->base);
>  	if (IS_ERR(sgt)) {
> -		if (!bo->base.base.import_attach)
> +		if (!drm_gem_is_imported(&bo->base.base))
>  			drm_gem_shmem_unpin(&bo->base);
>  
>  		ret = PTR_ERR(sgt);
> @@ -1256,7 +1256,7 @@ static int panthor_vm_prepare_map_op_ctx(struct panthor_vm_op_ctx *op_ctx,
>  
>  	preallocated_vm_bo = drm_gpuvm_bo_create(&vm->base, &bo->base.base);
>  	if (!preallocated_vm_bo) {
> -		if (!bo->base.base.import_attach)
> +		if (!drm_gem_is_imported(&bo->base.base))
>  			drm_gem_shmem_unpin(&bo->base);
>  
>  		ret = -ENOMEM;
> @@ -1282,7 +1282,7 @@ static int panthor_vm_prepare_map_op_ctx(struct panthor_vm_op_ctx *op_ctx,
>  	 * which will be released in panthor_vm_bo_put().
>  	 */
>  	if (preallocated_vm_bo != op_ctx->map.vm_bo &&
> -	    !bo->base.base.import_attach)
> +	    !drm_gem_is_imported(&bo->base.base))
>  		drm_gem_shmem_unpin(&bo->base);
>  
>  	op_ctx->map.bo_offset = offset;
> -- 
> 2.48.1
> 

-- 
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 06/15] drm/msm: Test for imported buffers with drm_gem_is_imported()
  2025-03-17 13:06 ` [PATCH 06/15] drm/msm: " Thomas Zimmermann
@ 2025-03-17 14:10   ` Dmitry Baryshkov
  0 siblings, 0 replies; 27+ messages in thread
From: Dmitry Baryshkov @ 2025-03-17 14:10 UTC (permalink / raw)
  To: Thomas Zimmermann
  Cc: airlied, simona, maarten.lankhorst, mripard, dri-devel, Rob Clark,
	Abhinav Kumar, Dmitry Baryshkov, Sean Paul, Marijn Suijten,
	linux-arm-msm, freedreno

On Mon, Mar 17, 2025 at 02:06:44PM +0100, Thomas Zimmermann wrote:
> Instead of testing import_attach for imported GEM buffers, invoke
> drm_gem_is_imported() to do the test. The helper tests the dma_buf
> itself while import_attach is just an artifact of the import. Prepares
> to make import_attach optional.
> 
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Rob Clark <robdclark@gmail.com>
> Cc: Abhinav Kumar <quic_abhinavk@quicinc.com>
> Cc: Dmitry Baryshkov <lumag@kernel.org>
> Cc: Sean Paul <sean@poorly.run>
> Cc: Marijn Suijten <marijn.suijten@somainline.org>
> Cc: linux-arm-msm@vger.kernel.org
> Cc: freedreno@lists.freedesktop.org
> ---
>  drivers/gpu/drm/msm/msm_drv.c       | 2 +-
>  drivers/gpu/drm/msm/msm_gem.c       | 4 ++--
>  drivers/gpu/drm/msm/msm_gem.h       | 2 +-
>  drivers/gpu/drm/msm/msm_gem_prime.c | 4 ++--
>  4 files changed, 6 insertions(+), 6 deletions(-)
> 

Acked-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>

-- 
With best wishes
Dmitry

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 03/15] drm/etnaviv: Use dma_buf from GEM object instance
  2025-03-17 13:06 ` [PATCH 03/15] drm/etnaviv: Use dma_buf from GEM object instance Thomas Zimmermann
@ 2025-03-17 14:54   ` Lucas Stach
  0 siblings, 0 replies; 27+ messages in thread
From: Lucas Stach @ 2025-03-17 14:54 UTC (permalink / raw)
  To: Thomas Zimmermann, airlied, simona, maarten.lankhorst, mripard
  Cc: dri-devel, Russell King, Christian Gmeiner, etnaviv

Hi Thomas,

Am Montag, dem 17.03.2025 um 14:06 +0100 schrieb Thomas Zimmermann:
> Avoid dereferencing struct drm_gem_object.import_attach for the
> imported dma-buf. The dma_buf field in the GEM object instance refers
> to the same buffer. Prepares to make import_attach optional.
> 
Both etnaviv patches are
Reviewed-by: Lucas Stach <l.stach@pengutronix.de>

Feel free to take them through drm-misc if you want to put further
cleanups on top of that series.

Regards,
Lucas

> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Lucas Stach <l.stach@pengutronix.de>
> Cc: Russell King <linux+etnaviv@armlinux.org.uk>
> Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
> Cc: etnaviv@lists.freedesktop.org
> ---
>  drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c b/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c
> index 40a50c60dfff..917ad527c961 100644
> --- a/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c
> +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c
> @@ -65,7 +65,7 @@ static void etnaviv_gem_prime_release(struct etnaviv_gem_object *etnaviv_obj)
>  	struct iosys_map map = IOSYS_MAP_INIT_VADDR(etnaviv_obj->vaddr);
>  
>  	if (etnaviv_obj->vaddr)
> -		dma_buf_vunmap_unlocked(etnaviv_obj->base.import_attach->dmabuf, &map);
> +		dma_buf_vunmap_unlocked(etnaviv_obj->base.dma_buf, &map);
>  
>  	/* Don't drop the pages for imported dmabuf, as they are not
>  	 * ours, just free the array we allocated:
> @@ -82,7 +82,7 @@ static void *etnaviv_gem_prime_vmap_impl(struct etnaviv_gem_object *etnaviv_obj)
>  
>  	lockdep_assert_held(&etnaviv_obj->lock);
>  
> -	ret = dma_buf_vmap(etnaviv_obj->base.import_attach->dmabuf, &map);
> +	ret = dma_buf_vmap(etnaviv_obj->base.dma_buf, &map);
>  	if (ret)
>  		return NULL;
>  	return map.vaddr;


^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 13/15] drm/vmwgfx: Test for imported buffers with drm_gem_is_imported()
  2025-03-17 13:06 ` [PATCH 13/15] drm/vmwgfx: " Thomas Zimmermann
@ 2025-03-17 16:12   ` Zack Rusin
  0 siblings, 0 replies; 27+ messages in thread
From: Zack Rusin @ 2025-03-17 16:12 UTC (permalink / raw)
  To: Thomas Zimmermann
  Cc: airlied, simona, maarten.lankhorst, mripard, dri-devel,
	Broadcom internal kernel review list

[-- Attachment #1: Type: text/plain, Size: 3258 bytes --]

On Mon, Mar 17, 2025 at 9:22 AM Thomas Zimmermann <tzimmermann@suse.de> wrote:
>
> Instead of testing import_attach for imported GEM buffers, invoke
> drm_gem_is_imported() to do the test. The helper tests the dma_buf
> itself while import_attach is just an artifact of the import. Prepares
> to make import_attach optional.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Zack Rusin <zack.rusin@broadcom.com>
> Cc: Broadcom internal kernel review list <bcm-kernel-feedback-list@broadcom.com>
> ---
>  drivers/gpu/drm/vmwgfx/vmwgfx_blit.c | 4 ++--
>  drivers/gpu/drm/vmwgfx/vmwgfx_gem.c  | 6 +++---
>  2 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c b/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c
> index 64bd7d74854e..fa5841fda659 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c
> @@ -429,7 +429,7 @@ static void *map_external(struct vmw_bo *bo, struct iosys_map *map)
>         void *ptr = NULL;
>         int ret;
>
> -       if (bo->tbo.base.import_attach) {
> +       if (drm_gem_is_imported(&bo->tbo.base)) {
>                 ret = dma_buf_vmap(bo->tbo.base.dma_buf, map);
>                 if (ret) {
>                         drm_dbg_driver(&vmw->drm,
> @@ -447,7 +447,7 @@ static void *map_external(struct vmw_bo *bo, struct iosys_map *map)
>
>  static void unmap_external(struct vmw_bo *bo, struct iosys_map *map)
>  {
> -       if (bo->tbo.base.import_attach)
> +       if (drm_gem_is_imported(&bo->tbo.base))
>                 dma_buf_vunmap(bo->tbo.base.dma_buf, map);
>         else
>                 vmw_bo_unmap(bo);
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c
> index ed5015ced392..200240fecf7d 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c
> @@ -84,7 +84,7 @@ static int vmw_gem_vmap(struct drm_gem_object *obj, struct iosys_map *map)
>         struct ttm_buffer_object *bo = drm_gem_ttm_of_gem(obj);
>         int ret;
>
> -       if (obj->import_attach) {
> +       if (drm_gem_is_imported(obj)) {
>                 ret = dma_buf_vmap(obj->import_attach->dmabuf, map);
>                 if (!ret) {
>                         if (drm_WARN_ON(obj->dev, map->is_iomem)) {
> @@ -101,7 +101,7 @@ static int vmw_gem_vmap(struct drm_gem_object *obj, struct iosys_map *map)
>
>  static void vmw_gem_vunmap(struct drm_gem_object *obj, struct iosys_map *map)
>  {
> -       if (obj->import_attach)
> +       if (drm_gem_is_imported(obj))
>                 dma_buf_vunmap(obj->import_attach->dmabuf, map);
>         else
>                 drm_gem_ttm_vunmap(obj, map);
> @@ -111,7 +111,7 @@ static int vmw_gem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
>  {
>         int ret;
>
> -       if (obj->import_attach) {
> +       if (drm_gem_is_imported(obj)) {
>                 /*
>                  * Reset both vm_ops and vm_private_data, so we don't end up with
>                  * vm_ops pointing to our implementation if the dma-buf backend
> --
> 2.48.1
>

Another great cleanup! Thanks.
Reviewed-by: Zack Rusin <zack.rusin@broadcom.com>

z

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 5414 bytes --]

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 14/15] drm/vmwgfx: Use dma_buf from GEM object instance
  2025-03-17 13:06 ` [PATCH 14/15] drm/vmwgfx: Use dma_buf from GEM object instance Thomas Zimmermann
@ 2025-03-17 16:13   ` Zack Rusin
  0 siblings, 0 replies; 27+ messages in thread
From: Zack Rusin @ 2025-03-17 16:13 UTC (permalink / raw)
  To: Thomas Zimmermann
  Cc: airlied, simona, maarten.lankhorst, mripard, dri-devel,
	Broadcom internal kernel review list

[-- Attachment #1: Type: text/plain, Size: 1980 bytes --]

On Mon, Mar 17, 2025 at 9:22 AM Thomas Zimmermann <tzimmermann@suse.de> wrote:
>
> Avoid dereferencing struct drm_gem_object.import_attach for the
> imported dma-buf. The dma_buf field in the GEM object instance refers
> to the same buffer. Prepares to make import_attach optional.
>
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Zack Rusin <zack.rusin@broadcom.com>
> Cc: Broadcom internal kernel review list <bcm-kernel-feedback-list@broadcom.com>
> ---
>  drivers/gpu/drm/vmwgfx/vmwgfx_gem.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c
> index 200240fecf7d..2a252e1d5e9f 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gem.c
> @@ -85,10 +85,10 @@ static int vmw_gem_vmap(struct drm_gem_object *obj, struct iosys_map *map)
>         int ret;
>
>         if (drm_gem_is_imported(obj)) {
> -               ret = dma_buf_vmap(obj->import_attach->dmabuf, map);
> +               ret = dma_buf_vmap(obj->dma_buf, map);
>                 if (!ret) {
>                         if (drm_WARN_ON(obj->dev, map->is_iomem)) {
> -                               dma_buf_vunmap(obj->import_attach->dmabuf, map);
> +                               dma_buf_vunmap(obj->dma_buf, map);
>                                 return -EIO;
>                         }
>                 }
> @@ -102,7 +102,7 @@ static int vmw_gem_vmap(struct drm_gem_object *obj, struct iosys_map *map)
>  static void vmw_gem_vunmap(struct drm_gem_object *obj, struct iosys_map *map)
>  {
>         if (drm_gem_is_imported(obj))
> -               dma_buf_vunmap(obj->import_attach->dmabuf, map);
> +               dma_buf_vunmap(obj->dma_buf, map);
>         else
>                 drm_gem_ttm_vunmap(obj, map);
>  }
> --
> 2.48.1
>

Looks good, thanks!
Reviewed-by: Zack Rusin <zack.rusin@broadcom.com>

z

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 5414 bytes --]

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 08/15] drm/panfrost: Test for imported buffers with drm_gem_is_imported()
  2025-03-17 13:06 ` [PATCH 08/15] drm/panfrost: " Thomas Zimmermann
@ 2025-03-31  9:02   ` Steven Price
  0 siblings, 0 replies; 27+ messages in thread
From: Steven Price @ 2025-03-31  9:02 UTC (permalink / raw)
  To: Thomas Zimmermann, airlied, simona, maarten.lankhorst, mripard
  Cc: dri-devel, Boris Brezillon, Rob Herring

On 17/03/2025 13:06, Thomas Zimmermann wrote:
> Instead of testing import_attach for imported GEM buffers, invoke
> drm_gem_is_imported() to do the test. The helper tests the dma_buf
> itself while import_attach is just an artifact of the import. Prepares
> to make import_attach optional.
> 
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Boris Brezillon <boris.brezillon@collabora.com>
> Cc: Rob Herring <robh@kernel.org>
> Cc: Steven Price <steven.price@arm.com>

Reviewed-by: Steven Price <steven.price@arm.com>

> ---
>  drivers/gpu/drm/panfrost/panfrost_gem.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.c b/drivers/gpu/drm/panfrost/panfrost_gem.c
> index 8e0ff3efede7..963f04ba2de6 100644
> --- a/drivers/gpu/drm/panfrost/panfrost_gem.c
> +++ b/drivers/gpu/drm/panfrost/panfrost_gem.c
> @@ -200,7 +200,7 @@ static enum drm_gem_object_status panfrost_gem_status(struct drm_gem_object *obj
>  	struct panfrost_gem_object *bo = to_panfrost_bo(obj);
>  	enum drm_gem_object_status res = 0;
>  
> -	if (bo->base.base.import_attach || bo->base.pages)
> +	if (drm_gem_is_imported(&bo->base.base) || bo->base.pages)
>  		res |= DRM_GEM_OBJECT_RESIDENT;
>  
>  	if (bo->base.madv == PANFROST_MADV_DONTNEED)


^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 09/15] drm/panthor: Test for imported buffers with drm_gem_is_imported()
  2025-03-17 13:06 ` [PATCH 09/15] drm/panthor: " Thomas Zimmermann
  2025-03-17 13:59   ` Liviu Dudau
@ 2025-03-31  9:02   ` Steven Price
  2025-04-25 13:34   ` Steven Price
  2 siblings, 0 replies; 27+ messages in thread
From: Steven Price @ 2025-03-31  9:02 UTC (permalink / raw)
  To: Thomas Zimmermann, airlied, simona, maarten.lankhorst, mripard
  Cc: dri-devel, Boris Brezillon, Liviu Dudau

On 17/03/2025 13:06, Thomas Zimmermann wrote:
> Instead of testing import_attach for imported GEM buffers, invoke
> drm_gem_is_imported() to do the test. The helper tests the dma_buf
> itself while import_attach is just an artifact of the import. Prepares
> to make import_attach optional.
> 
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Boris Brezillon <boris.brezillon@collabora.com>
> Cc: Steven Price <steven.price@arm.com>
> Cc: Liviu Dudau <liviu.dudau@arm.com>

Reviewed-by: Steven Price <steven.price@arm.com>

> ---
>  drivers/gpu/drm/panthor/panthor_gem.c |  2 +-
>  drivers/gpu/drm/panthor/panthor_mmu.c | 10 +++++-----
>  2 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/panthor/panthor_gem.c
> index 8244a4e6c2a2..fd014ccc3bfc 100644
> --- a/drivers/gpu/drm/panthor/panthor_gem.c
> +++ b/drivers/gpu/drm/panthor/panthor_gem.c
> @@ -155,7 +155,7 @@ static enum drm_gem_object_status panthor_gem_status(struct drm_gem_object *obj)
>  	struct panthor_gem_object *bo = to_panthor_bo(obj);
>  	enum drm_gem_object_status res = 0;
>  
> -	if (bo->base.base.import_attach || bo->base.pages)
> +	if (drm_gem_is_imported(&bo->base.base) || bo->base.pages)
>  		res |= DRM_GEM_OBJECT_RESIDENT;
>  
>  	return res;
> diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
> index 12a02e28f50f..3e123159ac10 100644
> --- a/drivers/gpu/drm/panthor/panthor_mmu.c
> +++ b/drivers/gpu/drm/panthor/panthor_mmu.c
> @@ -1103,7 +1103,7 @@ static void panthor_vm_bo_put(struct drm_gpuvm_bo *vm_bo)
>  	/* If the vm_bo object was destroyed, release the pin reference that
>  	 * was hold by this object.
>  	 */
> -	if (unpin && !bo->base.base.import_attach)
> +	if (unpin && !drm_gem_is_imported(&bo->base.base))
>  		drm_gem_shmem_unpin(&bo->base);
>  
>  	drm_gpuvm_put(vm);
> @@ -1234,7 +1234,7 @@ static int panthor_vm_prepare_map_op_ctx(struct panthor_vm_op_ctx *op_ctx,
>  	if (ret)
>  		goto err_cleanup;
>  
> -	if (!bo->base.base.import_attach) {
> +	if (!drm_gem_is_imported(&bo->base.base)) {
>  		/* Pre-reserve the BO pages, so the map operation doesn't have to
>  		 * allocate.
>  		 */
> @@ -1245,7 +1245,7 @@ static int panthor_vm_prepare_map_op_ctx(struct panthor_vm_op_ctx *op_ctx,
>  
>  	sgt = drm_gem_shmem_get_pages_sgt(&bo->base);
>  	if (IS_ERR(sgt)) {
> -		if (!bo->base.base.import_attach)
> +		if (!drm_gem_is_imported(&bo->base.base))
>  			drm_gem_shmem_unpin(&bo->base);
>  
>  		ret = PTR_ERR(sgt);
> @@ -1256,7 +1256,7 @@ static int panthor_vm_prepare_map_op_ctx(struct panthor_vm_op_ctx *op_ctx,
>  
>  	preallocated_vm_bo = drm_gpuvm_bo_create(&vm->base, &bo->base.base);
>  	if (!preallocated_vm_bo) {
> -		if (!bo->base.base.import_attach)
> +		if (!drm_gem_is_imported(&bo->base.base))
>  			drm_gem_shmem_unpin(&bo->base);
>  
>  		ret = -ENOMEM;
> @@ -1282,7 +1282,7 @@ static int panthor_vm_prepare_map_op_ctx(struct panthor_vm_op_ctx *op_ctx,
>  	 * which will be released in panthor_vm_bo_put().
>  	 */
>  	if (preallocated_vm_bo != op_ctx->map.vm_bo &&
> -	    !bo->base.base.import_attach)
> +	    !drm_gem_is_imported(&bo->base.base))
>  		drm_gem_shmem_unpin(&bo->base);
>  
>  	op_ctx->map.bo_offset = offset;


^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 00/15] drm: Do not use import_attach in drivers
  2025-03-17 13:06 [PATCH 00/15] drm: Do not use import_attach in drivers Thomas Zimmermann
                   ` (14 preceding siblings ...)
  2025-03-17 13:06 ` [PATCH 15/15] drm/xen: Test for imported buffers with drm_gem_is_imported() Thomas Zimmermann
@ 2025-04-10 17:27 ` Thomas Zimmermann
  15 siblings, 0 replies; 27+ messages in thread
From: Thomas Zimmermann @ 2025-04-10 17:27 UTC (permalink / raw)
  To: airlied, simona, maarten.lankhorst, mripard; +Cc: dri-devel

Ping for additional reviews of this series.

Am 17.03.25 um 14:06 schrieb Thomas Zimmermann:
> Avoid struct drm_gem_object.import_attach in many DRM drivers that
> use it to get the object's dma-buf or test for an imported buffer.
>
> The helper drm_gem_is_imported() tests if a GEM object's buffer
> has been imported into the driver. The corresponding dma-buf is
> referenced by the object itself. Both cases avoid import_attach.
>
> The import_attach field in struct drm_gem_object is an artifact of
> the import process, but should not be used otherwise. This series
> fixes most of the drivers in the DRM misc tree. Other DRM drivers
> can be converted when drm_gem_is_imported() becomes available in
> their tree.
>
> Thomas Zimmermann (15):
>    drm/armada: Test for imported buffers with drm_gem_is_imported()
>    drm/etnaviv: Test for imported buffers with drm_gem_is_imported()
>    drm/etnaviv: Use dma_buf from GEM object instance
>    drm/exynos: Test for imported buffers with drm_gem_is_imported()
>    drm/gud: Test for imported buffers with drm_gem_is_imported()
>    drm/msm: Test for imported buffers with drm_gem_is_imported()
>    drm/omapdrm: Test for imported buffers with drm_gem_is_imported()
>    drm/panfrost: Test for imported buffers with drm_gem_is_imported()
>    drm/panthor: Test for imported buffers with drm_gem_is_imported()
>    drm/rockchip: Test for imported buffers with drm_gem_is_imported()
>    drm/vc4: Test for imported buffers with drm_gem_is_imported()
>    drm/virtio: Test for imported buffers with drm_gem_is_imported()
>    drm/vmwgfx: Test for imported buffers with drm_gem_is_imported()
>    drm/vmwgfx: Use dma_buf from GEM object instance
>    drm/xen: Test for imported buffers with drm_gem_is_imported()
>
>   drivers/gpu/drm/armada/armada_fb.c          |  2 +-
>   drivers/gpu/drm/armada/armada_gem.c         |  2 +-
>   drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c |  8 ++++----
>   drivers/gpu/drm/exynos/exynos_drm_gem.c     |  4 ++--
>   drivers/gpu/drm/gud/gud_pipe.c              |  2 +-
>   drivers/gpu/drm/msm/msm_drv.c               |  2 +-
>   drivers/gpu/drm/msm/msm_gem.c               |  4 ++--
>   drivers/gpu/drm/msm/msm_gem.h               |  2 +-
>   drivers/gpu/drm/msm/msm_gem_prime.c         |  4 ++--
>   drivers/gpu/drm/omapdrm/omap_gem.c          |  2 +-
>   drivers/gpu/drm/panfrost/panfrost_gem.c     |  2 +-
>   drivers/gpu/drm/panthor/panthor_gem.c       |  2 +-
>   drivers/gpu/drm/panthor/panthor_mmu.c       | 10 +++++-----
>   drivers/gpu/drm/rockchip/rockchip_drm_gem.c |  2 +-
>   drivers/gpu/drm/vc4/vc4_bo.c                |  2 +-
>   drivers/gpu/drm/vc4/vc4_gem.c               |  2 +-
>   drivers/gpu/drm/virtio/virtgpu_plane.c      |  8 ++++----
>   drivers/gpu/drm/vmwgfx/vmwgfx_blit.c        |  4 ++--
>   drivers/gpu/drm/vmwgfx/vmwgfx_gem.c         | 12 ++++++------
>   drivers/gpu/drm/xen/xen_drm_front_gem.c     |  2 +-
>   20 files changed, 39 insertions(+), 39 deletions(-)
>

-- 
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)


^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 09/15] drm/panthor: Test for imported buffers with drm_gem_is_imported()
  2025-03-17 13:06 ` [PATCH 09/15] drm/panthor: " Thomas Zimmermann
  2025-03-17 13:59   ` Liviu Dudau
  2025-03-31  9:02   ` Steven Price
@ 2025-04-25 13:34   ` Steven Price
  2025-04-25 14:30     ` Boris Brezillon
  2 siblings, 1 reply; 27+ messages in thread
From: Steven Price @ 2025-04-25 13:34 UTC (permalink / raw)
  To: Thomas Zimmermann, airlied, simona, maarten.lankhorst, mripard
  Cc: dri-devel, Boris Brezillon, Liviu Dudau

On 17/03/2025 13:06, Thomas Zimmermann wrote:
> Instead of testing import_attach for imported GEM buffers, invoke
> drm_gem_is_imported() to do the test. The helper tests the dma_buf
> itself while import_attach is just an artifact of the import. Prepares
> to make import_attach optional.
> 
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Boris Brezillon <boris.brezillon@collabora.com>
> Cc: Steven Price <steven.price@arm.com>
> Cc: Liviu Dudau <liviu.dudau@arm.com>
> ---
>  drivers/gpu/drm/panthor/panthor_gem.c |  2 +-
>  drivers/gpu/drm/panthor/panthor_mmu.c | 10 +++++-----
>  2 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/panthor/panthor_gem.c
> index 8244a4e6c2a2..fd014ccc3bfc 100644
> --- a/drivers/gpu/drm/panthor/panthor_gem.c
> +++ b/drivers/gpu/drm/panthor/panthor_gem.c
> @@ -155,7 +155,7 @@ static enum drm_gem_object_status panthor_gem_status(struct drm_gem_object *obj)
>  	struct panthor_gem_object *bo = to_panthor_bo(obj);
>  	enum drm_gem_object_status res = 0;
>  
> -	if (bo->base.base.import_attach || bo->base.pages)
> +	if (drm_gem_is_imported(&bo->base.base) || bo->base.pages)
>  		res |= DRM_GEM_OBJECT_RESIDENT;
>  
>  	return res;
> diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
> index 12a02e28f50f..3e123159ac10 100644
> --- a/drivers/gpu/drm/panthor/panthor_mmu.c
> +++ b/drivers/gpu/drm/panthor/panthor_mmu.c
> @@ -1103,7 +1103,7 @@ static void panthor_vm_bo_put(struct drm_gpuvm_bo *vm_bo)
>  	/* If the vm_bo object was destroyed, release the pin reference that
>  	 * was hold by this object.
>  	 */
> -	if (unpin && !bo->base.base.import_attach)
> +	if (unpin && !drm_gem_is_imported(&bo->base.base))
>  		drm_gem_shmem_unpin(&bo->base);

I'm seeing issues on cleanup where drm_gem_is_imported() doesn't return 
the same as !!import_attach in the above code. Specifically this appears 
to be caused by drm_gem_object_exported_dma_buf_free() setting ->dma_buf 
to NULL which makes the BO look like it isn't imported.

Stashing the imported state in the BO fixes the problem (see below 
hack), but it would be nice to fix this more generally in case there are 
other drivers that need to know the imported state during cleanup.

Any suggestions for how drm_gem_is_imported() can more accurately report 
the state during cleanup?

Thanks,
Steve


diff --git a/drivers/gpu/drm/panthor/panthor_gem.h b/drivers/gpu/drm/panthor/panthor_gem.h
index 4641994ddd7f..160facc67b23 100644
--- a/drivers/gpu/drm/panthor/panthor_gem.h
+++ b/drivers/gpu/drm/panthor/panthor_gem.h
@@ -97,6 +97,9 @@ struct panthor_gem_object {
 	/** @flags: Combination of drm_panthor_bo_flags flags. */
 	u32 flags;
 
+	/** @imported: Has this BO been imported? */
+	bool imported;
+
 	/**
 	 * @label: BO tagging fields. The label can be assigned within the
 	 * driver itself or through a specific IOCTL.
diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
index 6ca9a2642a4e..f6c8cdc867be 100644
--- a/drivers/gpu/drm/panthor/panthor_mmu.c
+++ b/drivers/gpu/drm/panthor/panthor_mmu.c
@@ -1104,7 +1104,7 @@ static void panthor_vm_bo_put(struct drm_gpuvm_bo *vm_bo)
 	/* If the vm_bo object was destroyed, release the pin reference that
 	 * was hold by this object.
 	 */
-	if (unpin && !drm_gem_is_imported(&bo->base.base))
+	if (unpin && !bo->imported)
 		drm_gem_shmem_unpin(&bo->base);
 
 	drm_gpuvm_put(vm);
@@ -1235,7 +1235,8 @@ static int panthor_vm_prepare_map_op_ctx(struct panthor_vm_op_ctx *op_ctx,
 	if (ret)
 		goto err_cleanup;
 
-	if (!drm_gem_is_imported(&bo->base.base)) {
+	bo->imported = drm_gem_is_imported(&bo->base.base);
+	if (!bo->imported) {
 		/* Pre-reserve the BO pages, so the map operation doesn't have to
 		 * allocate.
 		 */
@@ -1246,7 +1247,7 @@ static int panthor_vm_prepare_map_op_ctx(struct panthor_vm_op_ctx *op_ctx,
 
 	sgt = drm_gem_shmem_get_pages_sgt(&bo->base);
 	if (IS_ERR(sgt)) {
-		if (!drm_gem_is_imported(&bo->base.base))
+		if (!bo->imported)
 			drm_gem_shmem_unpin(&bo->base);
 
 		ret = PTR_ERR(sgt);
@@ -1257,7 +1258,7 @@ static int panthor_vm_prepare_map_op_ctx(struct panthor_vm_op_ctx *op_ctx,
 
 	preallocated_vm_bo = drm_gpuvm_bo_create(&vm->base, &bo->base.base);
 	if (!preallocated_vm_bo) {
-		if (!drm_gem_is_imported(&bo->base.base))
+		if (!bo->imported)
 			drm_gem_shmem_unpin(&bo->base);
 
 		ret = -ENOMEM;
@@ -1282,8 +1283,7 @@ static int panthor_vm_prepare_map_op_ctx(struct panthor_vm_op_ctx *op_ctx,
 	 * If our pre-allocated vm_bo is picked, it now retains the pin ref,
 	 * which will be released in panthor_vm_bo_put().
 	 */
-	if (preallocated_vm_bo != op_ctx->map.vm_bo &&
-	    !drm_gem_is_imported(&bo->base.base))
+	if (preallocated_vm_bo != op_ctx->map.vm_bo && !bo->imported)
 		drm_gem_shmem_unpin(&bo->base);
 
 	op_ctx->map.bo_offset = offset;


^ permalink raw reply related	[flat|nested] 27+ messages in thread

* Re: [PATCH 09/15] drm/panthor: Test for imported buffers with drm_gem_is_imported()
  2025-04-25 13:34   ` Steven Price
@ 2025-04-25 14:30     ` Boris Brezillon
  2025-04-25 14:57       ` Steven Price
  0 siblings, 1 reply; 27+ messages in thread
From: Boris Brezillon @ 2025-04-25 14:30 UTC (permalink / raw)
  To: Steven Price
  Cc: Thomas Zimmermann, airlied, simona, maarten.lankhorst, mripard,
	dri-devel, Liviu Dudau

On Fri, 25 Apr 2025 14:34:53 +0100
Steven Price <steven.price@arm.com> wrote:

> On 17/03/2025 13:06, Thomas Zimmermann wrote:
> > Instead of testing import_attach for imported GEM buffers, invoke
> > drm_gem_is_imported() to do the test. The helper tests the dma_buf
> > itself while import_attach is just an artifact of the import. Prepares
> > to make import_attach optional.
> > 
> > Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> > Cc: Boris Brezillon <boris.brezillon@collabora.com>
> > Cc: Steven Price <steven.price@arm.com>
> > Cc: Liviu Dudau <liviu.dudau@arm.com>
> > ---
> >  drivers/gpu/drm/panthor/panthor_gem.c |  2 +-
> >  drivers/gpu/drm/panthor/panthor_mmu.c | 10 +++++-----
> >  2 files changed, 6 insertions(+), 6 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/panthor/panthor_gem.c
> > index 8244a4e6c2a2..fd014ccc3bfc 100644
> > --- a/drivers/gpu/drm/panthor/panthor_gem.c
> > +++ b/drivers/gpu/drm/panthor/panthor_gem.c
> > @@ -155,7 +155,7 @@ static enum drm_gem_object_status panthor_gem_status(struct drm_gem_object *obj)
> >  	struct panthor_gem_object *bo = to_panthor_bo(obj);
> >  	enum drm_gem_object_status res = 0;
> >  
> > -	if (bo->base.base.import_attach || bo->base.pages)
> > +	if (drm_gem_is_imported(&bo->base.base) || bo->base.pages)
> >  		res |= DRM_GEM_OBJECT_RESIDENT;
> >  
> >  	return res;
> > diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
> > index 12a02e28f50f..3e123159ac10 100644
> > --- a/drivers/gpu/drm/panthor/panthor_mmu.c
> > +++ b/drivers/gpu/drm/panthor/panthor_mmu.c
> > @@ -1103,7 +1103,7 @@ static void panthor_vm_bo_put(struct drm_gpuvm_bo *vm_bo)
> >  	/* If the vm_bo object was destroyed, release the pin reference that
> >  	 * was hold by this object.
> >  	 */
> > -	if (unpin && !bo->base.base.import_attach)
> > +	if (unpin && !drm_gem_is_imported(&bo->base.base))
> >  		drm_gem_shmem_unpin(&bo->base);  
> 
> I'm seeing issues on cleanup where drm_gem_is_imported() doesn't return 
> the same as !!import_attach in the above code. Specifically this appears 
> to be caused by drm_gem_object_exported_dma_buf_free() setting ->dma_buf 
> to NULL which makes the BO look like it isn't imported.
> 
> Stashing the imported state in the BO fixes the problem (see below 
> hack), but it would be nice to fix this more generally in case there are 
> other drivers that need to know the imported state during cleanup.
> 
> Any suggestions for how drm_gem_is_imported() can more accurately report 
> the state during cleanup?

This should be fixed by [1], but I wonder why it's not been merged in
drm-misc-next yet.

[1]https://patches.linaro.org/project/linux-media/patch/20250416065820.26076-1-tzimmermann@suse.de/

^ permalink raw reply	[flat|nested] 27+ messages in thread

* Re: [PATCH 09/15] drm/panthor: Test for imported buffers with drm_gem_is_imported()
  2025-04-25 14:30     ` Boris Brezillon
@ 2025-04-25 14:57       ` Steven Price
  0 siblings, 0 replies; 27+ messages in thread
From: Steven Price @ 2025-04-25 14:57 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: Thomas Zimmermann, airlied, simona, maarten.lankhorst, mripard,
	dri-devel, Liviu Dudau

On 25/04/2025 15:30, Boris Brezillon wrote:
> On Fri, 25 Apr 2025 14:34:53 +0100
> Steven Price <steven.price@arm.com> wrote:
> 
>> On 17/03/2025 13:06, Thomas Zimmermann wrote:
>>> Instead of testing import_attach for imported GEM buffers, invoke
>>> drm_gem_is_imported() to do the test. The helper tests the dma_buf
>>> itself while import_attach is just an artifact of the import. Prepares
>>> to make import_attach optional.
>>>
>>> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
>>> Cc: Boris Brezillon <boris.brezillon@collabora.com>
>>> Cc: Steven Price <steven.price@arm.com>
>>> Cc: Liviu Dudau <liviu.dudau@arm.com>
>>> ---
>>>  drivers/gpu/drm/panthor/panthor_gem.c |  2 +-
>>>  drivers/gpu/drm/panthor/panthor_mmu.c | 10 +++++-----
>>>  2 files changed, 6 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/panthor/panthor_gem.c
>>> index 8244a4e6c2a2..fd014ccc3bfc 100644
>>> --- a/drivers/gpu/drm/panthor/panthor_gem.c
>>> +++ b/drivers/gpu/drm/panthor/panthor_gem.c
>>> @@ -155,7 +155,7 @@ static enum drm_gem_object_status panthor_gem_status(struct drm_gem_object *obj)
>>>  	struct panthor_gem_object *bo = to_panthor_bo(obj);
>>>  	enum drm_gem_object_status res = 0;
>>>  
>>> -	if (bo->base.base.import_attach || bo->base.pages)
>>> +	if (drm_gem_is_imported(&bo->base.base) || bo->base.pages)
>>>  		res |= DRM_GEM_OBJECT_RESIDENT;
>>>  
>>>  	return res;
>>> diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
>>> index 12a02e28f50f..3e123159ac10 100644
>>> --- a/drivers/gpu/drm/panthor/panthor_mmu.c
>>> +++ b/drivers/gpu/drm/panthor/panthor_mmu.c
>>> @@ -1103,7 +1103,7 @@ static void panthor_vm_bo_put(struct drm_gpuvm_bo *vm_bo)
>>>  	/* If the vm_bo object was destroyed, release the pin reference that
>>>  	 * was hold by this object.
>>>  	 */
>>> -	if (unpin && !bo->base.base.import_attach)
>>> +	if (unpin && !drm_gem_is_imported(&bo->base.base))
>>>  		drm_gem_shmem_unpin(&bo->base);  
>>
>> I'm seeing issues on cleanup where drm_gem_is_imported() doesn't return 
>> the same as !!import_attach in the above code. Specifically this appears 
>> to be caused by drm_gem_object_exported_dma_buf_free() setting ->dma_buf 
>> to NULL which makes the BO look like it isn't imported.
>>
>> Stashing the imported state in the BO fixes the problem (see below 
>> hack), but it would be nice to fix this more generally in case there are 
>> other drivers that need to know the imported state during cleanup.
>>
>> Any suggestions for how drm_gem_is_imported() can more accurately report 
>> the state during cleanup?
> 
> This should be fixed by [1], but I wonder why it's not been merged in
> drm-misc-next yet.

Ah, yes that's exactly the bug I'm seeing - I missed the patch being
posted. Thanks for the link!

Steve

> [1]https://patches.linaro.org/project/linux-media/patch/20250416065820.26076-1-tzimmermann@suse.de/


^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2025-04-25 14:57 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-17 13:06 [PATCH 00/15] drm: Do not use import_attach in drivers Thomas Zimmermann
2025-03-17 13:06 ` [PATCH 01/15] drm/armada: Test for imported buffers with drm_gem_is_imported() Thomas Zimmermann
2025-03-17 13:06 ` [PATCH 02/15] drm/etnaviv: " Thomas Zimmermann
2025-03-17 13:06 ` [PATCH 03/15] drm/etnaviv: Use dma_buf from GEM object instance Thomas Zimmermann
2025-03-17 14:54   ` Lucas Stach
2025-03-17 13:06 ` [PATCH 04/15] drm/exynos: Test for imported buffers with drm_gem_is_imported() Thomas Zimmermann
2025-03-17 13:06 ` [PATCH 05/15] drm/gud: " Thomas Zimmermann
2025-03-17 13:06 ` [PATCH 06/15] drm/msm: " Thomas Zimmermann
2025-03-17 14:10   ` Dmitry Baryshkov
2025-03-17 13:06 ` [PATCH 07/15] drm/omapdrm: " Thomas Zimmermann
2025-03-17 13:06 ` [PATCH 08/15] drm/panfrost: " Thomas Zimmermann
2025-03-31  9:02   ` Steven Price
2025-03-17 13:06 ` [PATCH 09/15] drm/panthor: " Thomas Zimmermann
2025-03-17 13:59   ` Liviu Dudau
2025-03-31  9:02   ` Steven Price
2025-04-25 13:34   ` Steven Price
2025-04-25 14:30     ` Boris Brezillon
2025-04-25 14:57       ` Steven Price
2025-03-17 13:06 ` [PATCH 10/15] drm/rockchip: " Thomas Zimmermann
2025-03-17 13:06 ` [PATCH 11/15] drm/vc4: " Thomas Zimmermann
2025-03-17 13:06 ` [PATCH 12/15] drm/virtio: " Thomas Zimmermann
2025-03-17 13:06 ` [PATCH 13/15] drm/vmwgfx: " Thomas Zimmermann
2025-03-17 16:12   ` Zack Rusin
2025-03-17 13:06 ` [PATCH 14/15] drm/vmwgfx: Use dma_buf from GEM object instance Thomas Zimmermann
2025-03-17 16:13   ` Zack Rusin
2025-03-17 13:06 ` [PATCH 15/15] drm/xen: Test for imported buffers with drm_gem_is_imported() Thomas Zimmermann
2025-04-10 17:27 ` [PATCH 00/15] drm: Do not use import_attach in drivers Thomas Zimmermann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.