On 2026/10/06 22:55, Tom Desnoyers wrote:
When a gpu buffer backed by a guest-memory blob is unreferenced, virgl
and rutabaga free the resource but not its addrs field, leaking memory
on every unref.

In virtio-gpu-virgl.c, free res->base.addrs before freeing the resource.
In virtio-gpu-rutabaga.c, call virtio_gpu_cleanup_mapping() before
freeing the resource.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4634
Signed-off-by: Tom Desnoyers <[email protected]>
---
  hw/display/virtio-gpu-rutabaga.c | 1 +
  hw/display/virtio-gpu-virgl.c    | 1 +
  2 files changed, 2 insertions(+)

diff --git a/hw/display/virtio-gpu-rutabaga.c b/hw/display/virtio-gpu-rutabaga.c
index 3aafa4dc66..7907aea85a 100644
--- a/hw/display/virtio-gpu-rutabaga.c
+++ b/hw/display/virtio-gpu-rutabaga.c
@@ -164,6 +164,7 @@ virtio_gpu_rutabaga_resource_unref(VirtIOGPU *g,
      }
QTAILQ_REMOVE(&g->reslist, res, next);
+    virtio_gpu_cleanup_mapping(g, res);
      g_free(res);
  }
diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index f45571060f..b5b160c840 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -458,6 +458,7 @@ virtio_gpu_virgl_resource_unref(VirtIOGPU *g,
QTAILQ_REMOVE(&g->reslist, &res->base, next); + g_free(res->base.addrs);

Thanks for the patch. For the virtio-gpu-virgl.c changes, I think it would be better to update virtio_gpu_virgl_resource_unref() to use the virtio_gpu_cleanup_mapping() helper.

Previously, the virgl code only called virtio_gpu_cleanup_mapping_iov(), so there was little benefit to using the higher-level helper. However, since this fix requires us to free res->base.addrs as well, replacing both the _iov() call and this new g_free() call with a single call to virtio_gpu_cleanup_mapping() makes the code cleaner.

Regards,
Akihiko Odaki

      g_free(res);
return 0;


Reply via email to