History

net: add gso_ipv4_max_size and gro_ipv4_max_size per device

This patch introduces gso_ipv4_max_size and gro_ipv4_max_size per device and adds netlink attributes for them, so that IPV4 BIG TCP can be guarded by a separate tunable in the next patch. To not break the old application using "gso/gro_max_size" for IPv4 GSO packets, this patch updates "gso/gro_ipv4_max_size" in netif_set_gso/gro_max_size() if the new size isn't greater than GSO_LEGACY_MAX_SIZE, so that nothing will change even if userspace doesn't realize the new netlink attributes.

Xin Long committed 3 years ago

Commit 9eefedd1 parent 8e08bb75 files · +64 −0Browse files

Unified · Split

5 files
  1. include/linux/netdevice.h +6 −0
  2. include/uapi/linux/if_link.h +3 −0
  3. net/core/dev.c +4 −0
  4. net/core/dev.h +18 −0
  5. net/core/rtnetlink.c +33 −0
include/linux/netdevice.h+6−0
@@ -1964,6 +1964,8 @@ enum netdev_ml_priv_type { · 1963 unmodified lines
1964 * @gso_max_segs: Maximum number of segments that can be passed to the1964 * @gso_max_segs: Maximum number of segments that can be passed to the
1965 * NIC for GSO1965 * NIC for GSO
1966 * @tso_max_segs: Device (as in HW) limit on the max TSO segment count1966 * @tso_max_segs: Device (as in HW) limit on the max TSO segment count
1967 * @gso_ipv4_max_size: Maximum size of generic segmentation offload,
1968 * for IPv4.
1967 *1969 *
1968 * @dcbnl_ops: Data Center Bridging netlink ops1970 * @dcbnl_ops: Data Center Bridging netlink ops
1969 * @num_tc: Number of traffic classes in the net device1971 * @num_tc: Number of traffic classes in the net device
@@ -2004,6 +2006,8 @@ enum netdev_ml_priv_type { · 34 unmodified lines
2004 * keep a list of interfaces to be deleted.2006 * keep a list of interfaces to be deleted.
2005 * @gro_max_size: Maximum size of aggregated packet in generic2007 * @gro_max_size: Maximum size of aggregated packet in generic
2006 * receive offload (GRO)2008 * receive offload (GRO)
2009 * @gro_ipv4_max_size: Maximum size of aggregated packet in generic
2010 * receive offload (GRO), for IPv4.
2007 *2011 *
2008 * @dev_addr_shadow: Copy of @dev_addr to catch direct writes.2012 * @dev_addr_shadow: Copy of @dev_addr to catch direct writes.
2009 * @linkwatch_dev_tracker: refcount tracker used by linkwatch.2013 * @linkwatch_dev_tracker: refcount tracker used by linkwatch.
@@ -2207,6 +2211,7 @@ struct net_device { · 197 unmodified lines
2207 */2211 */
2208#define GRO_MAX_SIZE (8 * 65535u)2212#define GRO_MAX_SIZE (8 * 65535u)
2209 unsigned int gro_max_size;2213 unsigned int gro_max_size;
2214 unsigned int gro_ipv4_max_size;
2210 rx_handler_func_t __rcu *rx_handler;2215 rx_handler_func_t __rcu *rx_handler;
2211 void __rcu *rx_handler_data;2216 void __rcu *rx_handler_data;
2212 2217
@@ -2330,6 +2335,7 @@ struct net_device { · 117 unmodified lines
2330 u16 gso_max_segs;2335 u16 gso_max_segs;
2331#define TSO_MAX_SEGS U16_MAX2336#define TSO_MAX_SEGS U16_MAX
2332 u16 tso_max_segs;2337 u16 tso_max_segs;
2338 unsigned int gso_ipv4_max_size;
2333 2339
2334#ifdef CONFIG_DCB2340#ifdef CONFIG_DCB
2335 const struct dcbnl_rtnl_ops *dcbnl_ops;2341 const struct dcbnl_rtnl_ops *dcbnl_ops;
include/uapi/linux/if_link.h+3−0
@@ -374,6 +374,9 @@ enum { · 373 unmodified lines
374 374
375 IFLA_DEVLINK_PORT,375 IFLA_DEVLINK_PORT,
376 376
377 IFLA_GSO_IPV4_MAX_SIZE,
378 IFLA_GRO_IPV4_MAX_SIZE,
379
377 __IFLA_MAX380 __IFLA_MAX
378};381};
379 382
net/core/dev.c+4−0
@@ -3001,6 +3001,8 @@ void netif_set_tso_max_size(struct net_device *dev, unsigned int size) · 3000 unmodified lines
3001 dev->tso_max_size = min(GSO_MAX_SIZE, size);3001 dev->tso_max_size = min(GSO_MAX_SIZE, size);
3002 if (size < READ_ONCE(dev->gso_max_size))3002 if (size < READ_ONCE(dev->gso_max_size))
3003 netif_set_gso_max_size(dev, size);3003 netif_set_gso_max_size(dev, size);
3004 if (size < READ_ONCE(dev->gso_ipv4_max_size))
3005 netif_set_gso_ipv4_max_size(dev, size);
3004}3006}
3005EXPORT_SYMBOL(netif_set_tso_max_size);3007EXPORT_SYMBOL(netif_set_tso_max_size);
3006 3008
@@ -10614,6 +10616,8 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name, · 7607 unmodified lines
10614 dev->gso_max_size = GSO_LEGACY_MAX_SIZE;10616 dev->gso_max_size = GSO_LEGACY_MAX_SIZE;
10615 dev->gso_max_segs = GSO_MAX_SEGS;10617 dev->gso_max_segs = GSO_MAX_SEGS;
10616 dev->gro_max_size = GRO_LEGACY_MAX_SIZE;10618 dev->gro_max_size = GRO_LEGACY_MAX_SIZE;
10619 dev->gso_ipv4_max_size = GSO_LEGACY_MAX_SIZE;
10620 dev->gro_ipv4_max_size = GRO_LEGACY_MAX_SIZE;
10617 dev->tso_max_size = TSO_LEGACY_MAX_SIZE;10621 dev->tso_max_size = TSO_LEGACY_MAX_SIZE;
10618 dev->tso_max_segs = TSO_MAX_SEGS;10622 dev->tso_max_segs = TSO_MAX_SEGS;
10619 dev->upper_level = 1;10623 dev->upper_level = 1;
net/core/dev.h+18−0
@@ -100,6 +100,8 @@ static inline void netif_set_gso_max_size(struct net_device *dev, · 99 unmodified lines
100{100{
101 /* dev->gso_max_size is read locklessly from sk_setup_caps() */101 /* dev->gso_max_size is read locklessly from sk_setup_caps() */
102 WRITE_ONCE(dev->gso_max_size, size);102 WRITE_ONCE(dev->gso_max_size, size);
103 if (size <= GSO_LEGACY_MAX_SIZE)
104 WRITE_ONCE(dev->gso_ipv4_max_size, size);
103}105}
104 106
105static inline void netif_set_gso_max_segs(struct net_device *dev,107static inline void netif_set_gso_max_segs(struct net_device *dev,
@@ -114,6 +116,22 @@ static inline void netif_set_gro_max_size(struct net_device *dev, · 8 unmodified lines
114{116{
115 /* This pairs with the READ_ONCE() in skb_gro_receive() */117 /* This pairs with the READ_ONCE() in skb_gro_receive() */
116 WRITE_ONCE(dev->gro_max_size, size);118 WRITE_ONCE(dev->gro_max_size, size);
119 if (size <= GRO_LEGACY_MAX_SIZE)
120 WRITE_ONCE(dev->gro_ipv4_max_size, size);
121}
122
123static inline void netif_set_gso_ipv4_max_size(struct net_device *dev,
124 unsigned int size)
125{
126 /* dev->gso_ipv4_max_size is read locklessly from sk_setup_caps() */
127 WRITE_ONCE(dev->gso_ipv4_max_size, size);
128}
129
130static inline void netif_set_gro_ipv4_max_size(struct net_device *dev,
131 unsigned int size)
132{
133 /* This pairs with the READ_ONCE() in skb_gro_receive() */
134 WRITE_ONCE(dev->gro_ipv4_max_size, size);
117}135}
118 136
119#endif137#endif
net/core/rtnetlink.c+33−0
@@ -1074,6 +1074,8 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev, · 1073 unmodified lines
1074 + nla_total_size(4) /* IFLA_GSO_MAX_SEGS */1074 + nla_total_size(4) /* IFLA_GSO_MAX_SEGS */
1075 + nla_total_size(4) /* IFLA_GSO_MAX_SIZE */1075 + nla_total_size(4) /* IFLA_GSO_MAX_SIZE */
1076 + nla_total_size(4) /* IFLA_GRO_MAX_SIZE */1076 + nla_total_size(4) /* IFLA_GRO_MAX_SIZE */
1077 + nla_total_size(4) /* IFLA_GSO_IPV4_MAX_SIZE */
1078 + nla_total_size(4) /* IFLA_GRO_IPV4_MAX_SIZE */
1077 + nla_total_size(4) /* IFLA_TSO_MAX_SIZE */1079 + nla_total_size(4) /* IFLA_TSO_MAX_SIZE */
1078 + nla_total_size(4) /* IFLA_TSO_MAX_SEGS */1080 + nla_total_size(4) /* IFLA_TSO_MAX_SEGS */
1079 + nla_total_size(1) /* IFLA_OPERSTATE */1081 + nla_total_size(1) /* IFLA_OPERSTATE */
@@ -1807,6 +1809,8 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, · 727 unmodified lines
1807 nla_put_u32(skb, IFLA_GSO_MAX_SEGS, dev->gso_max_segs) ||1809 nla_put_u32(skb, IFLA_GSO_MAX_SEGS, dev->gso_max_segs) ||
1808 nla_put_u32(skb, IFLA_GSO_MAX_SIZE, dev->gso_max_size) ||1810 nla_put_u32(skb, IFLA_GSO_MAX_SIZE, dev->gso_max_size) ||
1809 nla_put_u32(skb, IFLA_GRO_MAX_SIZE, dev->gro_max_size) ||1811 nla_put_u32(skb, IFLA_GRO_MAX_SIZE, dev->gro_max_size) ||
1812 nla_put_u32(skb, IFLA_GSO_IPV4_MAX_SIZE, dev->gso_ipv4_max_size) ||
1813 nla_put_u32(skb, IFLA_GRO_IPV4_MAX_SIZE, dev->gro_ipv4_max_size) ||
1810 nla_put_u32(skb, IFLA_TSO_MAX_SIZE, dev->tso_max_size) ||1814 nla_put_u32(skb, IFLA_TSO_MAX_SIZE, dev->tso_max_size) ||
1811 nla_put_u32(skb, IFLA_TSO_MAX_SEGS, dev->tso_max_segs) ||1815 nla_put_u32(skb, IFLA_TSO_MAX_SEGS, dev->tso_max_segs) ||
1812#ifdef CONFIG_RPS1816#ifdef CONFIG_RPS
@@ -1968,6 +1972,8 @@ static const struct nla_policy ifla_policy[IFLA_MAX+1] = { · 155 unmodified lines
1968 [IFLA_TSO_MAX_SIZE] = { .type = NLA_REJECT },1972 [IFLA_TSO_MAX_SIZE] = { .type = NLA_REJECT },
1969 [IFLA_TSO_MAX_SEGS] = { .type = NLA_REJECT },1973 [IFLA_TSO_MAX_SEGS] = { .type = NLA_REJECT },
1970 [IFLA_ALLMULTI] = { .type = NLA_REJECT },1974 [IFLA_ALLMULTI] = { .type = NLA_REJECT },
1975 [IFLA_GSO_IPV4_MAX_SIZE] = { .type = NLA_U32 },
1976 [IFLA_GRO_IPV4_MAX_SIZE] = { .type = NLA_U32 },
1971};1977};
1972 1978
1973static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = {1979static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = {
@@ -2883,6 +2889,29 @@ static int do_setlink(const struct sk_buff *skb, · 909 unmodified lines
2883 }2889 }
2884 }2890 }
2885 2891
2892 if (tb[IFLA_GSO_IPV4_MAX_SIZE]) {
2893 u32 max_size = nla_get_u32(tb[IFLA_GSO_IPV4_MAX_SIZE]);
2894
2895 if (max_size > dev->tso_max_size) {
2896 err = -EINVAL;
2897 goto errout;
2898 }
2899
2900 if (dev->gso_ipv4_max_size ^ max_size) {
2901 netif_set_gso_ipv4_max_size(dev, max_size);
2902 status |= DO_SETLINK_MODIFIED;
2903 }
2904 }
2905
2906 if (tb[IFLA_GRO_IPV4_MAX_SIZE]) {
2907 u32 gro_max_size = nla_get_u32(tb[IFLA_GRO_IPV4_MAX_SIZE]);
2908
2909 if (dev->gro_ipv4_max_size ^ gro_max_size) {
2910 netif_set_gro_ipv4_max_size(dev, gro_max_size);
2911 status |= DO_SETLINK_MODIFIED;
2912 }
2913 }
2914
2886 if (tb[IFLA_OPERSTATE])2915 if (tb[IFLA_OPERSTATE])
2887 set_operstate(dev, nla_get_u8(tb[IFLA_OPERSTATE]));2916 set_operstate(dev, nla_get_u8(tb[IFLA_OPERSTATE]));
2888 2917
@@ -3325,6 +3354,10 @@ struct net_device *rtnl_create_link(struct net *net, const char *ifname, · 436 unmodified lines
3325 netif_set_gso_max_segs(dev, nla_get_u32(tb[IFLA_GSO_MAX_SEGS]));3354 netif_set_gso_max_segs(dev, nla_get_u32(tb[IFLA_GSO_MAX_SEGS]));
3326 if (tb[IFLA_GRO_MAX_SIZE])3355 if (tb[IFLA_GRO_MAX_SIZE])
3327 netif_set_gro_max_size(dev, nla_get_u32(tb[IFLA_GRO_MAX_SIZE]));3356 netif_set_gro_max_size(dev, nla_get_u32(tb[IFLA_GRO_MAX_SIZE]));
3357 if (tb[IFLA_GSO_IPV4_MAX_SIZE])
3358 netif_set_gso_ipv4_max_size(dev, nla_get_u32(tb[IFLA_GSO_IPV4_MAX_SIZE]));
3359 if (tb[IFLA_GRO_IPV4_MAX_SIZE])
3360 netif_set_gro_ipv4_max_size(dev, nla_get_u32(tb[IFLA_GRO_IPV4_MAX_SIZE]));
3328 3361
3329 return dev;3362 return dev;
3330}3363}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t