From nobody Mon May 6 21:17:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 149397867813861.49382694838846; Fri, 5 May 2017 03:04:38 -0700 (PDT) Received: from localhost ([::1]:45998 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6a6G-00072J-OV for importer@patchew.org; Fri, 05 May 2017 06:04:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45388) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6a4q-0006Ay-QN for qemu-devel@nongnu.org; Fri, 05 May 2017 06:03:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6a4p-0007O0-Vd for qemu-devel@nongnu.org; Fri, 05 May 2017 06:03:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48988) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d6a4j-0007G7-M6; Fri, 05 May 2017 06:03:01 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8FEA9448D6E; Fri, 5 May 2017 10:03:00 +0000 (UTC) Received: from localhost (unknown [10.36.118.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 87A5D4F6DC; Fri, 5 May 2017 10:02:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8FEA9448D6E Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=stefanha@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8FEA9448D6E From: Stefan Hajnoczi To: qemu-devel@nongnu.org Date: Fri, 5 May 2017 11:02:55 +0100 Message-Id: <20170505100255.11145-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 05 May 2017 10:03:00 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2] aio: add missing aio_notify() to aio_enable_external() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Fam Zheng , Stefan Hajnoczi , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=3Dkvm -m 1024 \ -object iothread,id=3Diothread0 \ -device virtio-scsi-pci,iothread=3Diothread0,id=3Dvirtio-scsi-pci0= \ -drive if=3Dnone,id=3Ddrive0,aio=3Dnative,cache=3Dnone,format=3Dra= w,file=3Dtest.img \ -device scsi-hd,id=3Dscsi-hd0,drive=3Ddrive0 \ -qmp tcp::5555,server,nowait $ scripts/qmp/qmp-shell localhost:5555 (qemu) blockdev-snapshot-sync device=3Ddrive0 snapshot-file=3Dsn1.qcow2 mode=3Dabsolute-paths format=3Dqcow2 After blockdev-snapshot-sync completes the SCSI disk will be unresponsive. This leads to request timeouts inside the guest. Reported-by: Qianqian Zhu Suggested-by: Fam Zheng Signed-off-by: Stefan Hajnoczi --- v2: * Only notify when necessary [Fam] 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..b3d6f76 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -454,8 +454,14 @@ static inline void aio_disable_external(AioContext *ct= x) */ static inline void aio_enable_external(AioContext *ctx) { - assert(ctx->external_disable_cnt > 0); - atomic_dec(&ctx->external_disable_cnt); + int old; + + old =3D atomic_dec_fetch(&ctx->external_disable_cnt); + assert(old > 0); + if (old =3D=3D 1) { + /* Kick event loop so it re-arms file descriptors */ + aio_notify(ctx); + } } =20 /** --=20 2.9.3