hw/display/virtio-gpu: introduce virtio_gpu_simple_resource_new()
PATCH 1/1 hw/display/virtio-gpu: introduce virtio_gpu_simple_resource_new()
From: Marc-André Lureau <[email protected]>
All allocation sites used g_new0() which zero-initializes fields. However share_handle must be SHAREABLE_NONE (-1 on Unix, NULL on Windows) and dmabuf_fd must be -1, not 0. Centralize allocation and field initialization in a single constructor to fix this and reduce code duplication.
This fixes -display dbus with virtio-gpu blob resources. The other end is currently receiving qemu fd 0.
--- hw/display/virtio-gpu-rutabaga.c | 20 +++++------------- hw/display/virtio-gpu.c | 35 +++++++++++++++++++++----------- include/hw/virtio/virtio-gpu.h | 4 ++++ 3 files changed, 32 insertions(+), 27 deletions(-)
hw/display/virtio-gpu-rutabaga.c +5 -15
@@ -100,12 +100,8 @@ rutabaga_cmd_create_resource_2d(VirtIOGPU *g, result =rutabaga_resource_create_3d (vr->rutabaga, c2d.resource_id, &rc_3d);CHECK (!result, cmd); - res = g_new0(struct virtio_gpu_simple_resource, 1); - res->width = c2d.width; - res->height = c2d.height; - res->format = c2d.format; - res->resource_id = c2d.resource_id; - + res =virtio_gpu_simple_resource_new (c2d.resource_id, c2d.width, + c2d.height, c2d.format);QTAILQ_INSERT_HEAD (&g->reslist, res, next); }
@@ -139,12 +135,8 @@ rutabaga_cmd_create_resource_3d(VirtIOGPU *g, result =rutabaga_resource_create_3d (vr->rutabaga, c3d.resource_id, &rc_3d);CHECK (!result, cmd); - res = g_new0(struct virtio_gpu_simple_resource, 1); - res->width = c3d.width; - res->height = c3d.height; - res->format = c3d.format; - res->resource_id = c3d.resource_id; - + res =virtio_gpu_simple_resource_new (c3d.resource_id, c3d.width, + c3d.height, c3d.format);QTAILQ_INSERT_HEAD (&g->reslist, res, next); }
@@ -634,9 +626,7 @@ rutabaga_cmd_resource_create_blob(VirtIOGPU *g,CHECK (cblob.resource_id !=0 , cmd); - res = g_new0(struct virtio_gpu_simple_resource, 1); - - res->resource_id = cblob.resource_id; + res =virtio_gpu_simple_resource_new (cblob.resource_id,0 ,0 ,0 ); res->blob_size = cblob.size;if (cblob.blob_mem !=VIRTIO_GPU_BLOB_MEM_HOST3D ) {
hw/display/virtio-gpu.c +23 -12
@@ -41,6 +41,24 @@ virtio_gpu_find_check_resource(VirtIOGPU *g, uint32_t resource_id,static void virtio_gpu_reset_bh (void *opaque); +struct virtio_gpu_simple_resource * +virtio_gpu_simple_resource_new (uint32_t resource_id,uint32_t width, +uint32_t height,uint32_t format) +{ +struct virtio_gpu_simple_resource *res = + g_new0(struct virtio_gpu_simple_resource, 1); + + res->share_handle =SHAREABLE_NONE ; + res->dmabuf_fd =-1 ; + + res->resource_id = resource_id; + res->width = width; + res->height = height; + res->format = format; + +return res; +} +void virtio_gpu_update_cursor_data (VirtIOGPU *g,struct virtio_gpu_scanout *s,uint32_t resource_id)
@@ -259,12 +277,8 @@ static void virtio_gpu_resource_create_2d(VirtIOGPU *g,return ; } - res = g_new0(struct virtio_gpu_simple_resource, 1); - - res->width = c2d.width; - res->height = c2d.height; - res->format = c2d.format; - res->resource_id = c2d.resource_id; + res =virtio_gpu_simple_resource_new (c2d.resource_id, c2d.width, + c2d.height, c2d.format); pformat =virtio_gpu_get_pixman_format (c2d.format);if (!pformat) {
@@ -345,8 +359,7 @@ static void virtio_gpu_resource_create_blob(VirtIOGPU *g,return ; } - res = g_new0(struct virtio_gpu_simple_resource, 1); - res->resource_id = cblob.resource_id; + res =virtio_gpu_simple_resource_new (cblob.resource_id,0 ,0 ,0 ); res->blob_size = cblob.size;if (cblob.nr_entries) {
@@ -1442,8 +1455,7 @@ static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size,return -EINVAL ; } - res = g_new0(struct virtio_gpu_simple_resource, 1); - res->resource_id = resource_id; + res =virtio_gpu_simple_resource_new (resource_id,0 ,0 ,0 ); res->width =qemu_get_be32 (f); res->height =qemu_get_be32 (f); res->format =qemu_get_be32 (f);
@@ -1555,8 +1567,7 @@ static int virtio_gpu_blob_load(QEMUFile *f, void *opaque, size_t size,return -EINVAL ; } - res = g_new0(struct virtio_gpu_simple_resource, 1); - res->resource_id = resource_id; + res =virtio_gpu_simple_resource_new (resource_id,0 ,0 ,0 ); res->blob_size =qemu_get_be32 (f); res->iov_cnt =qemu_get_be32 (f);
include/hw/virtio/virtio-gpu.h +4 -0
@@ -64,6 +64,10 @@ struct virtio_gpu_simple_resource {QTAILQ_ENTRY (virtio_gpu_simple_resource) next; }; +struct virtio_gpu_simple_resource * +virtio_gpu_simple_resource_new (uint32_t resource_id,uint32_t width, +uint32_t height,uint32_t format); +struct virtio_gpu_framebuffer {pixman_format_code_t format;uint32_t width, height;
Signature · 1 line
2.55.0.543.g5ebe2ebe4ea8
Quoted 11 lines · On Thu, Aug 27, 2026 at 11:09:41AM +0400, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
All allocation sites used
g_new0()which zero-initializes fields. Howevershare_handlemust beSHAREABLE_NONE(-1 on Unix, NULL on Windows) anddmabuf_fdmust be -1, not 0. Centralize allocation and field initialization in a single constructor to fix this and reduce code duplication.This fixes -display dbus with virtio-gpu blob resources. The other end is currently receiving qemu fd 0.
Quoted 6 lines
Signed-off-by Marc-André Lureau <[email protected]>--- hw/display/virtio-gpu-rutabaga.c | 20 +++++------------- hw/display/virtio-gpu.c | 35 +++++++++++++++++++++----------- include/hw/virtio/virtio-gpu.h | 4 ++++ 3 files changed, 32 insertions(+), 27 deletions(-)
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com ~~ https://hachyderm.io/@berrange :| |: https://libvirt.org ~~ https://entangle-photo.org :| |: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
Quoted 11 lines · On 27/8/26 09:09, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
All allocation sites used
g_new0()which zero-initializes fields. Howevershare_handlemust beSHAREABLE_NONE(-1 on Unix, NULL on Windows) anddmabuf_fdmust be -1, not 0. Centralize allocation and field initialization in a single constructor to fix this and reduce code duplication.This fixes -display dbus with virtio-gpu blob resources. The other end is currently receiving qemu fd 0.
Quoted 6 lines
Signed-off-by Marc-André Lureau <[email protected]>--- hw/display/virtio-gpu-rutabaga.c | 20 +++++------------- hw/display/virtio-gpu.c | 35 +++++++++++++++++++++----------- include/hw/virtio/virtio-gpu.h | 4 ++++ 3 files changed, 32 insertions(+), 27 deletions(-)