qemu-patch-raspberry4/include/block
Stefan Hajnoczi bc19a0a6e4 throttle-groups: fix restart coroutine iothread race
The following QMP command leads to a crash when iothreads are used:

  { 'execute': 'device_del', 'arguments': {'id': 'data'} }

The backtrace involves the queue restart coroutine where
tgm->throttle_state is a NULL pointer because
throttle_group_unregister_tgm() has already been called:

  (gdb) bt full
  #0  0x00005585a7a3b378 in qemu_mutex_lock_impl (mutex=0xffffffffffffffd0, file=0x5585a7bb3d54 "block/throttle-groups.c", line=412) at util/qemu-thread-posix.c:64
        err = <optimized out>
        __PRETTY_FUNCTION__ = "qemu_mutex_lock_impl"
        __func__ = "qemu_mutex_lock_impl"
  #1  0x00005585a79be074 in throttle_group_restart_queue_entry (opaque=0x5585a9de4eb0) at block/throttle-groups.c:412
        _f = <optimized out>
        data = 0x5585a9de4eb0
        tgm = 0x5585a9079440
        ts = 0x0
        tg = 0xffffffffffffff98
        is_write = false
        empty_queue = 255

This coroutine should not execute in the iothread after the throttle
group member has been unregistered!

The root cause is that the device_del code path schedules the restart
coroutine in the iothread while holding the AioContext lock.  Therefore
the iothread cannot execute the coroutine until after device_del
releases the lock - by this time it's too late.

This patch adds a reference count to ThrottleGroupMember so we can
synchronously wait for restart coroutines to complete.  Once they are
done it is safe to unregister the ThrottleGroupMember.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Message-id: 20190114133257.30299-2-stefanha@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2019-01-24 10:02:28 +00:00
..
accounting.h block/accounting: introduce latency histogram 2018-03-19 14:58:37 -05:00
aio-wait.h block: Use a single global AioWait 2018-09-25 15:50:15 +02:00
aio.h qemu-timer: introduce timer attributes 2018-10-19 13:44:03 +02:00
block.h block: Remove flags parameter from bdrv_reopen_queue() 2018-12-14 11:55:02 +01:00
block_backup.h block/backup: drop unused synchronization interface 2018-12-14 11:52:40 +01:00
block_int.h dirty-bitmap: rename bdrv_undo_clear_dirty_bitmap 2018-10-29 16:23:14 -04:00
blockjob.h block: Use a single global AioWait 2018-09-25 15:50:15 +02:00
blockjob_int.h block: Really pause block jobs on drain 2018-06-18 15:03:25 +02:00
dirty-bitmap.h Revert "block/dirty-bitmap: Add bdrv_dirty_iter_next_area" 2019-01-15 18:26:50 -05:00
nbd.h nbd/client: Add meta contexts to nbd_receive_export_list() 2019-01-21 15:49:52 -06:00
nvme.h block: Move NVMe constants to a separate header 2018-02-08 09:22:03 +08:00
qapi.h Drop superfluous includes of qapi-types.h and test-qapi-types.h 2018-02-09 05:05:11 +01:00
qdict.h block: Factor out qobject_input_visitor_new_flat_confused() 2018-06-15 14:49:44 +02:00
raw-aio.h file-posix: Make .bdrv_co_truncate asynchronous 2018-06-29 14:20:56 +02:00
snapshot.h Move include qemu/option.h from qemu-common.h to actual users 2018-02-09 13:52:16 +01:00
thread-pool.h Clean up decorations and whitespace around header guards 2016-07-12 16:20:46 +02:00
throttle-groups.h throttle-groups: fix restart coroutine iothread race 2019-01-24 10:02:28 +00:00
write-threshold.h Use scripts/clean-includes to drop redundant qemu/typedefs.h 2016-03-22 22:20:16 +01:00