Skip to contentSkip to conversation

Single MSS length in UDP GSO_PARTIAL

PATCH Applied Gal Pressman 6 participants 10 messages Jan 25 – Feb 4

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover Single MSS length in UDP GSO_PARTIAL

This series addresses an inconsistency in how UDP GSO_PARTIAL handles the UDP header length field.

Currently, when GSO_PARTIAL segmentation is used, the UDP header length contains the large MSS size, requiring drivers to manually adjust it before transmitting. This is inconsistent with how tunnel GSO_PARTIAL handles outer headers in UDP tunnels, where the length is set to the single segment size.

This was originally suggested by Alexander Duyck back in 2018:
https://lore.kernel.org/netdev/CAKgT0UcdnUWgr3KQ=RnLKigokkiUuYefmL-ePpDvJOBNpKScFA@mail.gmail.com/

The first patch fixes the core UDP offload code to set the UDP length field to the single segment size (gso_size + UDP header) instead of the large MSS size. This provides hardware with a proper template length value for final segmentation.

The subsequent patches remove the now redundant UDP header length adjustments from the mlx5e and aquantia drivers, as the core code now handles this correctly.
I couldn't find any other drivers that support UDP GSO_PARTIAL; idpf supports UDP segmentation, but it does not use GSO_PARTIAL.

Gal Pressman (3):
udp: gso: Use single MSS length in UDP header for GSO_PARTIAL net/mlx5e: Remove redundant UDP length adjustment with GSO_PARTIAL
net: aquantia: Remove redundant UDP length adjustment with GSO_PARTIAL

 drivers/net/ethernet/aquantia/atlantic/aq_nic.c |  3 ---
 .../mellanox/mlx5/core/en_accel/en_accel.h      | 17 -----------------
 net/ipv4/udp_offload.c                          |  6 ++++--
 3 files changed, 4 insertions(+), 22 deletions(-)
Signature · 1 line
2.40.1
#1 lore raw

PATCH 1/3 udp: gso: Use single MSS length in UDP header for GSO_PARTIAL

In GSO_PARTIAL segmentation, set the UDP length field to the single segment size (gso_size + UDP header) instead of the large MSS size. This provides hardware with a template length value for final segmentation, similar to how tunnel GSO_PARTIAL handles outer headers in UDP tunnels.

This will remove the need to manually adjust the UDP header length in the drivers, as can be seen in subsequent patches.

This was suggested by Alex in 2018:
https://lore.kernel.org/netdev/CAKgT0UcdnUWgr3KQ=RnLKigokkiUuYefmL-ePpDvJOBNpKScFA@mail.gmail.com/

---
 net/ipv4/udp_offload.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
net/ipv4/udp_offload.c +4 -2
index 19d0b5b09ffa..89e0b48b60ae 100644
@@ -483,11 +483,11 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
 	struct sock *sk = gso_skb->sk;
 	unsigned int sum_truesize = 0;
 	struct sk_buff *segs, *seg;
+	__be16 newlen, msslen;
 	struct udphdr *uh;
 	unsigned int mss;
 	bool copy_dtor;
 	__sum16 check;
-	__be16 newlen;
 	int ret = 0;
 
 	mss = skb_shinfo(gso_skb)->gso_size;
@@ -555,6 +555,8 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
 		return segs;
 	}
 
+	msslen = htons(sizeof(*uh) + mss);
+
 	/* GSO partial and frag_list segmentation only requires splitting
 	 * the frame into an MSS multiple and possibly a remainder, both
 	 * cases return a GSO skb. So update the mss now.
@@ -584,7 +586,7 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
 		if (!seg->next)
 			break;
 
-		uh->len = newlen;
+		uh->len = msslen;
 		uh->check = check;
 
 		if (seg->ip_summed == CHECKSUM_PARTIAL)
Signature · 1 line
2.40.1
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH net-next 1/3] udp: gso: Use single MSS length in UDP header for GSO_PARTIAL

Quoted 6 lines · Gal Pressman

In GSO_PARTIAL segmentation, set the UDP length field to the single segment size (gso_size + UDP header) instead of the large MSS size. This provides hardware with a template length value for final segmentation, similar to how tunnel GSO_PARTIAL handles outer headers in UDP tunnels.

Quoted 8 lines

This will remove the need to manually adjust the UDP header length in the drivers, as can be seen in subsequent patches.

This was suggested by Alex in 2018:
https://lore.kernel.org/netdev/CAKgT0UcdnUWgr3KQ=RnLKigokkiUuYefmL-ePpDvJOBNpKScFA@mail.gmail.com/

This only affects the udp header value when using GSO_PARTIAL, and these are the only two drivers that adversize USO using GSO_PARTIAL.

Quoted 42 lines
---
 net/ipv4/udp_offload.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
net/ipv4/udp_offload.c +4 -2
index 19d0b5b09ffa..89e0b48b60ae 100644
@@ -483,11 +483,11 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
 	struct sock *sk = gso_skb->sk;
 	unsigned int sum_truesize = 0;
 	struct sk_buff *segs, *seg;
+	__be16 newlen, msslen;
 	struct udphdr *uh;
 	unsigned int mss;
 	bool copy_dtor;
 	__sum16 check;
-	__be16 newlen;
 	int ret = 0;
 
 	mss = skb_shinfo(gso_skb)->gso_size;
@@ -555,6 +555,8 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
 		return segs;
 	}
 
+	msslen = htons(sizeof(*uh) + mss);
+
 	/* GSO partial and frag_list segmentation only requires splitting
 	 * the frame into an MSS multiple and possibly a remainder, both
 	 * cases return a GSO skb. So update the mss now.
@@ -584,7 +586,7 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
 		if (!seg->next)
 			break;
 
-		uh->len = newlen;
+		uh->len = msslen;
 		uh->check = check;
 
 		if (seg->ip_summed == CHECKSUM_PARTIAL)
Signature · 1 line
2.40.1
#3 lore raw

Re: [PATCH net-next 1/3] udp: gso: Use single MSS length in UDP header for GSO_PARTIAL

Quoted 13 lines · Willem de Bruijn
Quoted 12 lines · Gal Pressman

In GSO_PARTIAL segmentation, set the UDP length field to the single segment size (gso_size + UDP header) instead of the large MSS size. This provides hardware with a template length value for final segmentation, similar to how tunnel GSO_PARTIAL handles outer headers in UDP tunnels.

This will remove the need to manually adjust the UDP header length in the drivers, as can be seen in subsequent patches.

This was suggested by Alex in 2018:
https://lore.kernel.org/netdev/CAKgT0UcdnUWgr3KQ=RnLKigokkiUuYefmL-ePpDvJOBNpKScFA@mail.gmail.com/

Quoted 7 lines
Quoted 2 lines

This only affects the udp header value when using GSO_PARTIAL, and these are the only two drivers that adversize USO using GSO_PARTIAL.

I stumbled upon this patch when I was rebasing my stuff and saw a (trivial) conflict. I've got a couple of questions on this change, and I'd be glad if you could clarify it for me.

Quoted 25 lines
Quoted 25 lines
---
 net/ipv4/udp_offload.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
net/ipv4/udp_offload.c +1 -1
index 19d0b5b09ffa..89e0b48b60ae 100644
@@ -483,11 +483,11 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
 	struct sock *sk = gso_skb->sk;
 	unsigned int sum_truesize = 0;
 	struct sk_buff *segs, *seg;
+	__be16 newlen, msslen;
 	struct udphdr *uh;
 	unsigned int mss;
 	bool copy_dtor;
 	__sum16 check;
-	__be16 newlen;
 	int ret = 0;
 
 	mss = skb_shinfo(gso_skb)->gso_size;
@@ -555,6 +555,8 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
 		return segs;
 	}
 
Quoted 5 lines

net/ipv4/udp_offload.c struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, · line 562

Quoted 5 lines
net/ipv4/udp_offload.c +2 -0
+	msslen = htons(sizeof(*uh) + mss);
+
 	/* GSO partial and frag_list segmentation only requires splitting
 	 * the frame into an MSS multiple and possibly a remainder, both
 	 * cases return a GSO skb. So update the mss now.

What about the frag_list case? The comment says it would be a GSO SKB too (as I understand frag_list, it would be a linked list of SKBs forming one single packet). Is it appropriate to set UDP len = MSS in this case too? I'm not sure which code reads UDP len afterwards, I couldn't find any, so maybe its value doesn't matter at all (except for hardware, which this patch aims for).

Is it possible that this GSO_PARTIAL or frag_list packet shows up in tcpdump with UDP len set like this? E.g., if the GSO_PARTIAL segmentation happens before entering a veth pipe, and tcpdump listens on the other end? If so, tcpdump could fail to parse such a packet.

I haven't tried to reproduce any of these yet; I decided to ask first because you have more context. I'll appreciate if you can give me a clue whether my concerns are valid or not.

Other than that, I think the patch could be made simpler, if you just drop mss *= gso_segs below, and stick to newlen, which would be equal to msslen (now unneeded), and newlen and mss are not used anywhere else. I'll include this simplification in my next series, if you don't mind.

Quoted 12 lines
Quoted 12 lines
net/ipv4/udp_offload.c +1 -1
@@ -584,7 +586,7 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
 		if (!seg->next)
 			break;
 
-		uh->len = newlen;
+		uh->len = msslen;
 		uh->check = check;
 
 		if (seg->ip_summed == CHECKSUM_PARTIAL)
Signature · 1 line
2.40.1
#4 lore raw

Re: [PATCH net-next 1/3] udp: gso: Use single MSS length in UDP header for GSO_PARTIAL

Hello Alice,

Quoted 21 lines · Alice Mikityanska
Quoted 21 lines
Quoted 21 lines
net/ipv4/udp_offload.c +1 -1
index 19d0b5b09ffa..89e0b48b60ae 100644
@@ -483,11 +483,11 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
 	struct sock *sk = gso_skb->sk;
 	unsigned int sum_truesize = 0;
 	struct sk_buff *segs, *seg;
+	__be16 newlen, msslen;
 	struct udphdr *uh;
 	unsigned int mss;
 	bool copy_dtor;
 	__sum16 check;
-	__be16 newlen;
 	int ret = 0;
 
 	mss = skb_shinfo(gso_skb)->gso_size;
@@ -555,6 +555,8 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
 		return segs;
 	}
 
Quoted 12 lines
Quoted 5 lines

net/ipv4/udp_offload.c struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, · line 562

Quoted 5 lines
net/ipv4/udp_offload.c +2 -0
+	msslen = htons(sizeof(*uh) + mss);
+
 	/* GSO partial and frag_list segmentation only requires splitting
 	 * the frame into an MSS multiple and possibly a remainder, both
 	 * cases return a GSO skb. So update the mss now.

What about the frag_list case? The comment says it would be a GSO SKB too (as I understand frag_list, it would be a linked list of SKBs forming one single packet). Is it appropriate to set UDP len = MSS in this case too? I'm not sure which code reads UDP len afterwards, I couldn't find any, so maybe its value doesn't matter at all (except for hardware, which this patch aims for).

The behavior should be the same, the structure of the skbs the packet originated from shouldn't affect this change.

Quoted 5 lines

Is it possible that this GSO_PARTIAL or frag_list packet shows up in tcpdump with UDP len set like this? E.g., if the GSO_PARTIAL segmentation happens before entering a veth pipe, and tcpdump listens on the other end? If so, tcpdump could fail to parse such a packet.

You will see a large packet with a single MSS value in tcpdump, and that's consistent with the behavior we have for UDP tunnels. tcpdump parses the packet without any issues.

Quoted 9 lines

I haven't tried to reproduce any of these yet; I decided to ask first because you have more context. I'll appreciate if you can give me a clue whether my concerns are valid or not.

Other than that, I think the patch could be made simpler, if you just drop mss *= gso_segs below, and stick to newlen, which would be equal to msslen (now unneeded), and newlen and mss are not used anywhere else. I'll include this simplification in my next series, if you don't mind.

Feel free :).

#5 lore raw

Re: [PATCH net-next 1/3] udp: gso: Use single MSS length in UDP header for GSO_PARTIAL

Quoted 41 lines · Gal Pressman

Hello Alice,

Quoted 21 lines · Alice Mikityanska
Quoted 21 lines
Quoted 21 lines
net/ipv4/udp_offload.c +1 -1
index 19d0b5b09ffa..89e0b48b60ae 100644
@@ -483,11 +483,11 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
 	struct sock *sk = gso_skb->sk;
 	unsigned int sum_truesize = 0;
 	struct sk_buff *segs, *seg;
+	__be16 newlen, msslen;
 	struct udphdr *uh;
 	unsigned int mss;
 	bool copy_dtor;
 	__sum16 check;
-	__be16 newlen;
 	int ret = 0;
 
 	mss = skb_shinfo(gso_skb)->gso_size;
@@ -555,6 +555,8 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,
 		return segs;
 	}
 
Quoted 12 lines
Quoted 5 lines

net/ipv4/udp_offload.c struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, · line 562

Quoted 5 lines
net/ipv4/udp_offload.c +2 -0
+	msslen = htons(sizeof(*uh) + mss);
+
 	/* GSO partial and frag_list segmentation only requires splitting
 	 * the frame into an MSS multiple and possibly a remainder, both
 	 * cases return a GSO skb. So update the mss now.

What about the frag_list case? The comment says it would be a GSO SKB too (as I understand frag_list, it would be a linked list of SKBs forming one single packet). Is it appropriate to set UDP len = MSS in this case too? I'm not sure which code reads UDP len afterwards, I couldn't find any, so maybe its value doesn't matter at all (except for hardware, which this patch aims for).

The behavior should be the same, the structure of the skbs the packet originated from shouldn't affect this change.

Quoted 1 line
Quoted 8 lines
Quoted 4 lines

Is it possible that this GSO_PARTIAL or frag_list packet shows up in tcpdump with UDP len set like this? E.g., if the GSO_PARTIAL segmentation happens before entering a veth pipe, and tcpdump listens on the other end? If so, tcpdump could fail to parse such a packet.

You will see a large packet with a single MSS value in tcpdump, and that's consistent with the behavior we have for UDP tunnels. tcpdump parses the packet without any issues.

Yeah, just checked tcpdump: it shows the full payload, regardless of UDP length and IP length in the headers. Sounds good to me, thanks for the clarifications!

Quoted 11 lines
Quoted 9 lines

I haven't tried to reproduce any of these yet; I decided to ask first because you have more context. I'll appreciate if you can give me a clue whether my concerns are valid or not.

Other than that, I think the patch could be made simpler, if you just drop mss *= gso_segs below, and stick to newlen, which would be equal to msslen (now unneeded), and newlen and mss are not used anywhere else. I'll include this simplification in my next series, if you don't mind.

Feel free :).

#6 lore raw

PATCH 2/3 net/mlx5e: Remove redundant UDP length adjustment with GSO_PARTIAL

In reply to Gal Pressman

GSO_PARTIAL now takes care of updating the UDP header length, mlx5e_udp_gso_handle_tx_skb() is redundant, remove it.

---
 .../mellanox/mlx5/core/en_accel/en_accel.h      | 17 -----------------
 1 file changed, 17 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h +0 -17
index 8bef99e8367e..b526b3898c22 100644
@@ -100,20 +100,6 @@ static inline bool mlx5_geneve_tx_allowed(struct mlx5_core_dev *mdev)
 
 #endif /* CONFIG_GENEVE */
 
-static inline void
-mlx5e_udp_gso_handle_tx_skb(struct sk_buff *skb)
-{
-	int payload_len = skb_shinfo(skb)->gso_size + sizeof(struct udphdr);
-	struct udphdr *udphdr;
-
-	if (skb->encapsulation)
-		udphdr = (struct udphdr *)skb_inner_transport_header(skb);
-	else
-		udphdr = udp_hdr(skb);
-
-	udphdr->len = htons(payload_len);
-}
-
 struct mlx5e_accel_tx_state {
 #ifdef CONFIG_MLX5_EN_TLS
 	struct mlx5e_accel_tx_tls_state tls;
@@ -131,9 +117,6 @@ static inline bool mlx5e_accel_tx_begin(struct net_device *dev,
 					struct sk_buff *skb,
 					struct mlx5e_accel_tx_state *state)
 {
-	if (skb_is_gso(skb) && skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4)
-		mlx5e_udp_gso_handle_tx_skb(skb);
-
 #ifdef CONFIG_MLX5_EN_TLS
 	/* May send WQEs. */
 	if (tls_is_skb_tx_device_offloaded(skb))
Signature · 1 line
2.40.1
Reviewed-by on v1 2/3
#7 lore raw

Re: [PATCH net-next 2/3] net/mlx5e: Remove redundant UDP length adjustment with GSO_PARTIAL

Quoted 9 lines · Gal Pressman

GSO_PARTIAL now takes care of updating the UDP header length, mlx5e_udp_gso_handle_tx_skb() is redundant, remove it.

---
  .../mellanox/mlx5/core/en_accel/en_accel.h      | 17 -----------------
  1 file changed, 17 deletions(-)
#8 lore raw

PATCH 3/3 net: aquantia: Remove redundant UDP length adjustment with GSO_PARTIAL

In reply to Gal Pressman

GSO_PARTIAL now takes care of updating the UDP header length, remove the redundant assignment in aq_nic_map_skb().

---
 drivers/net/ethernet/aquantia/atlantic/aq_nic.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/net/ethernet/aquantia/atlantic/aq_nic.c +0 -3
index b24eaa5283fa..ef9447810071 100644
@@ -701,9 +701,6 @@ unsigned int aq_nic_map_skb(struct aq_nic_s *self, struct sk_buff *skb,
 		} else if (l4proto == IPPROTO_UDP) {
 			dx_buff->is_gso_udp = 1U;
 			dx_buff->len_l4 = sizeof(struct udphdr);
-			/* UDP GSO Hardware does not replace packet length. */
-			udp_hdr(skb)->len = htons(dx_buff->mss +
-						  dx_buff->len_l4);
 		} else {
 			WARN_ONCE(true, "Bad GSO mode");
 			goto exit;
Signature · 1 line
2.40.1
#9 lore raw
In reply to Gal Pressman
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Sun, 25 Jan 2026 14:16:46 +0200 you wrote:

This series addresses an inconsistency in how UDP GSO_PARTIAL handles the UDP header length field.

Currently, when GSO_PARTIAL segmentation is used, the UDP header length contains the large MSS size, requiring drivers to manually adjust it before transmitting. This is inconsistent with how tunnel GSO_PARTIAL handles outer headers in UDP tunnels, where the length is set to the single segment size.

[...]

Here is the summary with links:
- [net-next,1/3] udp: gso: Use single MSS length in UDP header for GSO_PARTIAL

    https://git.kernel.org/netdev/net-next/c/b10b446ce7ad
  - [net-next,2/3] net/mlx5e: Remove redundant UDP length adjustment with GSO_PARTIAL
    https://git.kernel.org/netdev/net-next/c/8d2eda97f464
  - [net-next,3/3] net: aquantia: Remove redundant UDP length adjustment with GSO_PARTIAL
    https://git.kernel.org/netdev/net-next/c/5b4015ad833c

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html