]> git.proxmox.com Git - pve-qemu.git/blob - debian/patches/extra/0002-virtio-blk-schedule-virtio_notify_config-to-run-on-m.patch
bump version to 4.1.1-4
[pve-qemu.git] / debian / patches / extra / 0002-virtio-blk-schedule-virtio_notify_config-to-run-on-m.patch
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Sergio Lopez <slp@redhat.com>
3 Date: Mon, 16 Sep 2019 13:24:12 +0200
4 Subject: [PATCH] virtio-blk: schedule virtio_notify_config to run on main
5 context
6
7 virtio_notify_config() needs to acquire the global mutex, which isn't
8 allowed from an iothread, and may lead to a deadlock like this:
9
10 - main thead
11 * Has acquired: qemu_global_mutex.
12 * Is trying the acquire: iothread AioContext lock via
13 AIO_WAIT_WHILE (after aio_poll).
14
15 - iothread
16 * Has acquired: AioContext lock.
17 * Is trying to acquire: qemu_global_mutex (via
18 virtio_notify_config->prepare_mmio_access).
19
20 If virtio_blk_resize() is called from an iothread, schedule
21 virtio_notify_config() to be run in the main context BH.
22
23 [Removed unnecessary newline as suggested by Kevin Wolf
24 <kwolf@redhat.com>.
25 --Stefan]
26
27 Signed-off-by: Sergio Lopez <slp@redhat.com>
28 Reviewed-by: Kevin Wolf <kwolf@redhat.com>
29 Message-id: 20190916112411.21636-1-slp@redhat.com
30 Message-Id: <20190916112411.21636-1-slp@redhat.com>
31 Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
32 ---
33 hw/block/virtio-blk.c | 16 +++++++++++++++-
34 1 file changed, 15 insertions(+), 1 deletion(-)
35
36 diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
37 index cbb3729158..0d9adcdaff 100644
38 --- a/hw/block/virtio-blk.c
39 +++ b/hw/block/virtio-blk.c
40 @@ -16,6 +16,7 @@
41 #include "qemu/iov.h"
42 #include "qemu/module.h"
43 #include "qemu/error-report.h"
44 +#include "qemu/main-loop.h"
45 #include "trace.h"
46 #include "hw/block/block.h"
47 #include "sysemu/blockdev.h"
48 @@ -1082,11 +1083,24 @@ static int virtio_blk_load_device(VirtIODevice *vdev, QEMUFile *f,
49 return 0;
50 }
51
52 +static void virtio_resize_cb(void *opaque)
53 +{
54 + VirtIODevice *vdev = opaque;
55 +
56 + assert(qemu_get_current_aio_context() == qemu_get_aio_context());
57 + virtio_notify_config(vdev);
58 +}
59 +
60 static void virtio_blk_resize(void *opaque)
61 {
62 VirtIODevice *vdev = VIRTIO_DEVICE(opaque);
63
64 - virtio_notify_config(vdev);
65 + /*
66 + * virtio_notify_config() needs to acquire the global mutex,
67 + * so it can't be called from an iothread. Instead, schedule
68 + * it to be run in the main context BH.
69 + */
70 + aio_bh_schedule_oneshot(qemu_get_aio_context(), virtio_resize_cb, vdev);
71 }
72
73 static const BlockDevOps virtio_block_ops = {
74 --
75 2.20.1
76