From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58885) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cC4zn-0005ON-Mx for qemu-devel@nongnu.org; Wed, 30 Nov 2016 08:32:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cC4zj-0004Wl-Qb for qemu-devel@nongnu.org; Wed, 30 Nov 2016 08:32:23 -0500 Date: Wed, 30 Nov 2016 13:31:16 +0000 From: Stefan Hajnoczi Message-ID: <20161130133116.GH2497@stefanha-x1.localdomain> References: <20161129114707.2975-1-pbonzini@redhat.com> <20161129114707.2975-7-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="vtJ+CqYNzKB4ukR4" Content-Disposition: inline In-Reply-To: <20161129114707.2975-7-pbonzini@redhat.com> Subject: Re: [Qemu-devel] [Qemu-block] [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: Paolo Bonzini Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org --vtJ+CqYNzKB4ukR4 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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 =3D false; > =20 > - 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; > =20 > revents =3D 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 =3D true; > + break; > } > if (revents & (G_IO_OUT | G_IO_ERR) && node->io_write && > aio_node_check(ctx, node->is_external)) { > - return true; > + result =3D true; > + break; > } > } > + qemu_lockcnt_dec(&ctx->list_lock); > =20 > - return false; > + return result; > } > =20 > 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); > =20 > - QLIST_FOREACH_SAFE(node, &ctx->aio_handlers, node, tmp) { > + QLIST_FOREACH_SAFE_RCU(node, &ctx->aio_handlers, node, tmp) { > int revents; > =20 > - revents =3D node->pfd.revents & node->pfd.events; > - node->pfd.revents =3D 0; > + revents =3D atomic_xchg(&node->pfd.revents, 0) & node->pfd.event= s; Why is node->pfd.revents accessed with atomic_*() here and in aio_poll() but not in aio_pending()? --vtJ+CqYNzKB4ukR4 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEcBAEBAgAGBQJYPtSkAAoJEJykq7OBq3PIhCgH/2X9PQwrFBe88rrOvNpzYIa7 ULnba/Nb/CJakc6APTpUoTh7vJ/81m/ChJhWJnzzlSCktBH7rTu8+sLnFkJDXs+v mjuI+jQtgTuqK8CdpT/wY/IBoCllDK7gqyIP/pKvEe1hM0kGxSzbwoQfSUDgwT3d oam7enG3vjLsqb4LCtw+ZxAP3gHIMXUz8lCueqSYDiemIrQqhrDovSUZfL/YtUvD wZkgF/I3TLfyEyYxUgVtqhEWTzmSD2ydkW8LwUE+1pFStO1vfeERFFBs8BCz/lgW HS1YGxzOylRBB5ICpg6aNBKZ23VGevqk7MyI321nNhk6yyj4sBXc86EjSrsXB+w= =4i7j -----END PGP SIGNATURE----- --vtJ+CqYNzKB4ukR4--