[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ea4ce9e9-9070-4733-8c96-41394035f046@gmail.com>
Date: Mon, 14 Jul 2025 09:49:22 +0300
From: Tariq Toukan <ttoukan.linux@...il.com>
To: cpaasch@...nai.com, Saeed Mahameed <saeedm@...dia.com>,
Tariq Toukan <tariqt@...dia.com>, Mark Bloch <mbloch@...dia.com>,
Leon Romanovsky <leon@...nel.org>, Andrew Lunn <andrew+netdev@...n.ch>,
"David S. Miller" <davem@...emloft.net>, Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
Amir Vadai <amirv@...lanox.com>
Cc: netdev@...r.kernel.org, linux-rdma@...r.kernel.org
Subject: Re: [PATCH net] net/mlx5: Correctly set gso_size when LRO is used
On 10/07/2025 21:26, christoph.paasch@...il.com wrote:
> From: Christoph Paasch <cpaasch@...nai.com>
>
> gso_size is expected by the networking stack to be the size of the
> payload (thus, not including ethernet/IP/TCP-headers). However, cqe_bcnt
> is the full sized frame (including the headers). Dividing cqe_bcnt by
> lro_num_seg will then give incorrect results.
>
> For example, running a bpftrace higher up in the TCP-stack
> (tcp_event_data_recv), we commonly have gso_size set to 1450 or 1451 even
> though in reality the payload was only 1448 bytes.
>
> So, we need to discount the protocol headers from cqe_bcnt so we can
> actually divide the payload by lro_num_seg to get the real gso_size.
>
> Fixes: e586b3b0baee ("net/mlx5: Ethernet Datapath files")
> Signed-off-by: Christoph Paasch <cpaasch@...nai.com>
> ---
> .../net/ethernet/mellanox/mlx5/core/en_rx.c | 20 +++++++++++++++----
> 1 file changed, 16 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
> index 84b1ab8233b8..e23bb80b0e0d 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
> @@ -1154,12 +1154,14 @@ static void mlx5e_lro_update_tcp_hdr(struct mlx5_cqe64 *cqe, struct tcphdr *tcp)
> }
> }
>
> -static void mlx5e_lro_update_hdr(struct sk_buff *skb, struct mlx5_cqe64 *cqe,
> - u32 cqe_bcnt)
> +static unsigned int mlx5e_lro_update_hdr(struct sk_buff *skb,
> + struct mlx5_cqe64 *cqe,
> + u32 cqe_bcnt)
> {
> struct ethhdr *eth = (struct ethhdr *)(skb->data);
> struct tcphdr *tcp;
> int network_depth = 0;
> + unsigned int hdrlen;
> __wsum check;
> __be16 proto;
> u16 tot_len;
> @@ -1169,11 +1171,14 @@ static void mlx5e_lro_update_hdr(struct sk_buff *skb, struct mlx5_cqe64 *cqe,
>
> tot_len = cqe_bcnt - network_depth;
> ip_p = skb->data + network_depth;
> + hdrlen = network_depth;
>
> if (proto == htons(ETH_P_IP)) {
> struct iphdr *ipv4 = ip_p;
>
> tcp = ip_p + sizeof(struct iphdr);
> + hdrlen += sizeof(struct iphdr);
> +
> skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
>
> ipv4->ttl = cqe->lro.min_ttl;
> @@ -1193,6 +1198,8 @@ static void mlx5e_lro_update_hdr(struct sk_buff *skb, struct mlx5_cqe64 *cqe,
> struct ipv6hdr *ipv6 = ip_p;
>
> tcp = ip_p + sizeof(struct ipv6hdr);
> + hdrlen += sizeof(struct ipv6hdr);
> +
> skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6;
>
> ipv6->hop_limit = cqe->lro.min_ttl;
> @@ -1205,6 +1212,10 @@ static void mlx5e_lro_update_hdr(struct sk_buff *skb, struct mlx5_cqe64 *cqe,
> tcp->check = tcp_v6_check(payload_len, &ipv6->saddr,
> &ipv6->daddr, check);
> }
> +
> + hdrlen += tcp->doff * 4;
> +
Thanks for your patch!
Calculations seem correct.
Wouldn't it be simpler to just return the below?
(void *)tcp + tcp->doff * 4 - skb->data
> + return hdrlen;
> }
>
> static void *mlx5e_shampo_get_packet_hd(struct mlx5e_rq *rq, u16 header_index)
> @@ -1561,8 +1572,9 @@ static inline void mlx5e_build_rx_skb(struct mlx5_cqe64 *cqe,
> mlx5e_macsec_offload_handle_rx_skb(netdev, skb, cqe);
>
> if (lro_num_seg > 1) {
> - mlx5e_lro_update_hdr(skb, cqe, cqe_bcnt);
> - skb_shinfo(skb)->gso_size = DIV_ROUND_UP(cqe_bcnt, lro_num_seg);
> + unsigned int hdrlen = mlx5e_lro_update_hdr(skb, cqe, cqe_bcnt);
> +
> + skb_shinfo(skb)->gso_size = DIV_ROUND_UP(cqe_bcnt - hdrlen, lro_num_seg);
> /* Subtract one since we already counted this as one
> * "regular" packet in mlx5e_complete_rx_cqe()
> */
Powered by blists - more mailing lists