From nobody Fri Jul 4 18:12:29 2025 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.zohomail.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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 15126777486540.3575666243506248; Thu, 7 Dec 2017 12:15:48 -0800 (PST) Received: from localhost ([::1]:34090 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eN2a6-0000GD-1E for importer@patchew.org; Thu, 07 Dec 2017 15:15:42 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46087) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eN2Y2-0007Mn-8K for qemu-devel@nongnu.org; Thu, 07 Dec 2017 15:13:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eN2Y1-0006hF-C7 for qemu-devel@nongnu.org; Thu, 07 Dec 2017 15:13:34 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58990) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eN2Xw-0006fS-3Y; Thu, 07 Dec 2017 15:13:28 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 50FD47970A; Thu, 7 Dec 2017 20:13:27 +0000 (UTC) Received: from localhost (ovpn-116-107.ams2.redhat.com [10.36.116.107]) by smtp.corp.redhat.com (Postfix) with ESMTP id D963378493; Thu, 7 Dec 2017 20:13:26 +0000 (UTC) From: Stefan Hajnoczi To: Date: Thu, 7 Dec 2017 20:13:15 +0000 Message-Id: <20171207201320.19284-2-stefanha@redhat.com> In-Reply-To: <20171207201320.19284-1-stefanha@redhat.com> References: <20171207201320.19284-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 07 Dec 2017 20:13:27 +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 1/6] 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: Kevin Wolf , Paolo Bonzini , 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" 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 --- 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