From nobody Mon Sep 22 23:39:17 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1647266172966587.0381259364185; Mon, 14 Mar 2022 06:56:12 -0700 (PDT) Received: from localhost ([::1]:49598 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nTlBE-00010v-9o for importer@patchew.org; Mon, 14 Mar 2022 09:56:12 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37950) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nTkbQ-0001Jx-Lm for qemu-devel@nongnu.org; Mon, 14 Mar 2022 09:19:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:43628) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nTkbM-0006Xq-NV for qemu-devel@nongnu.org; Mon, 14 Mar 2022 09:19:10 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-365-b9Nnso04OJCOPkGnE2i0Ow-1; Mon, 14 Mar 2022 09:19:04 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 78E03811E84; Mon, 14 Mar 2022 13:19:04 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 375DC1686D; Mon, 14 Mar 2022 13:19:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647263947; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sLxRe1acb4tSj42JtUO72Yu6ER2WDV9szzB0jGbhh9M=; b=HGY8DDOEe9W1Llt+6X8zAlYosOW7AO02uIxThU8Rr67BnSDh1kvhakTMrtjR//r1gbnfp7 QHy/g/zGDXxjeqSU4ITwacC04aKkigiTHV/GGB01MbKSHIBtMMBlnQ/B5xSgEPcWVLrbUY kXGCnQNhruOTYwMFAPIG87zUfTaaMfU= X-MC-Unique: b9Nnso04OJCOPkGnE2i0Ow-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Subject: [PATCH v2 01/10] drains: create bh only when polling Date: Mon, 14 Mar 2022 09:18:45 -0400 Message-Id: <20220314131854.2202651-2-eesposit@redhat.com> In-Reply-To: <20220314131854.2202651-1-eesposit@redhat.com> References: <20220314131854.2202651-1-eesposit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eesposit@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , Vladimir Sementsov-Ogievskiy , Emanuele Giuseppe Esposito , qemu-devel@nongnu.org, Hanna Reitz , Stefan Hajnoczi , Paolo Bonzini , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1647266175134100001 Content-Type: text/plain; charset="utf-8" We need to prevent coroutines from calling BDRV_POLL_WHILE, because it can create deadlocks. This is done by firstly creating a bottom half and then yielding. The bh is then scheduled in the main loop, performs the drain and polling, and then resumes the coroutine. The problem is that currently we create coroutine and bh regardless on whether we eventually poll or not. There is no need to do so, if no poll takes place. Signed-off-by: Emanuele Giuseppe Esposito --- block/io.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/block/io.c b/block/io.c index efc011ce65..4a3e8d037d 100644 --- a/block/io.c +++ b/block/io.c @@ -447,7 +447,7 @@ static void bdrv_do_drained_begin(BlockDriverState *bs,= bool recursive, { BdrvChild *child, *next; =20 - if (qemu_in_coroutine()) { + if (poll && qemu_in_coroutine()) { bdrv_co_yield_to_drain(bs, true, recursive, parent, ignore_bds_par= ents, poll, NULL); return; @@ -513,12 +513,6 @@ static void bdrv_do_drained_end(BlockDriverState *bs, = bool recursive, int old_quiesce_counter; =20 assert(drained_end_counter !=3D NULL); - - if (qemu_in_coroutine()) { - bdrv_co_yield_to_drain(bs, false, recursive, parent, ignore_bds_pa= rents, - false, drained_end_counter); - return; - } assert(bs->quiesce_counter > 0); =20 /* Re-enable things in child-to-parent order */ @@ -541,11 +535,24 @@ static void bdrv_do_drained_end(BlockDriverState *bs,= bool recursive, } } =20 +static void bdrv_do_drained_end_co(BlockDriverState *bs, bool recursive, + BdrvChild *parent, bool ignore_bds_pare= nts, + int *drained_end_counter) +{ + if (qemu_in_coroutine()) { + bdrv_co_yield_to_drain(bs, false, recursive, parent, ignore_bds_pa= rents, + false, drained_end_counter); + return; + } + + bdrv_do_drained_end(bs, recursive, parent, ignore_bds_parents, drained= _end_counter); +} + void bdrv_drained_end(BlockDriverState *bs) { int drained_end_counter =3D 0; IO_OR_GS_CODE(); - bdrv_do_drained_end(bs, false, NULL, false, &drained_end_counter); + bdrv_do_drained_end_co(bs, false, NULL, false, &drained_end_counter); BDRV_POLL_WHILE(bs, qatomic_read(&drained_end_counter) > 0); } =20 @@ -559,7 +566,7 @@ void bdrv_subtree_drained_end(BlockDriverState *bs) { int drained_end_counter =3D 0; IO_OR_GS_CODE(); - bdrv_do_drained_end(bs, true, NULL, false, &drained_end_counter); + bdrv_do_drained_end_co(bs, true, NULL, false, &drained_end_counter); BDRV_POLL_WHILE(bs, qatomic_read(&drained_end_counter) > 0); } =20 @@ -580,7 +587,7 @@ void bdrv_unapply_subtree_drain(BdrvChild *child, Block= DriverState *old_parent) IO_OR_GS_CODE(); =20 for (i =3D 0; i < old_parent->recursive_quiesce_counter; i++) { - bdrv_do_drained_end(child->bs, true, child, false, + bdrv_do_drained_end_co(child->bs, true, child, false, &drained_end_counter); } =20 @@ -703,7 +710,7 @@ void bdrv_drain_all_end_quiesce(BlockDriverState *bs) g_assert(!bs->refcnt); =20 while (bs->quiesce_counter) { - bdrv_do_drained_end(bs, false, NULL, true, &drained_end_counter); + bdrv_do_drained_end_co(bs, false, NULL, true, &drained_end_counter= ); } BDRV_POLL_WHILE(bs, qatomic_read(&drained_end_counter) > 0); } @@ -727,7 +734,7 @@ void bdrv_drain_all_end(void) AioContext *aio_context =3D bdrv_get_aio_context(bs); =20 aio_context_acquire(aio_context); - bdrv_do_drained_end(bs, false, NULL, true, &drained_end_counter); + bdrv_do_drained_end_co(bs, false, NULL, true, &drained_end_counter= ); aio_context_release(aio_context); } =20 --=20 2.31.1