qemu-cr16/chardev
Jie Song d6b9de8f9e monitor/qmp: cleanup SocketChardev listener sources early to avoid fd handling race
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.

Signed-off-by: Jie Song <songjie_yewu@cmss.chinamobile.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-ID: <20251125140706.114197-1-mail@jiesong.me>
(cherry picked from commit e714f1a3d4d1e66b9a3ff4be1ff999c32bbef29e)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
2026-01-08 17:44:39 +03:00
..
baum.c chardev/baum: Fix compiler warning for Windows builds 2025-09-03 10:56:11 +03:00
char-console.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
char-fd.c chardev: qemu_chr_open_fd(): add errp 2025-09-19 12:46:07 +01:00
char-fe.c char: rename CharBackend->CharFrontend 2025-10-28 14:49:52 +01:00
char-file.c chardev/char-file: fix failure path 2025-11-25 11:09:07 +04:00
char-hmp-cmds.c qapi: Move include/qapi/qmp/ to include/qobject/ 2025-02-10 15:33:16 +01:00
char-hub.c char: rename CharBackend->CharFrontend 2025-10-28 14:49:52 +01:00
char-io.c monitor/qmp: cleanup SocketChardev listener sources early to avoid fd handling race 2026-01-08 17:44:39 +03:00
char-mux.c char: rename CharBackend->CharFrontend 2025-10-28 14:49:52 +01:00
char-null.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
char-parallel.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
char-pipe.c chardev: qemu_chr_open_fd(): add errp 2025-09-19 12:46:07 +01:00
char-pty.c chardev/char-pty: Do not ignore chr_write() failures 2025-11-25 11:09:07 +04:00
char-ringbuf.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
char-serial.c chardev: close an fd on failure path 2025-09-19 12:46:07 +01:00
char-socket.c monitor/qmp: cleanup SocketChardev listener sources early to avoid fd handling race 2026-01-08 17:44:39 +03:00
char-stdio.c chardev: qemu_chr_open_fd(): add errp 2025-09-19 12:46:07 +01:00
char-udp.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
char-win-stdio.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
char-win.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
char.c trivial patches for 2025-10-29 2025-10-29 10:44:15 +01:00
chardev-internal.h char: rename CharBackend->CharFrontend 2025-10-28 14:49:52 +01:00
meson.build chardev/char-hub: implement backend chardev aggregator 2025-02-03 13:57:08 +04:00
msmouse.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
spice.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
testdev.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00
trace-events chardev: add tracing of socket error conditions 2024-07-24 10:39:10 +01:00
trace.h trace: switch position of headers to what Meson requires 2020-08-21 06:18:24 -04:00
wctablet.c qom: Have class_init() take a const data argument 2025-04-25 17:00:41 +02:00