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 949195A027A for ; Mon, 5 Feb 2024 07:13:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1707113625; bh=0L2zuQDWC9V0QNHnYWPwKYEUjEzuk0+wQAphdoRRcCc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Wdxp2TzW4tHKkt7FKIvI+93/efWXoL6smcDDAnZhNoeIICibRlsShVpJd4J5V4R5e OjC6/xtoZd4XVMaAr/XZzIHQ5mtMylYl8fSiD8HeWNKd70668TzjhyOguEXBZNqtCG jqYDc0B/Fjm2huC/gy3cCkPKFTMlShUiebwA1JHAhl+ONN2EVkK29tFn2melmaxctN Mk5fPK0jHATL8GmPAuGL40Q56w1mM3v/Fl0JDt/KUsFFHYbreMD0hRPMBorcTd1Aqw a0RQV1Qg/4+WxNnbI2ntrGZQA/LN7el5iig+xp8GgcwoDsFIJy4bzvps0ELOToQfwY 8E36G3jMDd6LQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4TSx092cZcz4wyg; Mon, 5 Feb 2024 17:13:45 +1100 (AEDT) Date: Mon, 5 Feb 2024 17:07:47 +1100 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH 04/24] checksum: add csum_iov() Message-ID: References: <20240202141151.3762941-1-lvivier@redhat.com> <20240202141151.3762941-5-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="I2rJsU4igA98HY2d" Content-Disposition: inline In-Reply-To: <20240202141151.3762941-5-lvivier@redhat.com> Message-ID-Hash: 4KEMI3F62BZZVD672PNKW4AA3LPRFPJC X-Message-ID-Hash: 4KEMI3F62BZZVD672PNKW4AA3LPRFPJC 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: --I2rJsU4igA98HY2d Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Feb 02, 2024 at 03:11:31PM +0100, Laurent Vivier wrote: > Signed-off-by: Laurent Vivier > --- > checksum.c | 39 ++++++++++++++++++++++----------------- > checksum.h | 1 + > 2 files changed, 23 insertions(+), 17 deletions(-) >=20 > diff --git a/checksum.c b/checksum.c > index c94980771c63..14b6057684d9 100644 > --- a/checksum.c > +++ b/checksum.c > @@ -395,17 +395,8 @@ less_than_128_bytes: > return (uint32_t)sum64; > } > =20 > -/** > - * csum() - Compute TCP/IP-style checksum > - * @buf: Input buffer, must be aligned to 32-byte boundary > - * @len: Input length > - * @init: Initial 32-bit checksum, 0 for no pre-computed checksum > - * > - * Return: 16-bit folded, complemented checksum sum > - */ > -/* 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) I'm wondering if this might be a little clearer with a feed() / final() interface something like siphash. > { > intptr_t align =3D ((intptr_t)buf + 0x1f) & ~(intptr_t)0x1f; > unsigned int pad =3D align - (intptr_t)buf; > @@ -419,24 +410,38 @@ 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__ */ > =20 > +__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__ */ > + > /** > * csum() - Compute TCP/IP-style checksum > - * @buf: Input buffer > + * @buf: Input buffer, must be aligned to 32-byte boundary I thought the point of the previous patch was that this didn't have to be 32-byte aligned any more. > * @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 > + * Return: 16-bit folded, complemented checksum sum "checksum sum" > */ > /* 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) > { > - return csum_unaligned(buf, len, init); > + return (uint16_t)~csum_fold(csum_unfolded(buf, len, init)); > } > =20 > -#endif /* !__AVX2__ */ > +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 --I2rJsU4igA98HY2d Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmXAezIACgkQzQJF27ox 2GdiYw//T4DHtxNflSkenjHZ57Bve58487/kOWuoWKdwHyemHZy1Of0AbKH8PVkI vFBdYFLEbUHYNs6/kd6VlKsZ11Swlo+Qcf0omQ5Yxq5T4DJAJCVj5OaJ5uiGnX9C GJYic3V9RhwDdU1Xx/1MUonrYuzdcnF2dP9NFf948lbRuuYs1PiPUfAbqPLn7F11 hVvrsdQaptSB3/3w4GBATWqjF4+BMnDnck6Ecq7s77D9jXFDL+PnrO3Dv9fw/5LG LB01xQjqkjO3B3W1Ps6VZHi3lee1tgIN2UM0B5W+mKYljjgQQ0sKt3hbRhtaoHRq 8TsupnLUPpRwUKROC0KgYopF/qsQpVPIdKb1xg8DzH4pgeJS16QmnJYEbxRGrGfm DR7Mvs1bIZdNwDPe80yLUOmDOf8aD/UPP3BiAfCYydWZE1ZFyU8q7gLjs+SRa36G aXGAV61PZ/QzXmLqsZorlINZ8OtTrCc8GcZyzc7zJgUsABhguWS3Q5I25QCDm0H+ yZaEtKoc1BHjoZdGyQljYp4ciDtzKfxY06YAxRb8JNKOfzNjzY8WCh0p/suGBc5T RGI6ZHeAYbQirK9q4je8S6eTW86KThOXVPQRCrp7tQ9tPIJ4cNlW9wmH7Zl9sN/F 7jWlbWmuzXNSZHqCYEf+ONCV22M2gFysqeBEewQCANhKXHFsGes= =CrWz -----END PGP SIGNATURE----- --I2rJsU4igA98HY2d--