From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id B03EE5A0272 for ; Wed, 7 Feb 2024 10:03:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707296583; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UWcTi0FcOsSPnny+dcjI4zNW76tLojG6Qp6gHd0UwFo=; b=ExyJ4emZoZVwKXD0qYaxFT2NwaQ59OJ1z4+deNywKfa/fwrn8X45E+Qj9NqPE3MTUdtPqs jfy6/bsZh0N6bDlkg0s3QKzpGCtjGa/NtyO/lZxePBZjd0eW7XhNXErlnNM4rOzgoBTfZq 0snFiABTp1/7S0VMghIdQjNbFid8Kuc= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-37-hgI2mb9kO9-U--cX0qOWPg-1; Wed, 07 Feb 2024 04:03:02 -0500 X-MC-Unique: hgI2mb9kO9-U--cX0qOWPg-1 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-5605a2937d4so184059a12.1 for ; Wed, 07 Feb 2024 01:03:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707296580; x=1707901380; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=UWcTi0FcOsSPnny+dcjI4zNW76tLojG6Qp6gHd0UwFo=; b=oXgZde/sLJGgzgWV9UNoAsna/NRTWob2Efz9uLWeSwXtiG9SwAJmMZ4iK6UQ0VUiPG d7eYU+iF98emlKBc84D96BlYoxwweHrIIktDeUt8FPlRuaO2cutDNp5e92vKAhVztNQZ yWW5yUaccjffQai0tHxeSpUFlijHLm8ZecOaoI1nVwFO62FhEqJkXSIUjt7kaj+n3mcl N5h8UaW3WbAOxkfNkvO77B/EM3Qdsc9g5y94dYHVl3DxJOdt4FNwfwbGkYZmlLDXcWHT tfNqMAQM17Ae6PO82rGom32og16VkYRq1pqiuYFMBNRngLIkWWDVVNllmLlxxkhpv1j8 GUJA== X-Gm-Message-State: AOJu0Yww1mPGdccyAii3JdOdSHkq0vdK11I9myhIaiSb6Kg5Sg2xmxD8 9yMClC+3oK5DR5qGO+il6HXTzBBMySxzBn1bdxcG+el1tvnOz5dJrYmWRuMc3x+qpEuQQO53Kc/ qoHRO3fp1eGBbKEuEs2F6gam3CMpYoF22w/MHPkPAFXRVFJfUvwhBd4C5SFsbGBgjHT5eZx6mmS wxCrIfWl8j2ZD+wMVC7YR1dDftUZDmYEaeRTg= X-Received: by 2002:a05:6402:31f3:b0:55f:ff43:d534 with SMTP id dy19-20020a05640231f300b0055fff43d534mr4061026edb.22.1707296580019; Wed, 07 Feb 2024 01:03:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IHOIle/bQ4U6rj0NUJM7Eu2stY4ZZET91suTZtcbkNqSc0PzBPNM79Kr9pVP8yJW/BCyuv9XQ== X-Received: by 2002:a05:6402:31f3:b0:55f:ff43:d534 with SMTP id dy19-20020a05640231f300b0055fff43d534mr4061001edb.22.1707296579494; Wed, 07 Feb 2024 01:02:59 -0800 (PST) Received: from maya.cloud.tilaa.com (maya.cloud.tilaa.com. [164.138.29.33]) by smtp.gmail.com with ESMTPSA id l21-20020aa7d955000000b005607fdd90b8sm450890eds.23.2024.02.07.01.02.58 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Feb 2024 01:02:58 -0800 (PST) Date: Wed, 7 Feb 2024 10:02:24 +0100 From: Stefano Brivio To: Laurent Vivier Subject: Re: [PATCH 04/24] checksum: add csum_iov() Message-ID: <20240207100224.2ff57ecb@elisabeth> In-Reply-To: <20240202141151.3762941-5-lvivier@redhat.com> References: <20240202141151.3762941-1-lvivier@redhat.com> <20240202141151.3762941-5-lvivier@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.1.1 (GTK 3.24.36; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: YH4775PXRVGRHHYY3DT7XXNJRPSLFDOJ X-Message-ID-Hash: YH4775PXRVGRHHYY3DT7XXNJRPSLFDOJ X-MailFrom: sbrivio@redhat.com 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: On Fri, 2 Feb 2024 15:11:31 +0100 Laurent Vivier wrote: > Signed-off-by: Laurent Vivier > --- > checksum.c | 39 ++++++++++++++++++++++----------------- > checksum.h | 1 + > 2 files changed, 23 insertions(+), 17 deletions(-) > > 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; > } > > -/** > - * 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) > { > intptr_t align = ((intptr_t)buf + 0x1f) & ~(intptr_t)0x1f; > unsigned int pad = align - (intptr_t)buf; > @@ -419,24 +410,38 @@ uint16_t csum(const void *buf, size_t len, uint32_t init) > if (len > pad) > init = csum_avx2((void *)align, len - pad, init); > > - return (uint16_t)~csum_fold(init); > + return init; > } > - > #else /* __AVX2__ */ > > +__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 > * @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 > */ > /* 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)); > } > > -#endif /* !__AVX2__ */ > +uint16_t csum_iov(struct iovec *iov, unsigned int n, uint32_t init) > +{ > + unsigned int i; > + > + for (i = 0; i < n; i++) Stray whitespace before i++. > + init = 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); > > #endif /* CHECKSUM_H */ -- Stefano