[dpdk-stable] patch 'net: fix aliasing in checksum computation' has been queued to stable release 20.11.4
Xueming Li
xuemingl at nvidia.com
Wed Nov 10 07:30:42 CET 2021
Hi,
FYI, your patch has been queued to stable release 20.11.4
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/12/21. 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/steevenlee/dpdk
This queued commit can be viewed at:
https://github.com/steevenlee/dpdk/commit/71d4385922a00ee9711471cbd54cf62eff45a664
Thanks.
Xueming Li <xuemingl at nvidia.com>
---
>From 71d4385922a00ee9711471cbd54cf62eff45a664 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
Cc: Xueming Li <xuemingl at nvidia.com>
[ 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 b188616ab8..52ef3c8cc1 100644
--- a/lib/librte_net/rte_ip.h
+++ b/lib/librte_net/rte_ip.h
@@ -134,29 +134,18 @@ 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)
{
- /* 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.33.0
---
Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- - 2021-11-10 14:17:08.969388054 +0800
+++ 0158-net-fix-aliasing-in-checksum-computation.patch 2021-11-10 14:17:01.964078660 +0800
@@ -1 +1 @@
-From 24f1955d1ecd13a3c261a328c72932115732825e Mon Sep 17 00:00:00 2001
+From 71d4385922a00ee9711471cbd54cf62eff45a664 Mon Sep 17 00:00:00 2001
@@ -7,0 +8,3 @@
+Cc: Xueming Li <xuemingl at nvidia.com>
+
+[ upstream commit 24f1955d1ecd13a3c261a328c72932115732825e ]
@@ -21 +23,0 @@
-Cc: stable at dpdk.org
@@ -27 +29 @@
- lib/net/rte_ip.h | 27 ++++++++-------------------
+ lib/librte_net/rte_ip.h | 27 ++++++++-------------------
@@ -30,5 +32,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 b188616ab8..52ef3c8cc1 100644
+--- a/lib/librte_net/rte_ip.h
++++ b/lib/librte_net/rte_ip.h
+@@ -134,29 +134,18 @@ rte_ipv4_hdr_len(const struct rte_ipv4_hdr *ipv4_hdr)
More information about the stable
mailing list