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 5C0565A027B for ; Thu, 15 Feb 2024 01:44:33 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1707957871; bh=CgqKsjy/pKjGlBxY5dw8P1gJRh+ntVw2zA/4DJS4Fn8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=X82rkta5fa27oyn5C5hAnqL60hLSKwKYvWLaYPAa9j7x7RD8uAs8dpBAsF2+RA2Sa OomNvVmb24+qT/nbDgtHLODQVD9yTAO6cnLQA3fesDzBQykBCf7LRQmWczA7OSvDOw dNu6aqDl5UtDWtVzO5t2qv73RJ+4M4azkbkYal11ddJHQRZN3CKyyGohC393eWwcjM e7r6USDKW0B3yi1plMDdJt57OaSpvC4xG2vQfUDre3BIDY8Ug5gnIMTGx2Bx6ZmqkR nwPLFB9j/sOtXUdMGcucj7GC4w5UxbO7N2D5DoB3LKMuIiiZLBrh4Dw/whUaCiTQIt wCh6GNjqFzfUA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4TZxCg323Mz4wcB; Thu, 15 Feb 2024 11:44:31 +1100 (AEDT) Date: Thu, 15 Feb 2024 11:44:25 +1100 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v2 4/8] checksum: add csum_iov() Message-ID: References: <20240214085628.210783-1-lvivier@redhat.com> <20240214085628.210783-5-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="3FTClr7bpYQQIDFL" Content-Disposition: inline In-Reply-To: <20240214085628.210783-5-lvivier@redhat.com> Message-ID-Hash: OF7QYXZ62YODCG2XCH4L2KOGVPQCFSC6 X-Message-ID-Hash: OF7QYXZ62YODCG2XCH4L2KOGVPQCFSC6 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: --3FTClr7bpYQQIDFL Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Feb 14, 2024 at 09:56:24AM +0100, Laurent Vivier wrote: > Introduce the function csum_unfolded() that computes the unfolded > 32-bit checksum of a data buffer, and call it from csum() that returns > the folded value. >=20 > Introduce csum_iov() that computes the checksum using csum_folded() on > all vectors of the iovec array and returns the folded result. >=20 > Signed-off-by: Laurent Vivier > --- >=20 > Notes: > v2: > - fix typo and superfluous space > - update comments >=20 > checksum.c | 46 ++++++++++++++++++++++++++++++++++------------ > checksum.h | 1 + > 2 files changed, 35 insertions(+), 12 deletions(-) >=20 > diff --git a/checksum.c b/checksum.c > index 65486b4625ba..ac2bc49f7eb0 100644 > --- a/checksum.c > +++ b/checksum.c > @@ -385,16 +385,16 @@ less_than_128_bytes: > } > =20 > /** > - * csum() - Compute TCP/IP-style checksum > - * @buf: Input buffer > - * @len: Input length > - * @init: Initial 32-bit checksum, 0 for no pre-computed checksum > + * csum_unfolded - Calculate the unfolded checksum of a data buffer. > * > - * Return: 16-bit folded, complemented checksum > + * @buf: Input buffer > + * @len: Input length > + * @init: Initial 32-bit checksum, 0 for no pre-computed checksum > + * > + * Return: 32-bit unfolded, complemented checksum This function neither folds nor complements (indeed, you can't complement until after you fold). > */ > -/* NOLINTNEXTLINE(clang-diagnostic-unknown-attributes) */ > __attribute__((optimize("-fno-strict-aliasing"))) /* See csum_16b() */ > -uint16_t csum(const void *buf, size_t len, uint32_t init) > +uint32_t csum_unfolded(const void *buf, size_t len, uint32_t init) > { > intptr_t align =3D ROUND_UP((intptr_t)buf, sizeof(__m256i)); > unsigned int pad =3D align - (intptr_t)buf; > @@ -408,16 +408,30 @@ uint16_t csum(const void *buf, size_t len, uint32_t= init) > if (len > pad) > init =3D csum_avx2((void *)align, len - pad, init); > =20 > - return (uint16_t)~csum_fold(init); > + return init; > } > - > #else /* __AVX2__ */ > +/** > + * csum_unfolded - Calculate the unfolded checksum of a data buffer. > + * > + * @buf: Input buffer > + * @len: Input length > + * @init: Initial 32-bit checksum, 0 for no pre-computed checksum > + * > + * Return: 32-bit unfolded, complemented checksum > + */ > +__attribute__((optimize("-fno-strict-aliasing"))) /* See csum_16b() */ > +uint32_t csum_unfolded(const void *buf, size_t len, uint32_t init) > +{ > + return sum_16b(buf, len) + init; > +} > +#endif /* !__AVX2__ */ > =20 > /** > * csum() - Compute TCP/IP-style checksum > * @buf: Input buffer > * @len: Input length > - * @sum: Initial 32-bit checksum, 0 for no pre-computed checksum > + * @init: Initial 32-bit checksum, 0 for no pre-computed checksum > * > * Return: 16-bit folded, complemented checksum > */ > @@ -425,7 +439,15 @@ uint16_t csum(const void *buf, size_t len, uint32_t = init) > __attribute__((optimize("-fno-strict-aliasing"))) /* See csum_16b() */ > uint16_t csum(const void *buf, size_t len, uint32_t init) > { > - return (uint16_t)~csum_fold(sum_16b(buf, len) + init); > + return (uint16_t)~csum_fold(csum_unfolded(buf, len, init)); > } > =20 > -#endif /* !__AVX2__ */ Function comment, please. > +uint16_t csum_iov(struct iovec *iov, unsigned int n, uint32_t init) > +{ > + unsigned int i; > + > + for (i =3D 0; i < n; i++) > + init =3D csum_unfolded(iov[i].iov_base, iov[i].iov_len, init); > + > + return (uint16_t)~csum_fold(init); > +} > diff --git a/checksum.h b/checksum.h > index 21c0310d3804..6a20297a5826 100644 > --- a/checksum.h > +++ b/checksum.h > @@ -25,5 +25,6 @@ void csum_icmp6(struct icmp6hdr *icmp6hr, > const struct in6_addr *saddr, const struct in6_addr *daddr, > const void *payload, size_t len); > uint16_t csum(const void *buf, size_t len, uint32_t init); > +uint16_t csum_iov(struct iovec *iov, unsigned int n, uint32_t init); > =20 > #endif /* CHECKSUM_H */ --=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 --3FTClr7bpYQQIDFL Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmXNXmgACgkQzQJF27ox 2Gcudg/+PjZqylILn6oGckqUavFvolEIZDpKzOm0C1ug3UI5vRbRTXJlApXHxTWB iX440f7Dspv78OZgkOvsJUEQcad1YcdEUBk+qHbsXtDdsQDy3Y6BkP81GtD39C5P vzuUQIzr6miB4f97nhHm6eH7A+u9tGi0UZpiiiMFmEFhN6FviZwTJGIgP9qjPjPi nh2hyE+eN+HLRN+xV7XuTnjiri4C1LGtTbuEjJO6ERi6BFZkWuhb35svN/uQOL01 rlgR9OOMl7j6Nk+PyzG5pdo8TnQkjthzuT+Zz+70VUvR3K1cEB3rA7D/43AbFm52 /sfRilvLHXvNyBe5OaKW21B4ZbA2EKRVxCNuO4gls3fJW68syWBqlUE8RI88M/si 9JAb1s7iWgXZ0oOBWvSYGGtzty1/6PvieVccFo1GrqTXSukc9wKX24qND30ufrCP 3CK2CBzb6CYP5t1hu7BAh3oOWvTB+eWOYARriSd8aMesY29DgXWZqTvB0Ws+4dmZ uskHk1VTbC+8lc88EhLUJkMJMTgz4D8ZGp0n+A7u33OGAsHPir/3aDGW9xTSbsBE 3+0+29of72xnLs0BkcOZJ86L+2+egbFtbIClMbbR9875WvNsL++B79Aw9wkU/FRs 3x/JoMkzYwRgPxzCs9/gdK5tpZ09eE9S0erDiI61k8C9wZHBfmc= =dwDL -----END PGP SIGNATURE----- --3FTClr7bpYQQIDFL--