From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id C2A7B42900;
	Thu, 13 Apr 2023 02:57:40 +0200 (CEST)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id B0F1640A84;
	Thu, 13 Apr 2023 02:57:40 +0200 (CEST)
Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187])
 by mails.dpdk.org (Postfix) with ESMTP id 6AAC84021F
 for <dev@dpdk.org>; Thu, 13 Apr 2023 02:57:39 +0200 (CEST)
Received: from kwepemm000002.china.huawei.com (unknown [172.30.72.57])
 by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Pxh3K3n9HzrbFl;
 Thu, 13 Apr 2023 08:56:13 +0800 (CST)
Received: from dggpeml500020.china.huawei.com (7.185.36.88) by
 kwepemm000002.china.huawei.com (7.193.23.144) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id
 15.1.2507.23; Thu, 13 Apr 2023 08:57:37 +0800
Received: from dggpeml500020.china.huawei.com ([7.185.36.88]) by
 dggpeml500020.china.huawei.com ([7.185.36.88]) with mapi id 15.01.2507.023;
 Thu, 13 Apr 2023 08:57:36 +0800
From: "jiangheng (G)" <jiangheng14@huawei.com>
To: Slava Ovsiienko <viacheslavo@nvidia.com>, "dev@dpdk.org" <dev@dpdk.org>,
 Matan Azrad <matan@nvidia.com>
Subject: [PATCH v2] net/mlx5: fix lro update tcp header cksum error
Thread-Topic: [PATCH v2] net/mlx5: fix lro update tcp header cksum error
Thread-Index: AdltS44M8bMLF/yVQHCVN+YyqPXRpg==
Date: Thu, 13 Apr 2023 00:57:36 +0000
Message-ID: <46433ee3531547aebf906e4144c520d1@huawei.com>
Accept-Language: zh-CN, en-US
Content-Language: zh-CN
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
x-originating-ip: [10.136.117.195]
Content-Type: text/plain; charset="koi8-r"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
X-CFilter-Loop: Reflected
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

The variable csum is the sum of three 16 bits integers, the max value
is 0x2FFFD. The corner case of sum of 3 is 0x1FFFF gives the wrong
result: 0x1 + 0xFFFF =3D 0x10000, the upper 16 bits are not 0.
It must be folded again to ensure that the upper 16 bits are 0.

Fixes: e4c2a16eb1de ("net/mlx5: handle LRO packets in Rx queue")
Cc: stable@dpdk.org

Signed-off-by: jiangheng <jiangheng14@huawei.com>
---
 drivers/net/mlx5/mlx5_rx.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/mlx5/mlx5_rx.c b/drivers/net/mlx5/mlx5_rx.c
index a2be523e9e..ae537dfffa 100644
--- a/drivers/net/mlx5/mlx5_rx.c
+++ b/drivers/net/mlx5/mlx5_rx.c
@@ -1090,6 +1090,7 @@ mlx5_lro_update_tcp_hdr(struct rte_tcp_hdr *__rte_res=
trict tcp,
 	tcp->cksum =3D 0;
 	csum +=3D rte_raw_cksum(tcp, (tcp->data_off >> 4) * 4);
 	csum =3D ((csum & 0xffff0000) >> 16) + (csum & 0xffff);
+	csum =3D ((csum & 0xffff0000) >> 16) + (csum & 0xffff);
 	csum =3D (~csum) & 0xffff;
 	if (csum =3D=3D 0)
 		csum =3D 0xffff;
--=20
2.27.0

> Hi,  Jiangheng
>
> You are right, the corner case of sum of 3 is 0x1FFFF gives the wrong res=
ult.
> Could you,  please, format the patch according to the rules and send v2 ?
> - add Fixes: tag with reference to appropriate commit
> - add Cc: stable@dpdk.org
> - fix typos in commit message - capitalize sentences, add trailing points=
, etc.
>
> With best regards,
> Slava
>
> > From: jiangheng (G) <jiangheng14@huawei.com>
> > Sent: =D3=D2=C5=C4=C1, 12 =C1=D0=D2=C5=CC=D1 2023 =C7. 14:39
> > To: dev@dpdk.org; Matan Azrad <matan@nvidia.com>; Slava Ovsiienko=20
> > <viacheslavo@nvidia.com>
> > Subject: [PATCH] net/mlx5: fix lro update tcp header cksum error
> >=20
> > csum is the sum of three 16 bits value it must be folded twice to=20
> > ensure that the upper 16 bits are 0
> > ---
> >  drivers/net/mlx5/mlx5_rx.c | 1 +
> >  1 file changed, 1 insertion(+)
> >=20
> > diff --git a/drivers/net/mlx5/mlx5_rx.c b/drivers/net/mlx5/mlx5_rx.c=20
> > index a2be523e9e..ae537dfffa 100644
> > --- a/drivers/net/mlx5/mlx5_rx.c
> > +++ b/drivers/net/mlx5/mlx5_rx.c
> > @@ -1090,6 +1090,7 @@ mlx5_lro_update_tcp_hdr(struct rte_tcp_hdr=20
> > *__rte_restrict tcp,
> >     tcp->cksum =3D 0;
> >     csum +=3D rte_raw_cksum(tcp, (tcp->data_off >> 4) * 4);
> >     csum =3D ((csum & 0xffff0000) >> 16) + (csum & 0xffff);
> > +   csum =3D ((csum & 0xffff0000) >> 16) + (csum & 0xffff);
> >     csum =3D (~csum) & 0xffff;
> >     if (csum =3D=3D 0)
> >         csum =3D 0xffff;
> > --
> > 2.27.0