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

Kevin Traynor ktraynor at redhat.com
Tue Oct 25 17:05:57 CEST 2022


Hi,

FYI, your patch has been queued to stable release 21.11.3

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/01/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/ac8fea22795ed3fd09ddb70f090636ee1a034d3d

Thanks.

Kevin

---
>From ac8fea22795ed3fd09ddb70f090636ee1a034d3d 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/net/rte_ip.h | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/lib/net/rte_ip.h b/lib/net/rte_ip.h
index c575250852..615e5b125e 100644
--- a/lib/net/rte_ip.h
+++ b/lib/net/rte_ip.h
@@ -155,16 +155,19 @@ 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.37.3

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2022-10-25 14:18:58.640593252 +0100
+++ 0002-net-accept-unaligned-data-in-checksum-routines.patch	2022-10-25 14:18:58.348797865 +0100
@@ -1 +1 @@
-From 1c9a7fba5c90e0422b517404499ed106f647bcff Mon Sep 17 00:00:00 2001
+From ac8fea22795ed3fd09ddb70f090636ee1a034d3d Mon Sep 17 00:00:00 2001
@@ -8,0 +9,2 @@
+[ upstream commit 1c9a7fba5c90e0422b517404499ed106f647bcff ]
+
@@ -29 +30,0 @@
-Cc: stable at dpdk.org
@@ -38 +39 @@
-index b502481670..ecd250e9be 100644
+index c575250852..615e5b125e 100644
@@ -41 +42 @@
-@@ -161,16 +161,19 @@ static inline uint32_t
+@@ -155,16 +155,19 @@ static inline uint32_t



More information about the stable mailing list