From nobody Mon Apr 14 04:07:49 2025 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513608945829637.4561398602299; Mon, 18 Dec 2017 06:55:45 -0800 (PST) Received: from localhost ([::1]:42140 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eQwpF-000719-G0 for importer@patchew.org; Mon, 18 Dec 2017 09:55:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46111) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eQwXQ-0007BK-61 for qemu-devel@nongnu.org; Mon, 18 Dec 2017 09:37:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eQwXP-0007az-BA for qemu-devel@nongnu.org; Mon, 18 Dec 2017 09:37:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60566) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eQwXP-0007Zk-4c for qemu-devel@nongnu.org; Mon, 18 Dec 2017 09:37:03 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5172280C15; Mon, 18 Dec 2017 14:37:02 +0000 (UTC) Received: from localhost (ovpn-116-227.ams2.redhat.com [10.36.116.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id ACC4880936; Mon, 18 Dec 2017 14:36:59 +0000 (UTC) From: Stefan Hajnoczi To: Date: Mon, 18 Dec 2017 14:35:25 +0000 Message-Id: <20171218143530.12082-19-stefanha@redhat.com> In-Reply-To: <20171218143530.12082-1-stefanha@redhat.com> References: <20171218143530.12082-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 18 Dec 2017 14:37:02 +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] [PULL 18/23] block: avoid recursive AioContext acquire in bdrv_inactivate_all() 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: Peter Maydell , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini BDRV_POLL_WHILE() does not support recursive AioContext locking. It only releases the AioContext lock once regardless of how many times the caller has acquired it. This results in a hang since the IOThread does not make progress while the AioContext is still locked. The following steps trigger the hang: $ qemu-system-x86_64 -M accel=3Dkvm -m 1G -cpu host \ -object iothread,id=3Diothread0 \ -device virtio-scsi-pci,iothread=3Diothread0 \ -drive if=3Dnone,id=3Ddrive0,file=3Dtest.img,format= =3Draw \ -device scsi-hd,drive=3Ddrive0 \ -drive if=3Dnone,id=3Ddrive1,file=3Dtest.img,format= =3Draw \ -device scsi-hd,drive=3Ddrive1 $ qemu-system-x86_64 ...same options... \ -incoming tcp::1234 (qemu) migrate tcp:127.0.0.1:1234 ...hang... Tested-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Reviewed-by: Eric Blake Message-id: 20171207201320.19284-2-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi --- block.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index 9a1a0d1e73..1c37ce4554 100644 --- a/block.c +++ b/block.c @@ -4320,9 +4320,15 @@ int bdrv_inactivate_all(void) BdrvNextIterator it; int ret =3D 0; int pass; + GSList *aio_ctxs =3D NULL, *ctx; =20 for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { - aio_context_acquire(bdrv_get_aio_context(bs)); + AioContext *aio_context =3D bdrv_get_aio_context(bs); + + if (!g_slist_find(aio_ctxs, aio_context)) { + aio_ctxs =3D g_slist_prepend(aio_ctxs, aio_context); + aio_context_acquire(aio_context); + } } =20 /* We do two passes of inactivation. The first pass calls to drivers' @@ -4340,9 +4346,11 @@ int bdrv_inactivate_all(void) } =20 out: - for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { - aio_context_release(bdrv_get_aio_context(bs)); + for (ctx =3D aio_ctxs; ctx !=3D NULL; ctx =3D ctx->next) { + AioContext *aio_context =3D ctx->data; + aio_context_release(aio_context); } + g_slist_free(aio_ctxs); =20 return ret; } --=20 2.14.3