net: better IFF_XMIT_DST_RELEASE support
authorEric Dumazet <edumazet@google.com>
Mon, 6 Oct 2014 01:38:35 +0000 (18:38 -0700)
committerDavid S. Miller <davem@davemloft.net>
Tue, 7 Oct 2014 17:22:11 +0000 (13:22 -0400)
Testing xmit_more support with netperf and connected UDP sockets,
I found strange dst refcount false sharing.

Current handling of IFF_XMIT_DST_RELEASE is not optimal.

Dropping dst in validate_xmit_skb() is certainly too late in case
packet was queued by cpu X but dequeued by cpu Y

The logical point to take care of drop/force is in __dev_queue_xmit()
before even taking qdisc lock.

As Julian Anastasov pointed out, need for skb_dst() might come from some
packet schedulers or classifiers.

This patch adds new helper to cleanly express needs of various drivers
or qdiscs/classifiers.

Drivers that need skb_dst() in their ndo_start_xmit() should call
following helper in their setup instead of the prior :

dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
->
netif_keep_dst(dev);

Instead of using a single bit, we use two bits, one being
eventually rebuilt in bonding/team drivers.

The other one, is permanent and blocks IFF_XMIT_DST_RELEASE being
rebuilt in bonding/team. Eventually, we could add something
smarter later.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Julian Anastasov <ja@ssi.bg>
Signed-off-by: David S. Miller <davem@davemloft.net>
27 files changed:
drivers/infiniband/ulp/ipoib/ipoib_main.c
drivers/net/appletalk/ipddp.c
drivers/net/bonding/bond_main.c
drivers/net/eql.c
drivers/net/ifb.c
drivers/net/loopback.c
drivers/net/macvlan.c
drivers/net/ppp/ppp_generic.c
drivers/net/team/team.c
drivers/net/vxlan.c
drivers/net/wan/hdlc_fr.c
drivers/s390/net/qeth_l3_main.c
include/linux/netdevice.h
net/8021q/vlan_dev.c
net/atm/clip.c
net/core/dev.c
net/ipv4/ip_gre.c
net/ipv4/ip_vti.c
net/ipv4/ipip.c
net/ipv6/ip6_gre.c
net/ipv6/ip6_tunnel.c
net/ipv6/ip6_vti.c
net/ipv6/sit.c
net/sched/cls_flow.c
net/sched/cls_route.c
net/sched/sch_generic.c
net/sched/sch_teql.c

index 13e6e04315920d7f361129945332cdbf41f8a930..58b5aa3b6f2dded5d2e6d15aff080551aa9eddd9 100644 (file)
@@ -1364,7 +1364,7 @@ void ipoib_setup(struct net_device *dev)
        dev->tx_queue_len        = ipoib_sendq_size * 2;
        dev->features            = (NETIF_F_VLAN_CHALLENGED     |
                                    NETIF_F_HIGHDMA);
-       dev->priv_flags         &= ~IFF_XMIT_DST_RELEASE;
+       netif_keep_dst(dev);
 
        memcpy(dev->broadcast, ipv4_bcast_addr, INFINIBAND_ALEN);
 
index 10d0dba572c2e319f630638e204ed8c12ae38b5e..e90c6a7333d76b4f11e3fccfdcad094be141108e 100644 (file)
@@ -74,7 +74,7 @@ static struct net_device * __init ipddp_init(void)
        if (!dev)
                return ERR_PTR(-ENOMEM);
 
-       dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
+       netif_keep_dst(dev);
        strcpy(dev->name, "ipddp%d");
 
        if (version_printed++ == 0)
index 3ad5413d4f57ead83ed41529ac0cee312a7addee..c9ac06cfe6b7b3a8f62568b70a6ad6d7ca9b44d0 100644 (file)
@@ -1002,7 +1002,8 @@ static netdev_features_t bond_fix_features(struct net_device *dev,
 
 static void bond_compute_features(struct bonding *bond)
 {
-       unsigned int flags, dst_release_flag = IFF_XMIT_DST_RELEASE;
+       unsigned int dst_release_flag = IFF_XMIT_DST_RELEASE |
+                                       IFF_XMIT_DST_RELEASE_PERM;
        netdev_features_t vlan_features = BOND_VLAN_FEATURES;
        netdev_features_t enc_features  = BOND_ENC_FEATURES;
        struct net_device *bond_dev = bond->dev;
@@ -1038,8 +1039,10 @@ done:
        bond_dev->gso_max_segs = gso_max_segs;
        netif_set_gso_max_size(bond_dev, gso_max_size);
 
-       flags = bond_dev->priv_flags & ~IFF_XMIT_DST_RELEASE;
-       bond_dev->priv_flags = flags | dst_release_flag;
+       bond_dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
+       if ((bond_dev->priv_flags & IFF_XMIT_DST_RELEASE_PERM) &&
+           dst_release_flag == (IFF_XMIT_DST_RELEASE | IFF_XMIT_DST_RELEASE_PERM))
+               bond_dev->priv_flags |= IFF_XMIT_DST_RELEASE;
 
        netdev_change_features(bond_dev);
 }
index 957e5c0cede337cff8d98c81089e879d83988dcb..a10ad74cc8d2225a40a7f1afd261c88834a6458a 100644 (file)
@@ -199,7 +199,7 @@ static void __init eql_setup(struct net_device *dev)
 
        dev->type               = ARPHRD_SLIP;
        dev->tx_queue_len       = 5;            /* Hands them off fast */
-       dev->priv_flags        &= ~IFF_XMIT_DST_RELEASE;
+       netif_keep_dst(dev);
 }
 
 static int eql_open(struct net_device *dev)
index d2d4a3d2237f7c735a326a949ec55561fe0c79f7..34f846b4bd0574a8168d669c408181e1086d3386 100644 (file)
@@ -185,7 +185,8 @@ static void ifb_setup(struct net_device *dev)
 
        dev->flags |= IFF_NOARP;
        dev->flags &= ~IFF_MULTICAST;
-       dev->priv_flags &= ~(IFF_XMIT_DST_RELEASE | IFF_TX_SKB_SHARING);
+       dev->priv_flags &= ~IFF_TX_SKB_SHARING;
+       netif_keep_dst(dev);
        eth_hw_addr_random(dev);
 }
 
index 8f2262540561caf546ea53740a20795b10f51205..c76283c2f84a4e7aa21b684770542e9b6202bffd 100644 (file)
@@ -169,7 +169,7 @@ static void loopback_setup(struct net_device *dev)
        dev->type               = ARPHRD_LOOPBACK;      /* 0x0001*/
        dev->flags              = IFF_LOOPBACK;
        dev->priv_flags         |= IFF_LIVE_ADDR_CHANGE;
-       dev->priv_flags        &= ~IFF_XMIT_DST_RELEASE;
+       netif_keep_dst(dev);
        dev->hw_features        = NETIF_F_ALL_TSO | NETIF_F_UFO;
        dev->features           = NETIF_F_SG | NETIF_F_FRAGLIST
                | NETIF_F_ALL_TSO
index e8a453f1b458df54d88a985ba97b2063a9ef71bb..38b4fae61f04ab32a2a0020ed50f0e12aef24a2c 100644 (file)
@@ -1025,7 +1025,8 @@ void macvlan_common_setup(struct net_device *dev)
 {
        ether_setup(dev);
 
-       dev->priv_flags        &= ~(IFF_XMIT_DST_RELEASE | IFF_TX_SKB_SHARING);
+       dev->priv_flags        &= ~IFF_TX_SKB_SHARING;
+       netif_keep_dst(dev);
        dev->priv_flags        |= IFF_UNICAST_FLT;
        dev->netdev_ops         = &macvlan_netdev_ops;
        dev->destructor         = free_netdev;
index fa0d71727894a2ef8dc74f8e27c68bbce87f44fa..80e6f3430f65e96dfe3e3b8b13d694f727f330cc 100644 (file)
@@ -1103,7 +1103,7 @@ static void ppp_setup(struct net_device *dev)
        dev->type = ARPHRD_PPP;
        dev->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST;
        dev->features |= NETIF_F_NETNS_LOCAL;
-       dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
+       netif_keep_dst(dev);
 }
 
 /*
index 2277c3679a518e5b68ded6ff7e9bbe9404f71a1e..a94a9df3e6bd241319afbf8c3105a25fced323b4 100644 (file)
@@ -970,7 +970,8 @@ static void __team_compute_features(struct team *team)
        struct team_port *port;
        u32 vlan_features = TEAM_VLAN_FEATURES & NETIF_F_ALL_FOR_ALL;
        unsigned short max_hard_header_len = ETH_HLEN;
-       unsigned int flags, dst_release_flag = IFF_XMIT_DST_RELEASE;
+       unsigned int dst_release_flag = IFF_XMIT_DST_RELEASE |
+                                       IFF_XMIT_DST_RELEASE_PERM;
 
        list_for_each_entry(port, &team->port_list, list) {
                vlan_features = netdev_increment_features(vlan_features,
@@ -985,8 +986,9 @@ static void __team_compute_features(struct team *team)
        team->dev->vlan_features = vlan_features;
        team->dev->hard_header_len = max_hard_header_len;
 
-       flags = team->dev->priv_flags & ~IFF_XMIT_DST_RELEASE;
-       team->dev->priv_flags = flags | dst_release_flag;
+       team->dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
+       if (dst_release_flag == (IFF_XMIT_DST_RELEASE | IFF_XMIT_DST_RELEASE_PERM))
+               team->dev->priv_flags |= IFF_XMIT_DST_RELEASE;
 
        netdev_change_features(team->dev);
 }
index 2af795d6ba0556f25c489b2b8609a30f2824393a..2a51e6e48e1ef27c3176f9501fcb9e8ae3594558 100644 (file)
@@ -2193,7 +2193,7 @@ static void vxlan_setup(struct net_device *dev)
        dev->hw_features |= NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_RXCSUM;
        dev->hw_features |= NETIF_F_GSO_SOFTWARE;
        dev->hw_features |= NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_STAG_TX;
-       dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
+       netif_keep_dst(dev);
        dev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
 
        INIT_LIST_HEAD(&vxlan->next);
index e5c7e6165a4b658046c0bba6173e14c7c62671f5..3ebed1c40abb11c192db0acc36d90bfd2028c646 100644 (file)
@@ -1047,7 +1047,7 @@ static void pvc_setup(struct net_device *dev)
        dev->flags = IFF_POINTOPOINT;
        dev->hard_header_len = 10;
        dev->addr_len = 2;
-       dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
+       netif_keep_dst(dev);
 }
 
 static const struct net_device_ops pvc_ops = {
index f8427a2c4840b9e2453e7a9129068cb69e438397..afebb9709763b0a011320b9ad7e66aa709eca9a3 100644 (file)
@@ -3306,7 +3306,7 @@ static int qeth_l3_setup_netdev(struct qeth_card *card)
        card->dev->features |=  NETIF_F_HW_VLAN_CTAG_TX |
                                NETIF_F_HW_VLAN_CTAG_RX |
                                NETIF_F_HW_VLAN_CTAG_FILTER;
-       card->dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
+       netif_keep_dst(card->dev);
        card->dev->gso_max_size = 15 * PAGE_SIZE;
 
        SET_NETDEV_DEV(card->dev, &card->gdev->dev);
index 2df86f50261c08d5a01cbef9f29031fd2960d2b1..3a4315b39d20bb042a04aba865cba083fff3572d 100644 (file)
@@ -1206,6 +1206,7 @@ enum netdev_priv_flags {
        IFF_SUPP_NOFCS                  = 1<<19,
        IFF_LIVE_ADDR_CHANGE            = 1<<20,
        IFF_MACVLAN                     = 1<<21,
+       IFF_XMIT_DST_RELEASE_PERM       = 1<<22,
 };
 
 #define IFF_802_1Q_VLAN                        IFF_802_1Q_VLAN
@@ -1230,6 +1231,7 @@ enum netdev_priv_flags {
 #define IFF_SUPP_NOFCS                 IFF_SUPP_NOFCS
 #define IFF_LIVE_ADDR_CHANGE           IFF_LIVE_ADDR_CHANGE
 #define IFF_MACVLAN                    IFF_MACVLAN
+#define IFF_XMIT_DST_RELEASE_PERM      IFF_XMIT_DST_RELEASE_PERM
 
 /**
  *     struct net_device - The DEVICE structure.
@@ -3588,6 +3590,12 @@ static inline bool netif_supports_nofcs(struct net_device *dev)
        return dev->priv_flags & IFF_SUPP_NOFCS;
 }
 
+/* This device needs to keep skb dst for qdisc enqueue or ndo_start_xmit() */
+static inline void netif_keep_dst(struct net_device *dev)
+{
+       dev->priv_flags &= ~(IFF_XMIT_DST_RELEASE | IFF_XMIT_DST_RELEASE_PERM);
+}
+
 extern struct pernet_operations __net_initdata loopback_net_ops;
 
 /* Logging, debugging and troubleshooting/diagnostic helpers. */
index 35a6b6b15e8a1d9e2f846b18aa8c448ad0e915fd..0d441ec8763ec87eec018d2b043b82a5ead50aa0 100644 (file)
@@ -799,7 +799,8 @@ void vlan_setup(struct net_device *dev)
        ether_setup(dev);
 
        dev->priv_flags         |= IFF_802_1Q_VLAN;
-       dev->priv_flags         &= ~(IFF_XMIT_DST_RELEASE | IFF_TX_SKB_SHARING);
+       dev->priv_flags         &= ~IFF_TX_SKB_SHARING;
+       netif_keep_dst(dev);
        dev->tx_queue_len       = 0;
 
        dev->netdev_ops         = &vlan_netdev_ops;
index 1d9eaa4f041a143fa4ef13edcbb54b35f150659a..17e55dfecbe2a133a2a0e02d363b583a0334aecc 100644 (file)
@@ -501,7 +501,7 @@ static void clip_setup(struct net_device *dev)
        /* without any more elaborate queuing. 100 is a reasonable */
        /* compromise between decent burst-tolerance and protection */
        /* against memory hogs. */
-       dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
+       netif_keep_dst(dev);
 }
 
 static int clip_create(int number)
index a63b8c43c1b6bf0249165dcec562031cdbac880d..3c5bdaa444862142f05e24fe4362c632150cbda4 100644 (file)
@@ -2665,12 +2665,6 @@ static struct sk_buff *validate_xmit_skb(struct sk_buff *skb, struct net_device
        if (skb->next)
                return skb;
 
-       /* If device doesn't need skb->dst, release it right now while
-        * its hot in this cpu cache
-        */
-       if (dev->priv_flags & IFF_XMIT_DST_RELEASE)
-               skb_dst_drop(skb);
-
        features = netif_skb_features(skb);
        skb = validate_xmit_vlan(skb, features);
        if (unlikely(!skb))
@@ -2811,8 +2805,6 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q,
                 * waiting to be sent out; and the qdisc is not running -
                 * xmit the skb directly.
                 */
-               if (!(dev->priv_flags & IFF_XMIT_DST_RELEASE))
-                       skb_dst_force(skb);
 
                qdisc_bstats_update(q, skb);
 
@@ -2827,7 +2819,6 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q,
 
                rc = NET_XMIT_SUCCESS;
        } else {
-               skb_dst_force(skb);
                rc = q->enqueue(skb, q) & NET_XMIT_MASK;
                if (qdisc_run_begin(q)) {
                        if (unlikely(contended)) {
@@ -2924,6 +2915,14 @@ static int __dev_queue_xmit(struct sk_buff *skb, void *accel_priv)
 
        skb_update_prio(skb);
 
+       /* If device/qdisc don't need skb->dst, release it right now while
+        * its hot in this cpu cache.
+        */
+       if (dev->priv_flags & IFF_XMIT_DST_RELEASE)
+               skb_dst_drop(skb);
+       else
+               skb_dst_force(skb);
+
        txq = netdev_pick_tx(dev, skb, accel_priv);
        q = rcu_dereference_bh(txq->qdisc);
 
@@ -6674,7 +6673,7 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
        INIT_LIST_HEAD(&dev->adj_list.lower);
        INIT_LIST_HEAD(&dev->all_adj_list.upper);
        INIT_LIST_HEAD(&dev->all_adj_list.lower);
-       dev->priv_flags = IFF_XMIT_DST_RELEASE;
+       dev->priv_flags = IFF_XMIT_DST_RELEASE | IFF_XMIT_DST_RELEASE_PERM;
        setup(dev);
 
        dev->num_tx_queues = txqs;
index 0485ef18d254205fe621d504a1ac294cb8f33480..12055fdbe716f0f1d905f288cbe36415f0e4f592 100644 (file)
@@ -510,7 +510,7 @@ static int ipgre_tunnel_init(struct net_device *dev)
        memcpy(dev->broadcast, &iph->daddr, 4);
 
        dev->flags              = IFF_NOARP;
-       dev->priv_flags         &= ~IFF_XMIT_DST_RELEASE;
+       netif_keep_dst(dev);
        dev->addr_len           = 4;
 
        if (iph->daddr) {
index e453cb724a950317d5f9b96db7de8bd969b7f111..3e861011e4a31e57b21c3fa507c178d3693a7970 100644 (file)
@@ -364,7 +364,7 @@ static int vti_tunnel_init(struct net_device *dev)
        dev->iflink             = 0;
        dev->addr_len           = 4;
        dev->features           |= NETIF_F_LLTX;
-       dev->priv_flags         &= ~IFF_XMIT_DST_RELEASE;
+       netif_keep_dst(dev);
 
        return ip_tunnel_init(dev);
 }
index ea88ab3102a869bda9e19b12e11a1a0f0edeec96..37096d64730ef0c3c7c7278995f9c0c6e64896e9 100644 (file)
@@ -289,7 +289,7 @@ static void ipip_tunnel_setup(struct net_device *dev)
        dev->iflink             = 0;
        dev->addr_len           = 4;
        dev->features           |= NETIF_F_LLTX;
-       dev->priv_flags         &= ~IFF_XMIT_DST_RELEASE;
+       netif_keep_dst(dev);
 
        dev->features           |= IPIP_FEATURES;
        dev->hw_features        |= IPIP_FEATURES;
index 74b677916a7036aadd85cd49be4829d909df4544..de3b1c86b8d35906ff12564cce8599c91fb547b8 100644 (file)
@@ -1242,7 +1242,7 @@ static void ip6gre_tunnel_setup(struct net_device *dev)
        dev->flags |= IFF_NOARP;
        dev->iflink = 0;
        dev->addr_len = sizeof(struct in6_addr);
-       dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
+       netif_keep_dst(dev);
 }
 
 static int ip6gre_tunnel_init(struct net_device *dev)
index d3e8888ad611cdac665fd6c98899c78a3cffbdf3..9409887fb664dd78d13937b89ea1b5044afdbc94 100644 (file)
@@ -1493,7 +1493,7 @@ static void ip6_tnl_dev_setup(struct net_device *dev)
                dev->mtu -= 8;
        dev->flags |= IFF_NOARP;
        dev->addr_len = sizeof(struct in6_addr);
-       dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
+       netif_keep_dst(dev);
        /* This perm addr will be used as interface identifier by IPv6 */
        dev->addr_assign_type = NET_ADDR_RANDOM;
        eth_random_addr(dev->perm_addr);
index 5833a2244467325caff4f75f5740adc809db235b..d440bb585524d72202f809ebd1f0cb4ee8b7cc79 100644 (file)
@@ -807,7 +807,7 @@ static void vti6_dev_setup(struct net_device *dev)
        dev->mtu = ETH_DATA_LEN;
        dev->flags |= IFF_NOARP;
        dev->addr_len = sizeof(struct in6_addr);
-       dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
+       netif_keep_dst(dev);
 }
 
 /**
index 0d4e27466f82b31667c32036e60996517b519057..6eab37cf53451b0f8112e51bff2437cb2b4da213 100644 (file)
@@ -1364,7 +1364,7 @@ static void ipip6_tunnel_setup(struct net_device *dev)
        dev->hard_header_len    = LL_MAX_HEADER + t_hlen;
        dev->mtu                = ETH_DATA_LEN - t_hlen;
        dev->flags              = IFF_NOARP;
-       dev->priv_flags        &= ~IFF_XMIT_DST_RELEASE;
+       netif_keep_dst(dev);
        dev->iflink             = 0;
        dev->addr_len           = 4;
        dev->features           |= NETIF_F_LLTX;
index a5d2b20db5606bea3ef5794ba9a6663010ff4589..4ac515f2a6cecbcb56159c9c11892771e3816ddd 100644 (file)
@@ -493,6 +493,8 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,
        tcf_exts_change(tp, &fnew->exts, &e);
        tcf_em_tree_change(tp, &fnew->ematches, &t);
 
+       netif_keep_dst(qdisc_dev(tp->q));
+
        if (tb[TCA_FLOW_KEYS]) {
                fnew->keymask = keymask;
                fnew->nkeys   = nkeys;
index 6f22baae0afa7a19c9e2138584b7b81ad5fec619..109a329b719858bea8f8a0afc29a27369cb3b9d0 100644 (file)
@@ -524,6 +524,7 @@ static int route4_change(struct net *net, struct sk_buff *in_skb,
                if (f->handle < f1->handle)
                        break;
 
+       netif_keep_dst(qdisc_dev(tp->q));
        rcu_assign_pointer(f->next, f1);
        rcu_assign_pointer(*fp, f);
 
index 2b349a4de3c8e3491fad210a9400d26bda5b52fe..38d58e6cef07a06663312965059b08c31e2189fd 100644 (file)
@@ -47,7 +47,6 @@ EXPORT_SYMBOL(default_qdisc_ops);
 
 static inline int dev_requeue_skb(struct sk_buff *skb, struct Qdisc *q)
 {
-       skb_dst_force(skb);
        q->gso_skb = skb;
        q->qstats.requeues++;
        q->q.qlen++;    /* it's still part of the queue */
@@ -218,8 +217,6 @@ static inline int qdisc_restart(struct Qdisc *q)
        if (unlikely(!skb))
                return 0;
 
-       WARN_ON_ONCE(skb_dst_is_noref(skb));
-
        root_lock = qdisc_lock(q);
        dev = qdisc_dev(q);
        txq = skb_get_tx_queue(dev, skb);
index 5cd291bd00e44291604dc876a19939dcb322da59..6ada42396a242123fd7738309b79720d0b46b38e 100644 (file)
@@ -470,7 +470,7 @@ static __init void teql_master_setup(struct net_device *dev)
        dev->tx_queue_len       = 100;
        dev->flags              = IFF_NOARP;
        dev->hard_header_len    = LL_MAX_HEADER;
-       dev->priv_flags         &= ~IFF_XMIT_DST_RELEASE;
+       netif_keep_dst(dev);
 }
 
 static LIST_HEAD(master_dev_list);