From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 090B246C6B; Fri, 1 Aug 2025 09:26:29 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8D87240263; Fri, 1 Aug 2025 09:26:28 +0200 (CEST) Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by mails.dpdk.org (Postfix) with ESMTP id E788E40156 for ; Fri, 1 Aug 2025 09:26:27 +0200 (CEST) Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-31ee880f7d2so1878565a91.0 for ; Fri, 01 Aug 2025 00:26:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1754033187; x=1754637987; darn=dpdk.org; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=RUmsKLO1d/QRyiYHp5wAq+gcZn04wmDtxPDtuF/s+gU=; b=Z/whK0V/mNOAhOd/tIIAydJINE4Zbk3Lu75+c664sYFlEej1X70a6QWdKYUL0Uaf8D hOvheqivUtDheAyOapQmHkp331QDXxX821gibdyxqGvZX74OC1PxzrNxdSxVRlkt9dhQ kURJ0MNrR0syfK4owBmixTlWQqG8C3YupXhqfXWhzVLqJh68gWWRmhXJRscjVE2UjRNV Fl6b6jwYl6dn1+6TBdByNkFVAxP2bWucTxszmIfJTgJKXhaIByCYXHp+xxkw6QKP+1/v /x0+6t/lhYH8r7XDZhh/RG1OT9U4Oh9fW3WEYGO1lbuwgpATqEnuTcK8sjRsUwhyG5Jx lkbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754033187; x=1754637987; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=RUmsKLO1d/QRyiYHp5wAq+gcZn04wmDtxPDtuF/s+gU=; b=UkbiDLdVjPc+jhcA5uMMNblQogYjJziwHbcEoPTwtNeNNg69gU6Ryv7buobQky3Luu tTc47yiBmYJqbCpdn8sbmRgpaS2PqXYC00hRKC+o8K2QlhsuNAcVP4BC4WH5xZ0rnGPx s1sk3SHCu/aLBLQ8y7Mipz7gKwbI7YIG+YbWFDj/Jwv02nUVL8EX90A6Wd5p/OZvjrsW Apq3iXptYjeBu7+lnX3Cev7GXVOexrBIJfkks6eyFoxPYaCg2EvZDMbU3XB6YE5X3t2j 7HkCserJniOHSJNk/9LzMk2J2FtS/dnBKX9Kmz7R5ve0Ry3sx3x/nbC/wmZolVDypkmn hHYw== X-Gm-Message-State: AOJu0Ywdgc0+4owalWc5zwMAlU6V2mt5SfEKeatQhuEmDbvIkQYzwqTX z4WWrRa3ooDq/60X9U5PtLVSAzSmV/J0kwnV6LFcJHzsY338cWM0zW+EJXu5IgUat/ZZOclt89T nTlGHkzNd38piihZK1QRdDlj4kl4WohKEsaCfbddzdGYUepj97LIwKCQ= X-Gm-Gg: ASbGncsZcrrIipZuWjYYElIArv5enHRNIVXbHlahmvl+KszLYqIMXX0MpMASQjcwCau pgATemlON0ObH4MLWkeGcx6BKKP5xH8mhFuuQGYunIhAFmuQecq2AWOhUd7VW7iBJbXkvvlohlQ 1ePAjjMf6OhH5hy3UZT4IpSWSxIjIwAX1+XP6CIO0/k3N/cMmjTSn5KTBXdUUDVuceIzkH52ViQ 9h1kZFZIA== X-Google-Smtp-Source: AGHT+IEHpDomf3aY9Kg8dMSUQF3c+wM/6+wi4SJJW0YUifKzSPvmuWe626NuRPAJjnej8nshBc6x/GAEwMc3awhtjNE= X-Received: by 2002:a17:90b:5286:b0:313:17e3:7ae0 with SMTP id 98e67ed59e1d1-31f5de7bac5mr13193486a91.34.1754033186528; Fri, 01 Aug 2025 00:26:26 -0700 (PDT) Received: from 44278815321 named unknown by gmailapi.google.com with HTTPREST; Fri, 1 Aug 2025 00:26:26 -0700 Received: from 44278815321 named unknown by gmailapi.google.com with HTTPREST; Fri, 1 Aug 2025 00:26:26 -0700 X-Mailer: git-send-email 2.39.2 (Apple Git-143) Mime-Version: 1.0 In-Reply-To: X-Original-From: Su Sai References: From: Su Sai Date: Fri, 1 Aug 2025 00:26:26 -0700 X-Gm-Features: Ac12FXyi5fIqFa2IujNJI8r1bO1qhHh0O7RD1Pw9rQ-Hv2bEEvnqGLJs3UBYV1Y Message-ID: Subject: [PATCH] net/cksum: compute raw cksum for several segments To: dev@dpdk.org Cc: Su Sai Content-Type: text/plain; charset="UTF-8" X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- .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 Zorik Machulsky Zyta Szpak Zyta Szpak +Su Sai 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)