From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 305745A026D for ; Wed, 20 Mar 2024 05:27:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1710908863; bh=VgghZ+u8C6iJqyvqHMKDmptYq1Xe94ppmupNrQNKw+A=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=bAOpyqIH5Y1WfHms2TScQOEk2Lch0bP3wA8d/mwdyaNaZay41aQMgwwX/wJUbsBm8 PSuIhfpChfYtLxz9UAGtAu69J6JIZe7ZQXJibpdm7NAgcUgiBX38ewao/EGLvOiXNo vRtMTFGe8ottvGf0JY4tANjt8OFBZNu639uQyFyhUaFElxlB7AY92ZDTCL0kd9hs+Y VlF2JqrqTpW/9QtFY+YdkmyJR2tbv9csfwpvyxORWmkckXW1rtD8LMU+QBkIadICpj EOn90F8R9jsYeA/Se8kG/sOh2yBEaBKXLDKsAaxp02tHLn5czC2+BRkqMu7QRqfMU5 TRlhz7bzIawgw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4TzwYW3kvfz4wck; Wed, 20 Mar 2024 15:27:43 +1100 (AEDT) Date: Wed, 20 Mar 2024 15:27:37 +1100 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH] util: fix confusion between offset in the iovec array and in the entry Message-ID: References: <20240319101340.1724586-1-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="29fHyA6gHwzAMFp6" Content-Disposition: inline In-Reply-To: <20240319101340.1724586-1-lvivier@redhat.com> Message-ID-Hash: 576W22BYBCTFN2PERQQFA2OYISS6AKZG X-Message-ID-Hash: 576W22BYBCTFN2PERQQFA2OYISS6AKZG X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --29fHyA6gHwzAMFp6 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Mar 19, 2024 at 11:13:40AM +0100, Laurent Vivier wrote: > In write_remainder() 'skip' is the offset to start the operation from > in the iovec array. >=20 > In iov_skip_bytes(), 'skip' is also the offset in the iovec array but > 'offset' is the first unskipped byte in the iovec entry. >=20 > As write_remainder() uses 'skip' for both, 'skip' is reset to the > first unskipped byte in the iovec entry rather to staying the first > unskipped byte in the iovec array. >=20 > Fix the problem by introducing a new variable not to overwrite 'skip' > on each loop. >=20 > Fixes: 8bdb0883b441 ("util: Add write_remainder() helper") > Cc: david@gibson.dropbear.id.au > Signed-off-by: Laurent Vivier Ouch. *dons paper bag* I believe this is correct as it stands, but.. > --- > util.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) >=20 > diff --git a/util.c b/util.c > index 3b2393d6bfa8..eee53aed811b 100644 > --- a/util.c > +++ b/util.c > @@ -533,13 +533,14 @@ int do_clone(int (*fn)(void *), char *stack_area, s= ize_t stack_size, int flags, > int write_remainder(int fd, const struct iovec *iov, int iovcnt, size_t = skip) > { > int i; > + size_t offset; > =20 > - while ((i =3D iov_skip_bytes(iov, iovcnt, skip, &skip)) < iovcnt) { > + while ((i =3D iov_skip_bytes(iov, iovcnt, skip, &offset)) < iovcnt) { > ssize_t rc; > =20 > if (skip) { =2E. it would be more optimal if you checked for offset !=3D 0 rather than skip !=3D 0 here. Otherwise even once we've written an entire buffer, we'll continue to write the rest of the buffers one by one, rather than writing them all with a writev(). > - rc =3D write(fd, (char *)iov[i].iov_base + skip, > - iov[i].iov_len - skip); > + rc =3D write(fd, (char *)iov[i].iov_base + offset, > + iov[i].iov_len - offset); > } else { > rc =3D writev(fd, &iov[i], iovcnt - i); > } --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --29fHyA6gHwzAMFp6 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmX6ZaYACgkQzQJF27ox 2Gce9xAAh3ELvMKNjw4/e9JllrphP3T8lliw3hFr939vJITIXwOnKdbRXw+86Mc/ nRNECH7mr0oJGfaUAWNT/WU+m4Ag+BOia0OEUyxwgOewtpYriRWD3pfTqZ0+JpGY 2ADIGZmbCNy07GyokJ/GTqQGW85Bi4UUAhOXrkb43M7IOISMDd4lmhq7Jr7Vtsw/ N3TBTZ6TqPidP5A0fhs2JarFdluCnraXCvrE5EFWqMKmYHVxZNbNebRuK2cL91QS OqHzqFUUdVEptG9EbjcsZyszcnWovSKWMFj5yo0m/VfubMmSTxcRIq5BRaw4kpci /weIlNiUa4S/+9ezxuD4Qxrgl9zt4rntrLwqml+gDe1lOhqLP4YzLmZwnnaoxdVA 6P9iRQWV49F3gCqTSaDXdnUMS9xa33bK4SYl4vGP/llequBs/ez5w6kWIACqmvYy K5afNJqoQKRCZBiU/u9VTe2DVxKqfK4+64WX9prGdLuKbwlEBLVKynkJ+7TcrLyp DkDB/mDal3NPch0dS0r0zTeE0oP04eV8weo+4UrjTB7tRhoHt3HjNdbLZyR5K0Fy LzGiTAyClkkB8TWyRw6J7Fu+gvwS24hfDNS9CweUtfHkllOv2Fvzl8VBEj9OJcpw 92VY852+NfdhWqW8GLTKXu6yg1giJYc4nwLAjJ9lvXZCyyRbNls= =I5ks -----END PGP SIGNATURE----- --29fHyA6gHwzAMFp6--