Monitor patches for 2026-01-07
[PULL 4/4] monitor/qmp: cleanup SocketChardev listener sources early to avoid fd handling race
In reply to Markus ArmbrusterFrom: Jie Song <[email protected]>
When starting a dummy QEMU process with virsh version, monitor_init_qmp() enables IOThread monitoring of the QMP fd by default. However, a race condition exists during the initialization phase: the IOThread only removes the main thread's fd watch when it reaches qio_net_listener_set_client_func_full(), which may be delayed under high system load.
This creates a window between monitor_qmp_setup_handlers_bh() and qio_net_listener_set_client_func_full() where both the main thread and IOThread are simultaneously monitoring the same fd and processing events. This race can cause either the main thread or the IOThread to hang and become unresponsive.
Fix this by proactively cleaning up the listener's IO sources in monitor_init_qmp() before the IOThread initializes QMP monitoring, ensuring exclusive fd ownership and eliminating the race condition.
Message-ID: <[email protected]>
--- include/chardev/char-io.h | 2 ++ include/chardev/char.h | 2 ++ chardev/char-io.c | 8 ++++++++ chardev/char-socket.c | 10 ++++++++++ monitor/qmp.c | 5 +++++ 5 files changed, 27 insertions(+)
include/chardev/char-io.h +2 -0
@@ -43,4 +43,6 @@ int io_channel_send(QIOChannel *ioc, const void *buf, size_t len);int io_channel_send_full (QIOChannel *ioc,const void *buf,size_t len,int *fds,size_t nfds); +void remove_listener_fd_in_watch (Chardev *chr); +#endif /* CHAR_IO_H */
include/chardev/char.h +2 -0
@@ -307,6 +307,8 @@ struct ChardevClass {/* handle various events */ void (*chr_be_event)(Chardev *s,QEMUChrEvent event); + +void (*chr_listener_cleanup)(Chardev *chr); }; Chardev *qemu_chardev_new(const char *id, const char *typename,
chardev/char-io.c +8 -0
@@ -182,3 +182,11 @@ int io_channel_send(QIOChannel *ioc, const void *buf, size_t len) {return io_channel_send_full (ioc, buf, len,NULL ,0 ); } + +void remove_listener_fd_in_watch (Chardev *chr) +{ +ChardevClass *cc =CHARDEV_GET_CLASS (chr); +if (cc->chr_listener_cleanup) { + cc->chr_listener_cleanup (chr); + } +}
chardev/char-socket.c +10 -0
@@ -1570,6 +1570,15 @@ char_socket_get_connected(Object *obj, Error **errp)return s->state ==TCP_CHARDEV_STATE_CONNECTED ; } +static void tcp_chr_listener_cleanup (Chardev *chr) +{ +SocketChardev *s =SOCKET_CHARDEV (chr); +if (s->listener) { +qio_net_listener_set_client_func_full (s->listener,NULL ,NULL , +NULL , chr->gcontext); + } +} +static void char_socket_class_init (ObjectClass *oc,const void *data) {ChardevClass *cc =CHARDEV_CLASS (oc);
@@ -1587,6 +1596,7 @@ static void char_socket_class_init(ObjectClass *oc, const void *data) cc->chr_add_client = tcp_chr_add_client; cc->chr_add_watch = tcp_chr_add_watch; cc->chr_update_read_handler = tcp_chr_update_read_handler; + cc->chr_listener_cleanup = tcp_chr_listener_cleanup; object_class_property_add(oc, "addr", "SocketAddress", char_socket_get_addr, NULL,
monitor/qmp.c +5 -0
@@ -539,6 +539,11 @@ void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp)* e.g. the chardev is in client mode, with wait=on. */ remove_fd_in_watch (chr); +/* +* Clean up listener IO sources early to prevent racy fd +* handling between the main thread and the I/O thread. +*/ +remove_listener_fd_in_watch (chr);/* * We can't call qemu_chr_fe_set_handlers() directly here * since chardev might be running in the monitor I/O
Signature · 1 line
2.52.0
[PULL 2/4] qdev: Legacy properties are now unused internally, drop
In reply to Markus ArmbrusterLegacy properties are an accidental and undocumented external interface. qom-set doesn't work for them (no .set() method). qom-get and qom-list-get work only when the underlying qdev property has a .print() method, i.e. the PCI address properties, as explained in the previous commit. Here's one that works:
(qemu) qom-get /machine/unattached/device[3]/pm addr 11
(qemu) qom-get /machine/unattached/device[3]/pm legacy-addr "01.3"
And here's one that doesn't:
(qemu) qom-get /machine/unattached/device[3]/pm bus "/machine/i440fx/pci.0"
(qemu) qom-get /machine/unattached/device[3]/pm legacy-bus
Error: Property 'PIIX4_PM.legacy-bus' is not readable
Actual use of this undocumented interface seems quite unlikely. A deprecation period seems unnecessary. Drop it.
Message-ID: <[email protected]>
--- hw/core/qdev-properties.c | 46 --------------------------------------- 1 file changed, 46 deletions(-)
hw/core/qdev-properties.c +0 -46
@@ -1110,51 +1110,6 @@ static void qdev_class_add_property(DeviceClass *klass, const char *name,object_class_property_set_description (oc, name, prop->info->description); } -/** -* Legacy property handling -*/ - -static void qdev_get_legacy_property (Object *obj,Visitor *v, -const char *name,void *opaque, -Error **errp) -{ -const Property *prop = opaque; -char *s; - - s = prop->info->visit_type_str (v, name, &s, errp); -g_free (s); -} - -/** -* qdev_class_add_legacy_property: -* @dev: Device to add the property to. -* @prop: The qdev property definition. -* -* Add a legacy QOM property to @dev for qdev property @prop. -* -* Legacy properties are string versions of QOM properties. The format of -* the string depends on the property type. Legacy properties are only -* needed for "info qtree". -* -* Do not use this in new code! QOM Properties added through this interface -* will be given names in the "legacy" namespace. -*/ -static void qdev_class_add_legacy_property (DeviceClass *dc,const Property *prop) -{ - g_autofree char *name = NULL; - -/* Register pointer properties as legacy properties */ -if (!prop->info->print && prop->info->get) { -return ; - } - - name =g_strdup_printf ("legacy-%s" , prop->name); -object_class_property_add (OBJECT_CLASS (dc), name,"str" , - prop->info->print ? qdev_get_legacy_property : prop->info->get, -NULL ,NULL , (Property *)prop); -} -void device_class_set_props_n (DeviceClass *dc,const Property *props,size_t n) {/* We used a hole in DeviceClass because that's still a lot. */
@@ -1167,7 +1122,6 @@ void device_class_set_props_n(DeviceClass *dc, const Property *props, size_t n)for (size_t i =0 ; i < n; ++i) {const Property *prop = &props[i];assert (prop->name); -qdev_class_add_legacy_property (dc, prop);qdev_class_add_property (dc, prop->name, prop); } }
Signature · 1 line
2.52.0
The following changes since commit 0fc482b73d8e085d1375b4e17b0647fd2e6fe8f0:
Merge tag 'pull-aspeed-20260105' of https://github.com/legoater/qemu into staging (2026-01-06 06:52:47 +1100)
are available in the Git repository at:
https://repo.or.cz/qemu/armbru.git tags/pull-monitor-2026-01-07
for you to fetch changes up to e714f1a3d4d1e66b9a3ff4be1ff999c32bbef29e:
monitor/qmp: cleanup SocketChardev listener sources early to avoid fd handling race (2026-01-07 17:05:25 +0100)
----------------------------------------------------------------
Monitor patches for 2026-01-07
----------------------------------------------------------------
Jie Song (1):
monitor/qmp: cleanup SocketChardev listener sources early to avoid fd handling race
Markus Armbruster (3):
qdev: Fix "info qtree" to show links
qdev: Legacy properties are now unused internally, drop scripts/device-crash-test: ERROR_RULE_LIST garbage collection
include/chardev/char-io.h | 2 ++ include/chardev/char.h | 2 ++ chardev/char-io.c | 8 ++++++++ chardev/char-socket.c | 10 ++++++++++ hw/core/qdev-properties.c | 46 ---------------------------------------------- monitor/qmp.c | 5 +++++ system/qdev-monitor.c | 7 +++---- scripts/device-crash-test | 7 ------- 8 files changed, 30 insertions(+), 57 deletions(-)
Signature · 1 line
2.52.0
[PULL 3/4] scripts/device-crash-test: ERROR_RULE_LIST garbage collection
Device 'nand' was dropped in commit commit e86c1f967a3.
Device 'vfio-amd-xgbe' was dropped in commit aeb1a50d4a7.
Device 'vfio-calxeda-xgmac' was dropped in commit 8ebc416ac17.
The last error messages matching r"images* must be given with the 'pflash' parameter" was dropped in commit a2ccff4d2bc.
The error message matching r"Option '-device [\w.,-]+' cannot be handled by this machine" was dropped in commit commit db78a605599.
The error message matching r"Ignoring smp_cpus value" ceased to match in commit f2ad5140fa5, and was then dropped in commit 72649619341.
The error message matching r"rom check and register reset failed" was lost in merge commit af3f37319cb.
Message-ID: <[email protected]>
--- scripts/device-crash-test | 7 ------- 1 file changed, 7 deletions(-)
scripts/device-crash-test +0 -7
@@ -93,7 +93,6 @@ ERROR_RULE_LIST = [ {'device':'ivshmem-doorbell', 'expected':True}, # You must specify a 'chardev' {'device':'ivshmem-plain', 'expected':True}, # You must specify a 'memdev' {'device':'loader', 'expected':True}, # please include valid arguments - {'device':'nand', 'expected':True}, # Unsupported NAND block size 0x1 {'device':'nvdimm', 'expected':True}, # 'memdev' property is not set {'device':'nvme', 'expected':True}, # Device initialization failed {'device':'pc-dimm', 'expected':True}, # 'memdev' property is not set
@@ -114,8 +113,6 @@ ERROR_RULE_LIST = [ {'device':'usb-redir', 'expected':True}, # Parameter 'chardev' is missing {'device':'usb-serial', 'expected':True}, # Property chardev is required {'device':'usb-storage', 'expected':True}, # drive property not set - {'device':'vfio-amd-xgbe', 'expected':True}, # -device vfio-amd-xgbe: vfio error: wrong host device name - {'device':'vfio-calxeda-xgmac', 'expected':True}, # -device vfio-calxeda-xgmac: vfio error: wrong host device name {'device':'vfio-pci', 'expected':True}, # No provided host device {'device':'vfio-pci-igd-lpc-bridge', 'expected':True}, # VFIO dummy ISA/LPC bridge must have address 1f.0 {'device':'vhost-scsi.*', 'expected':True}, # vhost-scsi: missing wwpn
@@ -159,7 +156,6 @@ ERROR_RULE_LIST = [ # Silence INFO messages for errors that are common on multiple # devices/machines: {'log':r"No '[\w-]+' bus found for device '[\w-]+'"}, - {'log':r"images* must be given with the 'pflash' parameter"}, {'log':r"(Guest|ROM|Flash|Kernel) image must be specified"}, {'log':r"[cC]ould not load [\w ]+ (BIOS|bios) '[\w-]+\.bin'"}, {'log':r"Couldn't find rom image '[\w-]+\.bin'"},
@@ -167,7 +163,6 @@ ERROR_RULE_LIST = [ {'log':r"Can't create a second ISA bus"}, {'log':r"duplicate fw_cfg file name"}, # sysbus-related error messages: most machines reject most dynamic sysbus devices: - {'log':r"Option '-device [\w.,-]+' cannot be handled by this machine"}, {'log':r"Device [\w.,-]+ is not supported by this machine yet"}, {'log':r"Device [\w.,-]+ can not be dynamically instantiated"}, {'log':r"Platform Bus: Can not fit MMIO region of size "},
@@ -175,11 +170,9 @@ ERROR_RULE_LIST = [ {'device':'.*-spapr-cpu-core', 'log':r"CPU core type should be"}, {'log':r"MSI(-X)? is not supported by interrupt controller"}, {'log':r"pxb-pcie? devices cannot reside on a PCIe? bus"}, - {'log':r"Ignoring smp_cpus value"}, {'log':r"sd_init failed: Drive 'sd0' is already in use because it has been automatically connected to another device"}, {'log':r"This CPU requires a smaller page size than the system is using"}, {'log':r"MSI-X support is mandatory in the S390 architecture"}, - {'log':r"rom check and register reset failed"}, {'log':r"Unable to initialize GIC, CPUState for CPU#0 not valid"}, {'log':r"Multiple VT220 operator consoles are not supported"}, {'log':r"core 0 already populated"},
Signature · 1 line
2.52.0
[PULL 1/4] qdev: Fix "info qtree" to show links
In reply to Markus Armbrusterqdev_print_props() retrieves a property's value from its legacy property if it exists. A legacy property is created by qdev_class_add_legacy_property() when the property has a print() method or does not have a get() method.
If it has a print() method, the legacy property's value is obtained from the property's print() method. This is used to format PCI addresses nicely, i.e. like 01.3 instead of 11.
Else, if doesn't have a get() method, the legacy property is unreadable. "info qtree" silently skips unreadable properties.
Link properties don't have a get() method, and are therefore skipped. This is wrong, because the underlying QOM property *is* readable.
Change qdev_print_props() to simply use a print() method directly if it exists, else get the value via QOM.
"info qtree" now shows links fine. For instance, machine "pc" onboard device "PIIX4_PM" property "bus" is now visible.
Message-ID: <[email protected]>
--- system/qdev-monitor.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
system/qdev-monitor.c +3 -4
@@ -762,19 +762,18 @@ static void qdev_print_props(Monitor *mon, DeviceState *dev, DeviceClass *dc,for (int i =0 , n = dc->props_count_; i < n; ++i) {const Property *prop = &dc->props_[i];char *value; -char *legacy_name =g_strdup_printf ("legacy-%s" , prop->name); -if (object_property_get_type (OBJECT (dev), legacy_name,NULL )) { - value =object_property_get_str (OBJECT (dev), legacy_name,NULL ); +if (prop->info->print) { + value = prop->info->OBJECT (dev), prop); }else { value =object_property_print (OBJECT (dev), prop->name, true,NULL ); } -g_free (legacy_name);if (!value) {continue ; } +qdev_printf ("%s = %s\n" , prop->name, *value ? value :"<null>" );g_free (value);
Signature · 1 line
2.52.0
Richard Henderson
AppliedQuoted 6 lines · Markus Armbruster
The following changes since commit
0fc482b73d8e085d1375b4e17b0647fd2e6fe8f0:Merge tag 'pull-aspeed-20260105' ofhttps://github.com/legoater/qemu into staging (2026-01-06 06:52:47 +1100)are available in the Git repository at:
Quoted 8 lines
https://repo.or.cz/qemu/armbru.git tags/pull-monitor-2026-01-07for you to fetch changes up to
e714f1a3d4d1e66b9a3ff4be1ff999c32bbef29e:monitor/qmp: cleanup SocketChardev listener sources early to avoid fd handling race (2026-01-07 17:05:25 +0100)
----------------------------------------------------------------
Monitor patches for 2026-01-07
Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/11.0 as appropriate.
r~