virtio-gpu/virgl: free BHs and timers on renderer reset
PATCH 1/1 virtio-gpu/virgl: free BHs and timers on renderer reset
From: Marc-André Lureau <[email protected]>
virtio_gpu_virgl_reset() does not free the bottom halves or timers allocated by the previous virtio_gpu_virgl_init() call. A subsequent virtio_gpu_virgl_init() overwrites the old pointers, leaking the previous allocations.
--- hw/display/virtio-gpu-virgl.c | 6 ++++++ 1 file changed, 6 insertions(+)
hw/display/virtio-gpu-virgl.c +6 -0
@@ -1425,6 +1425,7 @@ void virtio_gpu_virgl_reset_scanout(VirtIOGPU *g)static bool virtio_gpu_virgl_reset (VirtIOGPU *g) { +VirtIOGPUGL *gl =VIRTIO_GPU_GL (g);struct virtio_gpu_simple_resource *res, *tmp;/*
@@ -1443,6 +1444,11 @@ static bool virtio_gpu_virgl_reset(VirtIOGPU *g)virtio_gpu_virgl_reset_async_fences (g); +g_clear_pointer (&gl->cmdq_resume_bh, qemu_bh_delete); +g_clear_pointer (&gl->async_fence_bh, qemu_bh_delete); +g_clear_pointer (&gl->print_stats, timer_free); +g_clear_pointer (&gl->fence_poll, timer_free); +return true; }
Signature · 1 line
2.55.0.543.g5ebe2ebe4ea8
Quoted 26 lines · [email protected] writes:
From: Marc-André Lureau <[email protected]>
virtio_gpu_virgl_reset()does not free the bottom halves or timers allocated by the previousvirtio_gpu_virgl_init()call. A subsequentvirtio_gpu_virgl_init()overwrites the old pointers, leaking the previous allocations.Fixes bd9258917fbf ("virtio-gpu: Destroy virgl resources on virtio-gpu reset")Signed-off-by Marc-André Lureau <[email protected]>--- hw/display/virtio-gpu-virgl.c | 6 ++++++ 1 file changed, 6 insertions(+)hw/display/virtio-gpu-virgl.c +1
-0@@ -1425,6 +1425,7 @@ void virtio_gpu_virgl_reset_scanout(VirtIOGPU *g)static bool virtio_gpu_virgl_reset (VirtIOGPU *g) { +VirtIOGPUGL *gl =VIRTIO_GPU_GL (g);struct virtio_gpu_simple_resource *res, *tmp;/*
hw/display/virtio-gpu-virgl.c static bool virtio_gpu_virgl_reset(VirtIOGPU *g) · line 1451
Quoted 8 lines
hw/display/virtio-gpu-virgl.c +5
-0@@ -1443,6 +1444,11 @@ static bool virtio_gpu_virgl_reset(VirtIOGPU *g)virtio_gpu_virgl_reset_async_fences (g); +g_clear_pointer (&gl->cmdq_resume_bh, qemu_bh_delete); +g_clear_pointer (&gl->async_fence_bh, qemu_bh_delete); +g_clear_pointer (&gl->print_stats, timer_free); +g_clear_pointer (&gl->fence_poll, timer_free); +
Don't we need some ptr checks in virtio_gpu_gl_device_unrealize so a reset followed by an unplug doesn't causes segs chasing now NULL pointers?
Quoted 2 lines
hw/display/virtio-gpu-virgl.c +0
-0return true; }
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Hi
Quoted 32 lines · Alex Bennée
Quoted 29 lines · [email protected] writes:
From: Marc-André Lureau <[email protected]>
virtio_gpu_virgl_reset()does not free the bottom halves or timers allocated by the previousvirtio_gpu_virgl_init()call. A subsequentvirtio_gpu_virgl_init()overwrites the old pointers, leaking the previous allocations.Fixes bd9258917fbf ("virtio-gpu: Destroy virgl resources on virtio-gpu reset")Signed-off-by Marc-André Lureau <[email protected]>--- hw/display/virtio-gpu-virgl.c | 6 ++++++ 1 file changed, 6 insertions(+)hw/display/virtio-gpu-virgl.c +1
-0@@ -1425,6 +1425,7 @@ void virtio_gpu_virgl_reset_scanout(VirtIOGPU *g)static bool virtio_gpu_virgl_reset (VirtIOGPU *g) { +VirtIOGPUGL *gl =VIRTIO_GPU_GL (g);struct virtio_gpu_simple_resource *res, *tmp;/* @@ -1443,6 +1444,11 @@ static bool virtio_gpu_virgl_reset(VirtIOGPU *g)virtio_gpu_virgl_reset_async_fences (g);
Quoted 9 lines
hw/display/virtio-gpu-virgl.c static bool virtio_gpu_virgl_reset(VirtIOGPU *g) · line 1451
Quoted 5 lines
hw/display/virtio-gpu-virgl.c +5
-0+g_clear_pointer (&gl->cmdq_resume_bh, qemu_bh_delete); +g_clear_pointer (&gl->async_fence_bh, qemu_bh_delete); +g_clear_pointer (&gl->print_stats, timer_free); +g_clear_pointer (&gl->fence_poll, timer_free); +Don't we need some ptr checks in
virtio_gpu_gl_device_unrealizeso a reset followed by an unplug doesn't causes segs chasing now NULL pointers?
Good point, actually we should be safe, since render_state < RS_INITED.
But those qemu_bh_delete().. can we make it safe to call with NULL? timer_free() was fixed already.
Quoted 9 lines
hw/display/virtio-gpu-virgl.c static bool virtio_gpu_virgl_reset(VirtIOGPU *g) · line 1453
Quoted 4 lines
hw/display/virtio-gpu-virgl.c +0
-0return true; }--
Alex Bennée
Virtualisation Tech Lead @ Linaro
Quoted 45 lines · Marc-André Lureau
Hi
Quoted 32 lines · Alex Bennée
Quoted 29 lines · [email protected] writes:
From: Marc-André Lureau <[email protected]>
virtio_gpu_virgl_reset()does not free the bottom halves or timers allocated by the previousvirtio_gpu_virgl_init()call. A subsequentvirtio_gpu_virgl_init()overwrites the old pointers, leaking the previous allocations.Fixes bd9258917fbf ("virtio-gpu: Destroy virgl resources on virtio-gpu reset")Signed-off-by Marc-André Lureau <[email protected]>--- hw/display/virtio-gpu-virgl.c | 6 ++++++ 1 file changed, 6 insertions(+)hw/display/virtio-gpu-virgl.c +1
-0@@ -1425,6 +1425,7 @@ void virtio_gpu_virgl_reset_scanout(VirtIOGPU *g)static bool virtio_gpu_virgl_reset (VirtIOGPU *g) { +VirtIOGPUGL *gl =VIRTIO_GPU_GL (g);struct virtio_gpu_simple_resource *res, *tmp;/* @@ -1443,6 +1444,11 @@ static bool virtio_gpu_virgl_reset(VirtIOGPU *g)virtio_gpu_virgl_reset_async_fences (g);Quoted 9 lines
hw/display/virtio-gpu-virgl.c static bool virtio_gpu_virgl_reset(VirtIOGPU *g) · line 1451
Quoted 5 lines
hw/display/virtio-gpu-virgl.c +5
-0+g_clear_pointer (&gl->cmdq_resume_bh, qemu_bh_delete); +g_clear_pointer (&gl->async_fence_bh, qemu_bh_delete); +g_clear_pointer (&gl->print_stats, timer_free); +g_clear_pointer (&gl->fence_poll, timer_free); +Don't we need some ptr checks in
virtio_gpu_gl_device_unrealizeso a reset followed by an unplug doesn't causes segs chasing now NULL pointers?
Quoted 3 lines
Good point, actually we should be safe, since
render_state<RS_INITED.But those
qemu_bh_delete().. can we make it safe to call with NULL?
That seems sane as it will be on the exit path. I wouldn't tolerate NULL for any of the other qemu_bh functions though.
Quoted 11 lines
timer_free()was fixed already.Quoted 9 lines
hw/display/virtio-gpu-virgl.c static bool virtio_gpu_virgl_reset(VirtIOGPU *g) · line 1453
Quoted 4 lines
hw/display/virtio-gpu-virgl.c +0
-0return true; }--
Alex Bennée
Virtualisation Tech Lead @ Linaro
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Quoted 8 lines · On 2026/08/28 0:43, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
virtio_gpu_virgl_reset()does not free the bottom halves or timers allocated by the previousvirtio_gpu_virgl_init()call. A subsequentvirtio_gpu_virgl_init()overwrites the old pointers, leaking the previous allocations.Fixes bd9258917fbf ("virtio-gpu: Destroy virgl resources on virtio-gpu reset")
This Fixes: tag needs to be corrected. bd9258917fbf^ already reset the
renderer and re-entered virtio_gpu_virgl_init(), overwriting the allocations. That behavior began in 7e688d1bf515, so the current tag misses older affected releases. Please use:
With the Fixes tag corrected:
Regards,
Akihiko Odaki
Quoted 29 lines
Signed-off-by Marc-André Lureau <[email protected]>--- hw/display/virtio-gpu-virgl.c | 6 ++++++ 1 file changed, 6 insertions(+)hw/display/virtio-gpu-virgl.c +6
-0@@ -1425,6 +1425,7 @@ void virtio_gpu_virgl_reset_scanout(VirtIOGPU *g)static bool virtio_gpu_virgl_reset (VirtIOGPU *g) { +VirtIOGPUGL *gl =VIRTIO_GPU_GL (g);struct virtio_gpu_simple_resource *res, *tmp;/* @@ -1443,6 +1444,11 @@ static bool virtio_gpu_virgl_reset(VirtIOGPU *g)virtio_gpu_virgl_reset_async_fences (g); +g_clear_pointer (&gl->cmdq_resume_bh, qemu_bh_delete); +g_clear_pointer (&gl->async_fence_bh, qemu_bh_delete); +g_clear_pointer (&gl->print_stats, timer_free); +g_clear_pointer (&gl->fence_poll, timer_free); +return true; }