[v2,0/1] net: fix aliasing issue in checksum computation
Message ID | 20211017203718.801998-1-mail@gms.tf (mailing list archive) |
---|---|
Headers |
Return-Path: <dev-bounces@dpdk.org> X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6094CA0547; Sun, 17 Oct 2021 22:38:05 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E1ECF40041; Sun, 17 Oct 2021 22:38:04 +0200 (CEST) Received: from goedel.lru.li (goedel.lru.li [172.104.147.125]) by mails.dpdk.org (Postfix) with ESMTP id 71C1E4003C for <dev@dpdk.org>; Sun, 17 Oct 2021 22:38:03 +0200 (CEST) Received: from dell12.lru.li (unknown [IPv6:2001:1a80:303a:0:faca:b8ff:fe50:d072]) (Authenticated sender: georg) by goedel.lru.li (Postfix) with ESMTPSA id E80314E19B2; Sun, 17 Oct 2021 20:38:02 +0000 (UTC) Received: by dell12.lru.li (Postfix, from userid 1000) id DD4C21A6F20; Sun, 17 Oct 2021 22:38:01 +0200 (CEST) From: Georg Sauthoff <mail@gms.tf> To: =?utf-8?q?Morten_Br=C3=B8rup?= <mb@smartsharesystems.com>, Olivier Matz <olivier.matz@6wind.com>, Thomas Monjalon <thomas@monjalon.net>, David Marchand <david.marchand@redhat.com> Cc: dev@dpdk.org, Georg Sauthoff <mail@gms.tf> Date: Sun, 17 Oct 2021 22:37:17 +0200 Message-Id: <20211017203718.801998-1-mail@gms.tf> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2 0/1] net: fix aliasing issue in checksum computation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions <dev.dpdk.org> List-Unsubscribe: <https://mails.dpdk.org/options/dev>, <mailto:dev-request@dpdk.org?subject=unsubscribe> List-Archive: <http://mails.dpdk.org/archives/dev/> List-Post: <mailto:dev@dpdk.org> List-Help: <mailto:dev-request@dpdk.org?subject=help> List-Subscribe: <https://mails.dpdk.org/listinfo/dev>, <mailto:dev-request@dpdk.org?subject=subscribe> Errors-To: dev-bounces@dpdk.org Sender: "dev" <dev-bounces@dpdk.org> |
Message
Georg Sauthoff
Oct. 17, 2021, 8:37 p.m. UTC
The current __rte_raw_cksum() function violates the C strict-aliasing
rules since it uses a uint8_t pointer to access a trailing byte.
This patch also fixes a superfluous cast, i.e.:
uintptr_t ptr = (uintptr_t)buf;
typedef uint16_t __attribute__((__may_alias__)) u16_p;
const u16_p *u16_buf = (const u16_p *)ptr;
Transitive casting involving uintptr_t doesn't solve anything here.
It also doesn't help with fixing a strict-aliasing issue here.
The patch also simplifies the main loop, i.e. it eliminates the manually
unrolled loop
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;
}
since modern C compilers are in a better position to decide which level of
unrolling is optimal for the target architecture.
See also https://godbolt.org/z/6rYbYGnj7 which shows how GCC auto-vectorizes
the simplified loop using AVX instructions, when compiling for Haswell. When
looking at the number of instructions in the compiled code, the new version
is half as big as the existing one.
Signed-off-by: Georg Sauthoff <mail@gms.tf>
---
v2:
* Reword commit message (detail aliasing implications of uint8_t)
* Add unlikely()
Georg Sauthoff (1):
net: fix aliasing issue in checksum computation
lib/net/rte_ip.h | 27 ++++++++-------------------
1 file changed, 8 insertions(+), 19 deletions(-)