From: Tom Desnoyers <[email protected]> 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, call virtio_gpu_cleanup_mapping() instead of virtio_gpu_cleanup_mapping_iov(). In virtio-gpu-rutabaga.c, call virtio_gpu_cleanup_mapping() before freeing the resource. Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4634 Reviewed-by: Marc-André Lureau <[email protected]> Signed-off-by: Tom Desnoyers <[email protected]> Message-ID: <[email protected]> --- hw/display/virtio-gpu-rutabaga.c | 2 ++ hw/display/virtio-gpu-virgl.c | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/hw/display/virtio-gpu-rutabaga.c b/hw/display/virtio-gpu-rutabaga.c index edf7b6270329..1312a67d7011 100644 --- a/hw/display/virtio-gpu-rutabaga.c +++ b/hw/display/virtio-gpu-rutabaga.c @@ -164,6 +164,8 @@ 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 f45571060fea..f71f287d9486 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -451,13 +451,13 @@ virtio_gpu_virgl_resource_unref(VirtIOGPU *g, virgl_renderer_resource_detach_iov(res->base.resource_id, &res_iovs, &num_iovs); - if (res_iovs != NULL && num_iovs != 0) { - virtio_gpu_cleanup_mapping_iov(g, res_iovs, num_iovs); - } + res->base.iov = res_iovs; + res->base.iov_cnt = num_iovs; virgl_renderer_resource_unref(res->base.resource_id); QTAILQ_REMOVE(&g->reslist, &res->base, next); + virtio_gpu_cleanup_mapping(g, &res->base); g_free(res); return 0; -- 2.56.0.116.g6de20f6092dc
