aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
authorNikolay Aleksandrov <nikolay@redhat.com>2014-09-11 16:49:24 -0400
committerDavid S. Miller <davem@davemloft.net>2014-09-13 16:29:06 -0400
commit1c72cfdc96e63bf975cab514c4ca4d8a661ba0e6 (patch)
treeac7531a979920c5282f07fb71ad9f2c6a64d8ac4 /drivers/net
parent62c5f5185397f4bd8e5defe6fcb86420deeb2b38 (diff)
bonding: clean curr_slave_lock use
Mostly all users of curr_slave_lock already have RTNL as we've discussed previously so there's no point in using it, the one case where the lock must stay is the 3ad code, in fact it's the only one. It's okay to remove it from bond_do_fail_over_mac() as it's called with RTNL and drops the curr_slave_lock anyway. bond_change_active_slave() is one of the main places where curr_slave_lock was used, it's okay to remove it as all callers use RTNL these days before calling it, that's why we move the ASSERT_RTNL() in the beginning to catch any potential offenders to this rule. The RTNL argument actually applies to all of the places where curr_slave_lock has been removed from in this patch. Also remove the unnecessary bond_deref_active_protected() macro and use rtnl_dereference() instead. Signed-off-by: Nikolay Aleksandrov <nikolay@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/bonding/bond_alb.c4
-rw-r--r--drivers/net/bonding/bond_main.c62
-rw-r--r--drivers/net/bonding/bond_options.c10
-rw-r--r--drivers/net/bonding/bonding.h8
4 files changed, 14 insertions, 70 deletions
diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c
index cf4ede8594ff..b755659ddfdc 100644
--- a/drivers/net/bonding/bond_alb.c
+++ b/drivers/net/bonding/bond_alb.c
@@ -451,7 +451,7 @@ static struct slave *__rlb_next_rx_slave(struct bonding *bond)
451 */ 451 */
452static void rlb_teach_disabled_mac_on_primary(struct bonding *bond, u8 addr[]) 452static void rlb_teach_disabled_mac_on_primary(struct bonding *bond, u8 addr[])
453{ 453{
454 struct slave *curr_active = bond_deref_active_protected(bond); 454 struct slave *curr_active = rtnl_dereference(bond->curr_active_slave);
455 455
456 if (!curr_active) 456 if (!curr_active)
457 return; 457 return;
@@ -512,7 +512,7 @@ static void rlb_clear_slave(struct bonding *bond, struct slave *slave)
512 512
513 _unlock_rx_hashtbl_bh(bond); 513 _unlock_rx_hashtbl_bh(bond);
514 514
515 if (slave != bond_deref_active_protected(bond)) 515 if (slave != rtnl_dereference(bond->curr_active_slave))
516 rlb_teach_disabled_mac_on_primary(bond, slave->dev->dev_addr); 516 rlb_teach_disabled_mac_on_primary(bond, slave->dev->dev_addr);
517} 517}
518 518
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index b43b2df9e5d1..3b06685260b8 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -637,13 +637,11 @@ static void bond_set_dev_addr(struct net_device *bond_dev,
637 * 637 *
638 * Perform special MAC address swapping for fail_over_mac settings 638 * Perform special MAC address swapping for fail_over_mac settings
639 * 639 *
640 * Called with RTNL, curr_slave_lock for write_bh. 640 * Called with RTNL
641 */ 641 */
642static void bond_do_fail_over_mac(struct bonding *bond, 642static void bond_do_fail_over_mac(struct bonding *bond,
643 struct slave *new_active, 643 struct slave *new_active,
644 struct slave *old_active) 644 struct slave *old_active)
645 __releases(&bond->curr_slave_lock)
646 __acquires(&bond->curr_slave_lock)
647{ 645{
648 u8 tmp_mac[ETH_ALEN]; 646 u8 tmp_mac[ETH_ALEN];
649 struct sockaddr saddr; 647 struct sockaddr saddr;
@@ -651,11 +649,8 @@ static void bond_do_fail_over_mac(struct bonding *bond,
651 649
652 switch (bond->params.fail_over_mac) { 650 switch (bond->params.fail_over_mac) {
653 case BOND_FOM_ACTIVE: 651 case BOND_FOM_ACTIVE:
654 if (new_active) { 652 if (new_active)
655 write_unlock_bh(&bond->curr_slave_lock);
656 bond_set_dev_addr(bond->dev, new_active->dev); 653 bond_set_dev_addr(bond->dev, new_active->dev);
657 write_lock_bh(&bond->curr_slave_lock);
658 }
659 break; 654 break;
660 case BOND_FOM_FOLLOW: 655 case BOND_FOM_FOLLOW:
661 /* 656 /*
@@ -666,8 +661,6 @@ static void bond_do_fail_over_mac(struct bonding *bond,
666 if (!new_active) 661 if (!new_active)
667 return; 662 return;
668 663
669 write_unlock_bh(&bond->curr_slave_lock);
670
671 if (old_active) { 664 if (old_active) {
672 ether_addr_copy(tmp_mac, new_active->dev->dev_addr); 665 ether_addr_copy(tmp_mac, new_active->dev->dev_addr);
673 ether_addr_copy(saddr.sa_data, 666 ether_addr_copy(saddr.sa_data,
@@ -696,7 +689,6 @@ static void bond_do_fail_over_mac(struct bonding *bond,
696 netdev_err(bond->dev, "Error %d setting MAC of slave %s\n", 689 netdev_err(bond->dev, "Error %d setting MAC of slave %s\n",
697 -rv, new_active->dev->name); 690 -rv, new_active->dev->name);
698out: 691out:
699 write_lock_bh(&bond->curr_slave_lock);
700 break; 692 break;
701 default: 693 default:
702 netdev_err(bond->dev, "bond_do_fail_over_mac impossible: bad policy %d\n", 694 netdev_err(bond->dev, "bond_do_fail_over_mac impossible: bad policy %d\n",
@@ -709,7 +701,7 @@ out:
709static bool bond_should_change_active(struct bonding *bond) 701static bool bond_should_change_active(struct bonding *bond)
710{ 702{
711 struct slave *prim = rtnl_dereference(bond->primary_slave); 703 struct slave *prim = rtnl_dereference(bond->primary_slave);
712 struct slave *curr = bond_deref_active_protected(bond); 704 struct slave *curr = rtnl_dereference(bond->curr_active_slave);
713 705
714 if (!prim || !curr || curr->link != BOND_LINK_UP) 706 if (!prim || !curr || curr->link != BOND_LINK_UP)
715 return true; 707 return true;
@@ -785,15 +777,15 @@ static bool bond_should_notify_peers(struct bonding *bond)
785 * because it is apparently the best available slave we have, even though its 777 * because it is apparently the best available slave we have, even though its
786 * updelay hasn't timed out yet. 778 * updelay hasn't timed out yet.
787 * 779 *
788 * If new_active is not NULL, caller must hold curr_slave_lock for write_bh. 780 * Caller must hold RTNL.
789 */ 781 */
790void bond_change_active_slave(struct bonding *bond, struct slave *new_active) 782void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
791{ 783{
792 struct slave *old_active; 784 struct slave *old_active;
793 785
794 old_active = rcu_dereference_protected(bond->curr_active_slave, 786 ASSERT_RTNL();
795 !new_active || 787
796 lockdep_is_held(&bond->curr_slave_lock)); 788 old_active = rtnl_dereference(bond->curr_active_slave);
797 789
798 if (old_active == new_active) 790 if (old_active == new_active)
799 return; 791 return;
@@ -861,14 +853,10 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
861 bond_should_notify_peers(bond); 853 bond_should_notify_peers(bond);
862 } 854 }
863 855
864 write_unlock_bh(&bond->curr_slave_lock);
865
866 call_netdevice_notifiers(NETDEV_BONDING_FAILOVER, bond->dev); 856 call_netdevice_notifiers(NETDEV_BONDING_FAILOVER, bond->dev);
867 if (should_notify_peers) 857 if (should_notify_peers)
868 call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, 858 call_netdevice_notifiers(NETDEV_NOTIFY_PEERS,
869 bond->dev); 859 bond->dev);
870
871 write_lock_bh(&bond->curr_slave_lock);
872 } 860 }
873 } 861 }
874 862
@@ -893,7 +881,7 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
893 * - The primary_slave has got its link back. 881 * - The primary_slave has got its link back.
894 * - A slave has got its link back and there's no old curr_active_slave. 882 * - A slave has got its link back and there's no old curr_active_slave.
895 * 883 *
896 * Caller must hold curr_slave_lock for write_bh. 884 * Caller must hold RTNL.
897 */ 885 */
898void bond_select_active_slave(struct bonding *bond) 886void bond_select_active_slave(struct bonding *bond)
899{ 887{
@@ -901,7 +889,7 @@ void bond_select_active_slave(struct bonding *bond)
901 int rv; 889 int rv;
902 890
903 best_slave = bond_find_best_slave(bond); 891 best_slave = bond_find_best_slave(bond);
904 if (best_slave != bond_deref_active_protected(bond)) { 892 if (best_slave != rtnl_dereference(bond->curr_active_slave)) {
905 bond_change_active_slave(bond, best_slave); 893 bond_change_active_slave(bond, best_slave);
906 rv = bond_set_carrier(bond); 894 rv = bond_set_carrier(bond);
907 if (!rv) 895 if (!rv)
@@ -1571,9 +1559,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1571 1559
1572 if (bond_uses_primary(bond)) { 1560 if (bond_uses_primary(bond)) {
1573 block_netpoll_tx(); 1561 block_netpoll_tx();
1574 write_lock_bh(&bond->curr_slave_lock);
1575 bond_select_active_slave(bond); 1562 bond_select_active_slave(bond);
1576 write_unlock_bh(&bond->curr_slave_lock);
1577 unblock_netpoll_tx(); 1563 unblock_netpoll_tx();
1578 } 1564 }
1579 1565
@@ -1601,10 +1587,8 @@ err_detach:
1601 RCU_INIT_POINTER(bond->primary_slave, NULL); 1587 RCU_INIT_POINTER(bond->primary_slave, NULL);
1602 if (rcu_access_pointer(bond->curr_active_slave) == new_slave) { 1588 if (rcu_access_pointer(bond->curr_active_slave) == new_slave) {
1603 block_netpoll_tx(); 1589 block_netpoll_tx();
1604 write_lock_bh(&bond->curr_slave_lock);
1605 bond_change_active_slave(bond, NULL); 1590 bond_change_active_slave(bond, NULL);
1606 bond_select_active_slave(bond); 1591 bond_select_active_slave(bond);
1607 write_unlock_bh(&bond->curr_slave_lock);
1608 unblock_netpoll_tx(); 1592 unblock_netpoll_tx();
1609 } 1593 }
1610 /* either primary_slave or curr_active_slave might've changed */ 1594 /* either primary_slave or curr_active_slave might've changed */
@@ -1720,11 +1704,8 @@ static int __bond_release_one(struct net_device *bond_dev,
1720 if (rtnl_dereference(bond->primary_slave) == slave) 1704 if (rtnl_dereference(bond->primary_slave) == slave)
1721 RCU_INIT_POINTER(bond->primary_slave, NULL); 1705 RCU_INIT_POINTER(bond->primary_slave, NULL);
1722 1706
1723 if (oldcurrent == slave) { 1707 if (oldcurrent == slave)
1724 write_lock_bh(&bond->curr_slave_lock);
1725 bond_change_active_slave(bond, NULL); 1708 bond_change_active_slave(bond, NULL);
1726 write_unlock_bh(&bond->curr_slave_lock);
1727 }
1728 1709
1729 if (bond_is_lb(bond)) { 1710 if (bond_is_lb(bond)) {
1730 /* Must be called only after the slave has been 1711 /* Must be called only after the slave has been
@@ -1743,11 +1724,7 @@ static int __bond_release_one(struct net_device *bond_dev,
1743 * is no concern that another slave add/remove event 1724 * is no concern that another slave add/remove event
1744 * will interfere. 1725 * will interfere.
1745 */ 1726 */
1746 write_lock_bh(&bond->curr_slave_lock);
1747
1748 bond_select_active_slave(bond); 1727 bond_select_active_slave(bond);
1749
1750 write_unlock_bh(&bond->curr_slave_lock);
1751 } 1728 }
1752 1729
1753 if (!bond_has_slaves(bond)) { 1730 if (!bond_has_slaves(bond)) {
@@ -2058,9 +2035,7 @@ static void bond_miimon_commit(struct bonding *bond)
2058do_failover: 2035do_failover:
2059 ASSERT_RTNL(); 2036 ASSERT_RTNL();
2060 block_netpoll_tx(); 2037 block_netpoll_tx();
2061 write_lock_bh(&bond->curr_slave_lock);
2062 bond_select_active_slave(bond); 2038 bond_select_active_slave(bond);
2063 write_unlock_bh(&bond->curr_slave_lock);
2064 unblock_netpoll_tx(); 2039 unblock_netpoll_tx();
2065 } 2040 }
2066 2041
@@ -2506,15 +2481,8 @@ static void bond_loadbalance_arp_mon(struct work_struct *work)
2506 if (slave_state_changed) { 2481 if (slave_state_changed) {
2507 bond_slave_state_change(bond); 2482 bond_slave_state_change(bond);
2508 } else if (do_failover) { 2483 } else if (do_failover) {
2509 /* the bond_select_active_slave must hold RTNL
2510 * and curr_slave_lock for write.
2511 */
2512 block_netpoll_tx(); 2484 block_netpoll_tx();
2513 write_lock_bh(&bond->curr_slave_lock);
2514
2515 bond_select_active_slave(bond); 2485 bond_select_active_slave(bond);
2516
2517 write_unlock_bh(&bond->curr_slave_lock);
2518 unblock_netpoll_tx(); 2486 unblock_netpoll_tx();
2519 } 2487 }
2520 rtnl_unlock(); 2488 rtnl_unlock();
@@ -2670,9 +2638,7 @@ static void bond_ab_arp_commit(struct bonding *bond)
2670do_failover: 2638do_failover:
2671 ASSERT_RTNL(); 2639 ASSERT_RTNL();
2672 block_netpoll_tx(); 2640 block_netpoll_tx();
2673 write_lock_bh(&bond->curr_slave_lock);
2674 bond_select_active_slave(bond); 2641 bond_select_active_slave(bond);
2675 write_unlock_bh(&bond->curr_slave_lock);
2676 unblock_netpoll_tx(); 2642 unblock_netpoll_tx();
2677 } 2643 }
2678 2644
@@ -2939,9 +2905,7 @@ static int bond_slave_netdev_event(unsigned long event,
2939 primary ? slave_dev->name : "none"); 2905 primary ? slave_dev->name : "none");
2940 2906
2941 block_netpoll_tx(); 2907 block_netpoll_tx();
2942 write_lock_bh(&bond->curr_slave_lock);
2943 bond_select_active_slave(bond); 2908 bond_select_active_slave(bond);
2944 write_unlock_bh(&bond->curr_slave_lock);
2945 unblock_netpoll_tx(); 2909 unblock_netpoll_tx();
2946 break; 2910 break;
2947 case NETDEV_FEAT_CHANGE: 2911 case NETDEV_FEAT_CHANGE:
@@ -3106,7 +3070,6 @@ static int bond_open(struct net_device *bond_dev)
3106 3070
3107 /* reset slave->backup and slave->inactive */ 3071 /* reset slave->backup and slave->inactive */
3108 if (bond_has_slaves(bond)) { 3072 if (bond_has_slaves(bond)) {
3109 read_lock(&bond->curr_slave_lock);
3110 bond_for_each_slave(bond, slave, iter) { 3073 bond_for_each_slave(bond, slave, iter) {
3111 if (bond_uses_primary(bond) && 3074 if (bond_uses_primary(bond) &&
3112 slave != rcu_access_pointer(bond->curr_active_slave)) { 3075 slave != rcu_access_pointer(bond->curr_active_slave)) {
@@ -3117,7 +3080,6 @@ static int bond_open(struct net_device *bond_dev)
3117 BOND_SLAVE_NOTIFY_NOW); 3080 BOND_SLAVE_NOTIFY_NOW);
3118 } 3081 }
3119 } 3082 }
3120 read_unlock(&bond->curr_slave_lock);
3121 } 3083 }
3122 3084
3123 bond_work_init_all(bond); 3085 bond_work_init_all(bond);
@@ -3239,14 +3201,10 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
3239 if (!mii) 3201 if (!mii)
3240 return -EINVAL; 3202 return -EINVAL;
3241 3203
3242
3243 if (mii->reg_num == 1) { 3204 if (mii->reg_num == 1) {
3244 mii->val_out = 0; 3205 mii->val_out = 0;
3245 read_lock(&bond->curr_slave_lock);
3246 if (netif_carrier_ok(bond->dev)) 3206 if (netif_carrier_ok(bond->dev))
3247 mii->val_out = BMSR_LSTATUS; 3207 mii->val_out = BMSR_LSTATUS;
3248
3249 read_unlock(&bond->curr_slave_lock);
3250 } 3208 }
3251 3209
3252 return 0; 3210 return 0;
diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c
index 534c0600484e..b62697f4a3de 100644
--- a/drivers/net/bonding/bond_options.c
+++ b/drivers/net/bonding/bond_options.c
@@ -734,15 +734,13 @@ static int bond_option_active_slave_set(struct bonding *bond,
734 } 734 }
735 735
736 block_netpoll_tx(); 736 block_netpoll_tx();
737 write_lock_bh(&bond->curr_slave_lock);
738
739 /* check to see if we are clearing active */ 737 /* check to see if we are clearing active */
740 if (!slave_dev) { 738 if (!slave_dev) {
741 netdev_info(bond->dev, "Clearing current active slave\n"); 739 netdev_info(bond->dev, "Clearing current active slave\n");
742 RCU_INIT_POINTER(bond->curr_active_slave, NULL); 740 RCU_INIT_POINTER(bond->curr_active_slave, NULL);
743 bond_select_active_slave(bond); 741 bond_select_active_slave(bond);
744 } else { 742 } else {
745 struct slave *old_active = bond_deref_active_protected(bond); 743 struct slave *old_active = rtnl_dereference(bond->curr_active_slave);
746 struct slave *new_active = bond_slave_get_rtnl(slave_dev); 744 struct slave *new_active = bond_slave_get_rtnl(slave_dev);
747 745
748 BUG_ON(!new_active); 746 BUG_ON(!new_active);
@@ -765,8 +763,6 @@ static int bond_option_active_slave_set(struct bonding *bond,
765 } 763 }
766 } 764 }
767 } 765 }
768
769 write_unlock_bh(&bond->curr_slave_lock);
770 unblock_netpoll_tx(); 766 unblock_netpoll_tx();
771 767
772 return ret; 768 return ret;
@@ -1066,7 +1062,6 @@ static int bond_option_primary_set(struct bonding *bond,
1066 struct slave *slave; 1062 struct slave *slave;
1067 1063
1068 block_netpoll_tx(); 1064 block_netpoll_tx();
1069 write_lock_bh(&bond->curr_slave_lock);
1070 1065
1071 p = strchr(primary, '\n'); 1066 p = strchr(primary, '\n');
1072 if (p) 1067 if (p)
@@ -1103,7 +1098,6 @@ static int bond_option_primary_set(struct bonding *bond,
1103 primary, bond->dev->name); 1098 primary, bond->dev->name);
1104 1099
1105out: 1100out:
1106 write_unlock_bh(&bond->curr_slave_lock);
1107 unblock_netpoll_tx(); 1101 unblock_netpoll_tx();
1108 1102
1109 return 0; 1103 return 0;
@@ -1117,9 +1111,7 @@ static int bond_option_primary_reselect_set(struct bonding *bond,
1117 bond->params.primary_reselect = newval->value; 1111 bond->params.primary_reselect = newval->value;
1118 1112
1119 block_netpoll_tx(); 1113 block_netpoll_tx();
1120 write_lock_bh(&bond->curr_slave_lock);
1121 bond_select_active_slave(bond); 1114 bond_select_active_slave(bond);
1122 write_unlock_bh(&bond->curr_slave_lock);
1123 unblock_netpoll_tx(); 1115 unblock_netpoll_tx();
1124 1116
1125 return 0; 1117 return 0;
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index 78c461abaa09..02afdeb08765 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -184,9 +184,7 @@ struct slave {
184 184
185/* 185/*
186 * Here are the locking policies for the two bonding locks: 186 * Here are the locking policies for the two bonding locks:
187 * 187 * Get rcu_read_lock when reading or RTNL when writing slave list.
188 * 1) Get rcu_read_lock when reading or RTNL when writing slave list.
189 * 2) Get bond->curr_slave_lock when reading/writing bond->curr_active_slave.
190 */ 188 */
191struct bonding { 189struct bonding {
192 struct net_device *dev; /* first - useful for panic debug */ 190 struct net_device *dev; /* first - useful for panic debug */
@@ -227,10 +225,6 @@ struct bonding {
227#define bond_slave_get_rtnl(dev) \ 225#define bond_slave_get_rtnl(dev) \
228 ((struct slave *) rtnl_dereference(dev->rx_handler_data)) 226 ((struct slave *) rtnl_dereference(dev->rx_handler_data))
229 227
230#define bond_deref_active_protected(bond) \
231 rcu_dereference_protected(bond->curr_active_slave, \
232 lockdep_is_held(&bond->curr_slave_lock))
233
234struct bond_vlan_tag { 228struct bond_vlan_tag {
235 __be16 vlan_proto; 229 __be16 vlan_proto;
236 unsigned short vlan_id; 230 unsigned short vlan_id;