[{"id":1770263,"web_url":"http://patchwork.ozlabs.org/comment/1770263/","msgid":"<202ff1d3-f877-ad4a-19e1-15d8f6e6721f@redhat.com>","list_archive_url":null,"date":"2017-09-18T15:45:06","subject":"Re: [Qemu-devel] [PATCH v2 2/7] block/nbd-client: exit\n\treply-reading coroutine on incorrect handle","submitter":{"id":6591,"url":"http://patchwork.ozlabs.org/api/people/6591/","name":"Eric Blake","email":"eblake@redhat.com"},"content":"On 09/18/2017 08:59 AM, Vladimir Sementsov-Ogievskiy wrote:\n> Check reply-handle == request-handle in the same place, where\n\ns/,//\n\n> recv coroutine number is calculated from reply->handle and it's\n> correctness checked - in nbd_read_reply_entry.\n> \n> Also finish nbd_read_reply_entry in case of reply-handle !=\n> request-handle in the same way as in case of incorrect reply-handle.\n> \n> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>\n> ---\n>  block/nbd-client.h | 1 +\n>  block/nbd-client.c | 8 ++++++--\n>  2 files changed, 7 insertions(+), 2 deletions(-)\n> \n\nReviewed-by: Eric Blake <eblake@redhat.com>","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ext-mx10.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx10.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=eblake@redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xwr1z2QL1z9s06\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 19 Sep 2017 01:45:43 +1000 (AEST)","from localhost ([::1]:37399 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dtyEv-0008MM-GO\n\tfor incoming@patchwork.ozlabs.org; Mon, 18 Sep 2017 11:45:41 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:57702)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <eblake@redhat.com>) id 1dtyEV-0008Hv-Tj\n\tfor qemu-devel@nongnu.org; Mon, 18 Sep 2017 11:45:20 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <eblake@redhat.com>) id 1dtyEV-00077F-1j\n\tfor qemu-devel@nongnu.org; Mon, 18 Sep 2017 11:45:15 -0400","from mx1.redhat.com ([209.132.183.28]:36368)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <eblake@redhat.com>)\n\tid 1dtyEQ-00071A-2l; Mon, 18 Sep 2017 11:45:10 -0400","from smtp.corp.redhat.com\n\t(int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id 08B5AA0C12;\n\tMon, 18 Sep 2017 15:45:09 +0000 (UTC)","from [10.10.124.97] (ovpn-124-97.rdu2.redhat.com [10.10.124.97])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id 51E055C670;\n\tMon, 18 Sep 2017 15:45:07 +0000 (UTC)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com 08B5AA0C12","To":"Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,\n\tqemu-block@nongnu.org, qemu-devel@nongnu.org","References":"<20170918135935.255591-1-vsementsov@virtuozzo.com>\n\t<20170918135935.255591-3-vsementsov@virtuozzo.com>","From":"Eric Blake <eblake@redhat.com>","Openpgp":"url=http://people.redhat.com/eblake/eblake.gpg","Organization":"Red Hat, Inc.","Message-ID":"<202ff1d3-f877-ad4a-19e1-15d8f6e6721f@redhat.com>","Date":"Mon, 18 Sep 2017 10:45:06 -0500","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.3.0","MIME-Version":"1.0","In-Reply-To":"<20170918135935.255591-3-vsementsov@virtuozzo.com>","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\";\n\tboundary=\"wf7I5uavWQhV1L0TUQ6phNr3pLgt1SAUa\"","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.16","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.39]);\n\tMon, 18 Sep 2017 15:45:09 +0000 (UTC)","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","X-Content-Filtered-By":"Mailman/MimeDel 2.1.21","Subject":"Re: [Qemu-devel] [PATCH v2 2/7] block/nbd-client: exit\n\treply-reading coroutine on incorrect handle","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"kwolf@redhat.com, pbonzini@redhat.com, den@openvz.org, mreitz@redhat.com","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}},{"id":1770455,"web_url":"http://patchwork.ozlabs.org/comment/1770455/","msgid":"<31b5ba0a-9041-7cbc-625c-e12905e56169@redhat.com>","list_archive_url":null,"date":"2017-09-18T19:50:13","subject":"Re: [Qemu-devel] [PATCH v2 2/7] block/nbd-client: exit\n\treply-reading coroutine on incorrect handle","submitter":{"id":6591,"url":"http://patchwork.ozlabs.org/api/people/6591/","name":"Eric Blake","email":"eblake@redhat.com"},"content":"On 09/18/2017 08:59 AM, Vladimir Sementsov-Ogievskiy wrote:\n> Check reply-handle == request-handle in the same place, where\n> recv coroutine number is calculated from reply->handle and it's\n> correctness checked - in nbd_read_reply_entry.\n> \n> Also finish nbd_read_reply_entry in case of reply-handle !=\n> request-handle in the same way as in case of incorrect reply-handle.\n> \n> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>\n> ---\n>  block/nbd-client.h | 1 +\n>  block/nbd-client.c | 8 ++++++--\n>  2 files changed, 7 insertions(+), 2 deletions(-)\n\nOn second thought:\n\n> +++ b/block/nbd-client.c\n> @@ -92,7 +92,9 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque)\n>          i = HANDLE_TO_INDEX(s, s->reply.handle);\n>          if (i >= MAX_NBD_REQUESTS ||\n>              !s->requests[i].coroutine ||\n> -            !s->requests[i].receiving) {\n> +            !s->requests[i].receiving ||\n> +            s->reply.handle != s->requests[i].request->handle)\n\nHow can this condition ever be false?  s->reply.handle only ever\ncontains two values: 0 when it is being reused for the next iteration of\nthe loop, or the (munged) address of the request pointer.  But we are\ncareful that we never write s->reply.handle = 0 until after\ns->requests[i].receiving is false.  So we will never see s->reply.handle\nequal to 0 here.  (It may have been possible prior to the introduction\nof reply.receiving, in commit 40f4a218, but I'm not seeing it now)\n\nIf I'm right, then this patch can be simplified - we don't need to track\ns.requests[i].request, and can merely:\n\n> @@ -189,9 +192,10 @@ static int nbd_co_receive_reply(NBDClientSession *s,\n>      s->requests[i].receiving = true;\n>      qemu_coroutine_yield();\n>      s->requests[i].receiving = false;\n> -    if (s->reply.handle != request->handle || !s->ioc || s->quit) {\n\nshorten this conditional to remove the now-dead condition.\n\n> +    if (!s->ioc || s->quit) {\n>          ret = -EIO;\n>      } else {\n> +        assert(s->reply.handle == request->handle);\n>          ret = -s->reply.error;\n>          if (qiov && s->reply.error == 0) {\n>              assert(request->len == iov_size(qiov->iov, qiov->niov));\n> \n\n[Oh, and I just noticed HANDLE_TO_INDEX() and INDEX_TO_HANDLE() are\nimproperly parenthesized, although to no ill effect with current clients]","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ext-mx05.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx05.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=eblake@redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xwxWS6ZxGz9s7v\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 19 Sep 2017 05:53:08 +1000 (AEST)","from localhost ([::1]:38620 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1du26N-0007h7-0a\n\tfor incoming@patchwork.ozlabs.org; Mon, 18 Sep 2017 15:53:07 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:36879)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <eblake@redhat.com>) id 1du23j-0006GP-9G\n\tfor qemu-devel@nongnu.org; Mon, 18 Sep 2017 15:50:24 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <eblake@redhat.com>) id 1du23i-0005vT-Bn\n\tfor qemu-devel@nongnu.org; Mon, 18 Sep 2017 15:50:23 -0400","from mx1.redhat.com ([209.132.183.28]:44518)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <eblake@redhat.com>)\n\tid 1du23d-0005sE-ED; Mon, 18 Sep 2017 15:50:17 -0400","from smtp.corp.redhat.com\n\t(int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id 5311C2CE91B;\n\tMon, 18 Sep 2017 19:50:16 +0000 (UTC)","from [10.10.124.97] (ovpn-124-97.rdu2.redhat.com [10.10.124.97])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id 99B545D97B;\n\tMon, 18 Sep 2017 19:50:14 +0000 (UTC)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com 5311C2CE91B","To":"Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,\n\tqemu-block@nongnu.org, qemu-devel@nongnu.org","References":"<20170918135935.255591-1-vsementsov@virtuozzo.com>\n\t<20170918135935.255591-3-vsementsov@virtuozzo.com>","From":"Eric Blake <eblake@redhat.com>","Openpgp":"url=http://people.redhat.com/eblake/eblake.gpg","Organization":"Red Hat, Inc.","Message-ID":"<31b5ba0a-9041-7cbc-625c-e12905e56169@redhat.com>","Date":"Mon, 18 Sep 2017 14:50:13 -0500","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.3.0","MIME-Version":"1.0","In-Reply-To":"<20170918135935.255591-3-vsementsov@virtuozzo.com>","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\";\n\tboundary=\"nc3Ata7phFTOMtCQ5O7Qu2ivBs48hwIWd\"","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.14","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.29]);\n\tMon, 18 Sep 2017 19:50:16 +0000 (UTC)","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","X-Content-Filtered-By":"Mailman/MimeDel 2.1.21","Subject":"Re: [Qemu-devel] [PATCH v2 2/7] block/nbd-client: exit\n\treply-reading coroutine on incorrect handle","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"kwolf@redhat.com, pbonzini@redhat.com, den@openvz.org, mreitz@redhat.com","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}}]