From d090eaa20927f103899e3e228d94f38a32df8a66 Mon Sep 17 00:00:00 2001 From: Stefan Reiter Date: Mon, 25 Nov 2019 12:38:15 +0100 Subject: [PATCH] fix #2486: include fix for disk hot-resize regression (w/ iothread=1) See: https://lists.nongnu.org/archive/html/qemu-devel/2019-09/msg03201.html Signed-off-by: Stefan Reiter --- ...ule-virtio_notify_config-to-run-on-m.patch | 76 +++++++++++++++++++ debian/patches/series | 1 + 2 files changed, 77 insertions(+) create mode 100644 debian/patches/extra/0002-virtio-blk-schedule-virtio_notify_config-to-run-on-m.patch diff --git a/debian/patches/extra/0002-virtio-blk-schedule-virtio_notify_config-to-run-on-m.patch b/debian/patches/extra/0002-virtio-blk-schedule-virtio_notify_config-to-run-on-m.patch new file mode 100644 index 0000000..f20c7d7 --- /dev/null +++ b/debian/patches/extra/0002-virtio-blk-schedule-virtio_notify_config-to-run-on-m.patch @@ -0,0 +1,76 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Sergio Lopez +Date: Mon, 16 Sep 2019 13:24:12 +0200 +Subject: [PATCH] virtio-blk: schedule virtio_notify_config to run on main + context + +virtio_notify_config() needs to acquire the global mutex, which isn't +allowed from an iothread, and may lead to a deadlock like this: + + - main thead + * Has acquired: qemu_global_mutex. + * Is trying the acquire: iothread AioContext lock via + AIO_WAIT_WHILE (after aio_poll). + + - iothread + * Has acquired: AioContext lock. + * Is trying to acquire: qemu_global_mutex (via + virtio_notify_config->prepare_mmio_access). + +If virtio_blk_resize() is called from an iothread, schedule +virtio_notify_config() to be run in the main context BH. + +[Removed unnecessary newline as suggested by Kevin Wolf +. +--Stefan] + +Signed-off-by: Sergio Lopez +Reviewed-by: Kevin Wolf +Message-id: 20190916112411.21636-1-slp@redhat.com +Message-Id: <20190916112411.21636-1-slp@redhat.com> +Signed-off-by: Stefan Hajnoczi +--- + hw/block/virtio-blk.c | 16 +++++++++++++++- + 1 file changed, 15 insertions(+), 1 deletion(-) + +diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c +index cbb3729158..0d9adcdaff 100644 +--- a/hw/block/virtio-blk.c ++++ b/hw/block/virtio-blk.c +@@ -16,6 +16,7 @@ + #include "qemu/iov.h" + #include "qemu/module.h" + #include "qemu/error-report.h" ++#include "qemu/main-loop.h" + #include "trace.h" + #include "hw/block/block.h" + #include "sysemu/blockdev.h" +@@ -1082,11 +1083,24 @@ static int virtio_blk_load_device(VirtIODevice *vdev, QEMUFile *f, + return 0; + } + ++static void virtio_resize_cb(void *opaque) ++{ ++ VirtIODevice *vdev = opaque; ++ ++ assert(qemu_get_current_aio_context() == qemu_get_aio_context()); ++ virtio_notify_config(vdev); ++} ++ + static void virtio_blk_resize(void *opaque) + { + VirtIODevice *vdev = VIRTIO_DEVICE(opaque); + +- virtio_notify_config(vdev); ++ /* ++ * virtio_notify_config() needs to acquire the global mutex, ++ * so it can't be called from an iothread. Instead, schedule ++ * it to be run in the main context BH. ++ */ ++ aio_bh_schedule_oneshot(qemu_get_aio_context(), virtio_resize_cb, vdev); + } + + static const BlockDevOps virtio_block_ops = { +-- +2.20.1 + diff --git a/debian/patches/series b/debian/patches/series index a2c1271..a09ba1b 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -1,4 +1,5 @@ extra/0001-monitor-qmp-resume-monitor-when-clearing-its-queue.patch +extra/0002-virtio-blk-schedule-virtio_notify_config-to-run-on-m.patch pve/0001-PVE-Config-block-file-change-locking-default-to-off.patch pve/0002-PVE-Config-Adjust-network-script-path-to-etc-kvm.patch pve/0003-PVE-Config-set-the-CPU-model-to-kvm64-32-instead-of-.patch