From nobody Fri Oct 24 21:59:47 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520333734865804.1680493212192; Tue, 6 Mar 2018 02:55:34 -0800 (PST) Received: from localhost ([::1]:54708 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etAFe-0006ps-4h for importer@patchew.org; Tue, 06 Mar 2018 05:55:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45527) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etAEa-0006LL-BN for qemu-devel@nongnu.org; Tue, 06 Mar 2018 05:54:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1etAEZ-0007vG-Ld for qemu-devel@nongnu.org; Tue, 06 Mar 2018 05:54:16 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:59186 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1etAET-0007pO-Gw; Tue, 06 Mar 2018 05:54:09 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 24F834022909; Tue, 6 Mar 2018 10:54:00 +0000 (UTC) Received: from localhost (ovpn-117-188.ams2.redhat.com [10.36.117.188]) by smtp.corp.redhat.com (Postfix) with ESMTP id 52DF02026DFD; Tue, 6 Mar 2018 10:53:55 +0000 (UTC) From: Stefan Hajnoczi To: Date: Tue, 6 Mar 2018 10:53:54 +0000 Message-Id: <20180306105354.15197-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 06 Mar 2018 10:54:00 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 06 Mar 2018 10:54:00 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'stefanha@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH] block: make BDRV_POLL_WHILE() re-entrancy safe 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 , qemu-block@nongnu.org, Max Reitz , "fuweiwei \(C\)" , Stefan Hajnoczi , Paolo Bonzini 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" Nested BDRV_POLL_WHILE() calls can occur. Currently assert(!bs_->wakeup) will fail when this happens. This patch converts bs->wakeup from bool to a counter. Nesting works correctly because outer BDRV_POLL_WHILE() callers evaluate the condition again after the inner caller completes (invoking the inner caller counts as aio_poll() progress). Reported-by: "fuweiwei (C)" Cc: Paolo Bonzini Signed-off-by: Stefan Hajnoczi Reviewed-by: Paolo Bonzini --- Fu Weiwei: Please retest and let us know if this fixes the assertion failure you hit. Thanks! --- include/block/block.h | 7 +++---- include/block/block_int.h | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index fac401ba3e..990b97f0ad 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -385,9 +385,8 @@ void bdrv_drain_all(void); * other I/O threads' AioContexts (see for example \ * block_job_defer_to_main_loop for how to do it). \ */ \ - assert(!bs_->wakeup); \ - /* Set bs->wakeup before evaluating cond. */ \ - atomic_mb_set(&bs_->wakeup, true); \ + /* Increment bs->wakeup before evaluating cond. */ \ + atomic_inc(&bs_->wakeup); \ while (busy_) { \ if ((cond)) { \ waited_ =3D busy_ =3D true; \ @@ -399,7 +398,7 @@ void bdrv_drain_all(void); waited_ |=3D busy_; \ } \ } \ - atomic_set(&bs_->wakeup, false); \ + atomic_dec(&bs_->wakeup); \ } \ waited_; }) =20 diff --git a/include/block/block_int.h b/include/block/block_int.h index 5ea63f8fa8..0f360c0ed5 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -712,7 +712,7 @@ struct BlockDriverState { /* Internal to BDRV_POLL_WHILE and bdrv_wakeup. Accessed with atomic * ops. */ - bool wakeup; + unsigned wakeup; =20 /* counter for nested bdrv_io_plug. * Accessed with atomic ops. --=20 2.14.3