[PATCH v3 22/35] ui/dbus: implement display cleanup

Marc-André Lureau posted 35 patches 2 months ago
Maintainers: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>, Alex Williamson <alex@shazbot.org>, "Cédric Le Goater" <clg@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, "Philippe Mathieu-Daudé" <philmd@mailo.com>, Fabiano Rosas <farosas@suse.de>, Laurent Vivier <lvivier@redhat.com>, Peter Maydell <peter.maydell@linaro.org>, Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
There is a newer version of this series
[PATCH v3 22/35] ui/dbus: implement display cleanup
Posted by Marc-André Lureau 2 months ago
Add dbus_cleanup() to unparent the D-Bus display object, ensuring
proper teardown before user_creatable_cleanup() runs.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 ui/dbus-console.c |  3 +++
 ui/dbus.c         | 13 +++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/ui/dbus-console.c b/ui/dbus-console.c
index 742bf9639a4..63d21493101 100644
--- a/ui/dbus-console.c
+++ b/ui/dbus-console.c
@@ -152,6 +152,9 @@ dbus_display_console_dispose(GObject *object)
     DBusDisplayConsole *ddc = DBUS_DISPLAY_CONSOLE(object);
 
     qemu_console_unregister_listener(&ddc->dcl);
+    if (ddc->dcl.con) {
+        qemu_console_set_display_gl_ctx(ddc->dcl.con, NULL);
+    }
     qemu_remove_mouse_mode_change_notifier(&ddc->mouse_mode_notifier);
     g_clear_pointer(&ddc->kbd_leds_updated, qemu_remove_led_event_handler);
     g_clear_object(&ddc->iface_touch);
diff --git a/ui/dbus.c b/ui/dbus.c
index e02a94df2f3..b23cb44c535 100644
--- a/ui/dbus.c
+++ b/ui/dbus.c
@@ -615,10 +615,23 @@ static const TypeInfo dbus_display_info = {
     }
 };
 
+static void
+dbus_cleanup(void)
+{
+    Object *o;
+
+    o = object_resolve_path_component(object_get_objects_root(),
+                                      "dbus-display");
+    if (o) {
+        object_unparent(o);
+    }
+}
+
 static QemuDisplay qemu_display_dbus = {
     .type       = DISPLAY_TYPE_DBUS,
     .early_init = early_dbus_init,
     .init       = dbus_init,
+    .cleanup    = dbus_cleanup,
     .vc         = "vc",
 };
 

-- 
2.54.0


Re: [PATCH v3 22/35] ui/dbus: implement display cleanup
Posted by Akihiko Odaki 2 months ago
On 2026/06/11 18:03, Marc-André Lureau wrote:
> Add dbus_cleanup() to unparent the D-Bus display object, ensuring
> proper teardown before user_creatable_cleanup() runs.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>   ui/dbus-console.c |  3 +++
>   ui/dbus.c         | 13 +++++++++++++
>   2 files changed, 16 insertions(+)
> 
> diff --git a/ui/dbus-console.c b/ui/dbus-console.c
> index 742bf9639a4..63d21493101 100644
> --- a/ui/dbus-console.c
> +++ b/ui/dbus-console.c
> @@ -152,6 +152,9 @@ dbus_display_console_dispose(GObject *object)
>       DBusDisplayConsole *ddc = DBUS_DISPLAY_CONSOLE(object);
>   
>       qemu_console_unregister_listener(&ddc->dcl);
> +    if (ddc->dcl.con) {
> +        qemu_console_set_display_gl_ctx(ddc->dcl.con, NULL);

Somewhat weird, but theoretically this may clear a console GL context 
registered by another display. Below is an example I let an LLM generate 
(not tested):

qemu-system-x86_64 \
   -machine q35 \
   -device virtio-vga-gl \
   -display dbus,p2p=yes,gl=off \
   -spice unix=on,addr=/tmp/qemu-spice.sock,disable-ticketing=on,gl=on

> +    }
>       qemu_remove_mouse_mode_change_notifier(&ddc->mouse_mode_notifier);
>       g_clear_pointer(&ddc->kbd_leds_updated, qemu_remove_led_event_handler);
>       g_clear_object(&ddc->iface_touch);
> diff --git a/ui/dbus.c b/ui/dbus.c
> index e02a94df2f3..b23cb44c535 100644
> --- a/ui/dbus.c
> +++ b/ui/dbus.c
> @@ -615,10 +615,23 @@ static const TypeInfo dbus_display_info = {
>       }
>   };
>   
> +static void
> +dbus_cleanup(void)
> +{
> +    Object *o;
> +
> +    o = object_resolve_path_component(object_get_objects_root(),
> +                                      "dbus-display");
> +    if (o) {
> +        object_unparent(o);
> +    }
> +}
> +
>   static QemuDisplay qemu_display_dbus = {
>       .type       = DISPLAY_TYPE_DBUS,
>       .early_init = early_dbus_init,
>       .init       = dbus_init,
> +    .cleanup    = dbus_cleanup,
>       .vc         = "vc",
>   };
>   
> 


Re: [PATCH v3 22/35] ui/dbus: implement display cleanup
Posted by Marc-André Lureau 2 months ago
Hi

On Thu, Jun 11, 2026 at 5:19 PM Akihiko Odaki
<odaki@rsg.ci.i.u-tokyo.ac.jp> wrote:
>
> On 2026/06/11 18:03, Marc-André Lureau wrote:
> > Add dbus_cleanup() to unparent the D-Bus display object, ensuring
> > proper teardown before user_creatable_cleanup() runs.
> >
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >   ui/dbus-console.c |  3 +++
> >   ui/dbus.c         | 13 +++++++++++++
> >   2 files changed, 16 insertions(+)
> >
> > diff --git a/ui/dbus-console.c b/ui/dbus-console.c
> > index 742bf9639a4..63d21493101 100644
> > --- a/ui/dbus-console.c
> > +++ b/ui/dbus-console.c
> > @@ -152,6 +152,9 @@ dbus_display_console_dispose(GObject *object)
> >       DBusDisplayConsole *ddc = DBUS_DISPLAY_CONSOLE(object);
> >
> >       qemu_console_unregister_listener(&ddc->dcl);
> > +    if (ddc->dcl.con) {
> > +        qemu_console_set_display_gl_ctx(ddc->dcl.con, NULL);
>
> Somewhat weird, but theoretically this may clear a console GL context
> registered by another display. Below is an example I let an LLM generate
> (not tested):
>
> qemu-system-x86_64 \
>    -machine q35 \
>    -device virtio-vga-gl \
>    -display dbus,p2p=yes,gl=off \
>    -spice unix=on,addr=/tmp/qemu-spice.sock,disable-ticketing=on,gl=on
>

Right, it's a bit embarassing. I think spice should be a display (and
vnc too eventually..), so we wouldn't have 2 competing console/display
handlers that have their own GL.

I think the safest for now is to simply prevent spice with a display
providing GL. I'll work on a patch.