patch 'net: fix aliasing in checksum computation' has been queued to stable release 19.11.11

christian.ehrhardt at canonical.com christian.ehrhardt at canonical.com
Tue Nov 30 17:34:52 CET 2021


Hi,

FYI, your patch has been queued to stable release 19.11.11

Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before December 10th 2021. So please
shout if anyone has objections.

Also note that after the patch there's a diff of the upstream commit vs the
patch applied to the branch. This will indicate if there was any rebasing
needed to apply to the stable branch. If there were code changes for rebasing
(ie: not only metadata diffs), please double check that the rebase was
correctly done.

Queued patches are on a temporary branch at:
https://github.com/cpaelzer/dpdk-stable-queue

This queued commit can be viewed at:
https://github.com/cpaelzer/dpdk-stable-queue/commit/e3285b3e8ee70b46af72121ef796a7f710c1cb80

Thanks.

Christian Ehrhardt <christian.ehrhardt at canonical.com>

---
>From e3285b3e8ee70b46af72121ef796a7f710c1cb80 Mon Sep 17 00:00:00 2001
From: Georg Sauthoff <mail at gms.tf>
Date: Sun, 17 Oct 2021 22:37:18 +0200
Subject: [PATCH] net: fix aliasing in checksum computation
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

[ upstream commit 24f1955d1ecd13a3c261a328c72932115732825e ]

That means a superfluous cast is removed and aliasing through a uint8_t
pointer is eliminated. NB: The C standard specifies that a unsigned char
pointer may alias while the C standard doesn't include such requirement
for uint8_t pointers.

Also simplified the loop since a modern C compiler can speed up (i.e.
auto-vectorize) it in a similar way. For example, GCC auto-vectorizes it
for Haswell using AVX registers while halving the number of instructions
in the generated code.

Fixes: 6006818cfb26 ("net: new checksum functions")
Fixes: e079655c41fb ("net: fix build with gcc 4.4.7 and strict aliasing")

Signed-off-by: Georg Sauthoff <mail at gms.tf>
Reviewed-by: Morten Brørup <mb at smartsharesystems.com>
Acked-by: Olivier Matz <olivier.matz at 6wind.com>
---
 lib/librte_net/rte_ip.h | 27 ++++++++-------------------
 1 file changed, 8 insertions(+), 19 deletions(-)

diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h
index cedfd27ac1..279e88ee39 100644
--- a/lib/librte_net/rte_ip.h
+++ b/lib/librte_net/rte_ip.h
@@ -119,29 +119,18 @@ struct rte_ipv4_hdr {
 static inline uint32_t
 __rte_raw_cksum(const void *buf, size_t len, uint32_t sum)
 {
-	/* workaround gcc strict-aliasing warning */
-	uintptr_t ptr = (uintptr_t)buf;
+	/* extend strict-aliasing rules */
 	typedef uint16_t __attribute__((__may_alias__)) u16_p;
-	const u16_p *u16_buf = (const u16_p *)ptr;
-
-	while (len >= (sizeof(*u16_buf) * 4)) {
-		sum += u16_buf[0];
-		sum += u16_buf[1];
-		sum += u16_buf[2];
-		sum += u16_buf[3];
-		len -= sizeof(*u16_buf) * 4;
-		u16_buf += 4;
-	}
-	while (len >= sizeof(*u16_buf)) {
+	const u16_p *u16_buf = (const u16_p *)buf;
+	const u16_p *end = u16_buf + len / sizeof(*u16_buf);
+
+	for (; u16_buf != end; ++u16_buf)
 		sum += *u16_buf;
-		len -= sizeof(*u16_buf);
-		u16_buf += 1;
-	}
 
-	/* if length is in odd bytes */
-	if (len == 1) {
+	/* if length is odd, keeping it byte order independent */
+	if (unlikely(len % 2)) {
 		uint16_t left = 0;
-		*(uint8_t *)&left = *(const uint8_t *)u16_buf;
+		*(unsigned char *)&left = *(const unsigned char *)end;
 		sum += left;
 	}
 
-- 
2.34.0

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2021-11-30 16:50:11.079309029 +0100
+++ 0088-net-fix-aliasing-in-checksum-computation.patch	2021-11-30 16:50:05.878874175 +0100
@@ -1 +1 @@
-From 24f1955d1ecd13a3c261a328c72932115732825e Mon Sep 17 00:00:00 2001
+From e3285b3e8ee70b46af72121ef796a7f710c1cb80 Mon Sep 17 00:00:00 2001
@@ -8,0 +9,2 @@
+[ upstream commit 24f1955d1ecd13a3c261a328c72932115732825e ]
+
@@ -21 +22,0 @@
-Cc: stable at dpdk.org
@@ -27 +28 @@
- lib/net/rte_ip.h | 27 ++++++++-------------------
+ lib/librte_net/rte_ip.h | 27 ++++++++-------------------
@@ -30,5 +31,5 @@
-diff --git a/lib/net/rte_ip.h b/lib/net/rte_ip.h
-index 0ef2430607..41d90ca1b9 100644
---- a/lib/net/rte_ip.h
-+++ b/lib/net/rte_ip.h
-@@ -154,29 +154,18 @@ rte_ipv4_hdr_len(const struct rte_ipv4_hdr *ipv4_hdr)
+diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h
+index cedfd27ac1..279e88ee39 100644
+--- a/lib/librte_net/rte_ip.h
++++ b/lib/librte_net/rte_ip.h
+@@ -119,29 +119,18 @@ struct rte_ipv4_hdr {


More information about the stable mailing list