intel-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/7] drm: Revert general use of struct drm_gem_object.dma_buf
@ 2025-07-15  8:07 Thomas Zimmermann
  2025-07-15  8:07 ` [PATCH v2 1/7] Revert "drm/virtio: Use dma_buf from GEM object instance" Thomas Zimmermann
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Thomas Zimmermann @ 2025-07-15  8:07 UTC (permalink / raw)
  To: simona, airlied, christian.koenig, torvalds, maarten.lankhorst,
	mripard, l.stach, linux+etnaviv, kraxel, christian.gmeiner,
	dmitry.osipenko, gurchetansingh, olvaffe, zack.rusin
  Cc: bcm-kernel-feedback-list, dri-devel, etnaviv, virtualization,
	intel-gfx, Thomas Zimmermann

Revert the use of drm_gem_object.dma_buf back to .import_attach->dmabuf
in the affected places. Separates references to imported and exported DMA
bufs within a GEM object; as before.

The dma_buf field in struct drm_gem_object is not stable over the object
instance's lifetime. The field becomes NULL when user space releases the
final GEM handle on the buffer object. This resulted in a NULL-pointer
deref.

Workarounds in commit 5307dce878d4 ("drm/gem: Acquire references on GEM
handles for framebuffers") and commit f6bfc9afc751 ("drm/framebuffer:
Acquire internal references on GEM handles") only solved the problem
partially. They especially don't work for buffer objects without a DRM
framebuffer associated.

v2:
- extended commit messages (Sima)
- drop the GEM-handle changes to be resolved separately

Thomas Zimmermann (7):
  Revert "drm/virtio: Use dma_buf from GEM object instance"
  Revert "drm/vmwgfx: Use dma_buf from GEM object instance"
  Revert "drm/etnaviv: Use dma_buf from GEM object instance"
  Revert "drm/prime: Use dma_buf from GEM object instance"
  Revert "drm/gem-framebuffer: Use dma_buf from GEM object instance"
  Revert "drm/gem-shmem: Use dma_buf from GEM object instance"
  Revert "drm/gem-dma: Use dma_buf from GEM object instance"

 drivers/gpu/drm/drm_gem_dma_helper.c         | 2 +-
 drivers/gpu/drm/drm_gem_framebuffer_helper.c | 8 ++++++--
 drivers/gpu/drm/drm_gem_shmem_helper.c       | 4 ++--
 drivers/gpu/drm/drm_prime.c                  | 8 +++++++-
 drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c  | 4 ++--
 drivers/gpu/drm/virtio/virtgpu_prime.c       | 5 +++--
 drivers/gpu/drm/vmwgfx/vmwgfx_gem.c          | 6 +++---
 7 files changed, 24 insertions(+), 13 deletions(-)

-- 
2.50.0


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

* [PATCH v2 1/7] Revert "drm/virtio: Use dma_buf from GEM object instance"
  2025-07-15  8:07 [PATCH v2 0/7] drm: Revert general use of struct drm_gem_object.dma_buf Thomas Zimmermann
@ 2025-07-15  8:07 ` Thomas Zimmermann
  2025-07-15  8:07 ` [PATCH v2 2/7] Revert "drm/vmwgfx: " Thomas Zimmermann
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Thomas Zimmermann @ 2025-07-15  8:07 UTC (permalink / raw)
  To: simona, airlied, christian.koenig, torvalds, maarten.lankhorst,
	mripard, l.stach, linux+etnaviv, kraxel, christian.gmeiner,
	dmitry.osipenko, gurchetansingh, olvaffe, zack.rusin
  Cc: bcm-kernel-feedback-list, dri-devel, etnaviv, virtualization,
	intel-gfx, Thomas Zimmermann, Simona Vetter

This reverts commit 415cb45895f43015515473fbc40563ca5eec9a7c.

The dma_buf field in struct drm_gem_object is not stable over the
object instance's lifetime. The field becomes NULL when user space
releases the final GEM handle on the buffer object. This resulted
in a NULL-pointer deref.

Workarounds in commit 5307dce878d4 ("drm/gem: Acquire references on
GEM handles for framebuffers") and commit f6bfc9afc751 ("drm/framebuffer:
Acquire internal references on GEM handles") only solved the problem
partially. They especially don't work for buffer objects without a DRM
framebuffer associated.

Hence, this revert to going back to using .import_attach->dmabuf.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Simona Vetter <simona.vetter@ffwll.ch>
---
 drivers/gpu/drm/virtio/virtgpu_prime.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/virtio/virtgpu_prime.c b/drivers/gpu/drm/virtio/virtgpu_prime.c
index 722cde5e2d86..97aaee26cb02 100644
--- a/drivers/gpu/drm/virtio/virtgpu_prime.c
+++ b/drivers/gpu/drm/virtio/virtgpu_prime.c
@@ -204,15 +204,16 @@ static void virtgpu_dma_buf_free_obj(struct drm_gem_object *obj)
 {
 	struct virtio_gpu_object *bo = gem_to_virtio_gpu_obj(obj);
 	struct virtio_gpu_device *vgdev = obj->dev->dev_private;
+	struct dma_buf_attachment *attach = obj->import_attach;
 
 	if (drm_gem_is_imported(obj)) {
-		struct dma_buf *dmabuf = bo->dma_buf;
+		struct dma_buf *dmabuf = attach->dmabuf;
 
 		dma_resv_lock(dmabuf->resv, NULL);
 		virtgpu_dma_buf_unmap(bo);
 		dma_resv_unlock(dmabuf->resv);
 
-		dma_buf_detach(dmabuf, obj->import_attach);
+		dma_buf_detach(dmabuf, attach);
 		dma_buf_put(dmabuf);
 	}
 
-- 
2.50.0


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

* [PATCH v2 2/7] Revert "drm/vmwgfx: Use dma_buf from GEM object instance"
  2025-07-15  8:07 [PATCH v2 0/7] drm: Revert general use of struct drm_gem_object.dma_buf Thomas Zimmermann
  2025-07-15  8:07 ` [PATCH v2 1/7] Revert "drm/virtio: Use dma_buf from GEM object instance" Thomas Zimmermann
@ 2025-07-15  8:07 ` Thomas Zimmermann
  2025-07-15  8:07 ` [PATCH v2 3/7] Revert "drm/etnaviv: " Thomas Zimmermann
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Thomas Zimmermann @ 2025-07-15  8:07 UTC (permalink / raw)
  To: simona, airlied, christian.koenig, torvalds, maarten.lankhorst,
	mripard, l.stach, linux+etnaviv, kraxel, christian.gmeiner,
	dmitry.osipenko, gurchetansingh, olvaffe, zack.rusin
  Cc: bcm-kernel-feedback-list, dri-devel, etnaviv, virtualization,
	intel-gfx, Thomas Zimmermann, Simona Vetter

This reverts commit aec8a40228acb385d60feec59b54573d307e60f3.

The dma_buf field in struct drm_gem_object is not stable over the
object instance's lifetime. The field becomes NULL when user space
releases the final GEM handle on the buffer object. This resulted
in a NULL-pointer deref.

Workarounds in commit 5307dce878d4 ("drm/gem: Acquire references on
GEM handles for framebuffers") and commit f6bfc9afc751 ("drm/framebuffer:
Acquire internal references on GEM handles") only solved the problem
partially. They especially don't work for buffer objects without a DRM
framebuffer associated.

Hence, this revert to going back to using .import_attach->dmabuf.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Simona Vetter <simona.vetter@ffwll.ch>
---
 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 7057d852951b..eedf1fe60be7 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->dma_buf, map);
+		ret = dma_buf_vmap(obj->import_attach->dmabuf, map);
 		if (!ret) {
 			if (drm_WARN_ON(obj->dev, map->is_iomem)) {
-				dma_buf_vunmap(obj->dma_buf, map);
+				dma_buf_vunmap(obj->import_attach->dmabuf, 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->dma_buf, map);
+		dma_buf_vunmap(obj->import_attach->dmabuf, map);
 	else
 		drm_gem_ttm_vunmap(obj, map);
 }
-- 
2.50.0


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

* [PATCH v2 3/7] Revert "drm/etnaviv: Use dma_buf from GEM object instance"
  2025-07-15  8:07 [PATCH v2 0/7] drm: Revert general use of struct drm_gem_object.dma_buf Thomas Zimmermann
  2025-07-15  8:07 ` [PATCH v2 1/7] Revert "drm/virtio: Use dma_buf from GEM object instance" Thomas Zimmermann
  2025-07-15  8:07 ` [PATCH v2 2/7] Revert "drm/vmwgfx: " Thomas Zimmermann
@ 2025-07-15  8:07 ` Thomas Zimmermann
  2025-07-15  8:07 ` [PATCH v2 4/7] Revert "drm/prime: " Thomas Zimmermann
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Thomas Zimmermann @ 2025-07-15  8:07 UTC (permalink / raw)
  To: simona, airlied, christian.koenig, torvalds, maarten.lankhorst,
	mripard, l.stach, linux+etnaviv, kraxel, christian.gmeiner,
	dmitry.osipenko, gurchetansingh, olvaffe, zack.rusin
  Cc: bcm-kernel-feedback-list, dri-devel, etnaviv, virtualization,
	intel-gfx, Thomas Zimmermann, Simona Vetter

This reverts commit e91eb3ae415472b28211d7fed07fa283845b311e.

The dma_buf field in struct drm_gem_object is not stable over the
object instance's lifetime. The field becomes NULL when user space
releases the final GEM handle on the buffer object. This resulted
in a NULL-pointer deref.

Workarounds in commit 5307dce878d4 ("drm/gem: Acquire references on
GEM handles for framebuffers") and commit f6bfc9afc751 ("drm/framebuffer:
Acquire internal references on GEM handles") only solved the problem
partially. They especially don't work for buffer objects without a DRM
framebuffer associated.

Hence, this revert to going back to using .import_attach->dmabuf.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Simona Vetter <simona.vetter@ffwll.ch>
---
 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 917ad527c961..40a50c60dfff 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.dma_buf, &map);
+		dma_buf_vunmap_unlocked(etnaviv_obj->base.import_attach->dmabuf, &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.dma_buf, &map);
+	ret = dma_buf_vmap(etnaviv_obj->base.import_attach->dmabuf, &map);
 	if (ret)
 		return NULL;
 	return map.vaddr;
-- 
2.50.0


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

* [PATCH v2 4/7] Revert "drm/prime: Use dma_buf from GEM object instance"
  2025-07-15  8:07 [PATCH v2 0/7] drm: Revert general use of struct drm_gem_object.dma_buf Thomas Zimmermann
                   ` (2 preceding siblings ...)
  2025-07-15  8:07 ` [PATCH v2 3/7] Revert "drm/etnaviv: " Thomas Zimmermann
@ 2025-07-15  8:07 ` Thomas Zimmermann
  2025-07-15  8:07 ` [PATCH v2 5/7] Revert "drm/gem-framebuffer: " Thomas Zimmermann
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Thomas Zimmermann @ 2025-07-15  8:07 UTC (permalink / raw)
  To: simona, airlied, christian.koenig, torvalds, maarten.lankhorst,
	mripard, l.stach, linux+etnaviv, kraxel, christian.gmeiner,
	dmitry.osipenko, gurchetansingh, olvaffe, zack.rusin
  Cc: bcm-kernel-feedback-list, dri-devel, etnaviv, virtualization,
	intel-gfx, Thomas Zimmermann, Simona Vetter

This reverts commit f83a9b8c7fd0557b0c50784bfdc1bbe9140c9bf8.

The dma_buf field in struct drm_gem_object is not stable over the
object instance's lifetime. The field becomes NULL when user space
releases the final GEM handle on the buffer object. This resulted
in a NULL-pointer deref.

Workarounds in commit 5307dce878d4 ("drm/gem: Acquire references on
GEM handles for framebuffers") and commit f6bfc9afc751 ("drm/framebuffer:
Acquire internal references on GEM handles") only solved the problem
partially. They especially don't work for buffer objects without a DRM
framebuffer associated.

Hence, this revert to going back to using .import_attach->dmabuf.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Simona Vetter <simona.vetter@ffwll.ch>
---
 drivers/gpu/drm/drm_prime.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c
index b703f83874e1..a23fc712a8b7 100644
--- a/drivers/gpu/drm/drm_prime.c
+++ b/drivers/gpu/drm/drm_prime.c
@@ -453,7 +453,13 @@ struct dma_buf *drm_gem_prime_handle_to_dmabuf(struct drm_device *dev,
 	}
 
 	mutex_lock(&dev->object_name_lock);
-	/* re-export the original imported/exported object */
+	/* re-export the original imported object */
+	if (obj->import_attach) {
+		dmabuf = obj->import_attach->dmabuf;
+		get_dma_buf(dmabuf);
+		goto out_have_obj;
+	}
+
 	if (obj->dma_buf) {
 		get_dma_buf(obj->dma_buf);
 		dmabuf = obj->dma_buf;
-- 
2.50.0


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

* [PATCH v2 5/7] Revert "drm/gem-framebuffer: Use dma_buf from GEM object instance"
  2025-07-15  8:07 [PATCH v2 0/7] drm: Revert general use of struct drm_gem_object.dma_buf Thomas Zimmermann
                   ` (3 preceding siblings ...)
  2025-07-15  8:07 ` [PATCH v2 4/7] Revert "drm/prime: " Thomas Zimmermann
@ 2025-07-15  8:07 ` Thomas Zimmermann
  2025-07-15  8:07 ` [PATCH v2 6/7] Revert "drm/gem-shmem: " Thomas Zimmermann
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Thomas Zimmermann @ 2025-07-15  8:07 UTC (permalink / raw)
  To: simona, airlied, christian.koenig, torvalds, maarten.lankhorst,
	mripard, l.stach, linux+etnaviv, kraxel, christian.gmeiner,
	dmitry.osipenko, gurchetansingh, olvaffe, zack.rusin
  Cc: bcm-kernel-feedback-list, dri-devel, etnaviv, virtualization,
	intel-gfx, Thomas Zimmermann, Simona Vetter

This reverts commit cce16fcd7446dcff7480cd9d2b6417075ed81065.

The dma_buf field in struct drm_gem_object is not stable over the
object instance's lifetime. The field becomes NULL when user space
releases the final GEM handle on the buffer object. This resulted
in a NULL-pointer deref.

Workarounds in commit 5307dce878d4 ("drm/gem: Acquire references on
GEM handles for framebuffers") and commit f6bfc9afc751 ("drm/framebuffer:
Acquire internal references on GEM handles") only solved the problem
partially. They especially don't work for buffer objects without a DRM
framebuffer associated.

Hence, this revert to going back to using .import_attach->dmabuf.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Simona Vetter <simona.vetter@ffwll.ch>
---
 drivers/gpu/drm/drm_gem_framebuffer_helper.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
index 618ce725cd75..fefb2a0f6b40 100644
--- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c
+++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
@@ -420,6 +420,7 @@ EXPORT_SYMBOL(drm_gem_fb_vunmap);
 static void __drm_gem_fb_end_cpu_access(struct drm_framebuffer *fb, enum dma_data_direction dir,
 					unsigned int num_planes)
 {
+	struct dma_buf_attachment *import_attach;
 	struct drm_gem_object *obj;
 	int ret;
 
@@ -428,9 +429,10 @@ static void __drm_gem_fb_end_cpu_access(struct drm_framebuffer *fb, enum dma_dat
 		obj = drm_gem_fb_get_obj(fb, num_planes);
 		if (!obj)
 			continue;
+		import_attach = obj->import_attach;
 		if (!drm_gem_is_imported(obj))
 			continue;
-		ret = dma_buf_end_cpu_access(obj->dma_buf, dir);
+		ret = dma_buf_end_cpu_access(import_attach->dmabuf, dir);
 		if (ret)
 			drm_err(fb->dev, "dma_buf_end_cpu_access(%u, %d) failed: %d\n",
 				ret, num_planes, dir);
@@ -453,6 +455,7 @@ static void __drm_gem_fb_end_cpu_access(struct drm_framebuffer *fb, enum dma_dat
  */
 int drm_gem_fb_begin_cpu_access(struct drm_framebuffer *fb, enum dma_data_direction dir)
 {
+	struct dma_buf_attachment *import_attach;
 	struct drm_gem_object *obj;
 	unsigned int i;
 	int ret;
@@ -463,9 +466,10 @@ int drm_gem_fb_begin_cpu_access(struct drm_framebuffer *fb, enum dma_data_direct
 			ret = -EINVAL;
 			goto err___drm_gem_fb_end_cpu_access;
 		}
+		import_attach = obj->import_attach;
 		if (!drm_gem_is_imported(obj))
 			continue;
-		ret = dma_buf_begin_cpu_access(obj->dma_buf, dir);
+		ret = dma_buf_begin_cpu_access(import_attach->dmabuf, dir);
 		if (ret)
 			goto err___drm_gem_fb_end_cpu_access;
 	}
-- 
2.50.0


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

* [PATCH v2 6/7] Revert "drm/gem-shmem: Use dma_buf from GEM object instance"
  2025-07-15  8:07 [PATCH v2 0/7] drm: Revert general use of struct drm_gem_object.dma_buf Thomas Zimmermann
                   ` (4 preceding siblings ...)
  2025-07-15  8:07 ` [PATCH v2 5/7] Revert "drm/gem-framebuffer: " Thomas Zimmermann
@ 2025-07-15  8:07 ` Thomas Zimmermann
  2025-07-15  8:07 ` [PATCH v2 7/7] Revert "drm/gem-dma: " Thomas Zimmermann
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Thomas Zimmermann @ 2025-07-15  8:07 UTC (permalink / raw)
  To: simona, airlied, christian.koenig, torvalds, maarten.lankhorst,
	mripard, l.stach, linux+etnaviv, kraxel, christian.gmeiner,
	dmitry.osipenko, gurchetansingh, olvaffe, zack.rusin
  Cc: bcm-kernel-feedback-list, dri-devel, etnaviv, virtualization,
	intel-gfx, Thomas Zimmermann, Simona Vetter

This reverts commit 1a148af06000e545e714fe3210af3d77ff903c11.

The dma_buf field in struct drm_gem_object is not stable over the
object instance's lifetime. The field becomes NULL when user space
releases the final GEM handle on the buffer object. This resulted
in a NULL-pointer deref.

Workarounds in commit 5307dce878d4 ("drm/gem: Acquire references on
GEM handles for framebuffers") and commit f6bfc9afc751 ("drm/framebuffer:
Acquire internal references on GEM handles") only solved the problem
partially. They especially don't work for buffer objects without a DRM
framebuffer associated.

Hence, this revert to going back to using .import_attach->dmabuf.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Simona Vetter <simona.vetter@ffwll.ch>
---
 drivers/gpu/drm/drm_gem_shmem_helper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c
index 8ac0b1fa5287..5d1349c34afd 100644
--- a/drivers/gpu/drm/drm_gem_shmem_helper.c
+++ b/drivers/gpu/drm/drm_gem_shmem_helper.c
@@ -351,7 +351,7 @@ int drm_gem_shmem_vmap_locked(struct drm_gem_shmem_object *shmem,
 	dma_resv_assert_held(obj->resv);
 
 	if (drm_gem_is_imported(obj)) {
-		ret = dma_buf_vmap(obj->dma_buf, map);
+		ret = dma_buf_vmap(obj->import_attach->dmabuf, map);
 	} else {
 		pgprot_t prot = PAGE_KERNEL;
 
@@ -413,7 +413,7 @@ void drm_gem_shmem_vunmap_locked(struct drm_gem_shmem_object *shmem,
 	dma_resv_assert_held(obj->resv);
 
 	if (drm_gem_is_imported(obj)) {
-		dma_buf_vunmap(obj->dma_buf, map);
+		dma_buf_vunmap(obj->import_attach->dmabuf, map);
 	} else {
 		dma_resv_assert_held(shmem->base.resv);
 
-- 
2.50.0


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

* [PATCH v2 7/7] Revert "drm/gem-dma: Use dma_buf from GEM object instance"
  2025-07-15  8:07 [PATCH v2 0/7] drm: Revert general use of struct drm_gem_object.dma_buf Thomas Zimmermann
                   ` (5 preceding siblings ...)
  2025-07-15  8:07 ` [PATCH v2 6/7] Revert "drm/gem-shmem: " Thomas Zimmermann
@ 2025-07-15  8:07 ` Thomas Zimmermann
  2025-07-15  8:43 ` [PATCH v2 0/7] drm: Revert general use of struct drm_gem_object.dma_buf Christian König
  2025-07-15 19:37 ` ✓ i915.CI.BAT: success for drm: Revert general use of struct drm_gem_object.dma_buf (rev2) Patchwork
  8 siblings, 0 replies; 10+ messages in thread
From: Thomas Zimmermann @ 2025-07-15  8:07 UTC (permalink / raw)
  To: simona, airlied, christian.koenig, torvalds, maarten.lankhorst,
	mripard, l.stach, linux+etnaviv, kraxel, christian.gmeiner,
	dmitry.osipenko, gurchetansingh, olvaffe, zack.rusin
  Cc: bcm-kernel-feedback-list, dri-devel, etnaviv, virtualization,
	intel-gfx, Thomas Zimmermann, Simona Vetter

This reverts commit e8afa1557f4f963c9a511bd2c6074a941c308685.

The dma_buf field in struct drm_gem_object is not stable over the
object instance's lifetime. The field becomes NULL when user space
releases the final GEM handle on the buffer object. This resulted
in a NULL-pointer deref.

Workarounds in commit 5307dce878d4 ("drm/gem: Acquire references on
GEM handles for framebuffers") and commit f6bfc9afc751 ("drm/framebuffer:
Acquire internal references on GEM handles") only solved the problem
partially. They especially don't work for buffer objects without a DRM
framebuffer associated.

Hence, this revert to going back to using .import_attach->dmabuf.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Simona Vetter <simona.vetter@ffwll.ch>
---
 drivers/gpu/drm/drm_gem_dma_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_gem_dma_helper.c b/drivers/gpu/drm/drm_gem_dma_helper.c
index b7f033d4352a..4f0320df858f 100644
--- a/drivers/gpu/drm/drm_gem_dma_helper.c
+++ b/drivers/gpu/drm/drm_gem_dma_helper.c
@@ -230,7 +230,7 @@ void drm_gem_dma_free(struct drm_gem_dma_object *dma_obj)
 
 	if (drm_gem_is_imported(gem_obj)) {
 		if (dma_obj->vaddr)
-			dma_buf_vunmap_unlocked(gem_obj->dma_buf, &map);
+			dma_buf_vunmap_unlocked(gem_obj->import_attach->dmabuf, &map);
 		drm_prime_gem_destroy(gem_obj, dma_obj->sgt);
 	} else if (dma_obj->vaddr) {
 		if (dma_obj->map_noncoherent)
-- 
2.50.0


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

* Re: [PATCH v2 0/7] drm: Revert general use of struct drm_gem_object.dma_buf
  2025-07-15  8:07 [PATCH v2 0/7] drm: Revert general use of struct drm_gem_object.dma_buf Thomas Zimmermann
                   ` (6 preceding siblings ...)
  2025-07-15  8:07 ` [PATCH v2 7/7] Revert "drm/gem-dma: " Thomas Zimmermann
@ 2025-07-15  8:43 ` Christian König
  2025-07-15 19:37 ` ✓ i915.CI.BAT: success for drm: Revert general use of struct drm_gem_object.dma_buf (rev2) Patchwork
  8 siblings, 0 replies; 10+ messages in thread
From: Christian König @ 2025-07-15  8:43 UTC (permalink / raw)
  To: Thomas Zimmermann, simona, airlied, torvalds, maarten.lankhorst,
	mripard, l.stach, linux+etnaviv, kraxel, christian.gmeiner,
	dmitry.osipenko, gurchetansingh, olvaffe, zack.rusin
  Cc: bcm-kernel-feedback-list, dri-devel, etnaviv, virtualization,
	intel-gfx

If it helps Acked-by: Christian König <christian.koenig@amd.com> for the entire series.

Regards,
Christian.

On 15.07.25 10:07, Thomas Zimmermann wrote:
> Revert the use of drm_gem_object.dma_buf back to .import_attach->dmabuf
> in the affected places. Separates references to imported and exported DMA
> bufs within a GEM object; as before.
> 
> The dma_buf field in struct drm_gem_object is not stable over the object
> instance's lifetime. The field becomes NULL when user space releases the
> final GEM handle on the buffer object. This resulted in a NULL-pointer
> deref.
> 
> Workarounds in commit 5307dce878d4 ("drm/gem: Acquire references on GEM
> handles for framebuffers") and commit f6bfc9afc751 ("drm/framebuffer:
> Acquire internal references on GEM handles") only solved the problem
> partially. They especially don't work for buffer objects without a DRM
> framebuffer associated.
> 
> v2:
> - extended commit messages (Sima)
> - drop the GEM-handle changes to be resolved separately
> 
> Thomas Zimmermann (7):
>   Revert "drm/virtio: Use dma_buf from GEM object instance"
>   Revert "drm/vmwgfx: Use dma_buf from GEM object instance"
>   Revert "drm/etnaviv: Use dma_buf from GEM object instance"
>   Revert "drm/prime: Use dma_buf from GEM object instance"
>   Revert "drm/gem-framebuffer: Use dma_buf from GEM object instance"
>   Revert "drm/gem-shmem: Use dma_buf from GEM object instance"
>   Revert "drm/gem-dma: Use dma_buf from GEM object instance"
> 
>  drivers/gpu/drm/drm_gem_dma_helper.c         | 2 +-
>  drivers/gpu/drm/drm_gem_framebuffer_helper.c | 8 ++++++--
>  drivers/gpu/drm/drm_gem_shmem_helper.c       | 4 ++--
>  drivers/gpu/drm/drm_prime.c                  | 8 +++++++-
>  drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c  | 4 ++--
>  drivers/gpu/drm/virtio/virtgpu_prime.c       | 5 +++--
>  drivers/gpu/drm/vmwgfx/vmwgfx_gem.c          | 6 +++---
>  7 files changed, 24 insertions(+), 13 deletions(-)
> 


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

* ✓ i915.CI.BAT: success for drm: Revert general use of struct drm_gem_object.dma_buf (rev2)
  2025-07-15  8:07 [PATCH v2 0/7] drm: Revert general use of struct drm_gem_object.dma_buf Thomas Zimmermann
                   ` (7 preceding siblings ...)
  2025-07-15  8:43 ` [PATCH v2 0/7] drm: Revert general use of struct drm_gem_object.dma_buf Christian König
@ 2025-07-15 19:37 ` Patchwork
  8 siblings, 0 replies; 10+ messages in thread
From: Patchwork @ 2025-07-15 19:37 UTC (permalink / raw)
  To: Thomas Zimmermann; +Cc: intel-gfx

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

== Series Details ==

Series: drm: Revert general use of struct drm_gem_object.dma_buf (rev2)
URL   : https://patchwork.freedesktop.org/series/151494/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_16864 -> Patchwork_151494v2
====================================================

Summary
-------

  **SUCCESS**

  No regressions found.

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

Participating hosts (44 -> 44)
------------------------------

  Additional (1): fi-glk-j4005 
  Missing    (1): fi-snb-2520m 

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

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

### IGT changes ###

#### Issues hit ####

  * igt@dmabuf@all-tests:
    - bat-apl-1:          [PASS][1] -> [ABORT][2] ([i915#12904]) +1 other test abort
   [1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_16864/bat-apl-1/igt@dmabuf@all-tests.html
   [2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_151494v2/bat-apl-1/igt@dmabuf@all-tests.html

  * igt@gem_huc_copy@huc-copy:
    - fi-glk-j4005:       NOTRUN -> [SKIP][3] ([i915#2190])
   [3]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_151494v2/fi-glk-j4005/igt@gem_huc_copy@huc-copy.html

  * igt@gem_lmem_swapping@parallel-random-engines:
    - fi-glk-j4005:       NOTRUN -> [SKIP][4] ([i915#4613]) +3 other tests skip
   [4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_151494v2/fi-glk-j4005/igt@gem_lmem_swapping@parallel-random-engines.html

  * igt@i915_selftest@live@workarounds:
    - bat-dg2-14:         [PASS][5] -> [DMESG-FAIL][6] ([i915#12061]) +1 other test dmesg-fail
   [5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_16864/bat-dg2-14/igt@i915_selftest@live@workarounds.html
   [6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_151494v2/bat-dg2-14/igt@i915_selftest@live@workarounds.html

  * igt@kms_psr@psr-primary-page-flip:
    - fi-glk-j4005:       NOTRUN -> [SKIP][7] +11 other tests skip
   [7]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_151494v2/fi-glk-j4005/igt@kms_psr@psr-primary-page-flip.html

  
#### Possible fixes ####

  * igt@gem_exec_fence@basic-await@vecs0:
    - bat-rpls-4:         [DMESG-WARN][8] ([i915#13400]) -> [PASS][9] +2 other tests pass
   [8]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_16864/bat-rpls-4/igt@gem_exec_fence@basic-await@vecs0.html
   [9]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_151494v2/bat-rpls-4/igt@gem_exec_fence@basic-await@vecs0.html

  * igt@i915_selftest@live:
    - bat-jsl-1:          [DMESG-FAIL][10] ([i915#13774]) -> [PASS][11] +1 other test pass
   [10]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_16864/bat-jsl-1/igt@i915_selftest@live.html
   [11]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_151494v2/bat-jsl-1/igt@i915_selftest@live.html

  * igt@i915_selftest@live@workarounds:
    - bat-arls-5:         [DMESG-FAIL][12] ([i915#12061]) -> [PASS][13] +1 other test pass
   [12]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_16864/bat-arls-5/igt@i915_selftest@live@workarounds.html
   [13]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_151494v2/bat-arls-5/igt@i915_selftest@live@workarounds.html
    - bat-mtlp-6:         [DMESG-FAIL][14] ([i915#12061]) -> [PASS][15] +1 other test pass
   [14]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_16864/bat-mtlp-6/igt@i915_selftest@live@workarounds.html
   [15]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_151494v2/bat-mtlp-6/igt@i915_selftest@live@workarounds.html
    - bat-arls-6:         [DMESG-FAIL][16] ([i915#12061]) -> [PASS][17] +1 other test pass
   [16]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_16864/bat-arls-6/igt@i915_selftest@live@workarounds.html
   [17]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_151494v2/bat-arls-6/igt@i915_selftest@live@workarounds.html

  
#### Warnings ####

  * igt@i915_selftest@live:
    - bat-atsm-1:         [DMESG-FAIL][18] ([i915#12061] / [i915#14204]) -> [DMESG-FAIL][19] ([i915#12061] / [i915#13929])
   [18]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_16864/bat-atsm-1/igt@i915_selftest@live.html
   [19]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_151494v2/bat-atsm-1/igt@i915_selftest@live.html

  * igt@i915_selftest@live@mman:
    - bat-atsm-1:         [DMESG-FAIL][20] ([i915#14204]) -> [DMESG-FAIL][21] ([i915#13929])
   [20]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_16864/bat-atsm-1/igt@i915_selftest@live@mman.html
   [21]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_151494v2/bat-atsm-1/igt@i915_selftest@live@mman.html

  
  [i915#12061]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/12061
  [i915#12904]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/12904
  [i915#13400]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/13400
  [i915#13774]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/13774
  [i915#13929]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/13929
  [i915#14204]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/14204
  [i915#2190]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/2190
  [i915#4613]: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/4613


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

  * Linux: CI_DRM_16864 -> Patchwork_151494v2

  CI-20190529: 20190529
  CI_DRM_16864: b012f04b5be909a307ff629b297387e0ed55195a @ git://anongit.freedesktop.org/gfx-ci/linux
  IGT_8457: 756ebdbf0e4c75f0680c0a36db206a9f6ff126ce @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git
  Patchwork_151494v2: b012f04b5be909a307ff629b297387e0ed55195a @ git://anongit.freedesktop.org/gfx-ci/linux

== Logs ==

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

[-- Attachment #2: Type: text/html, Size: 7103 bytes --]

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

end of thread, other threads:[~2025-07-15 19:37 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-15  8:07 [PATCH v2 0/7] drm: Revert general use of struct drm_gem_object.dma_buf Thomas Zimmermann
2025-07-15  8:07 ` [PATCH v2 1/7] Revert "drm/virtio: Use dma_buf from GEM object instance" Thomas Zimmermann
2025-07-15  8:07 ` [PATCH v2 2/7] Revert "drm/vmwgfx: " Thomas Zimmermann
2025-07-15  8:07 ` [PATCH v2 3/7] Revert "drm/etnaviv: " Thomas Zimmermann
2025-07-15  8:07 ` [PATCH v2 4/7] Revert "drm/prime: " Thomas Zimmermann
2025-07-15  8:07 ` [PATCH v2 5/7] Revert "drm/gem-framebuffer: " Thomas Zimmermann
2025-07-15  8:07 ` [PATCH v2 6/7] Revert "drm/gem-shmem: " Thomas Zimmermann
2025-07-15  8:07 ` [PATCH v2 7/7] Revert "drm/gem-dma: " Thomas Zimmermann
2025-07-15  8:43 ` [PATCH v2 0/7] drm: Revert general use of struct drm_gem_object.dma_buf Christian König
2025-07-15 19:37 ` ✓ i915.CI.BAT: success for drm: Revert general use of struct drm_gem_object.dma_buf (rev2) Patchwork

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).