qemu-e2k/stubs
Peter Xu 62aa1d887f monitor: Fix unsafe sharing of @cur_mon among threads
@cur_mon is null unless the main thread is running monitor code, either
HMP code within monitor_read(), or QMP code within
monitor_qmp_dispatch().

Use of @cur_mon outside the main thread is therefore unsafe.

Most of its uses are in monitor command handlers.  These run in the main
thread.

However, there are also uses hiding elsewhere, such as in
error_vprintf(), and thus error_report(), making these functions unsafe
outside the main thread.  No such unsafe uses are known at this time.
Regardless, this is an unnecessary trap.  It's an ancient trap, though.

More recently, commit cf869d5317 "qmp: support out-of-band (oob)
execution" spiced things up: the monitor I/O thread assigns to @cur_mon
when executing commands out-of-band.  Having two threads save, set and
restore @cur_mon without synchronization is definitely unsafe.  We can
end up with @cur_mon null while the main thread runs monitor code, or
non-null while it runs non-monitor code.

We could fix this by making the I/O thread not mess with @cur_mon, but
that would leave the trap armed and ready.

Instead, make @cur_mon thread-local.  It's now reliably null unless the
thread is running monitor code.

Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
[peterx: update subject and commit message written by Markus]
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
Message-Id: <20180720033451.32710-1-peterx@redhat.com>
2018-07-23 14:00:03 +02:00
..
Makefile.objs pc-dimm: factor out MemoryDevice interface 2018-05-07 10:00:02 -03:00
arch-query-cpu-def.c Include qapi/error.h exactly where needed 2018-02-09 13:50:17 +01:00
arch-query-cpu-model-baseline.c Include qapi/error.h exactly where needed 2018-02-09 13:50:17 +01:00
arch-query-cpu-model-comparison.c Include qapi/error.h exactly where needed 2018-02-09 13:50:17 +01:00
arch-query-cpu-model-expansion.c Include qapi/error.h exactly where needed 2018-02-09 13:50:17 +01:00
bdrv-next-monitor-owned.c block: Add bdrv_next_monitor_owned() 2016-03-17 15:47:56 +01:00
blk-commit-all.c block: Move some bdrv_*_all() functions to BB 2016-03-17 15:47:56 +01:00
blockdev-close-all-bdrv-states.c all: Clean up includes 2016-02-16 14:29:28 +00:00
change-state-handler.c stubs: Add vm state change handler stubs 2017-08-15 10:03:27 -05:00
clock-warp.c icount: decouple warp calls 2016-03-15 18:23:45 +01:00
cpu-get-clock.c stubs: Clean up includes 2016-02-04 17:01:04 +00:00
cpu-get-icount.c cpus: define QEMUTimerListNotifyCB for QEMU system emulation 2017-03-14 13:28:29 +01:00
dump.c Include qmp-commands.h exactly where needed 2018-02-09 13:52:10 +01:00
error-printf.c tests: send error_report to test log 2016-11-01 16:06:57 +01:00
fd-register.c stubs: Clean up includes 2016-02-04 17:01:04 +00:00
fdset.c monitor: add lock to protect mon_fdsets 2018-06-18 15:48:22 +02:00
gdbstub.c Clean up includes some more 2016-03-22 22:20:16 +01:00
get-vm-name.c stubs: Clean up includes 2016-02-04 17:01:04 +00:00
iothread-lock.c stubs: Clean up includes 2016-02-04 17:01:04 +00:00
iothread.c aio: introduce qemu_get_current_aio_context 2016-10-28 21:50:18 +08:00
is-daemonized.c stubs: Clean up includes 2016-02-04 17:01:04 +00:00
linux-aio.c linux-aio: properly bubble up errors from initialization 2018-06-27 13:06:34 +01:00
machine-init-done.c vl: export machine_init_done 2018-03-12 16:12:46 +01:00
migr-blocker.c migration: Create migration/blocker.h 2017-05-17 12:04:59 +02:00
monitor.c monitor: Fix unsafe sharing of @cur_mon among threads 2018-07-23 14:00:03 +02:00
notify-event.c stubs: Clean up includes 2016-02-04 17:01:04 +00:00
pc_madt_cpu_entry.c machine: Make possible_cpu_arch_ids() return const pointer 2017-01-23 21:25:37 -02:00
pci-host-piix.c hw/acpi: Move acpi_set_pci_info to pcihp 2017-09-08 16:15:17 +03:00
qmp_memory_device.c pc-dimm: factor out MemoryDevice interface 2018-05-07 10:00:02 -03:00
qtest.c stubs: Clean up includes 2016-02-04 17:01:04 +00:00
ram-block.c stubs: Add stubs for ram block API 2018-02-08 09:22:03 +08:00
replay.c replay: make locking visible outside replay code 2018-03-12 16:12:50 +01:00
runstate-check.c stubs: Clean up includes 2016-02-04 17:01:04 +00:00
set-fd-handler.c block: move AioContext, QEMUTimer, main-loop to libqemuutil 2017-02-21 11:14:07 +00:00
slirp.c qemu-common: stop including qemu/host-utils.h from qemu-common.h 2016-05-19 16:42:28 +02:00
sysbus.c stubs: Clean up includes 2016-02-04 17:01:04 +00:00
target-get-monitor-def.c Clean up includes some more 2016-03-22 22:20:16 +01:00
target-monitor-defs.c Clean up includes some more 2016-03-22 22:20:16 +01:00
tpm.c Include less of the generated modular QAPI headers 2018-03-02 13:45:50 -06:00
trace-control.c trace: remove global 'uint16 dstate[]' array 2016-10-12 09:35:54 +02:00
uuid.c qapi: Empty out qapi-schema.json 2018-03-02 13:45:50 -06:00
vm-stop.c stubs: Clean up includes 2016-02-04 17:01:04 +00:00
vmgenid.c qapi: Empty out qapi-schema.json 2018-03-02 13:45:50 -06:00
vmstate.c migration: Move check_migratable() into qdev.c 2017-05-17 12:04:59 +02:00
xen-common.c move xen-common.c to hw/xen/ 2017-04-25 11:04:34 -07:00
xen-hvm.c qapi: Empty out qapi-schema.json 2018-03-02 13:45:50 -06:00