bonding: locking simplifications and cleanup
Subsystems (3)
cover bonding: locking simplifications and cleanup
Hello,
This small patchset aims to remove some use cases of bond->lock for mutual exclusion which will help in the RCUfication of the function users. It also does some small style cleanups and fixes.
Patch 01 - Drops the use of bond->lock as mutual exclusion for peer notification and relies on RTNL being held when send_peer_notif is modified Patch 02 - trivial outdated comment removal
Patch 03 - Drops the use of bond->lock as mutual exclusion for lacp rate update and relies on RTNL, also fixes possible races with mode change Patch 04 - Drops read_lock in bond_fix_features because RTNL is held Patch 05 - Drops read_lock in bond_compute_features because RTNL is held whenever it's called
Best regards,
Nikolay Aleksandrov
Nikolay Aleksandrov (5):
bonding: simplify and fix peer notification
bonding: trivial: remove outdated comment and braces
bonding: simplify bond_3ad_update_lacp_rate and use RTNL for sync
bonding: drop read_lock in bond_fix_features
bonding: drop read_lock in bond_compute_features
drivers/net/bonding/bond_3ad.c | 8 +------ drivers/net/bonding/bond_main.c | 48 ++++++++++++---------------------------- drivers/net/bonding/bond_sysfs.c | 7 +++++- 3 files changed, 21 insertions(+), 42 deletions(-)
Signature · 1 line
1.8.1.4
PATCH 1/5 bonding: simplify and fix peer notification
This patch aims to remove a use of the bond->lock for mutual exclusion which will later allow easier migration to RCU of the users of this functionality. We use RTNL as a synchronizing mechanism since it's always held when send_peer_notif is set, and when it is decremented from the notifier function. We can also drop some locking, and fix the leakage of the send_peer_notif counter.
--- drivers/net/bonding/bond_main.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-)
drivers/net/bonding/bond_main.c +7 -15
@@ -828,7 +828,6 @@ static bool bond_should_notify_peers(struct bonding *bond) test_bit(__LINK_STATE_LINKWATCH_PENDING, &slave->dev->state))return false; - bond->send_peer_notif--;return true; }
@@ -2259,12 +2258,8 @@ re_arm:read_unlock (&bond->lock);if (should_notify_peers) { -if (!rtnl_trylock ()) { -read_lock (&bond->lock); - bond->send_peer_notif++; -read_unlock (&bond->lock); +if (!rtnl_trylock ())return ; - }call_netdevice_notifiers (NETDEV_NOTIFY_PEERS , bond->dev);rtnl_unlock (); }
@@ -2876,12 +2871,8 @@ re_arm:read_unlock (&bond->lock);if (should_notify_peers) { -if (!rtnl_trylock ()) { -read_lock (&bond->lock); - bond->send_peer_notif++; -read_unlock (&bond->lock); +if (!rtnl_trylock ())return ; - }call_netdevice_notifiers (NETDEV_NOTIFY_PEERS , bond->dev);rtnl_unlock (); }
@@ -2916,6 +2907,10 @@ static int bond_master_netdev_event(unsigned long event,case NETDEV_REGISTER :bond_create_proc_entry (event_bond);break ; +case NETDEV_NOTIFY_PEERS : +if (event_bond->send_peer_notif) + event_bond->send_peer_notif--; +break ;default :break ; }
@@ -3213,11 +3208,8 @@ static int bond_close(struct net_device *bond_dev) {struct bonding *bond =netdev_priv (bond_dev); -write_lock_bh (&bond->lock); - bond->send_peer_notif =0 ; -write_unlock_bh (&bond->lock); -bond_work_cancel_all (bond); + bond->send_peer_notif =0 ;if (bond_is_lb (bond)) {/* Must be called only after all * slaves have been released
Signature · 1 line
1.8.1.4
PATCH 2/5 bonding: trivial: remove outdated comment and braces
In reply to Nikolay AleksandrovWe don't have to release all slaves when closing the bond dev, so remove the outdated comment and the braces around the left single statement.
--- drivers/net/bonding/bond_main.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/net/bonding/bond_main.c +1 -5
@@ -3210,12 +3210,8 @@ static int bond_close(struct net_device *bond_dev)bond_work_cancel_all (bond); bond->send_peer_notif =0 ; -if (bond_is_lb (bond)) { -/* Must be called only after all -* slaves have been released -*/ +if (bond_is_lb (bond))bond_alb_deinitialize (bond); - } bond->recv_probe =NULL ;return 0 ;
Signature · 1 line
1.8.1.4
PATCH 3/5 bonding: simplify bond_3ad_update_lacp_rate and use RTNL for sync
In reply to Nikolay AleksandrovWe can drop the use of bond->lock for mutual exclusion in bond_3ad_update_lacp_rate and use RTNL in the sysfs store function instead. This way we'll prevent races with mode change and interface up/down as well as simplify update_lacp_rate by removing the check for port->slave because it'll always be initialized (done while enslaving with RTNL). This change will also help in the future removal of reader bond->lock from bond_enslave.
--- drivers/net/bonding/bond_3ad.c | 8 +------- drivers/net/bonding/bond_sysfs.c | 7 ++++++- 2 files changed, 7 insertions(+), 8 deletions(-)
drivers/net/bonding/bond_3ad.c +1 -7
@@ -2514,17 +2514,13 @@ int bond_3ad_lacpdu_recv(const struct sk_buff *skb, struct bonding *bond,*/ void bond_3ad_update_lacp_rate (struct bonding *bond) { -struct slave *slave;struct port *port =NULL ; +struct slave *slave;int lacp_fast; -write_lock_bh (&bond->lock); lacp_fast = bond->params.lacp_fast; -bond_for_each_slave (bond, slave) { port = &(SLAVE_AD_INFO (slave).port); -if (port->slave ==NULL ) -continue ;__get_state_machine_lock (port);if (lacp_fast) port->actor_oper_port_state |=AD_STATE_LACP_TIMEOUT ;
@@ -2532,6 +2528,4 @@ void bond_3ad_update_lacp_rate(struct bonding *bond) port->actor_oper_port_state &= ~AD_STATE_LACP_TIMEOUT ;__release_state_machine_lock (port); } - -write_unlock_bh (&bond->lock); }
drivers/net/bonding/bond_sysfs.c +6 -1
@@ -852,8 +852,11 @@ static ssize_t bonding_store_lacp(struct device *d,struct device_attribute *attr, const char *buf, size_t count) { - int new_value, ret = count; struct bonding *bond = to_bond(d); +int new_value, ret = count; + +if (!rtnl_trylock ()) +return restart_syscall ();if (bond->dev->flags &IFF_UP ) { pr_err("%s: Unable to update LACP rate because interface is up.\n",
@@ -883,6 +886,8 @@ static ssize_t bonding_store_lacp(struct device *d, ret = -EINVAL ; } out: +rtnl_unlock (); +return ret; } static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR,
Signature · 1 line
1.8.1.4
PATCH 4/5 bonding: drop read_lock in bond_fix_features
In reply to Nikolay AleksandrovWe're protected by RTNL so nothing can happen and we can safely drop the read bond->lock.
--- drivers/net/bonding/bond_main.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/net/bonding/bond_main.c +3 -7
@@ -1084,18 +1084,16 @@ static void bond_netpoll_cleanup(struct net_device *bond_dev)/*---------------------------------- IOCTL ----------------------------------*/ static netdev_features_t bond_fix_features (struct net_device *dev, -netdev_features_t features) +netdev_features_t features) { -struct slave *slave;struct bonding *bond =netdev_priv (dev);netdev_features_t mask; - -read_lock (&bond->lock); +struct slave *slave;if (list_empty (&bond->slave_list)) {/* Disable adding VLANs to empty bond. But why? --mq */ features |=NETIF_F_VLAN_CHALLENGED ; - goto out; +return features; } mask = features;
@@ -1109,8 +1107,6 @@ static netdev_features_t bond_fix_features(struct net_device *dev, } features =netdev_add_tso_features (features, mask); -out: -read_unlock (&bond->lock);return features; }
Signature · 1 line
1.8.1.4
PATCH 5/5 bonding: drop read_lock in bond_compute_features
In reply to Nikolay Aleksandrovbond_compute_features is always called with RTNL held, so we can safely drop the read bond->lock.
--- drivers/net/bonding/bond_main.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/net/bonding/bond_main.c +3 -7
@@ -1116,15 +1116,13 @@ static netdev_features_t bond_fix_features(struct net_device *dev,static void bond_compute_features (struct bonding *bond) { -struct slave *slave; -struct net_device *bond_dev = bond->dev; +unsigned int flags, dst_release_flag =IFF_XMIT_DST_RELEASE ;netdev_features_t vlan_features =BOND_VLAN_FEATURES ;unsigned short max_hard_header_len =ETH_HLEN ;unsigned int gso_max_size =GSO_MAX_SIZE ; +struct net_device *bond_dev = bond->dev;u16 gso_max_segs =GSO_MAX_SEGS ; -unsigned int flags, dst_release_flag =IFF_XMIT_DST_RELEASE ; - -read_lock (&bond->lock); +struct slave *slave;if (list_empty (&bond->slave_list)) goto done;
@@ -1150,8 +1148,6 @@ done: flags = bond_dev->priv_flags & ~IFF_XMIT_DST_RELEASE ; bond_dev->priv_flags = flags | dst_release_flag; -read_unlock (&bond->lock); -netdev_change_features (bond_dev); }
Signature · 1 line
1.8.1.4
Quoted 24 lines · Nikolay Aleksandrov
Hello,
This small patchset aims to remove some use cases ofbond->lockfor mutual exclusion which will help in the RCUfication of the function users. It also does some small style cleanups and fixes.Patch 01 - Drops the use of
bond->lockas mutual exclusion for peer notification and relies on RTNL being held whensend_peer_notifis modified Patch 02 - trivial outdated comment removal
Patch 03 - Drops the use ofbond->lockas mutual exclusion for lacp rate update and relies on RTNL, also fixes possible races with mode change Patch 04 - Dropsread_lockinbond_fix_featuresbecause RTNL is held Patch 05 - Dropsread_lockinbond_compute_featuresbecause RTNL is held whenever it's calledBest regards,
Nikolay AleksandrovNikolay Aleksandrov (5):
bonding: simplify and fix peer notification
bonding: trivial: remove outdated comment and braces
bonding: simplifybond_3ad_update_lacp_rateand use RTNL for sync
bonding: dropread_lockinbond_fix_features
bonding: dropread_lockinbond_compute_features
Quoted 5 lines
drivers/net/bonding/bond_3ad.c | 8 +------ drivers/net/bonding/bond_main.c | 48 ++++++++++++---------------------------- drivers/net/bonding/bond_sysfs.c | 7 +++++- 3 files changed, 21 insertions(+), 42 deletions(-)
David Miller
maintainerFrom: Nikolay Aleksandrov <[email protected]>
Date: Mon, 2 Sep 2013 13:51:37 +0200
Quoted 3 lines
This small patchset aims to remove some use cases of
bond->lockfor mutual exclusion which will help in the RCUfication of the function users. It also does some small style cleanups and fixes.
Series applied.