patch 'net: accept unaligned data in checksum routines' has been queued to stable release 20.11.7

luca.boccassi at gmail.com luca.boccassi at gmail.com
Thu Nov 3 10:26:19 CET 2022


Hi,

FYI, your patch has been queued to stable release 20.11.7

Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 11/05/22. 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/kevintraynor/dpdk-stable

This queued commit can be viewed at:
https://github.com/kevintraynor/dpdk-stable/commit/370afad50d5df10bd6feb291aaaf3aced7f71531

Thanks.

Luca Boccassi

---
>From 370afad50d5df10bd6feb291aaaf3aced7f71531 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mattias=20R=C3=B6nnblom?= <mattias.ronnblom at ericsson.com>
Date: Mon, 11 Jul 2022 14:11:32 +0200
Subject: [PATCH] net: accept unaligned data in checksum routines
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

[ upstream commit 1c9a7fba5c90e0422b517404499ed106f647bcff ]

__rte_raw_cksum() (used by rte_raw_cksum() among others) accessed its
data through an uint16_t pointer, which allowed the compiler to assume
the data was 16-bit aligned. This in turn would, with certain
architectures and compiler flag combinations, result in code with SIMD
load or store instructions with restrictions on data alignment.

This patch keeps the old algorithm, but data is read using memcpy()
instead of direct pointer access, forcing the compiler to always
generate code that handles unaligned input. The __may_alias__ GCC
attribute is no longer needed.

The data on which the Internet checksum functions operates are almost
always 16-bit aligned, but there are exceptions. In particular, the
PDCP protocol header may (literally) have an odd size.

Performance impact seems to range from none to a very slight
regression.

Bugzilla ID: 1035
Fixes: 6006818cfb26 ("net: new checksum functions")

Signed-off-by: Mattias Rönnblom <mattias.ronnblom at ericsson.com>
Acked-by: Olivier Matz <olivier.matz at 6wind.com>
---
 lib/librte_net/rte_ip.h | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h
index 52ef3c8cc1..ac59ee1339 100644
--- a/lib/librte_net/rte_ip.h
+++ b/lib/librte_net/rte_ip.h
@@ -134,18 +134,21 @@ rte_ipv4_hdr_len(const struct rte_ipv4_hdr *ipv4_hdr)
 static inline uint32_t
 __rte_raw_cksum(const void *buf, size_t len, uint32_t sum)
 {
-	/* extend strict-aliasing rules */
-	typedef uint16_t __attribute__((__may_alias__)) u16_p;
-	const u16_p *u16_buf = (const u16_p *)buf;
-	const u16_p *end = u16_buf + len / sizeof(*u16_buf);
+	const void *end;
 
-	for (; u16_buf != end; ++u16_buf)
-		sum += *u16_buf;
+	for (end = RTE_PTR_ADD(buf, RTE_ALIGN_FLOOR(len, sizeof(uint16_t)));
+	     buf != end; buf = RTE_PTR_ADD(buf, sizeof(uint16_t))) {
+		uint16_t v;
+
+		memcpy(&v, buf, sizeof(uint16_t));
+		sum += v;
+	}
 
 	/* if length is odd, keeping it byte order independent */
 	if (unlikely(len % 2)) {
 		uint16_t left = 0;
-		*(unsigned char *)&left = *(const unsigned char *)end;
+
+		memcpy(&left, end, 1);
 		sum += left;
 	}
 
-- 
2.34.1

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2022-11-03 09:27:25.614123807 +0000
+++ 0001-net-accept-unaligned-data-in-checksum-routines.patch	2022-11-03 09:27:25.293420892 +0000
@@ -1 +1 @@
-From 1c9a7fba5c90e0422b517404499ed106f647bcff Mon Sep 17 00:00:00 2001
+From 370afad50d5df10bd6feb291aaaf3aced7f71531 Mon Sep 17 00:00:00 2001
@@ -8,0 +9,2 @@
+[ upstream commit 1c9a7fba5c90e0422b517404499ed106f647bcff ]
+
@@ -29 +30,0 @@
-Cc: stable at dpdk.org
@@ -34 +35 @@
- lib/net/rte_ip.h | 17 ++++++++++-------
+ lib/librte_net/rte_ip.h | 17 ++++++++++-------
@@ -37,5 +38,5 @@
-diff --git a/lib/net/rte_ip.h b/lib/net/rte_ip.h
-index b502481670..ecd250e9be 100644
---- a/lib/net/rte_ip.h
-+++ b/lib/net/rte_ip.h
-@@ -160,18 +160,21 @@ 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 52ef3c8cc1..ac59ee1339 100644
+--- a/lib/librte_net/rte_ip.h
++++ b/lib/librte_net/rte_ip.h
+@@ -134,18 +134,21 @@ rte_ipv4_hdr_len(const struct rte_ipv4_hdr *ipv4_hdr)


More information about the stable mailing list