]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
Revert "drm/gem-framebuffer: Use dma_buf from GEM object instance"
authorThomas Zimmermann <tzimmermann@suse.de>
Tue, 15 Jul 2025 15:58:15 +0000 (17:58 +0200)
committerThomas Zimmermann <tzimmermann@suse.de>
Thu, 17 Jul 2025 10:26:19 +0000 (12:26 +0200)
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.

v3:
- cc stable

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Simona Vetter <simona.vetter@ffwll.ch>
Acked-by: Christian König <christian.koenig@amd.com>
Acked-by: Zack Rusin <zack.rusin@broadcom.com>
Cc: <stable@vger.kernel.org> # v6.15+
Link: https://lore.kernel.org/r/20250715155934.150656-6-tzimmermann@suse.de
drivers/gpu/drm/drm_gem_framebuffer_helper.c

index 6f72e7a0f42750e3697e0eabada293a761663006..6ff22e04029e937d54251885470d7ff67f7da369 100644 (file)
@@ -419,6 +419,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;
 
@@ -427,9 +428,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);
@@ -452,6 +454,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;
@@ -462,9 +465,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;
        }