From patchwork Wed Mar 7 23:19:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 10265577 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CD1E76016D for ; Wed, 7 Mar 2018 23:20:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB5B6295CB for ; Wed, 7 Mar 2018 23:20:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AD586295D7; Wed, 7 Mar 2018 23:20:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 01376295CB for ; Wed, 7 Mar 2018 23:20:27 +0000 (UTC) Received: from localhost ([::1]:36055 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etiME-0001Wb-AD for patchwork-qemu-devel@patchwork.kernel.org; Wed, 07 Mar 2018 18:20:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60856) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etiLW-0000z0-5Q for qemu-devel@nongnu.org; Wed, 07 Mar 2018 18:19:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1etiLV-0000P0-1V for qemu-devel@nongnu.org; Wed, 07 Mar 2018 18:19:42 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:36460 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 1etiLP-0000OF-DB; Wed, 07 Mar 2018 18:19:35 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 091764000787; Wed, 7 Mar 2018 23:19:25 +0000 (UTC) Received: from [10.10.125.187] (ovpn-125-187.rdu2.redhat.com [10.10.125.187]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED333111DD13; Wed, 7 Mar 2018 23:19:13 +0000 (UTC) To: Stefan Hajnoczi , qemu-devel@nongnu.org References: <20180307124619.6218-1-stefanha@redhat.com> From: Eric Blake Organization: Red Hat, Inc. Message-ID: <015d4216-88f1-ea17-fefa-c4e93ec56ddd@redhat.com> Date: Wed, 7 Mar 2018 17:19:13 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180307124619.6218-1-stefanha@redhat.com> Content-Language: en-US X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 07 Mar 2018 23:19:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 07 Mar 2018 23:19:25 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eblake@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: Re: [Qemu-devel] [PATCH v2] 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 , Fam Zheng , qemu-block@nongnu.org, Max Reitz , "fuweiwei \(C\)" , Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP On 03/07/2018 06:46 AM, Stefan Hajnoczi wrote: > Nested BDRV_POLL_WHILE() calls can occur. Currently > assert(!wait_->wakeup) fails in AIO_WAIT_WHILE() when this happens. > > This patch converts the bool wait_->need_kick flag to an unsigned > wait_->num_waiters counter. > > Nesting works correctly because outer AIO_WAIT_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 > --- > v2: > * Rebase onto qemu.git/master now that AIO_WAIT_WHILE() has landed > [Kevin] > > include/block/aio-wait.h | 61 ++++++++++++++++++++++++------------------------ Looks big due to whitespace change when column for trailing \ changed. Viewing the diff with whitespace ignored made it easier to review. Reviewed-by: Eric Blake /** @@ -84,9 +84,8 @@ typedef struct { } else { \ assert(qemu_get_current_aio_context() == \ qemu_get_aio_context()); \ - assert(!wait_->need_kick); \ - /* Set wait_->need_kick before evaluating cond. */ \ - atomic_mb_set(&wait_->need_kick, true); \ + /* Increment wait_->num_waiters before evaluating cond. */ \ + atomic_inc(&wait_->num_waiters); \ while (busy_) { \ if ((cond)) { \ waited_ = busy_ = true; \ @@ -98,7 +97,7 @@ typedef struct { waited_ |= busy_; \ } \ } \ - atomic_set(&wait_->need_kick, false); \ + atomic_dec(&wait_->num_waiters); \ } \ waited_; }) diff --git c/include/block/aio-wait.h w/include/block/aio-wait.h index a48c744fa87..74cde07bef3 100644 --- c/include/block/aio-wait.h +++ w/include/block/aio-wait.h @@ -50,8 +50,8 @@ * } */ typedef struct { - /* Is the main loop waiting for a kick? Accessed with atomic ops. */ - bool need_kick; + /* Number of waiting AIO_WAIT_WHILE() callers. Accessed with atomic ops. */ + unsigned num_waiters; } AioWait;