Skip to contentSkip to conversation

drm/virtio: synchronous guest framebuffer update

PATCH New Dongwon Kim 1 participant 4 messages Sep 26, 2022

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

cover drm/virtio: synchronous guest framebuffer update

This series is for fixing some issues regarding scanout synchronization with host (e.g. QEMU/KVM) that uses virtio-gpu. This series replaces the previously submitted one, "[PATCH v2 0/2] drm/virtio: fence handling in case of multi scanouts".

Dongwon Kim (3):
drm/virtio: .release ops for virtgpu fence release drm/virtio: new fence for every plane update
drm/virtio: drm_gem_plane_helper_prepare_fb for obj synchronization

 drivers/gpu/drm/virtio/virtgpu_drv.h   |  7 +++
 drivers/gpu/drm/virtio/virtgpu_fence.c |  8 +++
 drivers/gpu/drm/virtio/virtgpu_plane.c | 85 +++++++++++++++-----------
 3 files changed, 65 insertions(+), 35 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

RFC PATCH 1/3 drm/virtio: .release ops for virtgpu fence release

virtio_gpu_fence_release is added to free virtio-gpu-fence upon release of dma_fence.

Cc Gurchetan Singh <[email protected]>
Cc Gerd Hoffmann <[email protected]>
Cc Vivek Kasireddy <[email protected]>
---
 drivers/gpu/drm/virtio/virtgpu_fence.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/gpu/drm/virtio/virtgpu_fence.c +8 -0
index f28357dbde35..ba659ac2a51d 100644
@@ -63,12 +63,20 @@ static void virtio_gpu_timeline_value_str(struct dma_fence *f, char *str,
 		 (u64)atomic64_read(&fence->drv->last_fence_id));
 }
 
+static void virtio_gpu_fence_release(struct dma_fence *f)
+{
+	struct virtio_gpu_fence *fence = to_virtio_gpu_fence(f);
+
+	kfree(fence);
+}
+
 static const struct dma_fence_ops virtio_gpu_fence_ops = {
 	.get_driver_name     = virtio_gpu_get_driver_name,
 	.get_timeline_name   = virtio_gpu_get_timeline_name,
 	.signaled            = virtio_gpu_fence_signaled,
 	.fence_value_str     = virtio_gpu_fence_value_str,
 	.timeline_value_str  = virtio_gpu_timeline_value_str,
+	.release	     = virtio_gpu_fence_release,
 };
 
 struct virtio_gpu_fence *virtio_gpu_fence_alloc(struct virtio_gpu_device *vgdev,
Signature · 1 line
2.20.1
#2 lore raw

RFC PATCH 2/3 drm/virtio: new fence for every plane update

In reply to Dongwon Kim

Having a fence linked to a virtio_gpu_framebuffer in plane update sequence would cause conflict when several planes referencing the same framebuffer especially when those planes are updated concurrently (e.g. Xorg screen covering multi-displays configured for an extended mode). So it is better for the fence to be created for every plane update event then link it to the plane state since each plane update comes with a new plane state obj.

The plane state for virtio-gpu, "struct virtio_gpu_plane_state" is added for this. This structure represents drm_plane_state and it contains the reference to virtio_gpu_fence, which was previously in
"struct virtio_gpu_framebuffer".

"virtio_gpu_plane_duplicate_state" and "virtio_gpu_plane_destroy_state" were added as well to manage virtio_gpu_plane_state.

Several drm helpers were slightly modified accordingly to use the fence in new plane state structure. virtio_gpu_plane_cleanup_fb was completely removed as none of code in the function are not required.

Also, the condition for adding fence, (plane->state->fb != new_state->fb) was removed for the sychronous FB update even when the same FB is flushed again consecutively.

Cc Gurchetan Singh <[email protected]>
Cc Gerd Hoffmann <[email protected]>
Cc Vivek Kasireddy <[email protected]>
---
 drivers/gpu/drm/virtio/virtgpu_drv.h   |  7 +++
 drivers/gpu/drm/virtio/virtgpu_plane.c | 76 +++++++++++++++-----------
 2 files changed, 51 insertions(+), 32 deletions(-)
drivers/gpu/drm/virtio/virtgpu_drv.h +7 -0
index 9b98470593b0..20a418f64533 100644
@@ -190,6 +190,13 @@ struct virtio_gpu_framebuffer {
 #define to_virtio_gpu_framebuffer(x) \
 	container_of(x, struct virtio_gpu_framebuffer, base)
 
+struct virtio_gpu_plane_state {
+	struct drm_plane_state base;
+	struct virtio_gpu_fence *fence;
+};
+#define to_virtio_gpu_plane_state(x) \
+	container_of(x, struct virtio_gpu_plane_state, base)
+
 struct virtio_gpu_queue {
 	struct virtqueue *vq;
 	spinlock_t qlock;
drivers/gpu/drm/virtio/virtgpu_plane.c +44 -32

158 lines not on this page · raw message

Signature · 1 line
2.20.1
#3 lore raw

RFC PATCH 3/3 drm/virtio: drm_gem_plane_helper_prepare_fb for obj synchronization

In reply to Dongwon Kim

This helper is needed for framebuffer synchronization. Old framebuffer data is often displayed on the guest display without this helper.

Cc Gurchetan Singh <[email protected]>
Cc Gerd Hoffmann <[email protected]>
Cc Vivek Kasireddy <[email protected]>
---
 drivers/gpu/drm/virtio/virtgpu_plane.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/virtio/virtgpu_plane.c +4 -0
index 51b14ee4ece9..968afd0029fa 100644
@@ -26,6 +26,7 @@
 #include <drm/drm_atomic_helper.h>
 #include <drm/drm_damage_helper.h>
 #include <drm/drm_fourcc.h>
+#include <drm/drm_gem_atomic_helper.h>
 
 #include "virtgpu_drv.h"
 
@@ -270,6 +271,9 @@ static int virtio_gpu_plane_prepare_fb(struct drm_plane *plane,
 	vgfb = to_virtio_gpu_framebuffer(new_state->fb);
 	vgplane_st = to_virtio_gpu_plane_state(new_state);
 	bo = gem_to_virtio_gpu_obj(vgfb->base.obj[0]);
+
+	drm_gem_plane_helper_prepare_fb(plane, new_state);
+
 	if (!bo || (plane->type == DRM_PLANE_TYPE_PRIMARY && !bo->guest_blob))
 		return 0;
 
Signature · 1 line
2.20.1