From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202602 header.b=HRLgKo+Q; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id A25C25A0274 for ; Mon, 02 Mar 2026 01:13:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1772410422; bh=DoEUapS8mcIqRSTA/etAHonvahQAhTiZJSZIG4Gwe9M=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HRLgKo+QuFbWlynK2xxSZZxUzz9rTIHgjqp6scNB6IFQZ+8V+azLnydNkqt948QfP QAPKJgtQtNJE8wrren2j64TUmUUnIBnY7WhtENn0dRASZm6o76FQOwg5lmvzS26i8x 6124PliqNMZyJqsQwKJHdn8i7TWyn8AU1F2yz5cBmJQhWvLja+NvmGEqFfPHSd5xHb a2oLZu8ybP9sOz6PiIV8lzi0N8sok4BryhtXxcmyL+poLFLHzSxJdgNi8AWJ0KCqBN qokEvH1hILLcZJ7pNd9jh8KEARcMXzvOdKGkn6y/vbKQUbS8yEGn6O7q9DGaHpWCqR A6wsgj8I7I4Hg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4fPKCp3t4pz4wCJ; Mon, 02 Mar 2026 11:13:42 +1100 (AEDT) Date: Mon, 2 Mar 2026 10:47:39 +1100 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH 01/12] iov: Add iov_tail_truncate() and iov_tail_zero_end() Message-ID: References: <20260227140330.2216753-1-lvivier@redhat.com> <20260227140330.2216753-2-lvivier@redhat.com> MIME-Version: 1.0 In-Reply-To: <20260227140330.2216753-2-lvivier@redhat.com> 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 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="gcNc8XK8/txM8hUm" Content-Disposition: inline Message-ID-Hash: YQPNB4KQ2N7OWZC4KKRQ6SL4ZRY4FOLR X-Message-ID-Hash: YQPNB4KQ2N7OWZC4KKRQ6SL4ZRY4FOLR 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: --gcNc8XK8/txM8hUm Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Feb 27, 2026 at 03:03:19PM +0100, Laurent Vivier wrote: > iov_tail_truncate() truncates a tail so it contains at most a given > number of bytes from the current position, adjusting both the last > iovec entry and the buffer count. >=20 > iov_tail_zero_end() zero-fills all backing buffer bytes beyond a given > number of leading bytes from the current tail position and can be > used to clear trailing padding in fixed-size frames. >=20 > Signed-off-by: Laurent Vivier > --- > iov.c | 39 +++++++++++++++++++++++++++++++++++++++ > iov.h | 2 ++ > 2 files changed, 41 insertions(+) >=20 > diff --git a/iov.c b/iov.c > index ad726daa4cd8..cb4d6fef5567 100644 > --- a/iov.c > +++ b/iov.c > @@ -170,6 +170,45 @@ bool iov_tail_prune(struct iov_tail *tail) > =09return !!tail->cnt; > } > =20 > +/** > + * iov_tail_truncate() - Truncate tail to at most @size bytes > + * @tail:=09IO vector tail (modified in place, including backing iovecs) > + * @size:=09Maximum number of bytes to keep, relative to current tail of= fset > + */ > +/* cppcheck-suppress unusedFunction */ > +void iov_tail_truncate(struct iov_tail *tail, size_t size) > +{ > +=09size_t i, off; > + > +=09i =3D iov_skip_bytes(tail->iov, tail->cnt, tail->off + size, &off); > + > +=09if (i < tail->cnt) { > +=09=09struct iovec *last =3D (struct iovec *)&tail->iov[i]; This cast makes me pretty nervous. Up until now, a global property of iov_tail has been that it never alters the underlying iovec array: the tail is just a view into an immutable underlying vector. Maybe it's worth changing that, but we should do so explicitly if we do, which would suggest to me removing the const from struct iov_tail, rather than making a const-discarding cast here. > + > +=09=09last->iov_len =3D off; > +=09=09tail->cnt =3D i + !!off; > +=09} > +} > + > +/** > + * iov_tail_zero_end() - Zero-fill tail bytes beyond @size > + * @tail:=09IO vector tail (backing buffers modified in place) > + * @size:=09Number of leading bytes to preserve > + */ > +/* cppcheck-suppress unusedFunction */ > +void iov_tail_zero_end(struct iov_tail *tail, size_t size) > +{ > +=09size_t i, off; > + > +=09i =3D iov_skip_bytes(tail->iov, tail->cnt, tail->off + size, &off); > + > +=09for (; i < tail->cnt; i++) { > +=09=09memset((char *)tail->iov[i].iov_base + off, 0, > +=09=09 tail->iov[i].iov_len - off); > +=09=09off =3D 0; > +=09} > +} > + > /** > * iov_tail_size() - Calculate the total size of an IO vector tail > * @tail:=09IO vector tail > diff --git a/iov.h b/iov.h > index d2184bfd12bd..a7b873d58134 100644 > --- a/iov.h > +++ b/iov.h > @@ -89,6 +89,8 @@ void *iov_peek_header_(struct iov_tail *tail, void *v, = size_t len, size_t align) > void *iov_remove_header_(struct iov_tail *tail, void *v, size_t len, siz= e_t align); > ssize_t iov_tail_clone(struct iovec *dst_iov, size_t dst_iov_cnt, > =09=09 struct iov_tail *tail); > +void iov_tail_truncate(struct iov_tail *tail, size_t size); > +void iov_tail_zero_end(struct iov_tail *tail, size_t size); > =20 > /** > * IOV_PEEK_HEADER() - Get typed pointer to a header from an IOV tail > --=20 > 2.53.0 >=20 --=20 David Gibson (he or they)=09| I'll have my music baroque, and my code david AT gibson.dropbear.id.au=09| minimalist, thank you, not the other way =09=09=09=09| around. http://www.ozlabs.org/~dgibson --gcNc8XK8/txM8hUm Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmmk0AwACgkQzQJF27ox 2GcBOA/9FEztMGe5NC6pbDIl9qXKAB6PNnsXobFiOkYxpbHTkpXYw2rdDNoCAQ/z /I4U07FT28VCRtwTXOObv3PGRh0ZHCwDiEGL+s0FyQ0/ZPtUt1fCYF6bSox/xXBE k1tBZ8+8BVMIxOT1lXqLTyX4LuDDWFjhiOHx7U5U/PQLfZq1QpUqFa649JMAbJFY 6AQ3dXmmmrpFXqCW0yvKTjtE8+hcYBi982pdsX0ZWSikFl7Fq6BQJhsDY7PaS6XE nVktz3R82d1oWQZ2TtzkJEvOb74l4NzHL7s348tg7gfS4GeylKUc7xGpiToOvrOt J3Hyd0KMsrSzgfIEcT5r+IEPWYMNOkQ2wxQAtwC0VKWWangn2nJnZK6dScxcAGH7 FCf2aiqZORiEkZm/KWe+6DXYG+Ew4Ggd4yFCZKwTi5dPOB/4LN+lRlCi8H+OS9Xx 8EbsclVSAVxZGdBxOEy6v12RHU9tzUywXXS9KGBOtMmHiodUM8V4OEixx3pU95IP pyVljGW3OToMAckt41EYorCAPZtYcofAg7J2ModsR3RHGWZrTIcRTMSEEYEw7iSF 2kbk2ow91b5XcF9ni4E9rVWg8Vv/Hmi6kbLo9iiMEZFdjXXei1GMJtOFJBBXXXcA Rpb2DsVCtmTHRNqsGRuSikbr/wDZZUC3ldWlq7LpLMk+Xgw17OQ= =vfQ5 -----END PGP SIGNATURE----- --gcNc8XK8/txM8hUm--