Skip to contentSkip to conversation

net/mlx5: fix lro update tcp header cksum error

PATCH In review jiangheng (G) 4 participants 4 messages Apr 13, 2023 – Jul 18, 2023 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net/mlx5: fix lro update tcp header cksum error

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 = 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")
---
 drivers/net/mlx5/mlx5_rx.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/mlx5/mlx5_rx.c +1 -0
index a2be523e9e..ae537dfffa 100644
@@ -1090,6 +1090,7 @@ mlx5_lro_update_tcp_hdr(struct rte_tcp_hdr *__rte_restrict tcp,
 	tcp->cksum = 0;
 	csum += rte_raw_cksum(tcp, (tcp->data_off >> 4) * 4);
 	csum = ((csum & 0xffff0000) >> 16) + (csum & 0xffff);
+	csum = ((csum & 0xffff0000) >> 16) + (csum & 0xffff);
 	csum = (~csum) & 0xffff;
 	if (csum == 0)
 		csum = 0xffff;
Signature · 1 line
2.27.0
Quoted 38 lines

Hi, Jiangheng

You are right, the corner case of sum of 3 is 0x1FFFF gives the wrong result. Could you, please, format the patch according to the rules and send v2 ?
- add Fixes: tag with reference to appropriate commit
- add Cc: [email protected]
- fix typos in commit message - capitalize sentences, add trailing points, etc.

With best regards,
Slava

Quoted 27 lines

From: jiangheng (G) <[email protected]>
Sent: среда, 12 апреля 2023 г. 14:39
To: [email protected]; Matan Azrad <[email protected]>; Slava Ovsiienko <[email protected]>
Subject: [PATCH] net/mlx5: fix lro update tcp header cksum error

csum is the sum of three 16 bits value it must be folded twice to ensure that the upper 16 bits are 0

---
 drivers/net/mlx5/mlx5_rx.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/mlx5/mlx5_rx.c +1 -0
index a2be523e9e..ae537dfffa 100644
@@ -1090,6 +1090,7 @@ mlx5_lro_update_tcp_hdr(struct rte_tcp_hdr 
 *__rte_restrict tcp,
    tcp->cksum = 0;
    csum += rte_raw_cksum(tcp, (tcp->data_off >> 4) * 4);
    csum = ((csum & 0xffff0000) >> 16) + (csum & 0xffff);
+   csum = ((csum & 0xffff0000) >> 16) + (csum & 0xffff);
    csum = (~csum) & 0xffff;
    if (csum == 0)
        csum = 0xffff;

--
2.27.0

#1 lore raw

Any comment on this patch?

13/04/2023 02:57, jiangheng (G):

Quoted 63 lines

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 = 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")
---
 drivers/net/mlx5/mlx5_rx.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/mlx5/mlx5_rx.c +1 -0
index a2be523e9e..ae537dfffa 100644
@@ -1090,6 +1090,7 @@ mlx5_lro_update_tcp_hdr(struct rte_tcp_hdr *__rte_restrict tcp,
 	tcp->cksum = 0;
 	csum += rte_raw_cksum(tcp, (tcp->data_off >> 4) * 4);
 	csum = ((csum & 0xffff0000) >> 16) + (csum & 0xffff);
+	csum = ((csum & 0xffff0000) >> 16) + (csum & 0xffff);
 	csum = (~csum) & 0xffff;
 	if (csum == 0)
 		csum = 0xffff;
Quoted 38 lines

Hi, Jiangheng

You are right, the corner case of sum of 3 is 0x1FFFF gives the wrong result. Could you, please, format the patch according to the rules and send v2 ?
- add Fixes: tag with reference to appropriate commit
- add Cc: [email protected]
- fix typos in commit message - capitalize sentences, add trailing points, etc.

With best regards,
Slava

Quoted 27 lines

From: jiangheng (G) <[email protected]>
Sent: среда, 12 апреля 2023 г. 14:39
To: [email protected]; Matan Azrad <[email protected]>; Slava Ovsiienko <[email protected]>
Subject: [PATCH] net/mlx5: fix lro update tcp header cksum error

csum is the sum of three 16 bits value it must be folded twice to ensure that the upper 16 bits are 0

---
 drivers/net/mlx5/mlx5_rx.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/mlx5/mlx5_rx.c +1 -0
index a2be523e9e..ae537dfffa 100644
@@ -1090,6 +1090,7 @@ mlx5_lro_update_tcp_hdr(struct rte_tcp_hdr 
 *__rte_restrict tcp,
    tcp->cksum = 0;
    csum += rte_raw_cksum(tcp, (tcp->data_off >> 4) * 4);
    csum = ((csum & 0xffff0000) >> 16) + (csum & 0xffff);
+   csum = ((csum & 0xffff0000) >> 16) + (csum & 0xffff);
    csum = (~csum) & 0xffff;
    if (csum == 0)
        csum = 0xffff;

--
2.27.0

#2 lore raw

Hi,

rte_raw_cksum() is doing __rte_raw_cksum_reduce(), so the returned result is always below 0x10000, upper half is zero. We add 3 16-bit values in range 0...0xFFFF, what is possible result? Let's consider the ranges:
upper/lower halves

0          0..0xFFFF, no carry
1          0..0xFFFF, one carry  - once we add upper half - we'll get carry again, should be added
2          0..0xFFFD, two carries 

So, yes, we need this patch, sorry I've missed adjusted v2.

With best regards,
Slava

Quoted 78 lines

-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Thursday, July 13, 2023 3:16 PM
To: Slava Ovsiienko <[email protected]>; Matan Azrad <[email protected]>; Raslan Darawsheh <[email protected]>
Cc: [email protected]; jiangheng (G) <[email protected]>
Subject: Re: [PATCH v2] net/mlx5: fix lro update tcp header cksum error

Any comment on this patch?

13/04/2023 02:57, jiangheng (G):

drivers/net/mlx5/mlx5_rx.c mlx5_lro_update_tcp_hdr(struct rte_tcp_hdr

Quoted 18 lines

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 = 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")
---
 drivers/net/mlx5/mlx5_rx.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/mlx5/mlx5_rx.c +0 -0
index a2be523e9e..ae537dfffa 100644
@@ -1090,6 +1090,7 @@ mlx5_lro_update_tcp_hdr(struct rte_tcp_hdr

*__rte_restrict tcp,

Quoted 10 lines
drivers/net/mlx5/mlx5_rx.c +1 -0
 	tcp->cksum = 0;
 	csum += rte_raw_cksum(tcp, (tcp->data_off >> 4) * 4);
 	csum = ((csum & 0xffff0000) >> 16) + (csum & 0xffff);
+	csum = ((csum & 0xffff0000) >> 16) + (csum & 0xffff);
 	csum = (~csum) & 0xffff;
 	if (csum == 0)
 		csum = 0xffff;
Quoted 3 lines

Hi, Jiangheng

You are right, the corner case of sum of 3 is 0x1FFFF gives the wrong

result.

Quoted 4 lines
Quoted 4 lines

Could you, please, format the patch according to the rules and send v2 ?
- add Fixes: tag with reference to appropriate commit
- add Cc: [email protected]
- fix typos in commit message - capitalize sentences, add trailing points,

etc.

Quoted 31 lines
Quoted 31 lines

With best regards,
Slava

Quoted 27 lines

From: jiangheng (G) <[email protected]>
Sent: среда, 12 апреля 2023 г. 14:39
To: [email protected]; Matan Azrad <[email protected]>; Slava Ovsiienko <[email protected]>
Subject: [PATCH] net/mlx5: fix lro update tcp header cksum error

csum is the sum of three 16 bits value it must be folded twice to ensure that the upper 16 bits are 0

---
 drivers/net/mlx5/mlx5_rx.c | 1 +
 1 file changed, 1 insertion(+)
(quoted diff) +0 -0

b/drivers/net/mlx5/mlx5_rx.c index a2be523e9e..ae537dfffa 100644

drivers/net/mlx5/mlx5_rx.c +1 -0
@@ -1090,6 +1090,7 @@ mlx5_lro_update_tcp_hdr(struct rte_tcp_hdr
 *__rte_restrict tcp,
    tcp->cksum = 0;
    csum += rte_raw_cksum(tcp, (tcp->data_off >> 4) * 4);
    csum = ((csum & 0xffff0000) >> 16) + (csum & 0xffff);
+   csum = ((csum & 0xffff0000) >> 16) + (csum & 0xffff);
    csum = (~csum) & 0xffff;
    if (csum == 0)
        csum = 0xffff;

--
2.27.0

#3 lore raw
In reply to jiangheng (G)

Hi,

Quoted 12 lines

-----Original Message-----
From: jiangheng (G) <[email protected]>
Sent: Thursday, April 13, 2023 3:58 AM
To: Slava Ovsiienko <[email protected]>; [email protected]; Matan Azrad <[email protected]>
Subject: [PATCH v2] net/mlx5: fix lro update tcp header cksum error

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 = 0x10000, the upper 16 bits are not 0. It must be folded again to ensure that the upper 16 bits are 0.

Quoted 4 lines
Fixes e4c2a16eb1de ("net/mlx5: handle LRO packets in Rx queue")

Patch applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh