From: Marat Khalili <marat.khalili@huawei.com>
To: 苏赛 <susai.ss@bytedance.com>,
"jasvinder.singh@intel.com" <jasvinder.singh@intel.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>
Subject: RE: [PATCH] net/cksum: compute raw cksum for several segments
Date: Thu, 31 Jul 2025 11:46:03 +0000 [thread overview]
Message-ID: <3fd88fc5be464291b3ee84853f39d3d6@huawei.com> (raw)
In-Reply-To: <CABsP7wOFAsE2-BmnHZW1c3rOkkrUWfox7qrbim6zmP6gbmJqzg@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3586 bytes --]
> -----Original Message-----
> From: 苏赛 <susai.ss@bytedance.com>
> Sent: Thursday 31 July 2025 10:55
> To: jasvinder.singh@intel.com
> Cc: dev@dpdk.org
> Subject: [PATCH] net/cksum: compute raw cksum for several segments
>
> The rte_raw_cksum_mbuf function is used to compute
> the raw checksum of a packet.
> If the packet payload stored in multi mbuf, the function
> will goto the hard case. In hard case,
> the variable 'tmp' is a type of uint32_t,
> so rte_bswap16 will drop high 16 bit.
> Meanwhile, the variable 'sum' is a type of uint32_t,
> so 'sum += tmp' will drop the carry when overflow.
> Both drop will make cksum incorrect.
> This commit fixes the above bug.
>
> Signed-off-by: Su Sai <susai.ss@bytedance.com>
> ---
> .mailmap | 1 +
> lib/net/rte_cksum.h | 26 +++++++++++++++++++++++---
> 2 files changed, 24 insertions(+), 3 deletions(-)
>
> diff --git a/.mailmap b/.mailmap
> index 34a99f93a1..838b544a97 100644
> --- a/.mailmap
> +++ b/.mailmap
> @@ -1891,3 +1891,4 @@ Zoltan Kiss <zoltan.kiss@schaman.hu> <zoltan.kiss@linaro.org>
> Zorik Machulsky <zorik@amazon.com>
> Zyta Szpak <zyta@marvell.com> <zr@semihalf.com>
> Zyta Szpak <zyta@marvell.com> <zyta.szpak@semihalf.com>
> +Su Sai <susai.ss@bytedance.com>
> diff --git a/lib/net/rte_cksum.h b/lib/net/rte_cksum.h
> index a8e8927952..aa584d5f8d 100644
> --- a/lib/net/rte_cksum.h
> +++ b/lib/net/rte_cksum.h
> @@ -80,6 +80,25 @@ __rte_raw_cksum_reduce(uint32_t sum)
> return (uint16_t)sum;
> }
>
> +/**
> + * @internal Reduce a sum to the non-complemented checksum.
> + * Helper routine for the rte_raw_cksum_mbuf().
> + *
> + * @param sum
> + * Value of the sum.
> + * @return
> + * The non-complemented checksum.
> + */
> +static inline uint16_t
> +__rte_raw_cksum_reduce_u64(uint64_t sum)
> +{
> + uint32_t tmp;
> +
> + tmp = __rte_raw_cksum_reduce((uint32_t)sum);
> + tmp += __rte_raw_cksum_reduce((uint32_t)(sum >> 32));
> + return __rte_raw_cksum_reduce(tmp);
> +}
> +
> /**
> * Process the non-complemented checksum of a buffer.
> *
> @@ -119,8 +138,9 @@ rte_raw_cksum_mbuf(const struct rte_mbuf *m, uint32_t off, uint32_t len,
> {
> const struct rte_mbuf *seg;
> const char *buf;
> - uint32_t sum, tmp;
> + uint32_t tmp;
> uint32_t seglen, done;
> + uint64_t sum;
>
> /* easy case: all data in the first segment */
> if (off + len <= rte_pktmbuf_data_len(m)) {
> @@ -157,7 +177,7 @@ rte_raw_cksum_mbuf(const struct rte_mbuf *m, uint32_t off, uint32_t len,
> for (;;) {
> tmp = __rte_raw_cksum(buf, seglen, 0);
> if (done & 1)
> - tmp = rte_bswap16((uint16_t)tmp);
> + tmp = rte_bswap32(tmp);
> sum += tmp;
> done += seglen;
> if (done == len)
> @@ -169,7 +189,7 @@ rte_raw_cksum_mbuf(const struct rte_mbuf *m, uint32_t off, uint32_t len,
> seglen = len - done;
> }
>
> - *cksum = __rte_raw_cksum_reduce(sum);
> + *cksum = __rte_raw_cksum_reduce_u64(sum);
> return 0;
> }
>
> --
> 2.39.2 (Apple Git-143)
Acked-by: Marat Khalili <marat.khalili@huawei.com<mailto:marat.khalili@huawei.com>>
[-- Attachment #2: Type: text/html, Size: 11376 bytes --]
next prev parent reply other threads:[~2025-07-31 11:46 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-31 9:55 苏赛
2025-07-31 10:51 ` Marat Khalili
2025-07-31 11:03 ` Marat Khalili
2025-07-31 11:31 ` [External] " Su Sai
2025-07-31 11:43 ` Marat Khalili
2025-07-31 11:46 ` Marat Khalili [this message]
2025-07-31 12:22 ` zhoumin
2025-08-01 7:26 ` Su Sai
2025-08-01 15:28 ` [v2] " Su Sai
2025-08-01 16:39 ` Marat Khalili
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=3fd88fc5be464291b3ee84853f39d3d6@huawei.com \
--to=marat.khalili@huawei.com \
--cc=dev@dpdk.org \
--cc=jasvinder.singh@intel.com \
--cc=susai.ss@bytedance.com \
/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).