Skip to content

Commit 2712ca8

Browse files
author
Thomas Zimmermann
committed
Revert "drm/gem-framebuffer: Use dma_buf from GEM object instance"
This reverts commit cce16fc. 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 5307dce ("drm/gem: Acquire references on GEM handles for framebuffers") and commit f6bfc9a ("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 <[email protected]> Reviewed-by: Simona Vetter <[email protected]> Acked-by: Christian König <[email protected]> Acked-by: Zack Rusin <[email protected]> Cc: <[email protected]> # v6.15+ Link: https://lore.kernel.org/r/[email protected]
1 parent fb4ef4a commit 2712ca8

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/gpu/drm/drm_gem_framebuffer_helper.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ EXPORT_SYMBOL(drm_gem_fb_vunmap);
419419
static void __drm_gem_fb_end_cpu_access(struct drm_framebuffer *fb, enum dma_data_direction dir,
420420
unsigned int num_planes)
421421
{
422+
struct dma_buf_attachment *import_attach;
422423
struct drm_gem_object *obj;
423424
int ret;
424425

@@ -427,9 +428,10 @@ static void __drm_gem_fb_end_cpu_access(struct drm_framebuffer *fb, enum dma_dat
427428
obj = drm_gem_fb_get_obj(fb, num_planes);
428429
if (!obj)
429430
continue;
431+
import_attach = obj->import_attach;
430432
if (!drm_gem_is_imported(obj))
431433
continue;
432-
ret = dma_buf_end_cpu_access(obj->dma_buf, dir);
434+
ret = dma_buf_end_cpu_access(import_attach->dmabuf, dir);
433435
if (ret)
434436
drm_err(fb->dev, "dma_buf_end_cpu_access(%u, %d) failed: %d\n",
435437
ret, num_planes, dir);
@@ -452,6 +454,7 @@ static void __drm_gem_fb_end_cpu_access(struct drm_framebuffer *fb, enum dma_dat
452454
*/
453455
int drm_gem_fb_begin_cpu_access(struct drm_framebuffer *fb, enum dma_data_direction dir)
454456
{
457+
struct dma_buf_attachment *import_attach;
455458
struct drm_gem_object *obj;
456459
unsigned int i;
457460
int ret;
@@ -462,9 +465,10 @@ int drm_gem_fb_begin_cpu_access(struct drm_framebuffer *fb, enum dma_data_direct
462465
ret = -EINVAL;
463466
goto err___drm_gem_fb_end_cpu_access;
464467
}
468+
import_attach = obj->import_attach;
465469
if (!drm_gem_is_imported(obj))
466470
continue;
467-
ret = dma_buf_begin_cpu_access(obj->dma_buf, dir);
471+
ret = dma_buf_begin_cpu_access(import_attach->dmabuf, dir);
468472
if (ret)
469473
goto err___drm_gem_fb_end_cpu_access;
470474
}

0 commit comments

Comments
 (0)