Skip to content

Commit 0fe79f2

Browse files
ahduyckdavem330
authored andcommitted
net: allow gro_max_size to exceed 65536
Allow the gro_max_size to exceed a value larger than 65536. There weren't really any external limitations that prevented this other than the fact that IPv4 only supports a 16 bit length field. Since we have the option of adding a hop-by-hop header for IPv6 we can allow IPv6 to exceed this value and for IPv4 and non-TCP flows we can cap things at 65536 via a constant rather than relying on gro_max_size. [edumazet] limit GRO_MAX_SIZE to (8 * 65535) to avoid overflows. Signed-off-by: Alexander Duyck <[email protected]> Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 81fbc81 commit 0fe79f2

File tree

6 files changed

+16
-12
lines changed

6 files changed

+16
-12
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en_rx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2038,7 +2038,7 @@ mlx5e_hw_gro_skb_has_enough_space(struct sk_buff *skb, u16 data_bcnt)
20382038
{
20392039
int nr_frags = skb_shinfo(skb)->nr_frags;
20402040

2041-
return PAGE_SIZE * nr_frags + data_bcnt <= GRO_MAX_SIZE;
2041+
return PAGE_SIZE * nr_frags + data_bcnt <= GRO_LEGACY_MAX_SIZE;
20422042
}
20432043

20442044
static void

include/linux/netdevice.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2161,7 +2161,11 @@ struct net_device {
21612161
struct bpf_prog __rcu *xdp_prog;
21622162
unsigned long gro_flush_timeout;
21632163
int napi_defer_hard_irqs;
2164-
#define GRO_MAX_SIZE 65536
2164+
#define GRO_LEGACY_MAX_SIZE 65536u
2165+
/* TCP minimal MSS is 8 (TCP_MIN_GSO_SIZE),
2166+
* and shinfo->gso_segs is a 16bit field.
2167+
*/
2168+
#define GRO_MAX_SIZE (8 * 65535u)
21652169
unsigned int gro_max_size;
21662170
rx_handler_func_t __rcu *rx_handler;
21672171
void __rcu *rx_handler_data;

include/net/ipv6.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ static inline int ipv6_has_hopopt_jumbo(const struct sk_buff *skb)
477477
const struct hop_jumbo_hdr *jhdr;
478478
const struct ipv6hdr *nhdr;
479479

480-
if (likely(skb->len <= GRO_MAX_SIZE))
480+
if (likely(skb->len <= GRO_LEGACY_MAX_SIZE))
481481
return 0;
482482

483483
if (skb->protocol != htons(ETH_P_IPV6))

net/core/dev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10598,7 +10598,7 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
1059810598

1059910599
dev->gso_max_size = GSO_LEGACY_MAX_SIZE;
1060010600
dev->gso_max_segs = GSO_MAX_SEGS;
10601-
dev->gro_max_size = GRO_MAX_SIZE;
10601+
dev->gro_max_size = GRO_LEGACY_MAX_SIZE;
1060210602
dev->tso_max_size = TSO_LEGACY_MAX_SIZE;
1060310603
dev->tso_max_segs = TSO_MAX_SEGS;
1060410604
dev->upper_level = 1;

net/core/gro.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb)
167167
if (unlikely(p->len + len >= gro_max_size || NAPI_GRO_CB(skb)->flush))
168168
return -E2BIG;
169169

170+
if (unlikely(p->len + len >= GRO_LEGACY_MAX_SIZE)) {
171+
if (p->protocol != htons(ETH_P_IPV6) ||
172+
skb_headroom(p) < sizeof(struct hop_jumbo_hdr) ||
173+
ipv6_hdr(p)->nexthdr != IPPROTO_TCP ||
174+
p->encapsulation)
175+
return -E2BIG;
176+
}
177+
170178
lp = NAPI_GRO_CB(p)->last;
171179
pinfo = skb_shinfo(lp);
172180

net/core/rtnetlink.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2360,14 +2360,6 @@ static int validate_linkmsg(struct net_device *dev, struct nlattr *tb[],
23602360
}
23612361
}
23622362

2363-
if (tb[IFLA_GRO_MAX_SIZE]) {
2364-
u32 gro_max_size = nla_get_u32(tb[IFLA_GRO_MAX_SIZE]);
2365-
2366-
if (gro_max_size > GRO_MAX_SIZE) {
2367-
NL_SET_ERR_MSG(extack, "too big gro_max_size");
2368-
return -EINVAL;
2369-
}
2370-
}
23712363
return 0;
23722364
}
23732365

0 commit comments

Comments
 (0)