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 <m...@smartsharesystems.com> 
> wrote:
> >
> > > From: Bruce Richardson [mailto:bruce.richard...@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.richard...@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.richard...@intel.com>
> > > > > Acked-by: Stephen Hemminger <step...@networkplumber.org>
> > > > > Acked-by: Morten Brørup <m...@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

Reply via email to