virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] drm/virtio: Avoid struct drm_gem_object.import_attach
@ 2025-04-14 13:11 Thomas Zimmermann
  2025-04-14 13:12 ` [PATCH 1/2] drm/virtio: Test for imported buffers with drm_gem_is_imported() Thomas Zimmermann
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Thomas Zimmermann @ 2025-04-14 13:11 UTC (permalink / raw)
  To: airlied, dmitry.osipenko, gurchetansingh, olvaffe
  Cc: dri-devel, virtualization, Thomas Zimmermann

Avoid the use of struct drm_gem_object.import_attach to get the
object's dma-buf or test for an imported buffer. The import_attach
field in struct drm_gem_object is an artifact of the import process,
but should not be used otherwise.

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.

Thomas Zimmermann (2):
  drm/virtio: Test for imported buffers with drm_gem_is_imported()
  drm/virtio: Use dma_buf from GEM object instance

 drivers/gpu/drm/virtio/virtgpu_plane.c | 8 ++++----
 drivers/gpu/drm/virtio/virtgpu_prime.c | 7 +++----
 2 files changed, 7 insertions(+), 8 deletions(-)

-- 
2.49.0


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

* [PATCH 1/2] drm/virtio: Test for imported buffers with drm_gem_is_imported()
  2025-04-14 13:11 [PATCH 0/2] drm/virtio: Avoid struct drm_gem_object.import_attach Thomas Zimmermann
@ 2025-04-14 13:12 ` Thomas Zimmermann
  2025-04-16  6:39   ` Dmitry Osipenko
  2025-04-14 13:12 ` [PATCH 2/2] drm/virtio: Use dma_buf from GEM object instance Thomas Zimmermann
  2025-04-16  7:27 ` [PATCH 0/2] drm/virtio: Avoid struct drm_gem_object.import_attach Dmitry Osipenko
  2 siblings, 1 reply; 6+ messages in thread
From: Thomas Zimmermann @ 2025-04-14 13:12 UTC (permalink / raw)
  To: airlied, dmitry.osipenko, gurchetansingh, olvaffe
  Cc: dri-devel, virtualization, 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/virtio/virtgpu_plane.c | 8 ++++----
 drivers/gpu/drm/virtio/virtgpu_prime.c | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/virtio/virtgpu_plane.c b/drivers/gpu/drm/virtio/virtgpu_plane.c
index 87e584add042..43e755248977 100644
--- a/drivers/gpu/drm/virtio/virtgpu_plane.c
+++ b/drivers/gpu/drm/virtio/virtgpu_plane.c
@@ -366,7 +366,7 @@ static int virtio_gpu_plane_prepare_fb(struct drm_plane *plane,
 		return 0;
 
 	obj = new_state->fb->obj[0];
-	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);
@@ -374,7 +374,7 @@ static int virtio_gpu_plane_prepare_fb(struct drm_plane *plane,
 			return -ENOMEM;
 	}
 
-	if (obj->import_attach) {
+	if (drm_gem_is_imported(obj)) {
 		ret = virtio_gpu_prepare_imported_obj(plane, new_state, obj);
 		if (ret)
 			goto err_fence;
@@ -417,7 +417,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);
 }
 
@@ -509,7 +509,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);
diff --git a/drivers/gpu/drm/virtio/virtgpu_prime.c b/drivers/gpu/drm/virtio/virtgpu_prime.c
index 9b4bde3fda18..ce49282198cb 100644
--- a/drivers/gpu/drm/virtio/virtgpu_prime.c
+++ b/drivers/gpu/drm/virtio/virtgpu_prime.c
@@ -206,7 +206,7 @@ static void virtgpu_dma_buf_free_obj(struct drm_gem_object *obj)
 	struct virtio_gpu_device *vgdev = obj->dev->dev_private;
 	struct dma_buf_attachment *attach = obj->import_attach;
 
-	if (attach) {
+	if (drm_gem_is_imported(obj)) {
 		struct dma_buf *dmabuf = attach->dmabuf;
 
 		dma_resv_lock(dmabuf->resv, NULL);
-- 
2.49.0


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

* [PATCH 2/2] drm/virtio: Use dma_buf from GEM object instance
  2025-04-14 13:11 [PATCH 0/2] drm/virtio: Avoid struct drm_gem_object.import_attach Thomas Zimmermann
  2025-04-14 13:12 ` [PATCH 1/2] drm/virtio: Test for imported buffers with drm_gem_is_imported() Thomas Zimmermann
@ 2025-04-14 13:12 ` Thomas Zimmermann
  2025-04-16  6:40   ` Dmitry Osipenko
  2025-04-16  7:27 ` [PATCH 0/2] drm/virtio: Avoid struct drm_gem_object.import_attach Dmitry Osipenko
  2 siblings, 1 reply; 6+ messages in thread
From: Thomas Zimmermann @ 2025-04-14 13:12 UTC (permalink / raw)
  To: airlied, dmitry.osipenko, gurchetansingh, olvaffe
  Cc: dri-devel, virtualization, 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.

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

diff --git a/drivers/gpu/drm/virtio/virtgpu_prime.c b/drivers/gpu/drm/virtio/virtgpu_prime.c
index ce49282198cb..1118a0250279 100644
--- a/drivers/gpu/drm/virtio/virtgpu_prime.c
+++ b/drivers/gpu/drm/virtio/virtgpu_prime.c
@@ -204,16 +204,15 @@ 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 = attach->dmabuf;
+		struct dma_buf *dmabuf = obj->dma_buf;
 
 		dma_resv_lock(dmabuf->resv, NULL);
 		virtgpu_dma_buf_unmap(bo);
 		dma_resv_unlock(dmabuf->resv);
 
-		dma_buf_detach(dmabuf, attach);
+		dma_buf_detach(dmabuf, obj->import_attach);
 		dma_buf_put(dmabuf);
 	}
 
-- 
2.49.0


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

* Re: [PATCH 1/2] drm/virtio: Test for imported buffers with drm_gem_is_imported()
  2025-04-14 13:12 ` [PATCH 1/2] drm/virtio: Test for imported buffers with drm_gem_is_imported() Thomas Zimmermann
@ 2025-04-16  6:39   ` Dmitry Osipenko
  0 siblings, 0 replies; 6+ messages in thread
From: Dmitry Osipenko @ 2025-04-16  6:39 UTC (permalink / raw)
  To: Thomas Zimmermann, airlied, gurchetansingh, olvaffe
  Cc: dri-devel, virtualization

On 4/14/25 16:12, 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>
> ---
>  drivers/gpu/drm/virtio/virtgpu_plane.c | 8 ++++----
>  drivers/gpu/drm/virtio/virtgpu_prime.c | 2 +-
>  2 files changed, 5 insertions(+), 5 deletions(-)

Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>

-- 
Best regards,
Dmitry

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

* Re: [PATCH 2/2] drm/virtio: Use dma_buf from GEM object instance
  2025-04-14 13:12 ` [PATCH 2/2] drm/virtio: Use dma_buf from GEM object instance Thomas Zimmermann
@ 2025-04-16  6:40   ` Dmitry Osipenko
  0 siblings, 0 replies; 6+ messages in thread
From: Dmitry Osipenko @ 2025-04-16  6:40 UTC (permalink / raw)
  To: Thomas Zimmermann, airlied, gurchetansingh, olvaffe
  Cc: dri-devel, virtualization

On 4/14/25 16:12, Thomas Zimmermann 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>
> ---
>  drivers/gpu/drm/virtio/virtgpu_prime.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/virtio/virtgpu_prime.c b/drivers/gpu/drm/virtio/virtgpu_prime.c
> index ce49282198cb..1118a0250279 100644
> --- a/drivers/gpu/drm/virtio/virtgpu_prime.c
> +++ b/drivers/gpu/drm/virtio/virtgpu_prime.c
> @@ -204,16 +204,15 @@ 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 = attach->dmabuf;
> +		struct dma_buf *dmabuf = obj->dma_buf;
>  
>  		dma_resv_lock(dmabuf->resv, NULL);
>  		virtgpu_dma_buf_unmap(bo);
>  		dma_resv_unlock(dmabuf->resv);
>  
> -		dma_buf_detach(dmabuf, attach);
> +		dma_buf_detach(dmabuf, obj->import_attach);
>  		dma_buf_put(dmabuf);
>  	}
>  

Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>

-- 
Best regards,
Dmitry

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

* Re: [PATCH 0/2] drm/virtio: Avoid struct drm_gem_object.import_attach
  2025-04-14 13:11 [PATCH 0/2] drm/virtio: Avoid struct drm_gem_object.import_attach Thomas Zimmermann
  2025-04-14 13:12 ` [PATCH 1/2] drm/virtio: Test for imported buffers with drm_gem_is_imported() Thomas Zimmermann
  2025-04-14 13:12 ` [PATCH 2/2] drm/virtio: Use dma_buf from GEM object instance Thomas Zimmermann
@ 2025-04-16  7:27 ` Dmitry Osipenko
  2 siblings, 0 replies; 6+ messages in thread
From: Dmitry Osipenko @ 2025-04-16  7:27 UTC (permalink / raw)
  To: Thomas Zimmermann, airlied, gurchetansingh, olvaffe
  Cc: dri-devel, virtualization

On 4/14/25 16:11, Thomas Zimmermann wrote:
> Avoid the use of struct drm_gem_object.import_attach to get the
> object's dma-buf or test for an imported buffer. The import_attach
> field in struct drm_gem_object is an artifact of the import process,
> but should not be used otherwise.
> 
> 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.
> 
> Thomas Zimmermann (2):
>   drm/virtio: Test for imported buffers with drm_gem_is_imported()
>   drm/virtio: Use dma_buf from GEM object instance
> 
>  drivers/gpu/drm/virtio/virtgpu_plane.c | 8 ++++----
>  drivers/gpu/drm/virtio/virtgpu_prime.c | 7 +++----
>  2 files changed, 7 insertions(+), 8 deletions(-)
> 

Applied to misc-next, thanks!

-- 
Best regards,
Dmitry

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

end of thread, other threads:[~2025-04-16  7:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-14 13:11 [PATCH 0/2] drm/virtio: Avoid struct drm_gem_object.import_attach Thomas Zimmermann
2025-04-14 13:12 ` [PATCH 1/2] drm/virtio: Test for imported buffers with drm_gem_is_imported() Thomas Zimmermann
2025-04-16  6:39   ` Dmitry Osipenko
2025-04-14 13:12 ` [PATCH 2/2] drm/virtio: Use dma_buf from GEM object instance Thomas Zimmermann
2025-04-16  6:40   ` Dmitry Osipenko
2025-04-16  7:27 ` [PATCH 0/2] drm/virtio: Avoid struct drm_gem_object.import_attach Dmitry Osipenko

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).