On 2026/06/08 16:16, Marc-André Lureau wrote:
Consoles created after init_displaystate() (e.g. hotplugged
display devices) were never added to the /backend/console[N]
QOM tree. Extract qemu_console_add_to_qom() and call it from
qemu_console_register() when the display is already initialized.
Signed-off-by: Marc-André Lureau <[email protected]>
---
ui/console.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/ui/console.c b/ui/console.c
index 975eaf15706..e01d893df4b 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -376,6 +376,13 @@ void qemu_text_console_put_string(QemuTextConsole *s,
const char *str, int len)
}
}
+static void qemu_console_add_to_qom(QemuConsole *con)
+{
+ g_autofree gchar *name = g_strdup_printf("console[%d]", con->index);
+ object_property_add_child(object_get_container("backend"),
+ name, OBJECT(con));
+}
+
static void
qemu_console_register(QemuConsole *c)
{
@@ -413,6 +420,10 @@ qemu_console_register(QemuConsole *c)
}
}
}
+
+ if (phase_check(PHASE_MACHINE_READY)) {
+ qemu_console_add_to_qom(c);
+ }
Coldplugged consoles are not added to the QOM tree when -preconfig is
specified because x-exit-preconfig will happen after init_displaystate()
but before phase_advance(PHASE_MACHINE_READY). Below is an LLM-written
reproduction case:
build/qemu-system-x86_64 \
-machine q35 -nodefaults -display none -S -preconfig \
-device bochs-display,id=gfx0 -qmp stdio <<'EOF'
{"execute":"qmp_capabilities"}
{"execute":"qom-list","arguments":{"path":"/backend"}}
{"execute":"x-exit-preconfig"}
{"execute":"qom-list","arguments":{"path":"/backend"}}
{"execute":"qom-list","arguments":{"path":"/machine/peripheral"}}
{"execute":"qom-list","arguments":{"path":"/backend/console[0]"}}
{"execute":"quit"}
EOF
Regards,
Akihiko Odaki
}
static void
@@ -1089,17 +1100,13 @@ void qemu_console_remove_notifier(Notifier *notifier)
*/
DisplayState *init_displaystate(void)
{
- gchar *name;
QemuConsole *con;
QTAILQ_FOREACH(con, &consoles, next) {
/* Hook up into the qom tree here (not in object_new()), once
* all QemuConsoles are created and the order / numbering
* doesn't change any more */
- name = g_strdup_printf("console[%d]", con->index);
- object_property_add_child(object_get_container("backend"),
- name, OBJECT(con));
- g_free(name);
+ qemu_console_add_to_qom(con);
}
return display_state;