net: Add netif_get_gro_max_size helper for GRO
Subsystems (2)
PATCH 1/2 net: Add netif_get_gro_max_size helper for GRO
Add a small netif_get_gro_max_size() helper which returns the maximum IPv4 or IPv6 GRO size of the netdevice.
We later add a netif_get_gso_max_size() equivalent as well for GSO, so that these helpers can be used consistently instead of open-coded checks.
--- include/linux/netdevice.h | 9 +++++++++ net/core/gro.c | 9 ++------- 2 files changed, 11 insertions(+), 7 deletions(-)
include/linux/netdevice.h +9 -0
@@ -5029,6 +5029,15 @@ void netif_set_tso_max_segs(struct net_device *dev, unsigned int segs);void netif_inherit_tso_max (struct net_device *to,const struct net_device *from); +static inline unsigned int +netif_get_gro_max_size (const struct net_device *dev,const struct sk_buff *skb) +{ +/* pairs with WRITE_ONCE() in netif_set_gro(_ipv4)_max_size() */ +return skb->protocol ==htons (ETH_P_IPV6 ) ? +READ_ONCE (dev->gro_max_size) : +READ_ONCE (dev->gro_ipv4_max_size); +} +static inline bool netif_is_macsec (const struct net_device *dev) {return dev->priv_flags &IFF_MACSEC ;
net/core/gro.c +2 -7
@@ -98,7 +98,6 @@ int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb)unsigned int headlen =skb_headlen (skb);unsigned int len =skb_gro_len (skb);unsigned int delta_truesize; -unsigned int gro_max_size;unsigned int new_truesize;struct sk_buff *lp;int segs;
@@ -112,12 +111,8 @@ int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb)if (p->pp_recycle != skb->pp_recycle)return -ETOOMANYREFS ; -/* pairs with WRITE_ONCE() in netif_set_gro(_ipv4)_max_size() */ - gro_max_size = p->protocol ==htons (ETH_P_IPV6 ) ? -READ_ONCE (p->dev->gro_max_size) : -READ_ONCE (p->dev->gro_ipv4_max_size); - -if (unlikely (p->len + len >= gro_max_size ||NAPI_GRO_CB (skb)->flush)) +if (unlikely (p->len + len >=netif_get_gro_max_size (p->dev, p) || +NAPI_GRO_CB (skb)->flush))return -E2BIG ;if (unlikely (p->len + len >=GRO_LEGACY_MAX_SIZE )) {
Signature · 1 line
2.43.0
PATCH 2/2 net: Fix gso_features_check to check for both dev->gso_{ipv4_,}max_size
Commit 24ab059d2ebd ("net: check dev->gso_max_size in gso_features_check()") added a dev->gso_max_size test to gso_features_check() in order to fall back to GSO when needed.
This was added as it was noticed that some drivers could misbehave if TSO packets get too big. However, the check doesn't respect dev->gso_ipv4_max_size limit. For instance, a device could be configured with BIG TCP for IPv4, but not IPv6.
Therefore, add a netif_get_gso_max_size() equivalent to netif_get_gro_max_size() and use the helper to respect both limits before falling back to GSO engine.
--- include/linux/netdevice.h | 9 +++++++++ net/core/dev.c | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-)
include/linux/netdevice.h +9 -0
@@ -5038,6 +5038,15 @@ netif_get_gro_max_size(const struct net_device *dev, const struct sk_buff *skb)READ_ONCE (dev->gro_ipv4_max_size); } +static inline unsigned int +netif_get_gso_max_size (const struct net_device *dev,const struct sk_buff *skb) +{ +/* pairs with WRITE_ONCE() in netif_set_gso(_ipv4)_max_size() */ +return skb->protocol ==htons (ETH_P_IPV6 ) ? +READ_ONCE (dev->gso_max_size) : +READ_ONCE (dev->gso_ipv4_max_size); +} +static inline bool netif_is_macsec (const struct net_device *dev) {return dev->priv_flags &IFF_MACSEC ;
net/core/dev.c +1 -1
@@ -3512,7 +3512,7 @@ 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))) +if (unlikely (skb->len >=netif_get_gso_max_size (dev, skb)))return features & ~NETIF_F_GSO_MASK ;if (!skb_shinfo (skb)->gso_type) {
Signature · 1 line
2.43.0
Re: [PATCH net 2/2] net: Fix gso_features_check to check for both dev->gso_{ipv4_,}max_size
Quoted 9 lines · Daniel Borkmann
Commit
24ab059d2ebd("net: checkdev->gso_max_sizeingso_features_check()") added adev->gso_max_sizetest togso_features_check()in order to fall back to GSO when needed.This was added as it was noticed that some drivers could misbehave if TSO packets get too big. However, the check doesn't respect
dev->gso_ipv4_max_sizelimit. For instance, a device could be configured with BIG TCP for IPv4, but not IPv6.
Quoted 7 lines
Therefore, add a
netif_get_gso_max_size()equivalent tonetif_get_gro_max_size()and use the helper to respect both limits before falling back to GSO engine.Fixes 24ab059d2ebd ("net: check dev->gso_max_size in gso_features_check()")Signed-off-by Daniel Borkmann <[email protected]>Cc Eric Dumazet <[email protected]>Cc Paolo Abeni <[email protected]>
(Sorry, Cc got missed due to config issue as I recently switched to a
new machine.)
Re: [PATCH net 2/2] net: Fix gso_features_check to check for both dev->gso_{ipv4_,}max_size
In reply to Daniel BorkmannQuoted 9 lines · Daniel Borkmann
Commit
24ab059d2ebd("net: checkdev->gso_max_sizeingso_features_check()") added adev->gso_max_sizetest togso_features_check()in order to fall back to GSO when needed.This was added as it was noticed that some drivers could misbehave if TSO packets get too big. However, the check doesn't respect
dev->gso_ipv4_max_sizelimit. For instance, a device could be configured with BIG TCP for IPv4, but not IPv6.
Quoted 8 lines
Therefore, add a
netif_get_gso_max_size()equivalent tonetif_get_gro_max_size()and use the helper to respect both limits before falling back to GSO engine.Fixes 24ab059d2ebd ("net: check dev->gso_max_size in gso_features_check()")Signed-off-by Daniel Borkmann <[email protected]>Cc Eric Dumazet <[email protected]>Cc Paolo Abeni <[email protected]>---
Quoted 9 lines · Daniel Borkmann
Add a small
netif_get_gro_max_size()helper which returns the maximum IPv4 or IPv6 GRO size of the netdevice.We later add a
netif_get_gso_max_size()equivalent as well for GSO, so that these helpers can be used consistently instead of open-coded checks.Signed-off-by Daniel Borkmann <[email protected]>Cc Eric Dumazet <[email protected]>Cc Paolo Abeni <[email protected]>
Quoted 52 lines
--- include/linux/netdevice.h | 9 +++++++++ net/core/gro.c | 9 ++------- 2 files changed, 11 insertions(+), 7 deletions(-)include/linux/netdevice.h +9
-0@@ -5029,6 +5029,15 @@ void netif_set_tso_max_segs(struct net_device *dev, unsigned int segs);void netif_inherit_tso_max (struct net_device *to,const struct net_device *from); +static inline unsigned int +netif_get_gro_max_size (const struct net_device *dev,const struct sk_buff *skb) +{ +/* pairs with WRITE_ONCE() in netif_set_gro(_ipv4)_max_size() */ +return skb->protocol ==htons (ETH_P_IPV6 ) ? +READ_ONCE (dev->gro_max_size) : +READ_ONCE (dev->gro_ipv4_max_size); +} +static inline bool netif_is_macsec (const struct net_device *dev) {return dev->priv_flags &IFF_MACSEC ;net/core/gro.c +2
-7@@ -98,7 +98,6 @@ int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb)unsigned int headlen =skb_headlen (skb);unsigned int len =skb_gro_len (skb);unsigned int delta_truesize; -unsigned int gro_max_size;unsigned int new_truesize;struct sk_buff *lp;int segs;@@ -112,12 +111,8 @@ int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb)if (p->pp_recycle != skb->pp_recycle)return -ETOOMANYREFS ; -/* pairs with WRITE_ONCE() in netif_set_gro(_ipv4)_max_size() */ - gro_max_size = p->protocol ==htons (ETH_P_IPV6 ) ? -READ_ONCE (p->dev->gro_max_size) : -READ_ONCE (p->dev->gro_ipv4_max_size); - -if (unlikely (p->len + len >= gro_max_size ||NAPI_GRO_CB (skb)->flush)) +if (unlikely (p->len + len >=netif_get_gro_max_size (p->dev, p) || +NAPI_GRO_CB (skb)->flush))return -E2BIG ;if (unlikely (p->len + len >=GRO_LEGACY_MAX_SIZE )) {
This series was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 11 lines · On Mon, 23 Sep 2024 23:22:41 +0200 you wrote:
Add a small
netif_get_gro_max_size()helper which returns the maximum IPv4 or IPv6 GRO size of the netdevice.We later add a
netif_get_gso_max_size()equivalent as well for GSO, so that these helpers can be used consistently instead of open-coded checks.Signed-off-by Daniel Borkmann <[email protected]>Cc Eric Dumazet <[email protected]>Cc Paolo Abeni <[email protected]>[...]
Here is the summary with links:
- [net,1/2] net: Add netif_get_gro_max_size helper for GRO
https://git.kernel.org/netdev/net/c/e8d4d34df715 - [net,2/2] net: Fix gso_features_check to check for both dev->gso_{ipv4_,}max_size https://git.kernel.org/netdev/net/c/e609c959a939
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html