Received: from eggs.gnu.org ([2001:4830:134:3::10]:39132) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cCTLk-0007fC-Pa for qemu-devel@nongnu.org; Thu, 01 Dec 2016 10:32:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cCTLj-00023j-5D for qemu-devel@nongnu.org; Thu, 01 Dec 2016 10:32:40 -0500 Sender: Paolo Bonzini References: <20161129114707.2975-1-pbonzini@redhat.com> <20161129114707.2975-7-pbonzini@redhat.com> <20161130133116.GH2497@stefanha-x1.localdomain> From: Paolo Bonzini Message-ID: <2a908016-bb5a-9507-af9c-2a71f703403f@redhat.com> Date: Thu, 1 Dec 2016 16:32:31 +0100 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 06/10] aio-posix: remove walking_handlers, protecting AioHandler list with list_lock List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org On 30/11/2016 14:36, Paolo Bonzini wrote: > > > On 30/11/2016 14:31, Stefan Hajnoczi wrote: >> On Tue, Nov 29, 2016 at 12:47:03PM +0100, Paolo Bonzini wrote: >>> @@ -272,22 +275,32 @@ bool aio_prepare(AioContext *ctx) >>> bool aio_pending(AioContext *ctx) >>> { >>> AioHandler *node; >>> + bool result = false; >>> >>> - QLIST_FOREACH(node, &ctx->aio_handlers, node) { >>> + /* >>> + * We have to walk very carefully in case aio_set_fd_handler is >>> + * called while we're walking. >>> + */ >>> + qemu_lockcnt_inc(&ctx->list_lock); >>> + >>> + QLIST_FOREACH_RCU(node, &ctx->aio_handlers, node) { >>> int revents; >>> >>> revents = node->pfd.revents & node->pfd.events; >>> if (revents & (G_IO_IN | G_IO_HUP | G_IO_ERR) && node->io_read && >>> aio_node_check(ctx, node->is_external)) { >>> - return true; >>> + result = true; >>> + break; >>> } >>> if (revents & (G_IO_OUT | G_IO_ERR) && node->io_write && >>> aio_node_check(ctx, node->is_external)) { >>> - return true; >>> + result = true; >>> + break; >>> } >>> } >>> + qemu_lockcnt_dec(&ctx->list_lock); >>> >>> - return false; >>> + return result; >>> } >>> >>> bool aio_dispatch(AioContext *ctx) >>> @@ -308,13 +321,12 @@ bool aio_dispatch(AioContext *ctx) >>> * We have to walk very carefully in case aio_set_fd_handler is >>> * called while we're walking. >>> */ >>> - ctx->walking_handlers++; >>> + qemu_lockcnt_inc(&ctx->list_lock); >>> >>> - QLIST_FOREACH_SAFE(node, &ctx->aio_handlers, node, tmp) { >>> + QLIST_FOREACH_SAFE_RCU(node, &ctx->aio_handlers, node, tmp) { >>> int revents; >>> >>> - revents = node->pfd.revents & node->pfd.events; >>> - node->pfd.revents = 0; >>> + revents = atomic_xchg(&node->pfd.revents, 0) & node->pfd.events; >> >> Why is node->pfd.revents accessed with atomic_*() here and in aio_poll() >> but not in aio_pending()? > > It could use atomic_read there, indeed. Actually, thanks to the (already committed) patches that limit aio_poll to the I/O thread, these atomic accesses are not needed anymore. Paolo