From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60561) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cC53z-0007x4-GX for qemu-devel@nongnu.org; Wed, 30 Nov 2016 08:36:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cC53t-00061f-JF for qemu-devel@nongnu.org; Wed, 30 Nov 2016 08:36:43 -0500 References: <20161129114707.2975-1-pbonzini@redhat.com> <20161129114707.2975-7-pbonzini@redhat.com> <20161130133116.GH2497@stefanha-x1.localdomain> From: Paolo Bonzini Message-ID: Date: Wed, 30 Nov 2016 14:36:23 +0100 MIME-Version: 1.0 In-Reply-To: <20161130133116.GH2497@stefanha-x1.localdomain> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="wi7EuPCDpFuH8U6dE1BSn60OE7J5kjxln" 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: Stefan Hajnoczi Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --wi7EuPCDpFuH8U6dE1BSn60OE7J5kjxln From: Paolo Bonzini To: Stefan Hajnoczi Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org Message-ID: Subject: Re: [Qemu-block] [PATCH 06/10] aio-posix: remove walking_handlers, protecting AioHandler list with list_lock References: <20161129114707.2975-1-pbonzini@redhat.com> <20161129114707.2975-7-pbonzini@redhat.com> <20161130133116.GH2497@stefanha-x1.localdomain> In-Reply-To: <20161130133116.GH2497@stefanha-x1.localdomain> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable 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 =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_rea= d && >> 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.ev= ents; >=20 > 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. Paolo --wi7EuPCDpFuH8U6dE1BSn60OE7J5kjxln Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJYPtXXAAoJEL/70l94x66DQOkIAJq1f9Ig9h38qd5vmF7nlOr9 hBh2g+2RGcRRcSigMG7RDXNdwlgNofBFz+f78P0a3EYV0adDV9CgMmnvNrx3pMuS iWoHdHFE5tfyQfpPDpAQZofUsI1pFc5103yNr06g/37pduM4YbY45EhbhzD6OEaY SvVoSTXo7ImGQq1dfJO5R/kEeN8N3nh8Qu1uN7r3nhT+FmJ1PGUAVvJx6a/coHDx hPQP6rIYwZhZ7ZFnlcs43aH8s9YkqqpnKIKo7trSkkazqg4JROwS3cbOwL+nx+cw renDp73XZFxBw7ek6lC6kOoSFtXMzFSdoHu74mj1XdygdhbC7KNfHPBYJG6+uWQ= =3D9d -----END PGP SIGNATURE----- --wi7EuPCDpFuH8U6dE1BSn60OE7J5kjxln--