drm: Do not use import_attach in drivers
Subsystems (19)
Thomas Zimmermann
maintainercover drm: Do not use import_attach in drivers
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(-)
Signature · 1 line
2.48.1
Thomas Zimmermann
maintainerPATCH 1/15 drm/armada: Test for imported buffers with drm_gem_is_imported()
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.
--- drivers/gpu/drm/armada/armada_fb.c | 2 +- drivers/gpu/drm/armada/armada_gem.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/armada/armada_fb.c +1 -1
@@ -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;
drivers/gpu/drm/armada/armada_gem.c +1 -1
@@ -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,
Signature · 1 line
2.48.1
Thomas Zimmermann
maintainerPATCH 2/15 drm/etnaviv: Test for imported buffers with drm_gem_is_imported()
In reply to Thomas ZimmermannInstead 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.
--- drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c +2 -2
@@ -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);
Signature · 1 line
2.48.1
Thomas Zimmermann
maintainerPATCH 3/15 drm/etnaviv: Use dma_buf from GEM object instance
In reply to Thomas ZimmermannAvoid 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.
--- drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c +2 -2
@@ -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;
Signature · 1 line
2.48.1
Re: [PATCH 03/15] drm/etnaviv: Use dma_buf from GEM object instance
Hi Thomas,
Am Montag, dem 17.03.2025 um 14:06 +0100 schrieb Thomas Zimmermann:
Quoted 4 lines
Avoid dereferencing struct drm_gem_object.import_attach for the imported dma-buf. The
dma_buffield in the GEM object instance refers to the same buffer. Prepares to makeimport_attachoptional.
Both etnaviv patches are
Feel free to take them through drm-misc if you want to put further cleanups on top of that series.
Regards,
Lucas
Quoted 31 lines
Signed-off-by Thomas Zimmermann <[email protected]>Cc Lucas Stach <[email protected]>Cc Russell King <[email protected]>Cc Christian Gmeiner <[email protected]>--- drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c +2
-2@@ -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;
Thomas Zimmermann
maintainerPATCH 4/15 drm/exynos: Test for imported buffers with drm_gem_is_imported()
In reply to Thomas ZimmermannInstead 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.
--- drivers/gpu/drm/exynos/exynos_drm_gem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/exynos/exynos_drm_gem.c +2 -2
@@ -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_structstruct 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 );
Signature · 1 line
2.48.1
Thomas Zimmermann
maintainerPATCH 5/15 drm/gud: Test for imported buffers with drm_gem_is_imported()
In reply to Thomas ZimmermannInstead 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.
--- drivers/gpu/drm/gud/gud_pipe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/gud/gud_pipe.c +1 -1
@@ -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,
Signature · 1 line
2.48.1
Thomas Zimmermann
maintainerPATCH 6/15 drm/msm: Test for imported buffers with drm_gem_is_imported()
In reply to Thomas ZimmermannInstead 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.
--- 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(-)
drivers/gpu/drm/msm/msm_drv.c +1 -1
@@ -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 ; }
drivers/gpu/drm/msm/msm_gem.c +2 -2
@@ -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
drivers/gpu/drm/msm/msm_gem.h +1 -1
@@ -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)
drivers/gpu/drm/msm/msm_gem_prime.c +2 -2
@@ -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);
Signature · 1 line
2.48.1
Re: [PATCH 06/15] drm/msm: Test for imported buffers with drm_gem_is_imported()
Quoted 13 lines · Thomas Zimmermann
Instead of testing
import_attachfor imported GEM buffers, invokedrm_gem_is_imported()to do the test. The helper tests thedma_bufitself whileimport_attachis just an artifact of the import. Prepares to makeimport_attachoptional.Signed-off-by Thomas Zimmermann <[email protected]>Cc Rob Clark <[email protected]>Cc Abhinav Kumar <[email protected]>Cc Dmitry Baryshkov <[email protected]>Cc Sean Paul <[email protected]>Cc Marijn Suijten <[email protected]>
Quoted 7 lines
--- 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(-)
Signature · 2 lines
With best wishes Dmitry
Thomas Zimmermann
maintainerPATCH 7/15 drm/omapdrm: Test for imported buffers with drm_gem_is_imported()
In reply to Thomas ZimmermannInstead 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.
--- drivers/gpu/drm/omapdrm/omap_gem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/omapdrm/omap_gem.c +1 -1
@@ -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); }
Signature · 1 line
2.48.1
Thomas Zimmermann
maintainerPATCH 8/15 drm/panfrost: Test for imported buffers with drm_gem_is_imported()
In reply to Thomas ZimmermannInstead 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.
--- drivers/gpu/drm/panfrost/panfrost_gem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/panfrost/panfrost_gem.c +1 -1
@@ -200,7 +200,7 @@ static enum drm_gem_object_status panfrost_gem_status(struct drm_gem_object *objstruct 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 )
Signature · 1 line
2.48.1
Re: [PATCH 08/15] drm/panfrost: Test for imported buffers with drm_gem_is_imported()
Quoted 9 lines · Thomas Zimmermann
Instead of testing
import_attachfor imported GEM buffers, invokedrm_gem_is_imported()to do the test. The helper tests thedma_bufitself whileimport_attachis just an artifact of the import. Prepares to makeimport_attachoptional.Signed-off-by Thomas Zimmermann <[email protected]>Cc Boris Brezillon <[email protected]>Cc Rob Herring <[email protected]>Cc Steven Price <[email protected]>
Quoted 17 lines
--- drivers/gpu/drm/panfrost/panfrost_gem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/panfrost/panfrost_gem.c +1
-1@@ -200,7 +200,7 @@ static enum drm_gem_object_status panfrost_gem_status(struct drm_gem_object *objstruct 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 )
Thomas Zimmermann
maintainerPATCH 9/15 drm/panthor: Test for imported buffers with drm_gem_is_imported()
In reply to Thomas ZimmermannInstead 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.
--- drivers/gpu/drm/panthor/panthor_gem.c | 2 +- drivers/gpu/drm/panthor/panthor_mmu.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/panthor/panthor_gem.c +1 -1
@@ -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;
drivers/gpu/drm/panthor/panthor_mmu.c +5 -5
@@ -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;
Signature · 1 line
2.48.1
Re: [PATCH 09/15] drm/panthor: Test for imported buffers with drm_gem_is_imported()
Quoted 9 lines · Thomas Zimmermann
Instead of testing
import_attachfor imported GEM buffers, invokedrm_gem_is_imported()to do the test. The helper tests thedma_bufitself whileimport_attachis just an artifact of the import. Prepares to makeimport_attachoptional.Signed-off-by Thomas Zimmermann <[email protected]>Cc Boris Brezillon <[email protected]>Cc Steven Price <[email protected]>Cc Liviu Dudau <[email protected]>
Best regards,
Liviu
Quoted 70 lines
--- drivers/gpu/drm/panthor/panthor_gem.c | 2 +- drivers/gpu/drm/panthor/panthor_mmu.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-)drivers/gpu/drm/panthor/panthor_gem.c +1
-1@@ -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;drivers/gpu/drm/panthor/panthor_mmu.c +5
-5@@ -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;Signature · 1 line
2.48.1
Signature · 8 lines
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯Re: [PATCH 09/15] drm/panthor: Test for imported buffers with drm_gem_is_imported()
In reply to Thomas ZimmermannQuoted 9 lines · Thomas Zimmermann
Instead of testing
import_attachfor imported GEM buffers, invokedrm_gem_is_imported()to do the test. The helper tests thedma_bufitself whileimport_attachis just an artifact of the import. Prepares to makeimport_attachoptional.Signed-off-by Thomas Zimmermann <[email protected]>Cc Boris Brezillon <[email protected]>Cc Steven Price <[email protected]>Cc Liviu Dudau <[email protected]>
Quoted 67 lines
--- drivers/gpu/drm/panthor/panthor_gem.c | 2 +- drivers/gpu/drm/panthor/panthor_mmu.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-)drivers/gpu/drm/panthor/panthor_gem.c +1
-1@@ -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;drivers/gpu/drm/panthor/panthor_mmu.c +5
-5@@ -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;
Steven Price
maintainerRe: [PATCH 09/15] drm/panthor: Test for imported buffers with drm_gem_is_imported()
In reply to Thomas ZimmermannQuoted 32 lines · Thomas Zimmermann
Instead of testing
import_attachfor imported GEM buffers, invokedrm_gem_is_imported()to do the test. The helper tests thedma_bufitself whileimport_attachis just an artifact of the import. Prepares to makeimport_attachoptional.Signed-off-by Thomas Zimmermann <[email protected]>Cc Boris Brezillon <[email protected]>Cc Steven Price <[email protected]>Cc Liviu Dudau <[email protected]>--- drivers/gpu/drm/panthor/panthor_gem.c | 2 +- drivers/gpu/drm/panthor/panthor_mmu.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-)drivers/gpu/drm/panthor/panthor_gem.c +1
-1@@ -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;drivers/gpu/drm/panthor/panthor_mmu.c +0
-0
drivers/gpu/drm/panthor/panthor_mmu.c static void panthor_vm_bo_put(struct drm_gpuvm_bo *vm_bo) · line 1107
Quoted 6 lines
drivers/gpu/drm/panthor/panthor_mmu.c +1
-1@@ -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
drivers/gpu/drm/panthor/panthor_gem.h +3 -0
@@ -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.
drivers/gpu/drm/panthor/panthor_mmu.c +6 -6
@@ -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;
Boris Brezillon
maintainerRe: [PATCH 09/15] drm/panthor: Test for imported buffers with drm_gem_is_imported()
Quoted 45 lines · On Fri, 25 Apr 2025 14:34:53 +0100 Steven Price <[email protected]> wrote:
Quoted 32 lines · Thomas Zimmermann
Instead of testing
import_attachfor imported GEM buffers, invokedrm_gem_is_imported()to do the test. The helper tests thedma_bufitself whileimport_attachis just an artifact of the import. Prepares to makeimport_attachoptional.Signed-off-by Thomas Zimmermann <[email protected]>Cc Boris Brezillon <[email protected]>Cc Steven Price <[email protected]>Cc Liviu Dudau <[email protected]>--- drivers/gpu/drm/panthor/panthor_gem.c | 2 +- drivers/gpu/drm/panthor/panthor_mmu.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-)drivers/gpu/drm/panthor/panthor_gem.c +1
-1@@ -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;drivers/gpu/drm/panthor/panthor_mmu.c +0
-0drivers/gpu/drm/panthor/panthor_mmu.c static void panthor_vm_bo_put(struct drm_gpuvm_bo *vm_bo) · line 1107
Quoted 6 lines
drivers/gpu/drm/panthor/panthor_mmu.c +1
-1@@ -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 bydrm_gem_object_exported_dma_buf_free()setting ->dma_buf to NULL which makes the BO look like it isn't imported.
Quoted 6 lines
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/[email protected]/
Steven Price
maintainerRe: [PATCH 09/15] drm/panthor: Test for imported buffers with drm_gem_is_imported()
Quoted 52 lines · Boris Brezillon
Quoted 49 lines · On Fri, 25 Apr 2025 14:34:53 +0100 Steven Price <[email protected]> wrote:
Quoted 32 lines · Thomas Zimmermann
Instead of testing
import_attachfor imported GEM buffers, invokedrm_gem_is_imported()to do the test. The helper tests thedma_bufitself whileimport_attachis just an artifact of the import. Prepares to makeimport_attachoptional.Signed-off-by Thomas Zimmermann <[email protected]>Cc Boris Brezillon <[email protected]>Cc Steven Price <[email protected]>Cc Liviu Dudau <[email protected]>--- drivers/gpu/drm/panthor/panthor_gem.c | 2 +- drivers/gpu/drm/panthor/panthor_mmu.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-)drivers/gpu/drm/panthor/panthor_gem.c +1
-1@@ -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;drivers/gpu/drm/panthor/panthor_mmu.c +0
-0drivers/gpu/drm/panthor/panthor_mmu.c static void panthor_vm_bo_put(struct drm_gpuvm_bo *vm_bo) · line 1107
Quoted 6 lines
drivers/gpu/drm/panthor/panthor_mmu.c +1
-1@@ -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 bydrm_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.
Quoted 5 lines
Quoted 2 lines
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
Thomas Zimmermann
maintainerPATCH 10/15 drm/rockchip: Test for imported buffers with drm_gem_is_imported()
In reply to Thomas ZimmermannInstead 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.
--- drivers/gpu/drm/rockchip/rockchip_drm_gem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/rockchip/rockchip_drm_gem.c +1 -1
@@ -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 {
Signature · 1 line
2.48.1
Thomas Zimmermann
maintainerPATCH 11/15 drm/vc4: Test for imported buffers with drm_gem_is_imported()
In reply to Thomas ZimmermannInstead 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.
--- drivers/gpu/drm/vc4/vc4_bo.c | 2 +- drivers/gpu/drm/vc4/vc4_gem.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/vc4/vc4_bo.c +1 -1
@@ -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; }
drivers/gpu/drm/vc4/vc4_gem.c +1 -1
@@ -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;
Signature · 1 line
2.48.1
Thomas Zimmermann
maintainerPATCH 12/15 drm/virtio: Test for imported buffers with drm_gem_is_imported()
In reply to Thomas ZimmermannInstead 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.
--- drivers/gpu/drm/virtio/virtgpu_plane.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/virtio/virtgpu_plane.c +4 -4
@@ -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);
Signature · 1 line
2.48.1
Thomas Zimmermann
maintainerPATCH 13/15 drm/vmwgfx: Test for imported buffers with drm_gem_is_imported()
In reply to Thomas ZimmermannInstead 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.
--- drivers/gpu/drm/vmwgfx/vmwgfx_blit.c | 4 ++-- drivers/gpu/drm/vmwgfx/vmwgfx_gem.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_blit.c +2 -2
@@ -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);
drivers/gpu/drm/vmwgfx/vmwgfx_gem.c +3 -3
@@ -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
Signature · 1 line
2.48.1
Re: [PATCH 13/15] drm/vmwgfx: Test for imported buffers with drm_gem_is_imported()
Quoted 68 lines · Thomas Zimmermann
Instead of testing
import_attachfor imported GEM buffers, invokedrm_gem_is_imported()to do the test. The helper tests thedma_bufitself whileimport_attachis just an artifact of the import. Prepares to makeimport_attachoptional.Signed-off-by Thomas Zimmermann <[email protected]>Cc Zack Rusin <[email protected]>Cc Broadcom internal kernel review list <[email protected]>--- drivers/gpu/drm/vmwgfx/vmwgfx_blit.c | 4 ++-- drivers/gpu/drm/vmwgfx/vmwgfx_gem.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-)drivers/gpu/drm/vmwgfx/vmwgfx_blit.c +2
-2@@ -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);drivers/gpu/drm/vmwgfx/vmwgfx_gem.c +3
-4@@ -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 --
Quoted 2 lines
2.48.1
Another great cleanup! Thanks.
z
Thomas Zimmermann
maintainerPATCH 14/15 drm/vmwgfx: Use dma_buf from GEM object instance
In reply to Thomas ZimmermannAvoid 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.
--- drivers/gpu/drm/vmwgfx/vmwgfx_gem.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_gem.c +3 -3
@@ -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); }
Signature · 1 line
2.48.1
Re: [PATCH 14/15] drm/vmwgfx: Use dma_buf from GEM object instance
Quoted 39 lines · Thomas Zimmermann
Avoid dereferencing struct drm_gem_object.import_attach for the imported dma-buf. The
dma_buffield in the GEM object instance refers to the same buffer. Prepares to makeimport_attachoptional.Signed-off-by Thomas Zimmermann <[email protected]>Cc Zack Rusin <[email protected]>Cc Broadcom internal kernel review list <[email protected]>--- drivers/gpu/drm/vmwgfx/vmwgfx_gem.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/gpu/drm/vmwgfx/vmwgfx_gem.c +3
-4@@ -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); } --
Quoted 2 lines
2.48.1
Looks good, thanks!
z
Thomas Zimmermann
maintainerPATCH 15/15 drm/xen: Test for imported buffers with drm_gem_is_imported()
In reply to Thomas ZimmermannInstead 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.
--- drivers/gpu/drm/xen/xen_drm_front_gem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/xen/xen_drm_front_gem.c +1 -1
@@ -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 {
Signature · 1 line
2.48.1
Thomas Zimmermann
maintainerPing for additional reviews of this series.
Am 17.03.25 um 14:06 schrieb Thomas Zimmermann:
Quoted 52 lines
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 avoidimport_attach.The
import_attachfield in structdrm_gem_objectis 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 whendrm_gem_is_imported()becomes available in their tree.Thomas Zimmermann (15):
drm/armada: Test for imported buffers withdrm_gem_is_imported()drm/etnaviv: Test for imported buffers withdrm_gem_is_imported()drm/etnaviv: Usedma_buffrom GEM object instance drm/exynos: Test for imported buffers withdrm_gem_is_imported()drm/gud: Test for imported buffers withdrm_gem_is_imported()drm/msm: Test for imported buffers withdrm_gem_is_imported()drm/omapdrm: Test for imported buffers withdrm_gem_is_imported()drm/panfrost: Test for imported buffers withdrm_gem_is_imported()drm/panthor: Test for imported buffers withdrm_gem_is_imported()drm/rockchip: Test for imported buffers withdrm_gem_is_imported()drm/vc4: Test for imported buffers withdrm_gem_is_imported()drm/virtio: Test for imported buffers withdrm_gem_is_imported()drm/vmwgfx: Test for imported buffers withdrm_gem_is_imported()drm/vmwgfx: Usedma_buffrom GEM object instance drm/xen: Test for imported buffers withdrm_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(-)
Signature · 7 lines
-- 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)