From: Bruce Richardson <bruce.richardson@intel.com>
To: David Marchand <david.marchand@redhat.com>
Cc: "Morten Brørup" <mb@smartsharesystems.com>,
dev@dpdk.org, "Stephen Hemminger" <stephen@networkplumber.org>,
"Jerin Jacob" <jerinj@marvell.com>,
"Aman Singh" <aman.deep.singh@intel.com>,
"Konstantin Ananyev" <konstantin.v.ananyev@yandex.ru>
Subject: Re: [PATCH v2 5/6] net: add smaller IPv4 cksum function for simple cases
Date: Wed, 30 Oct 2024 14:45:28 +0000 [thread overview]
Message-ID: <ZyJGiBEZQFeJYylJ@bricha3-mobl1.ger.corp.intel.com> (raw)
In-Reply-To: <CAJFAV8w0Ct+cszLRmY0asG79tBV0ruC2JxzHdtpHUGBrjVP8Rg@mail.gmail.com>
On Wed, Oct 30, 2024 at 03:08:06PM +0100, David Marchand wrote:
> On Wed, Oct 30, 2024 at 12:32 PM Morten Brørup <mb@smartsharesystems.com> wrote:
> >
> > > From: Bruce Richardson [mailto:bruce.richardson@intel.com]
> > > Sent: Wednesday, 30 October 2024 12.28
> > >
> > > On Wed, Oct 30, 2024 at 12:21:00PM +0100, David Marchand wrote:
> > > > Hello Bruce,
> > > >
> > > > On Fri, Oct 25, 2024 at 6:51 PM Bruce Richardson
> > > > <bruce.richardson@intel.com> wrote:
> > > > >
> > > > > There are multiple instances in the DPDK app folder where we set up
> > > an
> > > > > IP header and then compute the checksum field by direct addition of
> > > > > nine uint16_t values in the header (20 bytes less the cksum field).
> > > > > The existing rte_ip.h checksum function is more general than
> > > necessary
> > > > > here and requires that the checksum field is already set to zero -
> > > > > rather than having it skipped.
> > > > >
> > > > > Fix the code duplication present in the apps by creating a new
> > > > > rte_ipv4_cksum_simple function - taking the code from the existing
> > > > > testpmd icmpecho.c file - and using that in app/test, testpmd and
> > > > > testeventdev.
> > > > >
> > > > > Within that new function, we can adjust slightly how the
> > > typecasting to
> > > > > uint16_t is done, and thereby ensure that the app can all be
> > > compiled
> > > > > without -Wno-address-of-packed-member compiler flag.
> > > > >
> > > > > Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> > > > > Acked-by: Stephen Hemminger <stephen@networkplumber.org>
> > > > > Acked-by: Morten Brørup <mb@smartsharesystems.com>
> > > >
> > > > This added function triggers a build error with OVS because of -
> > > Wcast-align:
> > > > https://github.com/david-
> > > marchand/ovs/actions/runs/11401635820/job/32273090691#step:12:514
> > > >
> > > > libtool: compile: env REAL_CC=gcc "CHECK=sparse -Wsparse-error -I
> > > > ./include/sparse -I ./include -m64 -I /usr/local/include -I
> > > > /usr/include/x86_64-linux-gnu " cgcc -target=x86_64
> > > > -target=host_os_specs -D__MMX__=1 -D__MMX_WITH_SSE__=1
> > > > -D__SSE2_MATH__=1 -D__SSE_MATH__=1 -D__SSE__=1 -D__SSE2__=1
> > > > -DHAVE_CONFIG_H -I. -I ./include -I ./include -I ./lib -I ./lib
> > > > -Wstrict-prototypes -Wall -Wextra -Wno-sign-compare -Wpointer-arith
> > > > -Wformat -Wformat-security -Wswitch-enum -Wunused-parameter
> > > > -Wbad-function-cast -Wcast-align -Wstrict-prototypes
> > > > -Wold-style-definition -Wmissing-prototypes
> > > > -Wmissing-field-initializers -fno-strict-aliasing -Wswitch-bool
> > > > -Wlogical-not-parentheses -Wsizeof-array-argument -Wbool-compare
> > > > -Wshift-negative-value -Wduplicated-cond -Wshadow
> > > > -Wmultistatement-macros -Wcast-align=strict -mssse3
> > > > -I/home/runner/work/ovs/ovs/dpdk-dir/include -include rte_config.h
> > > > -mrtm -Werror -D_FILE_OFFSET_BITS=64 -g -O2 -MT lib/ofp-protocol.lo
> > > > -MD -MP -MF lib/.deps/ofp-protocol.Tpo -c lib/ofp-protocol.c -o
> > > > lib/ofp-protocol.o
> > > > In file included from /home/runner/work/ovs/ovs/dpdk-
> > > dir/include/rte_ip.h:9,
> > > > from /home/runner/work/ovs/ovs/dpdk-dir/include/rte_flow.h:25,
> > > > from lib/netdev-dpdk.h:30,
> > > > from lib/dp-packet.h:30,
> > > > from lib/ofp-print.c:34:
> > > > /home/runner/work/ovs/ovs/dpdk-dir/include/rte_ip4.h: In function
> > > > ‘rte_ipv4_cksum_simple’:
> > > > /home/runner/work/ovs/ovs/dpdk-dir/include/rte_ip4.h:191:17: error:
> > > > cast increases required alignment of target type [-Werror=cast-align]
> > > > 191 | v16_h = (const unaligned_uint16_t *)&ipv4_hdr->version_ihl;
> > > > | ^
> > > Ok, I'll see if I can rework it to avoid issues.
> >
> > Would be easier if IP(v4/v6) headers were 2-byte aligned, like the Ethernet header.
> > Just saying. ;-)
>
> Aligning rte_ipv4_hdr is not enough.
> Pointing at a uint8_t triggers a warning (with clang at least).
>
> I guess we need something like:
>
> diff --git a/lib/net/rte_ip4.h b/lib/net/rte_ip4.h
> index 4dd0058cc5..f9b8333332 100644
> --- a/lib/net/rte_ip4.h
> +++ b/lib/net/rte_ip4.h
> @@ -39,7 +39,7 @@ extern "C" {
> /**
> * IPv4 Header
> */
> -struct rte_ipv4_hdr {
> +struct __rte_aligned(2) rte_ipv4_hdr {
> __extension__
> union {
> uint8_t version_ihl; /**< version and header length */
> @@ -188,7 +188,7 @@ rte_ipv4_cksum_simple(const struct rte_ipv4_hdr *ipv4_hdr)
> * Compute the sum of successive 16-bit words of the IPv4 header,
> * skipping the checksum field of the header.
> */
> - v16_h = (const unaligned_uint16_t *)&ipv4_hdr->version_ihl;
> + v16_h = (const uint16_t *)ipv4_hdr;
> ip_cksum = v16_h[0] + v16_h[1] + v16_h[2] + v16_h[3] +
> v16_h[4] + v16_h[6] + v16_h[7] + v16_h[8] + v16_h[9];
>
>
Yes.
For the latter assignment part, the original code use ipv4_hdr, but that
triggered other warnings in DPDK build. With properly aligning the
structure, I think it should be fine. Therefore, what you have above looks
the best solution to me.
/Bruce
next prev parent reply other threads:[~2024-10-30 14:45 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-17 14:22 [PATCH 0/6] Reduce scope address-of-packed-member warning Bruce Richardson
2024-10-17 14:22 ` [PATCH 1/6] ip_frag: remove use of unaligned variable Bruce Richardson
2024-10-17 16:26 ` Stephen Hemminger
2024-10-17 16:42 ` Konstantin Ananyev
2024-10-17 14:22 ` [PATCH 2/6] efd: remove unnecessary packed attributes Bruce Richardson
2024-10-17 16:22 ` Stephen Hemminger
2024-10-17 14:22 ` [PATCH 3/6] bus/ifpga: remove packed attribute Bruce Richardson
2024-10-17 14:52 ` Xu, Rosen
2024-10-17 16:25 ` Stephen Hemminger
2024-10-17 14:22 ` [PATCH 4/6] pipeline: " Bruce Richardson
2024-10-17 14:24 ` Bruce Richardson
2024-10-17 16:25 ` Stephen Hemminger
2024-10-17 14:22 ` [PATCH 5/6] net: add smaller IPv4 cksum function for simple cases Bruce Richardson
2024-10-17 16:24 ` Stephen Hemminger
2024-10-17 17:01 ` Bruce Richardson
2024-10-17 17:15 ` Morten Brørup
2024-10-17 19:03 ` Bruce Richardson
2024-10-17 19:34 ` Stephen Hemminger
2024-10-18 0:32 ` Morten Brørup
2024-10-17 14:22 ` [PATCH 6/6] build: limit scope of packed member warning disabling Bruce Richardson
2024-10-19 15:38 ` Stephen Hemminger
2024-10-17 16:21 ` [PATCH 0/6] Reduce scope address-of-packed-member warning Stephen Hemminger
2024-10-17 17:02 ` Bruce Richardson
2024-10-25 13:24 ` David Marchand
2024-10-25 14:55 ` David Marchand
2024-10-25 16:51 ` Bruce Richardson
2024-10-25 16:50 ` [PATCH v2 " Bruce Richardson
2024-10-25 16:50 ` [PATCH v2 1/6] ip_frag: remove use of unaligned variable Bruce Richardson
2024-10-25 16:50 ` [PATCH v2 2/6] efd: remove unnecessary packed attributes Bruce Richardson
2024-10-25 16:50 ` [PATCH v2 3/6] bus/ifpga: remove packed attribute Bruce Richardson
2024-10-25 16:50 ` [PATCH v2 4/6] pipeline: " Bruce Richardson
2024-10-25 16:50 ` [PATCH v2 5/6] net: add smaller IPv4 cksum function for simple cases Bruce Richardson
2024-10-30 11:21 ` David Marchand
2024-10-30 11:27 ` Bruce Richardson
2024-10-30 11:32 ` Morten Brørup
2024-10-30 12:28 ` Bruce Richardson
2024-10-30 12:33 ` Morten Brørup
2024-10-30 14:08 ` David Marchand
2024-10-30 14:45 ` Bruce Richardson [this message]
2024-10-25 16:50 ` [PATCH v2 6/6] build: limit scope of packed member warning disabling Bruce Richardson
2024-10-28 12:51 ` [PATCH v2 0/6] Reduce scope address-of-packed-member warning fengchengwen
2024-10-30 8:22 ` David Marchand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZyJGiBEZQFeJYylJ@bricha3-mobl1.ger.corp.intel.com \
--to=bruce.richardson@intel.com \
--cc=aman.deep.singh@intel.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=jerinj@marvell.com \
--cc=konstantin.v.ananyev@yandex.ru \
--cc=mb@smartsharesystems.com \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).