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=202508 header.b=Zy8kwRW3; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 3E7E35A0279 for ; Wed, 13 Aug 2025 04:41:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202508; t=1755052904; bh=b3kTcCiu8yavRr+kPviFxfNPHRM1kmxioVOlRKiwQ0U=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Zy8kwRW3sSTwKEGgvw4P35+9PJ6fee9LRlG9fb5J3PoTcoT8G9sMEGl440G9aXMzW kGKZf1WyHajI9sG8G6aSaD2eKMr2vlqLiT0KgpPU1Tqj+vu7Lgk02RULVqxIewsij4 T2lsyKUGdtXbcfdwh9m99i6dtwyal5qvL7F8/25527Wk/KRVCe6li6E304RPM4o9tY gDyAxfrxoxaPYUpZ44kBw5evMfJKrcuYvXYDKJe40gnzntY1rzSOPkUpaFRQKXXS5R 7NfNTgVgRiFv0wm9rR75odzNyrTZGBohDojWbnVrWzf6mNsiSjtTeLvhNIHZdfqORd 7BSUlTAfzPdVg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4c1t1N5LjCz4x6J; Wed, 13 Aug 2025 12:41:44 +1000 (AEST) Date: Wed, 13 Aug 2025 12:37:21 +1000 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v9 02/30] iov: Introduce iov_tail_clone() and iov_tail_drop(). Message-ID: References: <20250808140142.3404325-1-lvivier@redhat.com> <20250808140142.3404325-3-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="e/jmZbvTqkj7x2po" Content-Disposition: inline In-Reply-To: <20250808140142.3404325-3-lvivier@redhat.com> Message-ID-Hash: FOYKQF4CFSMGRWKSI2VPDXU2DXRXFAUA X-Message-ID-Hash: FOYKQF4CFSMGRWKSI2VPDXU2DXRXFAUA 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: --e/jmZbvTqkj7x2po Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Aug 08, 2025 at 04:01:14PM +0200, Laurent Vivier wrote: > These utilities enhance iov_tail manipulation, useful for > efficient packet processing by enabling iovec array cloning and > header stripping without data copies. >=20 > - iov_tail_drop(): Discards a specified number of bytes from the > beginning of an iov_tail by advancing its internal offset and pruning > consumed elements. >=20 > - iov_tail_clone(): Clone an iov_tail into an iovec array, adjusting the > first iovec entry to remove the iov_tail offset. >=20 > Signed-off-by: Laurent Vivier Reviewed-by: David Gibson For correctness, but some minor comments below: > --- > iov.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ > iov.h | 3 +++ > 2 files changed, 55 insertions(+) >=20 > diff --git a/iov.c b/iov.c > index edf0444d1955..9d282d4af461 100644 > --- a/iov.c > +++ b/iov.c > @@ -192,6 +192,21 @@ size_t iov_tail_size(struct iov_tail *tail) > return iov_size(tail->iov, tail->cnt) - tail->off; > } > =20 > +/** > + * iov_tail_drop() - Discard a header from an IOV tail > + * @tail: IO vector tail > + * @len: length to move the head of the tail > + * > + * Return: true if the item still contains any bytes, otherwise false > + */ > +/* cppcheck-suppress unusedFunction */ > +bool iov_tail_drop(struct iov_tail *tail, size_t len) I'd prefer the name iov_drop_header(), to match iov_peek_header() and iov_remove_header(). > +{ > + tail->off =3D tail->off + len; > + > + return iov_tail_prune(tail); > +} > + > /** > * iov_peek_header_() - Get pointer to a header from an IOV tail > * @tail: IOV tail to get header from > @@ -248,3 +263,40 @@ void *iov_remove_header_(struct iov_tail *tail, size= _t len, size_t align) > tail->off =3D tail->off + len; > return p; > } > + > +/** > + * iov_tail_clone() - Assign iov references referencing a subset of the = data > + * in an iov_tail I find that short description very hard to parse. Maybe iov_tail_clone() - Clone an iov tail into a new iovec array > + * > + * @dst_iov: Pointer to the destination array of struct iovec descri= bing > + * the scatter/gather I/O vector to shallow copy to. > + * @dst_iov_cnt: Maximum number of elements in the destination iov array. > + * @tail: Pointer to the source iov_tail > + * > + * Return: the number of elements successfully referenced from the desti= nation > + * iov array, a negative value if there is not enough room in the > + * destination iov array > + */ > +/* cppcheck-suppress unusedFunction */ > +ssize_t iov_tail_clone(struct iovec *dst_iov, size_t dst_iov_cnt, > + struct iov_tail *tail) > +{ > + const struct iovec *iov =3D &tail->iov[0]; > + size_t iov_cnt =3D tail->cnt; > + size_t offset =3D tail->off; > + unsigned int i, j; > + > + i =3D iov_skip_bytes(iov, iov_cnt, offset, &offset); As noted several times previously we can clean up this and a number of other places if we clarify that always being pruned is part of an iov_tail's invariant. > + At this point we can already test if dst_iov_cnt is long enough, which I think would be a little cleaner than counting through it and only then finding it's not enough. > + /* assign iov references referencing a subset of the source one */ > + for (j =3D 0; i < iov_cnt && j < dst_iov_cnt; i++, j++) { > + dst_iov[j].iov_base =3D (char *)iov[i].iov_base + offset; > + dst_iov[j].iov_len =3D iov[i].iov_len - offset; > + offset =3D 0; > + } > + > + if (j =3D=3D dst_iov_cnt && i !=3D iov_cnt) > + return -1; > + > + return j; > +} > diff --git a/iov.h b/iov.h > index 3fc96ab9755a..bf9820ac52ab 100644 > --- a/iov.h > +++ b/iov.h > @@ -72,8 +72,11 @@ struct iov_tail { > =20 > bool iov_tail_prune(struct iov_tail *tail); > size_t iov_tail_size(struct iov_tail *tail); > +bool iov_tail_drop(struct iov_tail *tail, size_t len); > void *iov_peek_header_(struct iov_tail *tail, size_t len, size_t align); > void *iov_remove_header_(struct iov_tail *tail, size_t len, size_t align= ); > +ssize_t iov_tail_clone(struct iovec *dst_iov, size_t dst_iov_cnt, > + struct iov_tail *tail); > =20 > /** > * IOV_PEEK_HEADER() - Get typed pointer to a header from an IOV tail --=20 David Gibson (he or they) | 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 --e/jmZbvTqkj7x2po Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmib+mAACgkQzQJF27ox 2GdFcxAAqOdKwK9P20Aaf9PZeYqvsTOSpCICnSFk1N/YG0g4nG409AcgGfBPouI9 vmWHpsbnQGN0Ahz9sudYDe/8hswQ4mV+ihCNJzLBqndcrPJ68s7QV35uLhLiGGSt XPg7LIWnF0GZ/ZIYrlt3whYYRYRcT/pZPMg14FTI+01YPf8Lc4Uw4yTe1MXarWsA BKCKtOc3UMNnTbRixcz0b1YmnSEBWbrvRW3WqgTpfLvd6lTgkRUSxTq1kdRNo5QB EXkolTUff/DuZEUlCBtdXlpuVEexxtD1NVULuRuKzqqWzL60NJeiBWt0wtUJKbuW SVUClO/ru6P/fu5y8yGwtlroaHv1AlZJprWP61PvB/f+zfWqgw8/guDrZb0mXopX 3ikBuf2pmbAnqJ7FiqB5L9k8h5K0TJMgK1/cwmgeuDmAWu01N1Nk12E5rEJBwLtg j8rMdGsQzNYqbZVq5oFC6sJauOJGWQC0t3zdOdnGeMubzFlS2QJP3br3bIyTtZeu Q/VRZJthtK5+eqEwhAPG+zMKqoPSjTFIYSuaRn9zAb3dCLKV/9uqJIj4/Ar6fsqN 1QjQFzXMM3VDt5cGBDzKeNhoPl5y8qEp6lgmogfLkwZCEirfTqeyWAXRSFIZD7f3 vnI9+tR+qlBcLQvVgrjbOnAO6/vXwxz8hRfcrchy+otRwUO1Z84= =iXdJ -----END PGP SIGNATURE----- --e/jmZbvTqkj7x2po--