Skip to content

Commit 7c4e983

Browse files
ahduyckdavem330
authored andcommitted
net: allow gso_max_size to exceed 65536
The code for gso_max_size was added originally to allow for debugging and workaround of buggy devices that couldn't support TSO with blocks 64K in size. The original reason for limiting it to 64K was because that was the existing limits of IPv4 and non-jumbogram IPv6 length fields. With the addition of Big TCP we can remove this limit and allow the value to potentially go up to UINT_MAX and instead be limited by the tso_max_size value. So in order to support this we need to go through and clean up the remaining users of the gso_max_size value so that the values will cap at 64K for non-TCPv6 flows. In addition we can clean up the GSO_MAX_SIZE value so that 64K becomes GSO_LEGACY_MAX_SIZE and UINT_MAX will now be the upper limit for GSO_MAX_SIZE. v6: (edumazet) fixed a compile error if CONFIG_IPV6=n, in a new sk_trim_gso_size() helper. netif_set_tso_max_size() caps the requested TSO size with GSO_MAX_SIZE. Signed-off-by: Alexander Duyck <[email protected]> Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 89527be commit 7c4e983

File tree

16 files changed

+40
-17
lines changed

16 files changed

+40
-17
lines changed

drivers/net/ethernet/amd/xgbe/xgbe.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@
151151
#define XGBE_TX_MAX_BUF_SIZE (0x3fff & ~(64 - 1))
152152

153153
/* Descriptors required for maximum contiguous TSO/GSO packet */
154-
#define XGBE_TX_MAX_SPLIT ((GSO_MAX_SIZE / XGBE_TX_MAX_BUF_SIZE) + 1)
154+
#define XGBE_TX_MAX_SPLIT \
155+
((GSO_LEGACY_MAX_SIZE / XGBE_TX_MAX_BUF_SIZE) + 1)
155156

156157
/* Maximum possible descriptors needed for an SKB:
157158
* - Maximum number of SKB frags

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 <= GSO_MAX_SIZE;
2041+
return PAGE_SIZE * nr_frags + data_bcnt <= GRO_MAX_SIZE;
20422042
}
20432043

20442044
static void

drivers/net/ethernet/sfc/ef100_nic.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,8 @@ static int ef100_process_design_param(struct efx_nic *efx,
10081008
}
10091009
return 0;
10101010
case ESE_EF100_DP_GZ_TSO_MAX_PAYLOAD_LEN:
1011-
nic_data->tso_max_payload_len = min_t(u64, reader->value, GSO_MAX_SIZE);
1011+
nic_data->tso_max_payload_len = min_t(u64, reader->value,
1012+
GSO_LEGACY_MAX_SIZE);
10121013
netif_set_tso_max_size(efx->net_dev,
10131014
nic_data->tso_max_payload_len);
10141015
return 0;

drivers/net/ethernet/sfc/falcon/tx.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ unsigned int ef4_tx_max_skb_descs(struct ef4_nic *efx)
9898
/* Possibly more for PCIe page boundaries within input fragments */
9999
if (PAGE_SIZE > EF4_PAGE_SIZE)
100100
max_descs += max_t(unsigned int, MAX_SKB_FRAGS,
101-
DIV_ROUND_UP(GSO_MAX_SIZE, EF4_PAGE_SIZE));
101+
DIV_ROUND_UP(GSO_LEGACY_MAX_SIZE,
102+
EF4_PAGE_SIZE));
102103

103104
return max_descs;
104105
}

drivers/net/ethernet/sfc/tx_common.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,8 @@ unsigned int efx_tx_max_skb_descs(struct efx_nic *efx)
416416
/* Possibly more for PCIe page boundaries within input fragments */
417417
if (PAGE_SIZE > EFX_PAGE_SIZE)
418418
max_descs += max_t(unsigned int, MAX_SKB_FRAGS,
419-
DIV_ROUND_UP(GSO_MAX_SIZE, EFX_PAGE_SIZE));
419+
DIV_ROUND_UP(GSO_LEGACY_MAX_SIZE,
420+
EFX_PAGE_SIZE));
420421

421422
return max_descs;
422423
}

drivers/net/ethernet/synopsys/dwc-xlgmac.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
#define XLGMAC_RX_DESC_MAX_DIRTY (XLGMAC_RX_DESC_CNT >> 3)
3939

4040
/* Descriptors required for maximum contiguous TSO/GSO packet */
41-
#define XLGMAC_TX_MAX_SPLIT ((GSO_MAX_SIZE / XLGMAC_TX_MAX_BUF_SIZE) + 1)
41+
#define XLGMAC_TX_MAX_SPLIT \
42+
((GSO_LEGACY_MAX_SIZE / XLGMAC_TX_MAX_BUF_SIZE) + 1)
4243

4344
/* Maximum possible descriptors needed for a SKB */
4445
#define XLGMAC_TX_MAX_DESC_NR (MAX_SKB_FRAGS + XLGMAC_TX_MAX_SPLIT + 2)

drivers/net/hyperv/rndis_filter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,7 @@ static int rndis_netdev_set_hwcaps(struct rndis_device *rndis_device,
13491349
struct net_device_context *net_device_ctx = netdev_priv(net);
13501350
struct ndis_offload hwcaps;
13511351
struct ndis_offload_params offloads;
1352-
unsigned int gso_max_size = GSO_MAX_SIZE;
1352+
unsigned int gso_max_size = GSO_LEGACY_MAX_SIZE;
13531353
int ret;
13541354

13551355
/* Find HW offload capabilities */

drivers/scsi/fcoe/fcoe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ static void fcoe_netdev_features_change(struct fc_lport *lport,
667667

668668
if (netdev->features & NETIF_F_FSO) {
669669
lport->seq_offload = 1;
670-
lport->lso_max = netdev->gso_max_size;
670+
lport->lso_max = min(netdev->gso_max_size, GSO_LEGACY_MAX_SIZE);
671671
FCOE_NETDEV_DBG(netdev, "Supports LSO for max len 0x%x\n",
672672
lport->lso_max);
673673
} else {

include/linux/netdevice.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2272,7 +2272,9 @@ struct net_device {
22722272
const struct rtnl_link_ops *rtnl_link_ops;
22732273

22742274
/* for setting kernel sock attribute on TCP connection setup */
2275-
#define GSO_MAX_SIZE 65536
2275+
#define GSO_LEGACY_MAX_SIZE 65536u
2276+
#define GSO_MAX_SIZE UINT_MAX
2277+
22762278
unsigned int gso_max_size;
22772279
#define TSO_LEGACY_MAX_SIZE 65536
22782280
#define TSO_MAX_SIZE UINT_MAX

net/bpf/test_run.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ static int convert___skb_to_skb(struct sk_buff *skb, struct __sk_buff *__skb)
10011001
cb->pkt_len = skb->len;
10021002
} else {
10031003
if (__skb->wire_len < skb->len ||
1004-
__skb->wire_len > GSO_MAX_SIZE)
1004+
__skb->wire_len > GSO_LEGACY_MAX_SIZE)
10051005
return -EINVAL;
10061006
cb->pkt_len = __skb->wire_len;
10071007
}

net/core/dev.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2998,11 +2998,12 @@ EXPORT_SYMBOL(netif_set_real_num_queues);
29982998
* @size: max skb->len of a TSO frame
29992999
*
30003000
* Set the limit on the size of TSO super-frames the device can handle.
3001-
* Unless explicitly set the stack will assume the value of %GSO_MAX_SIZE.
3001+
* Unless explicitly set the stack will assume the value of
3002+
* %GSO_LEGACY_MAX_SIZE.
30023003
*/
30033004
void netif_set_tso_max_size(struct net_device *dev, unsigned int size)
30043005
{
3005-
dev->tso_max_size = size;
3006+
dev->tso_max_size = min(GSO_MAX_SIZE, size);
30063007
if (size < READ_ONCE(dev->gso_max_size))
30073008
netif_set_gso_max_size(dev, size);
30083009
}
@@ -10595,7 +10596,7 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
1059510596

1059610597
dev_net_set(dev, &init_net);
1059710598

10598-
dev->gso_max_size = GSO_MAX_SIZE;
10599+
dev->gso_max_size = GSO_LEGACY_MAX_SIZE;
1059910600
dev->gso_max_segs = GSO_MAX_SEGS;
1060010601
dev->gro_max_size = GRO_MAX_SIZE;
1060110602
dev->tso_max_size = TSO_LEGACY_MAX_SIZE;

net/core/rtnetlink.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2817,7 +2817,7 @@ static int do_setlink(const struct sk_buff *skb,
28172817
if (tb[IFLA_GSO_MAX_SIZE]) {
28182818
u32 max_size = nla_get_u32(tb[IFLA_GSO_MAX_SIZE]);
28192819

2820-
if (max_size > GSO_MAX_SIZE || max_size > dev->tso_max_size) {
2820+
if (max_size > dev->tso_max_size) {
28212821
err = -EINVAL;
28222822
goto errout;
28232823
}

net/core/sock.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,6 +2293,19 @@ void sk_free_unlock_clone(struct sock *sk)
22932293
}
22942294
EXPORT_SYMBOL_GPL(sk_free_unlock_clone);
22952295

2296+
static void sk_trim_gso_size(struct sock *sk)
2297+
{
2298+
if (sk->sk_gso_max_size <= GSO_LEGACY_MAX_SIZE)
2299+
return;
2300+
#if IS_ENABLED(CONFIG_IPV6)
2301+
if (sk->sk_family == AF_INET6 &&
2302+
sk_is_tcp(sk) &&
2303+
!ipv6_addr_v4mapped(&sk->sk_v6_rcv_saddr))
2304+
return;
2305+
#endif
2306+
sk->sk_gso_max_size = GSO_LEGACY_MAX_SIZE;
2307+
}
2308+
22962309
void sk_setup_caps(struct sock *sk, struct dst_entry *dst)
22972310
{
22982311
u32 max_segs = 1;
@@ -2312,6 +2325,7 @@ void sk_setup_caps(struct sock *sk, struct dst_entry *dst)
23122325
sk->sk_route_caps |= NETIF_F_SG | NETIF_F_HW_CSUM;
23132326
/* pairs with the WRITE_ONCE() in netif_set_gso_max_size() */
23142327
sk->sk_gso_max_size = READ_ONCE(dst->dev->gso_max_size);
2328+
sk_trim_gso_size(sk);
23152329
sk->sk_gso_max_size -= (MAX_TCP_HEADER + 1);
23162330
/* pairs with the WRITE_ONCE() in netif_set_gso_max_segs() */
23172331
max_segs = max_t(u32, READ_ONCE(dst->dev->gso_max_segs), 1);

net/ipv4/tcp_bbr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ static u32 bbr_tso_segs_goal(struct sock *sk)
310310
*/
311311
bytes = min_t(unsigned long,
312312
sk->sk_pacing_rate >> READ_ONCE(sk->sk_pacing_shift),
313-
GSO_MAX_SIZE - 1 - MAX_TCP_HEADER);
313+
GSO_LEGACY_MAX_SIZE - 1 - MAX_TCP_HEADER);
314314
segs = max_t(u32, bytes / tp->mss_cache, bbr_min_tso_segs(sk));
315315

316316
return min(segs, 0x7FU);

net/ipv4/tcp_output.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1553,7 +1553,7 @@ int tcp_fragment(struct sock *sk, enum tcp_queue tcp_queue,
15531553
* SO_SNDBUF values.
15541554
* Also allow first and last skb in retransmit queue to be split.
15551555
*/
1556-
limit = sk->sk_sndbuf + 2 * SKB_TRUESIZE(GSO_MAX_SIZE);
1556+
limit = sk->sk_sndbuf + 2 * SKB_TRUESIZE(GSO_LEGACY_MAX_SIZE);
15571557
if (unlikely((sk->sk_wmem_queued >> 1) > limit &&
15581558
tcp_queue != TCP_FRAG_IN_WRITE_QUEUE &&
15591559
skb != tcp_rtx_queue_head(sk) &&

net/sctp/output.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ void sctp_packet_config(struct sctp_packet *packet, __u32 vtag,
134134
dst_hold(tp->dst);
135135
sk_setup_caps(sk, tp->dst);
136136
}
137-
packet->max_size = sk_can_gso(sk) ? READ_ONCE(tp->dst->dev->gso_max_size)
137+
packet->max_size = sk_can_gso(sk) ? min(READ_ONCE(tp->dst->dev->gso_max_size),
138+
GSO_LEGACY_MAX_SIZE)
138139
: asoc->pathmtu;
139140
rcu_read_unlock();
140141
}

0 commit comments

Comments
 (0)