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=PPvonkz6; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id B02885A0271 for ; Wed, 06 Aug 2025 03:58:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202508; t=1754445502; bh=I2MOsSpuLMDWZoaQ8SWBAS++O1DoWQVM2GRKSUwXlr4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=PPvonkz6u0sD2p76yqa8KmFatRNoFD7zgIP3HGay+/IT6knZ2Vz7vd+/FdAhg7AYa Ji+PQA2ZYv1SKfOmopN1QA1AQ9vuLAFJsOvhBQ0fDvEgC9YQYEIA3pbvBFg89p0vTy JwpZY6Jz9Wm8WYnIo/WIaH8V2M+4u0zYdWJDP48sSR3PIeMAD04PxstJvOMIebxOka NlSL5LXy/HY5LdJNiwXB6Q4US+rn3/+22H4B1pzgjQY5DoRduDkSciErG7IgF1p3Qo EeNPbBKY//E/xtOUn3GT8qdBTpLEFsVXrM0KBbXu3RKGX/y5eNlq90twHZ9Nbvthd1 /9z4SziHYsMwQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4bxYNZ6F6hz4wbY; Wed, 6 Aug 2025 11:58:22 +1000 (AEST) Date: Wed, 6 Aug 2025 11:32:04 +1000 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v8 02/30] iov: Introduce iov_tail_clone() and iov_tail_drop(). Message-ID: References: <20250805154628.301343-1-lvivier@redhat.com> <20250805154628.301343-3-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="XQMMnC/MF+9dVTu+" Content-Disposition: inline In-Reply-To: <20250805154628.301343-3-lvivier@redhat.com> Message-ID-Hash: 4ZAIDKLNVEFMC52SN6UZZZGHDJR4MADL X-Message-ID-Hash: 4ZAIDKLNVEFMC52SN6UZZZGHDJR4MADL 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: --XQMMnC/MF+9dVTu+ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Aug 05, 2025 at 05:46:00PM +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 To the extent that the functions look useful and the implementations look correct; a couple of suggested improvements 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 Maybe _drop_hdr() to clarify that it's dropping specifically from the start. Or maybe not, I'm torn between brevity and specificity. > + * @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) > +{ > + 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 > + * > + * @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); If you prune first, then you can assume that offset is within the first entry, and you'll also know that you need exactly tail->cnt entries in the destination. You could then: if (tail->off !=3D 0) /* copy partial first entry */ /* memcpy the rest */ > + /* 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 --XQMMnC/MF+9dVTu+ Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmiSsHoACgkQzQJF27ox 2GdFWxAAm+Q7GzXfk9VIzyZdQxUHELPM2tN6wyaNvnkv7b68S/HA2nTfsZ5reoHK 0fQ4iVg+3jf6Gdd4jdYm+c8HZKbTUan26vREm8Wa/vKGNrdVRoYvGFU3vtmnRlBB qrcH66bZquMq6hJZZy59hhlYJ768g/k94ui+6JSX4JrBRhE0VQlh8pV4o0Bs+DhF krc9/V3yWory+y1JlaaJ7KjuspnfQeBqyge0nCadg2hCJnXTTfdXD7m3+PV5Mgv8 F+hbp7qd++7yuoQdJ/X9j8rTV6EahpZZa8LJS3P22EMWN4Gm3q+aqY7Yo9wNh7bj yOM8foZj1YHs6CrZpZcNLZVqy/MvNPWYD6g7A6uN7c2LnVpL9bHqmVyhie/JkcWp XCakgSF6gkcy2491lFyTKJXlOTHNrxuf4P3J3MXclu1olSc8/nAAGeRAJ1T0LmNR t0qOhCJeb7KG+BZyTR5K0LyEi56HHXh3wGZEkEYpK5d/ZmTjgTKa6IpnBlgCXMHF dHNe8TvXtlVw2UQmsF19GOxiZaIrLktk/jO8r69Ur9ifN607+x02tIfObB5ZPoZn nUMNoj41f9ETPLfSgvqbDr7x3rz8A8Puzpa5dDpIf9DbloH1nEE89IkUs7gLpyHe Pr68IUWwZB5OqRJAnygGjhTuMZrxYrIY59rkS4uBKrFgyHg2OCU= =8P5D -----END PGP SIGNATURE----- --XQMMnC/MF+9dVTu+--