From nobody Sat Apr 27 06:05:03 2024 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 1512582952224581.3317673853993; Wed, 6 Dec 2017 09:55:52 -0800 (PST) Received: from localhost ([::1]:56867 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMdus-0000WE-TQ for importer@patchew.org; Wed, 06 Dec 2017 12:55:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33342) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eMdto-0008P7-9U for qemu-devel@nongnu.org; Wed, 06 Dec 2017 12:54:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eMdtn-0001fl-Cc for qemu-devel@nongnu.org; Wed, 06 Dec 2017 12:54:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57522) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eMdti-0001bo-52; Wed, 06 Dec 2017 12:54:18 -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 B2B68C04AC60; Wed, 6 Dec 2017 17:54:16 +0000 (UTC) Received: from localhost (ovpn-117-13.ams2.redhat.com [10.36.117.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id EC9C662660; Wed, 6 Dec 2017 17:54:15 +0000 (UTC) From: Stefan Hajnoczi To: Date: Wed, 6 Dec 2017 17:54:14 +0000 Message-Id: <20171206175414.27666-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.31]); Wed, 06 Dec 2017 17:54:16 +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] 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: Paolo Bonzini , qemu-stable@nongnu.org, qemu-block@nongnu.org, "Dr. David Alan Gilbert" 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 --- 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