All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] virtio-gpu/virgl: free BHs and timers on renderer reset
@ 2026-08-27 15:43 marcandre.lureau
  2026-08-27 16:11 ` Alex Bennée
  2026-08-28 12:47 ` Akihiko Odaki
  0 siblings, 2 replies; 5+ messages in thread
From: marcandre.lureau @ 2026-08-27 15:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: akihiko.odaki, Marc-André Lureau

From: Marc-André Lureau <marcandre.lureau@redhat.com>

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.

Fixes: bd9258917fbf ("virtio-gpu: Destroy virgl resources on virtio-gpu reset")
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 hw/display/virtio-gpu-virgl.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index 0b79aef8d1f5..8bf6417c6514 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -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;
 }
 
-- 
2.55.0.543.g5ebe2ebe4ea8



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] virtio-gpu/virgl: free BHs and timers on renderer reset
  2026-08-27 15:43 [PATCH] virtio-gpu/virgl: free BHs and timers on renderer reset marcandre.lureau
@ 2026-08-27 16:11 ` Alex Bennée
  2026-08-27 16:31   ` Marc-André Lureau
  2026-08-28 12:47 ` Akihiko Odaki
  1 sibling, 1 reply; 5+ messages in thread
From: Alex Bennée @ 2026-08-27 16:11 UTC (permalink / raw)
  To: marcandre.lureau; +Cc: qemu-devel, akihiko.odaki

marcandre.lureau@redhat.com writes:

> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>
> 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.
>
> Fixes: bd9258917fbf ("virtio-gpu: Destroy virgl resources on virtio-gpu reset")
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  hw/display/virtio-gpu-virgl.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
> index 0b79aef8d1f5..8bf6417c6514 100644
> --- a/hw/display/virtio-gpu-virgl.c
> +++ b/hw/display/virtio-gpu-virgl.c
> @@ -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);
> +

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?


>      return true;
>  }

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] virtio-gpu/virgl: free BHs and timers on renderer reset
  2026-08-27 16:11 ` Alex Bennée
@ 2026-08-27 16:31   ` Marc-André Lureau
  2026-08-27 17:07     ` Alex Bennée
  0 siblings, 1 reply; 5+ messages in thread
From: Marc-André Lureau @ 2026-08-27 16:31 UTC (permalink / raw)
  To: Alex Bennée; +Cc: qemu-devel, akihiko.odaki

Hi

On Thu, Aug 27, 2026 at 8:11 PM Alex Bennée <alex.bennee@linaro.org> wrote:
>
> marcandre.lureau@redhat.com writes:
>
> > From: Marc-André Lureau <marcandre.lureau@redhat.com>
> >
> > 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.
> >
> > Fixes: bd9258917fbf ("virtio-gpu: Destroy virgl resources on virtio-gpu reset")
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  hw/display/virtio-gpu-virgl.c | 6 ++++++
> >  1 file changed, 6 insertions(+)
> >
> > diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
> > index 0b79aef8d1f5..8bf6417c6514 100644
> > --- a/hw/display/virtio-gpu-virgl.c
> > +++ b/hw/display/virtio-gpu-virgl.c
> > @@ -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);
> > +
>
> 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?

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.

>
>
> >      return true;
> >  }
>
> --
> Alex Bennée
> Virtualisation Tech Lead @ Linaro
>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] virtio-gpu/virgl: free BHs and timers on renderer reset
  2026-08-27 16:31   ` Marc-André Lureau
@ 2026-08-27 17:07     ` Alex Bennée
  0 siblings, 0 replies; 5+ messages in thread
From: Alex Bennée @ 2026-08-27 17:07 UTC (permalink / raw)
  To: Marc-André Lureau; +Cc: qemu-devel, akihiko.odaki

Marc-André Lureau <marcandre.lureau@redhat.com> writes:

> Hi
>
> On Thu, Aug 27, 2026 at 8:11 PM Alex Bennée <alex.bennee@linaro.org> wrote:
>>
>> marcandre.lureau@redhat.com writes:
>>
>> > From: Marc-André Lureau <marcandre.lureau@redhat.com>
>> >
>> > 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.
>> >
>> > Fixes: bd9258917fbf ("virtio-gpu: Destroy virgl resources on virtio-gpu reset")
>> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>> > ---
>> >  hw/display/virtio-gpu-virgl.c | 6 ++++++
>> >  1 file changed, 6 insertions(+)
>> >
>> > diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
>> > index 0b79aef8d1f5..8bf6417c6514 100644
>> > --- a/hw/display/virtio-gpu-virgl.c
>> > +++ b/hw/display/virtio-gpu-virgl.c
>> > @@ -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);
>> > +
>>
>> 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?
>
> 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.

> timer_free() was fixed already.
>
>>
>>
>> >      return true;
>> >  }
>>
>> --
>> Alex Bennée
>> Virtualisation Tech Lead @ Linaro
>>

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] virtio-gpu/virgl: free BHs and timers on renderer reset
  2026-08-27 15:43 [PATCH] virtio-gpu/virgl: free BHs and timers on renderer reset marcandre.lureau
  2026-08-27 16:11 ` Alex Bennée
@ 2026-08-28 12:47 ` Akihiko Odaki
  1 sibling, 0 replies; 5+ messages in thread
From: Akihiko Odaki @ 2026-08-28 12:47 UTC (permalink / raw)
  To: marcandre.lureau, qemu-devel

On 2026/08/28 0:43, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> 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.
> 
> 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:

Fixes: 7e688d1bf515 ("virtio-gpu: Handle virtio_gpu_virgl_init() failure")

With the Fixes tag corrected:

Reviewed-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>

Regards,
Akihiko Odaki

> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>   hw/display/virtio-gpu-virgl.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
> index 0b79aef8d1f5..8bf6417c6514 100644
> --- a/hw/display/virtio-gpu-virgl.c
> +++ b/hw/display/virtio-gpu-virgl.c
> @@ -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;
>   }
>   



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-08-28 12:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-27 15:43 [PATCH] virtio-gpu/virgl: free BHs and timers on renderer reset marcandre.lureau
2026-08-27 16:11 ` Alex Bennée
2026-08-27 16:31   ` Marc-André Lureau
2026-08-27 17:07     ` Alex Bennée
2026-08-28 12:47 ` Akihiko Odaki

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.