From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45139) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bUDZN-0002jk-3S for qemu-devel@nongnu.org; Mon, 01 Aug 2016 09:47:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bUDZI-0003fJ-6Z for qemu-devel@nongnu.org; Mon, 01 Aug 2016 09:47:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47708) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bUDZI-0003fE-0V for qemu-devel@nongnu.org; Mon, 01 Aug 2016 09:47:44 -0400 References: <1469447015-2276-1-git-send-email-shmulik.ladkani@oracle.com> From: Paolo Bonzini Message-ID: <2e4aeb04-c23e-dada-779d-f0ef9e1eac70@redhat.com> Date: Mon, 1 Aug 2016 15:47:39 +0200 MIME-Version: 1.0 In-Reply-To: <1469447015-2276-1-git-send-email-shmulik.ladkani@oracle.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] util: Relax assertion in iov_copy() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Shmulik Ladkani , "Michael S. Tsirkin" , qemu-devel@nongnu.org Cc: Dmitry Fleytman , Jason Wang , Shmulik Ladkani On 25/07/2016 13:43, Shmulik Ladkani wrote: > From: Shmulik Ladkani >=20 > In cases where iov_copy() is passed with zero 'bytes' argument and a > non-zero 'offset' argument, nothing gets copied - as expected. >=20 > However since no copy iterations are performed, 'offset' is left > unaltered, leading to the final assert(offset =3D=3D 0) to fail. >=20 > Relax the assertion: if j (number of dst elements assigned) is zero, no > need to err. >=20 > Only if j!=3D0 (some dst elements assigned) AND offset!=3D0 we should e= rr. This is actually intended; the comment in qemu_iovec_concat_iov says why: assert(soffset =3D=3D 0); /* offset beyond end of src */ so the pedantic fix could be (if I understand the issue correctly) to check for "offset || bytes" in the for condition. This is similar to what the other functions do (e.g. iov_from_buf_full). The performance effect should practically be absent. Paolo > Signed-off-by: Shmulik Ladkani > --- > util/iov.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) >=20 > Flow that led to the assertion was: > net_tx_pkt_rebuild_payload() > iov_copy(... , pkt->payload_len) >=20 > where pkt->payload_len was correctly calculated to be 0 (a packet > carrying just ipv4 header, without any payload). >=20 > An alternative is to place the below code, early in iov_copy(): > if (!bytes) > return 0; >=20 > diff --git a/util/iov.c b/util/iov.c > index 003fcce..17de52d 100644 > --- a/util/iov.c > +++ b/util/iov.c > @@ -260,7 +260,7 @@ unsigned iov_copy(struct iovec *dst_iov, unsigned i= nt dst_iov_cnt, > bytes -=3D len; > offset =3D 0; > } > - assert(offset =3D=3D 0); > + assert(j =3D=3D 0 || offset =3D=3D 0); > return j; > } > =20 >=20