From 988413c0fb5eed4d0f11d218e2d2a883d713e777 Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Mon, 15 May 2017 14:25:31 +0200 Subject: [PATCH 4/5] aio: add missing aio_notify() to aio_enable_external() RH-Author: Stefan Hajnoczi Message-id: <20170515142531.15830-2-stefanha@redhat.com> Patchwork-id: 75165 O-Subject: [RHV-7.4 qemu-kvm-rhev PATCH 1/1] aio: add missing aio_notify() to aio_enable_external() Bugzilla: 1446498 RH-Acked-by: Paolo Bonzini RH-Acked-by: Fam Zheng RH-Acked-by: Laurent Vivier The main loop uses aio_disable_external()/aio_enable_external() to temporarily disable processing of external AioContext clients like device emulation. This allows monitor commands to quiesce I/O and prevent the guest from submitting new requests while a monitor command is in progress. The aio_enable_external() API is currently broken when an IOThread is in aio_poll() waiting for fd activity when the main loop re-enables external clients. Incrementing ctx->external_disable_cnt does not wake the IOThread from ppoll(2) so fd processing remains suspended and leads to unresponsive emulated devices. This patch adds an aio_notify() call to aio_enable_external() so the IOThread is kicked out of ppoll(2) and will re-arm the file descriptors. The bug can be reproduced as follows: $ qemu -M accel=kvm -m 1024 \ -object iothread,id=iothread0 \ -device virtio-scsi-pci,iothread=iothread0,id=virtio-scsi-pci0 \ -drive if=none,id=drive0,aio=native,cache=none,format=raw,file=test.img \ -device scsi-hd,id=scsi-hd0,drive=drive0 \ -qmp tcp::5555,server,nowait $ scripts/qmp/qmp-shell localhost:5555 (qemu) blockdev-snapshot-sync device=drive0 snapshot-file=sn1.qcow2 mode=absolute-paths format=qcow2 After blockdev-snapshot-sync completes the SCSI disk will be unresponsive. This leads to request timeouts inside the guest. Reported-by: Qianqian Zhu Reviewed-by: Fam Zheng Signed-off-by: Stefan Hajnoczi Message-id: 20170508180705.20609-1-stefanha@redhat.com Suggested-by: Fam Zheng Signed-off-by: Stefan Hajnoczi (cherry picked from commit 321d1dba8bef9676a77e9399484e3cd8bf2cf16a) Signed-off-by: Stefan Hajnoczi Signed-off-by: Miroslav Rezanina --- include/block/aio.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/block/aio.h b/include/block/aio.h index 406e323..e9aeeae 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -454,8 +454,14 @@ static inline void aio_disable_external(AioContext *ctx) */ static inline void aio_enable_external(AioContext *ctx) { - assert(ctx->external_disable_cnt > 0); - atomic_dec(&ctx->external_disable_cnt); + int old; + + old = atomic_fetch_dec(&ctx->external_disable_cnt); + assert(old > 0); + if (old == 1) { + /* Kick event loop so it re-arms file descriptors */ + aio_notify(ctx); + } } /** -- 1.8.3.1