net: annotate accesses to dev->gso_max_size
authorEric Dumazet <edumazet@google.com>
Fri, 19 Nov 2021 15:43:31 +0000 (07:43 -0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 22 Nov 2021 12:49:42 +0000 (12:49 +0000)
dev->gso_max_size is written under RTNL protection, or when the device is
not yet visible, but is read locklessly.

Add the READ_ONCE()/WRITE_ONCE() pairs, and use netif_set_gso_max_size()
where we can to better document what is going on.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
13 files changed:
drivers/net/ethernet/netronome/nfp/nfp_net_repr.c
drivers/net/ethernet/realtek/r8169_main.c
drivers/net/ethernet/sfc/ef100_nic.c
drivers/net/ipvlan/ipvlan_main.c
drivers/net/macvlan.c
drivers/net/veth.c
drivers/net/vxlan.c
include/linux/netdevice.h
net/8021q/vlan.c
net/8021q/vlan_dev.c
net/bridge/br_if.c
net/core/sock.c
net/sctp/output.c

index 369f6ae..927ddbd 100644 (file)
@@ -286,7 +286,7 @@ nfp_repr_transfer_features(struct net_device *netdev, struct net_device *lower)
        if (repr->dst->u.port_info.lower_dev != lower)
                return;
 
-       netdev->gso_max_size = lower->gso_max_size;
+       netif_set_gso_max_size(netdev, lower->gso_max_size);
        netdev->gso_max_segs = lower->gso_max_segs;
 
        netdev_update_features(netdev);
index 14dd04b..ff222c5 100644 (file)
@@ -5390,11 +5390,11 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
         */
        if (rtl_chip_supports_csum_v2(tp)) {
                dev->hw_features |= NETIF_F_SG | NETIF_F_TSO | NETIF_F_TSO6;
-               dev->gso_max_size = RTL_GSO_MAX_SIZE_V2;
+               netif_set_gso_max_size(dev, RTL_GSO_MAX_SIZE_V2);
                dev->gso_max_segs = RTL_GSO_MAX_SEGS_V2;
        } else {
                dev->hw_features |= NETIF_F_SG | NETIF_F_TSO;
-               dev->gso_max_size = RTL_GSO_MAX_SIZE_V1;
+               netif_set_gso_max_size(dev, RTL_GSO_MAX_SIZE_V1);
                dev->gso_max_segs = RTL_GSO_MAX_SEGS_V1;
        }
 
index 6aa8122..d9015a7 100644 (file)
@@ -993,7 +993,7 @@ static int ef100_process_design_param(struct efx_nic *efx,
                return 0;
        case ESE_EF100_DP_GZ_TSO_MAX_PAYLOAD_LEN:
                nic_data->tso_max_payload_len = min_t(u64, reader->value, GSO_MAX_SIZE);
-               efx->net_dev->gso_max_size = nic_data->tso_max_payload_len;
+               netif_set_gso_max_size(efx->net_dev, nic_data->tso_max_payload_len);
                return 0;
        case ESE_EF100_DP_GZ_TSO_MAX_PAYLOAD_NUM_SEGS:
                nic_data->tso_max_payload_num_segs = min_t(u64, reader->value, 0xffff);
index 1d2f4e7..0ba63ec 100644 (file)
@@ -140,7 +140,7 @@ static int ipvlan_init(struct net_device *dev)
        dev->vlan_features = phy_dev->vlan_features & IPVLAN_FEATURES;
        dev->vlan_features |= IPVLAN_ALWAYS_ON_OFLOADS;
        dev->hw_enc_features |= dev->features;
-       dev->gso_max_size = phy_dev->gso_max_size;
+       netif_set_gso_max_size(dev, phy_dev->gso_max_size);
        dev->gso_max_segs = phy_dev->gso_max_segs;
        dev->hard_header_len = phy_dev->hard_header_len;
 
@@ -763,7 +763,7 @@ static int ipvlan_device_event(struct notifier_block *unused,
 
        case NETDEV_FEAT_CHANGE:
                list_for_each_entry(ipvlan, &port->ipvlans, pnode) {
-                       ipvlan->dev->gso_max_size = dev->gso_max_size;
+                       netif_set_gso_max_size(ipvlan->dev, dev->gso_max_size);
                        ipvlan->dev->gso_max_segs = dev->gso_max_segs;
                        netdev_update_features(ipvlan->dev);
                }
index d2f830e..506e955 100644 (file)
@@ -900,7 +900,7 @@ static int macvlan_init(struct net_device *dev)
        dev->vlan_features      = lowerdev->vlan_features & MACVLAN_FEATURES;
        dev->vlan_features      |= ALWAYS_ON_OFFLOADS;
        dev->hw_enc_features    |= dev->features;
-       dev->gso_max_size       = lowerdev->gso_max_size;
+       netif_set_gso_max_size(dev, lowerdev->gso_max_size);
        dev->gso_max_segs       = lowerdev->gso_max_segs;
        dev->hard_header_len    = lowerdev->hard_header_len;
        macvlan_set_lockdep_class(dev);
@@ -1748,7 +1748,7 @@ static int macvlan_device_event(struct notifier_block *unused,
                break;
        case NETDEV_FEAT_CHANGE:
                list_for_each_entry(vlan, &port->vlans, list) {
-                       vlan->dev->gso_max_size = dev->gso_max_size;
+                       netif_set_gso_max_size(vlan->dev, dev->gso_max_size);
                        vlan->dev->gso_max_segs = dev->gso_max_segs;
                        netdev_update_features(vlan->dev);
                }
index 50eb43e..f2f66fb 100644 (file)
@@ -1689,7 +1689,7 @@ static int veth_newlink(struct net *src_net, struct net_device *dev,
        if (ifmp && (dev->ifindex != 0))
                peer->ifindex = ifmp->ifi_index;
 
-       peer->gso_max_size = dev->gso_max_size;
+       netif_set_gso_max_size(peer, dev->gso_max_size);
        peer->gso_max_segs = dev->gso_max_segs;
 
        err = register_netdevice(peer);
index 563f86d..df4f171 100644 (file)
@@ -3811,7 +3811,7 @@ static void vxlan_config_apply(struct net_device *dev,
        if (lowerdev) {
                dst->remote_ifindex = conf->remote_ifindex;
 
-               dev->gso_max_size = lowerdev->gso_max_size;
+               netif_set_gso_max_size(dev, lowerdev->gso_max_size);
                dev->gso_max_segs = lowerdev->gso_max_segs;
 
                needed_headroom = lowerdev->hard_header_len;
index cb7f266..14eeb58 100644 (file)
@@ -4731,7 +4731,8 @@ static inline bool netif_needs_gso(struct sk_buff *skb,
 static inline void netif_set_gso_max_size(struct net_device *dev,
                                          unsigned int size)
 {
-       dev->gso_max_size = size;
+       /* dev->gso_max_size is read locklessly from sk_setup_caps() */
+       WRITE_ONCE(dev->gso_max_size, size);
 }
 
 static inline void skb_gso_error_unwind(struct sk_buff *skb, __be16 protocol,
index a3a0a5e..34c0ffa 100644 (file)
@@ -322,7 +322,7 @@ static void vlan_transfer_features(struct net_device *dev,
 {
        struct vlan_dev_priv *vlan = vlan_dev_priv(vlandev);
 
-       vlandev->gso_max_size = dev->gso_max_size;
+       netif_set_gso_max_size(vlandev, dev->gso_max_size);
        vlandev->gso_max_segs = dev->gso_max_segs;
 
        if (vlan_hw_offload_capable(dev->features, vlan->vlan_proto))
index ab6dee2..208f684 100644 (file)
@@ -573,7 +573,7 @@ static int vlan_dev_init(struct net_device *dev)
                           NETIF_F_ALL_FCOE;
 
        dev->features |= dev->hw_features | NETIF_F_LLTX;
-       dev->gso_max_size = real_dev->gso_max_size;
+       netif_set_gso_max_size(dev, real_dev->gso_max_size);
        dev->gso_max_segs = real_dev->gso_max_segs;
        if (dev->features & NETIF_F_VLAN_FEATURES)
                netdev_warn(real_dev, "VLAN features are set incorrectly.  Q-in-Q configurations may not work correctly.\n");
index 64b2d4f..d3e1c22 100644 (file)
@@ -525,7 +525,7 @@ static void br_set_gso_limits(struct net_bridge *br)
                gso_max_size = min(gso_max_size, p->dev->gso_max_size);
                gso_max_segs = min(gso_max_segs, p->dev->gso_max_segs);
        }
-       br->dev->gso_max_size = gso_max_size;
+       netif_set_gso_max_size(br->dev, gso_max_size);
        br->dev->gso_max_segs = gso_max_segs;
 }
 
index 1f9be26..4418e2a 100644 (file)
@@ -2257,7 +2257,8 @@ void sk_setup_caps(struct sock *sk, struct dst_entry *dst)
                        sk->sk_route_caps &= ~NETIF_F_GSO_MASK;
                } else {
                        sk->sk_route_caps |= NETIF_F_SG | NETIF_F_HW_CSUM;
-                       sk->sk_gso_max_size = dst->dev->gso_max_size;
+                       /* pairs with the WRITE_ONCE() in netif_set_gso_max_size() */
+                       sk->sk_gso_max_size = READ_ONCE(dst->dev->gso_max_size);
                        max_segs = max_t(u32, dst->dev->gso_max_segs, 1);
                }
        }
index cdfdbd3..72fe666 100644 (file)
@@ -134,7 +134,7 @@ void sctp_packet_config(struct sctp_packet *packet, __u32 vtag,
                dst_hold(tp->dst);
                sk_setup_caps(sk, tp->dst);
        }
-       packet->max_size = sk_can_gso(sk) ? tp->dst->dev->gso_max_size
+       packet->max_size = sk_can_gso(sk) ? READ_ONCE(tp->dst->dev->gso_max_size)
                                          : asoc->pathmtu;
        rcu_read_unlock();
 }