net: check dev->gso_max_size in gso_features_check()
Subsystems (2)
PATCH 1/1 net: check dev->gso_max_size in gso_features_check()
Some drivers might misbehave if TSO packets get too big.
GVE for instance uses a 16bit field in its TX descriptor, and will do bad things if a packet is bigger than 2^16 bytes.
Linux TCP stack honors dev->gso_max_size, but there are other ways for too big packets to reach an ndo_start_xmit() handler : virtio_net, af_packet, GRO...
Add a generic check in gso_features_check() and fallback to GSO when needed.
gso_max_size was added in the blamed commit.
--- net/core/dev.c | 3 +++ 1 file changed, 3 insertions(+)
net/core/dev.c +3 -0
@@ -3471,6 +3471,9 @@ static netdev_features_t gso_features_check(const struct sk_buff *skb,if (gso_segs >READ_ONCE (dev->gso_max_segs))return features & ~NETIF_F_GSO_MASK ; +if (unlikely (skb->len >=READ_ONCE (dev->gso_max_size))) +return features & ~NETIF_F_GSO_MASK ; +if (!skb_shinfo (skb)->gso_type) {skb_warn_bad_offload (skb);return features & ~NETIF_F_GSO_MASK ;
Signature · 1 line
2.43.0.472.g3155946c3a-goog
Paolo Abeni
maintainernet/core/dev.c static netdev_features_t gso_features_check(const struct sk_buff *skb, · line 3474
Quoted 9 lines · Eric Dumazet
net/core/dev.c +1
-0@@ -3471,6 +3471,9 @@ static netdev_features_t gso_features_check(const struct sk_buff *skb,if (gso_segs >READ_ONCE (dev->gso_max_segs))return features & ~NETIF_F_GSO_MASK ; +if (unlikely (skb->len >=READ_ONCE (dev->gso_max_size)))
Since we are checking vs the limit supported by the NIC, should the above be 'tso_max_size'?
My understanding is that 'gso{,_ipv4}_max_size' is the max aggregate size the device asks for, and 'tso_max_size' is the actual limit supported by the NIC.
Thanks!
Paolo
Quoted 10 lines · Paolo Abeni
Quoted 8 lines · Eric Dumazet
net/core/dev.c +0
-0@@ -3471,6 +3471,9 @@ static netdev_features_t gso_features_check(const struct sk_buff *skb,if (gso_segs >READ_ONCE (dev->gso_max_segs))return features & ~NETIF_F_GSO_MASK ;
Quoted 9 lines
net/core/dev.c static netdev_features_t gso_features_check(const struct sk_buff *skb, · line 3474
Quoted 1 line
net/core/dev.c +1
-0+if (unlikely (skb->len >=READ_ONCE (dev->gso_max_size)))Since we are checking vs the limit supported by the NIC, should the above be '
tso_max_size'?My understanding is that 'gso{,_ipv4}_max_size' is the max aggregate size the device asks for, and '
tso_max_size' is the actual limit supported by the NIC.
Problem is tso_max_size has been added very recently, depending on this would make backports tricky.
I think the fix using gso_max_size is more portable to stable versions, and allows the user to tweak the value, and build tests.
As a bonus, dev->gso_max_size is in the net_device_read_tx cacheline, while tso_max_size is currently far away.
Hey all,
Quoted 22 lines · Eric Dumazet
Quoted 9 lines · Paolo Abeni
Quoted 8 lines · Eric Dumazet
net/core/dev.c +0
-0@@ -3471,6 +3471,9 @@ static netdev_features_t gso_features_check(const struct sk_buff *skb,if (gso_segs >READ_ONCE (dev->gso_max_segs))return features & ~NETIF_F_GSO_MASK ;Quoted 8 lines
net/core/dev.c static netdev_features_t gso_features_check(const struct sk_buff *skb, · line 3474
Quoted 1 line
net/core/dev.c +1
-0+if (unlikely (skb->len >=READ_ONCE (dev->gso_max_size)))Since we are checking vs the limit supported by the NIC, should the above be '
tso_max_size'?My understanding is that 'gso{,_ipv4}_max_size' is the max aggregate size the device asks for, and '
tso_max_size' is the actual limit supported by the NIC.Problem is
tso_max_sizehas been added very recently, depending on this would make backports tricky.
Quoted 6 lines
I think the fix using
gso_max_sizeis more portable to stable versions, and allows the user to tweak the value, and build tests.As a bonus,
dev->gso_max_sizeis in thenet_device_read_txcacheline, whiletso_max_sizeis currently far away.
We noticed in Cilium which supports both BIG TCP IPv4 as well as BIG TCP IPv6 that when a user has configured the former but not the latter, we get a performance regression. Meaning, kernel creates larger super packets for IPv4, but later hits the lower IPv6 dev->gso_max_size limit. :/
Given tso_max_size is far away, would sth like the below fix be acceptable?
Thanks,
Daniel
From 65260578ffda2969acfa5109eeef0484b7dd9193 Mon Sep 17 00:00:00 2001
From: Daniel Borkmann <[email protected]>
Date: Mon, 10 Jun 2024 12:52:22 +0000
Subject: [PATCH net] net, gso: Fix regression in BIG TCP v4 when BIG TCP v6 is not set
[ commit sg tbd ]
Fxies: 24ab059d2ebd ("net: check dev->gso_max_size in gso_features_check()")
--- net/core/dev.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
net/core/dev.c +8 -1
@@ -3502,7 +3502,14 @@ static netdev_features_t gso_features_check(const struct sk_buff *skb,if (gso_segs >READ_ONCE (dev->gso_max_segs))return features & ~NETIF_F_GSO_MASK ; -if (unlikely (skb->len >=READ_ONCE (dev->gso_max_size))) +/* Both GSO max sizes need to be checked e.g. for the case +* when BIG TCP is enabled for IPv4 but not for IPv6. This +* is checking the limits supported by the NIC (tso_max_size). +* However, the latter is not hot in net_device_read_tx. +*/ +if (unlikely (skb->len >= +max (READ_ONCE (dev->gso_max_size), +READ_ONCE (dev->gso_ipv4_max_size))))return features & ~NETIF_F_GSO_MASK ;if (!skb_shinfo (skb)->gso_type) {
Signature · 1 line
2.34.1
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 10 lines · On Tue, 19 Dec 2023 12:53:31 +0000 you wrote:
Some drivers might misbehave if TSO packets get too big.
GVE for instance uses a 16bit field in its TX descriptor, and will do bad things if a packet is bigger than 2^16 bytes.
Linux TCP stack honors
dev->gso_max_size, but there are other ways for too big packets to reach anndo_start_xmit()handler :virtio_net,af_packet, GRO...[...]
Here is the summary with links:
- [net] net: check dev->gso_max_size in gso_features_check()
https://git.kernel.org/netdev/net/c/24ab059d2ebd
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html