From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 6015A5A0279 for ; Mon, 19 Feb 2024 03:52:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1708311146; bh=1MShANJEdO085sokwogPWRq0tYSAGPSp11yrxPaz21M=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=nBMpUwleCDkypzUVmzTNL8gT4QbxHGyq/tV5tUM4y/plogVOw8tuoKIT9MKBKv7Xj m/PCJvhE8hIzfM7yNhZKXSdfa1ackMflo5xl7FHKlfuFYLOjIJk8vGX8odNQkAVF2m A1fGrS5p7fvku7OuItZaYVPv5w7uMUXxrH2izPwVrTL2DQRShnPX0dWyD3XfNEhOQN Nb4T6CKIcOJBRuHXhK7eoGLWc08JQlADoYSE4ImRs8bygpLD/CA+q6WN2EcNSjd7Zs GxS+SIpM98rvzyI/5pJqMlACstpJZpAAYqZNcQ9HeRcK8b/+eOD8nntUlZAkYZlEDY ctaOoap1CuagQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4TdRsQ0wWCz4wcM; Mon, 19 Feb 2024 13:52:26 +1100 (AEDT) Date: Mon, 19 Feb 2024 13:52:21 +1100 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v3 4/9] checksum: add csum_iov() Message-ID: References: <20240217150725.661467-1-lvivier@redhat.com> <20240217150725.661467-5-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="gYfGssbKc779dcbG" Content-Disposition: inline In-Reply-To: <20240217150725.661467-5-lvivier@redhat.com> Message-ID-Hash: SHCNZ5GCRN64BZAH6XXNAEMPLXOIX2WC X-Message-ID-Hash: SHCNZ5GCRN64BZAH6XXNAEMPLXOIX2WC 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: --gYfGssbKc779dcbG Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Feb 17, 2024 at 04:07:20PM +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 Reviewed-by: David Gibson > --- >=20 > Notes: > v3: > - update comments > - use size_t for the IO vectors length > - include checksum.h in checksum.c > - export csum_unfolded() (for later) > =20 > v2: > - fix typo and superfluous space > - update comments >=20 > checksum.c | 56 ++++++++++++++++++++++++++++++++++++++++++------------ > checksum.h | 2 ++ > 2 files changed, 46 insertions(+), 12 deletions(-) >=20 > diff --git a/checksum.c b/checksum.c > index 65486b4625ba..74e3742bc6f6 100644 > --- a/checksum.c > +++ b/checksum.c > @@ -57,6 +57,7 @@ > #include > =20 > #include "util.h" > +#include "checksum.h" > =20 > /* Checksums are optional for UDP over IPv4, so we usually just set > * them to 0. Change this to 1 to calculate real UDP over IPv4 > @@ -385,16 +386,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 > */ > -/* 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 +409,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 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 +440,24 @@ 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__ */ > +/** > + * csum_iov() - Calculates the unfolded checksum over an array of IO vec= tors > + * > + * @iov Pointer to the array of IO vectors > + * @n Length of the array > + * @init Initial 32-bit checksum, 0 for no pre-computed checksum > + * > + * Return: 16-bit folded, complemented checksum > + */ > +uint16_t csum_iov(struct iovec *iov, size_t 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..dfa705a04a24 100644 > --- a/checksum.h > +++ b/checksum.h > @@ -24,6 +24,8 @@ void csum_udp6(struct udphdr *udp6hr, > void csum_icmp6(struct icmp6hdr *icmp6hr, > const struct in6_addr *saddr, const struct in6_addr *daddr, > const void *payload, size_t len); > +uint32_t csum_unfolded(const void *buf, size_t len, uint32_t init); > uint16_t csum(const void *buf, size_t len, uint32_t init); > +uint16_t csum_iov(struct iovec *iov, size_t 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 --gYfGssbKc779dcbG Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmXSwmQACgkQzQJF27ox 2GcZug//RN7D34ha/Vv2t6iWreSOiko1ZupvQpe3P2jJcGeIJi9NZxN/K/vf9Ozc J70RrI5Vtf0HUsjMssDLxo95eFMyby8b7EtKamtKJEF0U0TBPKdo+L7RnofowUKC IvIepJCrZC3luCvVWVbg7qZKWiIk8j+H0O/rBgOe41mZmqWgpMdwVYEyg+k++f8a WyifZgAVNwYTty9IQ3SvMWK3g+OobiNp5/sUCl0LQAuRL1c9IJAhIeYj8ZJbgxzP ZGHkUt2PrcFwNUumOHtTvVtDcHvkbV+99yotZjPMPA/AfW0teh7URcVqvgYsKnmg ulKjLdc8M8/djtNMCH4yPw1i4rqLW+CMo8JgthYOmIwcHfFVp0XTiUo1QrG5YF7u ayefoJXTuphVGdYeaGoJfhxQTLJaOrZOiUjT4Bkhfm2dK+o/1v8V1JSQ0HPvCYvX strFDu4xtkOR2gWqZNxxNG3O2m6FCBtiwc1jdPCuXTPaotkHuVMDHSs4t5Dk2Fif +pXS5xL4jKAq3ylbSQ5/3s8tqGoPoEDwgdcy3zT5hcyf6WB2Ybd65X+Pn2tOKoIt ODwbBugiHfBiYBrm1LqzBXxDlAC+SxieN77puLCZOD0gBx1ip4UlleBXfmpzqyw4 kCKqeOFSkgUahiCXJbMOPjRqfCYsn1xJaWbbULSRK2VPfeE26RM= =fdB3 -----END PGP SIGNATURE----- --gYfGssbKc779dcbG--