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.
Unified · Split
| @@ -5029,6 +5029,15 @@ void netif_set_tso_max_segs(struct net_device *dev, unsigned int segs); · 5028 unmodified lines | ||
| 5029 | 5029 | void netif_inherit_tso_max(struct net_device *to, |
| 5030 | 5030 | const struct net_device *from); |
| 5031 | 5031 | |
| 5032 | +static inline unsigned int | |
| 5033 | +netif_get_gro_max_size(const struct net_device *dev, const struct sk_buff *skb) | |
| 5034 | +{ | |
| 5035 | + /* pairs with WRITE_ONCE() in netif_set_gro(_ipv4)_max_size() */ | |
| 5036 | + return skb->protocol == htons(ETH_P_IPV6) ? | |
| 5037 | + READ_ONCE(dev->gro_max_size) : | |
| 5038 | + READ_ONCE(dev->gro_ipv4_max_size); | |
| 5039 | +} | |
| 5040 | + | |
| 5032 | 5041 | static inline bool netif_is_macsec(const struct net_device *dev) |
| 5033 | 5042 | { |
| 5034 | 5043 | return dev->priv_flags & IFF_MACSEC; |
| @@ -98,7 +98,6 @@ int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb) · 97 unmodified lines | ||
| 98 | 98 | unsigned int headlen = skb_headlen(skb); |
| 99 | 99 | unsigned int len = skb_gro_len(skb); |
| 100 | 100 | unsigned int delta_truesize; |
| 101 | − unsigned int gro_max_size; | |
| 102 | 101 | unsigned int new_truesize; |
| 103 | 102 | struct sk_buff *lp; |
| 104 | 103 | int segs; |
| @@ -112,12 +111,8 @@ int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb) · 7 unmodified lines | ||
| 112 | 111 | if (p->pp_recycle != skb->pp_recycle) |
| 113 | 112 | return -ETOOMANYREFS; |
| 114 | 113 | |
| 115 | − /* pairs with WRITE_ONCE() in netif_set_gro(_ipv4)_max_size() */ | |
| 116 | − gro_max_size = p->protocol == htons(ETH_P_IPV6) ? | |
| 117 | − READ_ONCE(p->dev->gro_max_size) : | |
| 118 | − READ_ONCE(p->dev->gro_ipv4_max_size); | |
| 119 | − | |
| 120 | − if (unlikely(p->len + len >= gro_max_size || NAPI_GRO_CB(skb)->flush)) | |
| 114 | + if (unlikely(p->len + len >= netif_get_gro_max_size(p->dev, p) || | |
| 115 | + NAPI_GRO_CB(skb)->flush)) | |
| 121 | 116 | return -E2BIG; |
| 122 | 117 | |
| 123 | 118 | if (unlikely(p->len + len >= GRO_LEGACY_MAX_SIZE)) { |