bonding: fix bond_arp_rcv() race of curr_active_slave
[firefly-linux-kernel-4.4.55.git] / drivers / net / bonding / bond_main.c
index 14e023de09d6ce39515392b11502c54f351ea4bf..bd70bbc7992cfea6aaaf49333316d280e7d152ce 100644 (file)
@@ -674,8 +674,8 @@ static void bond_do_fail_over_mac(struct bonding *bond,
 
                if (old_active) {
                        ether_addr_copy(tmp_mac, new_active->dev->dev_addr);
-                       memcpy(saddr.sa_data, old_active->dev->dev_addr,
-                              ETH_ALEN);
+                       ether_addr_copy(saddr.sa_data,
+                                       old_active->dev->dev_addr);
                        saddr.sa_family = new_active->dev->type;
                } else {
                        ether_addr_copy(saddr.sa_data, bond->dev->dev_addr);
@@ -798,7 +798,7 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
                return;
 
        if (new_active) {
-               new_active->jiffies = jiffies;
+               new_active->last_link_up = jiffies;
 
                if (new_active->link == BOND_LINK_BACK) {
                        if (USES_PRIMARY(bond->params.mode)) {
@@ -1139,7 +1139,7 @@ static rx_handler_result_t bond_handle_frame(struct sk_buff **pskb)
                        kfree_skb(skb);
                        return RX_HANDLER_CONSUMED;
                }
-               memcpy(eth_hdr(skb)->h_dest, bond->dev->dev_addr, ETH_ALEN);
+               ether_addr_copy(eth_hdr(skb)->h_dest, bond->dev->dev_addr);
        }
 
        return ret;
@@ -1397,10 +1397,10 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
 
        bond_update_speed_duplex(new_slave);
 
-       new_slave->last_arp_rx = jiffies -
+       new_slave->last_rx = jiffies -
                (msecs_to_jiffies(bond->params.arp_interval) + 1);
        for (i = 0; i < BOND_MAX_ARP_TARGETS; i++)
-               new_slave->target_last_arp_rx[i] = new_slave->last_arp_rx;
+               new_slave->target_last_arp_rx[i] = new_slave->last_rx;
 
        if (bond->params.miimon && !bond->params.use_carrier) {
                link_reporting = bond_check_dev_link(bond, slave_dev, 1);
@@ -1444,7 +1444,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
        }
 
        if (new_slave->link != BOND_LINK_DOWN)
-               new_slave->jiffies = jiffies;
+               new_slave->last_link_up = jiffies;
        pr_debug("Initial state of slave_dev is BOND_LINK_%s\n",
                 new_slave->link == BOND_LINK_DOWN ? "DOWN" :
                 (new_slave->link == BOND_LINK_UP ? "UP" : "BACK"));
@@ -1538,9 +1538,11 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
        bond_set_carrier(bond);
 
        if (USES_PRIMARY(bond->params.mode)) {
+               block_netpoll_tx();
                write_lock_bh(&bond->curr_slave_lock);
                bond_select_active_slave(bond);
                write_unlock_bh(&bond->curr_slave_lock);
+               unblock_netpoll_tx();
        }
 
        pr_info("%s: Enslaving %s as %s interface with %s link\n",
@@ -1566,10 +1568,12 @@ err_detach:
        if (bond->primary_slave == new_slave)
                bond->primary_slave = NULL;
        if (bond->curr_active_slave == new_slave) {
+               block_netpoll_tx();
                write_lock_bh(&bond->curr_slave_lock);
                bond_change_active_slave(bond, NULL);
                bond_select_active_slave(bond);
                write_unlock_bh(&bond->curr_slave_lock);
+               unblock_netpoll_tx();
        }
        slave_disable_netpoll(new_slave);
 
@@ -1891,7 +1895,7 @@ static int bond_miimon_inspect(struct bonding *bond)
                                 * recovered before downdelay expired
                                 */
                                slave->link = BOND_LINK_UP;
-                               slave->jiffies = jiffies;
+                               slave->last_link_up = jiffies;
                                pr_info("%s: link status up again after %d ms for interface %s\n",
                                        bond->dev->name,
                                        (bond->params.downdelay - slave->delay) *
@@ -1966,7 +1970,7 @@ static void bond_miimon_commit(struct bonding *bond)
 
                case BOND_LINK_UP:
                        slave->link = BOND_LINK_UP;
-                       slave->jiffies = jiffies;
+                       slave->last_link_up = jiffies;
 
                        if (bond->params.mode == BOND_MODE_8023AD) {
                                /* prevent it from being the active one */
@@ -2242,7 +2246,7 @@ static void bond_validate_arp(struct bonding *bond, struct slave *slave, __be32
                pr_debug("bva: sip %pI4 not found in targets\n", &sip);
                return;
        }
-       slave->last_arp_rx = jiffies;
+       slave->last_rx = jiffies;
        slave->target_last_arp_rx[i] = jiffies;
 }
 
@@ -2250,6 +2254,7 @@ int bond_arp_rcv(const struct sk_buff *skb, struct bonding *bond,
                 struct slave *slave)
 {
        struct arphdr *arp = (struct arphdr *)skb->data;
+       struct slave *curr_active_slave;
        unsigned char *arp_ptr;
        __be32 sip, tip;
        int alen, is_arp = skb->protocol == __cpu_to_be16(ETH_P_ARP);
@@ -2257,7 +2262,7 @@ int bond_arp_rcv(const struct sk_buff *skb, struct bonding *bond,
        if (!slave_do_arp_validate(bond, slave)) {
                if ((slave_do_arp_validate_only(bond, slave) && is_arp) ||
                    !slave_do_arp_validate_only(bond, slave))
-                       slave->last_arp_rx = jiffies;
+                       slave->last_rx = jiffies;
                return RX_HANDLER_ANOTHER;
        } else if (!is_arp) {
                return RX_HANDLER_ANOTHER;
@@ -2295,6 +2300,8 @@ int bond_arp_rcv(const struct sk_buff *skb, struct bonding *bond,
                 bond->params.arp_validate, slave_do_arp_validate(bond, slave),
                 &sip, &tip);
 
+       curr_active_slave = rcu_dereference(bond->curr_active_slave);
+
        /*
         * Backup slaves won't see the ARP reply, but do come through
         * here for each ARP probe (so we swap the sip/tip to validate
@@ -2308,11 +2315,12 @@ int bond_arp_rcv(const struct sk_buff *skb, struct bonding *bond,
         * is done to avoid endless looping when we can't reach the
         * arp_ip_target and fool ourselves with our own arp requests.
         */
+
        if (bond_is_active_slave(slave))
                bond_validate_arp(bond, slave, sip, tip);
-       else if (bond->curr_active_slave &&
-                time_after(slave_last_rx(bond, bond->curr_active_slave),
-                           bond->curr_active_slave->jiffies))
+       else if (curr_active_slave &&
+                time_after(slave_last_rx(bond, curr_active_slave),
+                           curr_active_slave->last_link_up))
                bond_validate_arp(bond, slave, tip, sip);
 
 out_unlock:
@@ -2358,9 +2366,9 @@ static void bond_loadbalance_arp_mon(struct work_struct *work)
        oldcurrent = ACCESS_ONCE(bond->curr_active_slave);
        /* see if any of the previous devices are up now (i.e. they have
         * xmt and rcv traffic). the curr_active_slave does not come into
-        * the picture unless it is null. also, slave->jiffies is not needed
-        * here because we send an arp on each slave and give a slave as
-        * long as it needs to get the tx/rx within the delta.
+        * the picture unless it is null. also, slave->last_link_up is not
+        * needed here because we send an arp on each slave and give a slave
+        * as long as it needs to get the tx/rx within the delta.
         * TODO: what about up/down delay in arp mode? it wasn't here before
         *       so it can wait
         */
@@ -2369,7 +2377,7 @@ static void bond_loadbalance_arp_mon(struct work_struct *work)
 
                if (slave->link != BOND_LINK_UP) {
                        if (bond_time_in_interval(bond, trans_start, 1) &&
-                           bond_time_in_interval(bond, slave->last_arp_rx, 1)) {
+                           bond_time_in_interval(bond, slave->last_rx, 1)) {
 
                                slave->link  = BOND_LINK_UP;
                                slave_state_changed = 1;
@@ -2398,7 +2406,7 @@ static void bond_loadbalance_arp_mon(struct work_struct *work)
                         * if we don't know our ip yet
                         */
                        if (!bond_time_in_interval(bond, trans_start, 2) ||
-                           !bond_time_in_interval(bond, slave->last_arp_rx, 2)) {
+                           !bond_time_in_interval(bond, slave->last_rx, 2)) {
 
                                slave->link  = BOND_LINK_DOWN;
                                slave_state_changed = 1;
@@ -2486,7 +2494,7 @@ static int bond_ab_arp_inspect(struct bonding *bond)
                 * active.  This avoids bouncing, as the last receive
                 * times need a full ARP monitor cycle to be updated.
                 */
-               if (bond_time_in_interval(bond, slave->jiffies, 2))
+               if (bond_time_in_interval(bond, slave->last_link_up, 2))
                        continue;
 
                /*
@@ -2687,7 +2695,7 @@ static bool bond_ab_arp_probe(struct bonding *bond)
        new_slave->link = BOND_LINK_BACK;
        bond_set_slave_active_flags(new_slave);
        bond_arp_send_all(bond, new_slave);
-       new_slave->jiffies = jiffies;
+       new_slave->last_link_up = jiffies;
        rcu_assign_pointer(bond->current_arp_slave, new_slave);
        rtnl_unlock();
 
@@ -2858,9 +2866,12 @@ static int bond_slave_netdev_event(unsigned long event,
                pr_info("%s: Primary slave changed to %s, reselecting active slave\n",
                        bond->dev->name,
                        bond->primary_slave ? slave_dev->name : "none");
+
+               block_netpoll_tx();
                write_lock_bh(&bond->curr_slave_lock);
                bond_select_active_slave(bond);
                write_unlock_bh(&bond->curr_slave_lock);
+               unblock_netpoll_tx();
                break;
        case NETDEV_FEAT_CHANGE:
                bond_compute_features(bond);
@@ -3683,7 +3694,7 @@ static inline int bond_slave_override(struct bonding *bond,
 
 
 static u16 bond_select_queue(struct net_device *dev, struct sk_buff *skb,
-                            void *accel_priv)
+                            void *accel_priv, select_queue_fallback_t fallback)
 {
        /*
         * This helper function exists to help dev_pick_tx get the correct