Skip to contentSkip to conversation

drm/virtio: Fix flickering issue seen with imported dmabufs

PATCH Applied Vivek Kasireddy 2 participants 4 messages Mar 25, 2025 – Mar 26, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/virtio: Fix flickering issue seen with imported dmabufs

We need to save the reservation object pointer associated with the imported dmabuf in the newly created GEM object to allow drm_gem_plane_helper_prepare_fb() to extract the exclusive fence from it and attach it to the plane state during prepare phase. This is needed to ensure that drm_atomic_helper_wait_for_fences() correctly waits for the relevant fences (move, etc) associated with the reservation object, thereby implementing proper synchronization.

Otherwise, artifacts or slight flickering can be seen when apps are dragged across the screen when running Gnome (Wayland). This problem is mostly seen with dGPUs in the case where the FBs are allocated in VRAM but need to be migrated to System RAM as they are shared with virtio-gpu.

Fixes ca77f27a2665 ("drm/virtio: Import prime buffers from other devices as guest blobs")
Cc Gerd Hoffmann <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Gurchetan Singh <[email protected]>
Cc Chia-I Wu <[email protected]>
---
 drivers/gpu/drm/virtio/virtgpu_prime.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/virtio/virtgpu_prime.c +1 -0
index fe6a0b018571..ceb0401a000b 100644
@@ -332,6 +332,7 @@ struct drm_gem_object *virtgpu_gem_prime_import(struct drm_device *dev,
 	}
 
 	obj->import_attach = attach;
+	obj->resv = buf->resv;
 	get_dma_buf(buf);
 
 	ret = virtgpu_dma_buf_init_obj(dev, bo, attach);
Signature · 1 line
2.48.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 29 lines · Vivek Kasireddy

We need to save the reservation object pointer associated with the imported dmabuf in the newly created GEM object to allow drm_gem_plane_helper_prepare_fb() to extract the exclusive fence from it and attach it to the plane state during prepare phase. This is needed to ensure that drm_atomic_helper_wait_for_fences() correctly waits for the relevant fences (move, etc) associated with the reservation object, thereby implementing proper synchronization.

Otherwise, artifacts or slight flickering can be seen when apps are dragged across the screen when running Gnome (Wayland). This problem is mostly seen with dGPUs in the case where the FBs are allocated in VRAM but need to be migrated to System RAM as they are shared with virtio-gpu.

Fixes ca77f27a2665 ("drm/virtio: Import prime buffers from other devices as guest blobs")
Cc Gerd Hoffmann <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Gurchetan Singh <[email protected]>
Cc Chia-I Wu <[email protected]>
---
 drivers/gpu/drm/virtio/virtgpu_prime.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/virtio/virtgpu_prime.c +0 -0
index fe6a0b018571..ceb0401a000b 100644

drivers/gpu/drm/virtio/virtgpu_prime.c struct drm_gem_object *virtgpu_gem_prime_import(struct drm_device *dev, · line 338

Quoted 7 lines
drivers/gpu/drm/virtio/virtgpu_prime.c +1 -0
@@ -332,6 +332,7 @@ struct drm_gem_object *virtgpu_gem_prime_import(struct drm_device *dev,
 	}
 
 	obj->import_attach = attach;
+	obj->resv = buf->resv;
 	get_dma_buf(buf);
 
 	ret = virtgpu_dma_buf_init_obj(dev, bo, attach);

Will be better to set obj->resv before drm_gem_private_object_init() since it checks whether obj->resv was pre-inited. I'll change it while applying, thanks.

Signature · 2 lines
Best regards,
Dmitry
#2 lore raw
Quoted 42 lines

Subject: Re: [PATCH] drm/virtio: Fix flickering issue seen with imported dmabufs

Quoted 8 lines · Vivek Kasireddy

We need to save the reservation object pointer associated with the imported dmabuf in the newly created GEM object to allow drm_gem_plane_helper_prepare_fb() to extract the exclusive fence from it and attach it to the plane state during prepare phase. This is needed to ensure that drm_atomic_helper_wait_for_fences() correctly waits for the relevant fences (move, etc) associated with the reservation object, thereby implementing proper synchronization.

Quoted 7 lines

Otherwise, artifacts or slight flickering can be seen when apps are dragged across the screen when running Gnome (Wayland). This problem is mostly seen with dGPUs in the case where the FBs are allocated in VRAM but need to be migrated to System RAM as they are shared with virtio-gpu.

Fixes ca77f27a2665 ("drm/virtio: Import prime buffers from other devices as

guest blobs")

Review

Quoted 10 lines
Cc Gerd Hoffmann <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Gurchetan Singh <[email protected]>
Cc Chia-I Wu <[email protected]>
---
 drivers/gpu/drm/virtio/virtgpu_prime.c | 1 +
 1 file changed, 1 insertion(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/virtio/virtgpu_prime.c

drivers/gpu/drm/virtio/virtgpu_prime.c struct drm_gem_object

Quoted 4 lines

index fe6a0b018571..ceb0401a000b 100644

drivers/gpu/drm/virtio/virtgpu_prime.c +0 -0
@@ -332,6 +332,7 @@ struct drm_gem_object

*virtgpu_gem_prime_import(struct drm_device *dev,

Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_prime.c +1 -0
 	}
 
 	obj->import_attach = attach;
+	obj->resv = buf->resv;
 	get_dma_buf(buf);
 
Quoted 5 lines

drivers/gpu/drm/virtio/virtgpu_prime.c struct drm_gem_object *virtgpu_gem_prime_import(struct drm_device *dev, · line 338

Quoted 1 line
drivers/gpu/drm/virtio/virtgpu_prime.c +0 -0
 	ret = virtgpu_dma_buf_init_obj(dev, bo, attach);

Will be better to set obj->resv before drm_gem_private_object_init() since it checks whether obj->resv was pre-inited. I'll change it while applying, thanks.

Sounds good. Thank you Dmitry!

Thanks,
Vivek

Quoted 6 lines

--
Best regards,
Dmitry

maintainer Applied
#3 lore raw
Quoted 42 lines · Vivek
Quoted 42 lines

Subject: Re: [PATCH] drm/virtio: Fix flickering issue seen with imported dmabufs

Quoted 8 lines · Vivek Kasireddy

We need to save the reservation object pointer associated with the imported dmabuf in the newly created GEM object to allow drm_gem_plane_helper_prepare_fb() to extract the exclusive fence from it and attach it to the plane state during prepare phase. This is needed to ensure that drm_atomic_helper_wait_for_fences() correctly waits for the relevant fences (move, etc) associated with the reservation object, thereby implementing proper synchronization.

Quoted 7 lines

Otherwise, artifacts or slight flickering can be seen when apps are dragged across the screen when running Gnome (Wayland). This problem is mostly seen with dGPUs in the case where the FBs are allocated in VRAM but need to be migrated to System RAM as they are shared with virtio-gpu.

Fixes ca77f27a2665 ("drm/virtio: Import prime buffers from other devices as

guest blobs")

Review

Quoted 10 lines
Cc Gerd Hoffmann <[email protected]>
Cc Dmitry Osipenko <[email protected]>
Cc Gurchetan Singh <[email protected]>
Cc Chia-I Wu <[email protected]>
---
 drivers/gpu/drm/virtio/virtgpu_prime.c | 1 +
 1 file changed, 1 insertion(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/virtio/virtgpu_prime.c

drivers/gpu/drm/virtio/virtgpu_prime.c struct drm_gem_object

Quoted 4 lines

index fe6a0b018571..ceb0401a000b 100644

drivers/gpu/drm/virtio/virtgpu_prime.c +0 -0
@@ -332,6 +332,7 @@ struct drm_gem_object

*virtgpu_gem_prime_import(struct drm_device *dev,

Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_prime.c +1 -0
 	}
 
 	obj->import_attach = attach;
+	obj->resv = buf->resv;
 	get_dma_buf(buf);
 
Quoted 6 lines
Quoted 5 lines

drivers/gpu/drm/virtio/virtgpu_prime.c struct drm_gem_object *virtgpu_gem_prime_import(struct drm_device *dev, · line 338

Quoted 1 line
drivers/gpu/drm/virtio/virtgpu_prime.c +0 -0
 	ret = virtgpu_dma_buf_init_obj(dev, bo, attach);

Will be better to set obj->resv before drm_gem_private_object_init() since it checks whether obj->resv was pre-inited. I'll change it while applying, thanks.

Sounds good. Thank you Dmitry!

Applied to misc-fixes, thanks!

Will keep an eye on the patch status in the misc. Too early to apply now to misc-fixes, I rushed a bit by accident.

Signature · 2 lines
Best regards,
Dmitry