* [PATCH net-next 0/5] bonding: locking simplifications and cleanup
@ 2013-09-02 11:51 Nikolay Aleksandrov
2013-09-02 11:51 ` [PATCH net-next 1/5] bonding: simplify and fix peer notification Nikolay Aleksandrov
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: Nikolay Aleksandrov @ 2013-09-02 11:51 UTC (permalink / raw)
To: netdev; +Cc: andy, fubar, davem
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(-)
--
1.8.1.4
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH net-next 1/5] bonding: simplify and fix peer notification
2013-09-02 11:51 [PATCH net-next 0/5] bonding: locking simplifications and cleanup Nikolay Aleksandrov
@ 2013-09-02 11:51 ` Nikolay Aleksandrov
2013-09-02 11:51 ` [PATCH net-next 2/5] bonding: trivial: remove outdated comment and braces Nikolay Aleksandrov
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Nikolay Aleksandrov @ 2013-09-02 11:51 UTC (permalink / raw)
To: netdev; +Cc: andy, fubar, davem
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.
Signed-off-by: Nikolay Aleksandrov <nikolay@redhat.com>
---
drivers/net/bonding/bond_main.c | 22 +++++++---------------
1 file changed, 7 insertions(+), 15 deletions(-)
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index c50679f..05e638b 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -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
--
1.8.1.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net-next 2/5] bonding: trivial: remove outdated comment and braces
2013-09-02 11:51 [PATCH net-next 0/5] bonding: locking simplifications and cleanup Nikolay Aleksandrov
2013-09-02 11:51 ` [PATCH net-next 1/5] bonding: simplify and fix peer notification Nikolay Aleksandrov
@ 2013-09-02 11:51 ` Nikolay Aleksandrov
2013-09-02 11:51 ` [PATCH net-next 3/5] bonding: simplify bond_3ad_update_lacp_rate and use RTNL for sync Nikolay Aleksandrov
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Nikolay Aleksandrov @ 2013-09-02 11:51 UTC (permalink / raw)
To: netdev; +Cc: andy, fubar, davem
We 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.
Signed-off-by: Nikolay Aleksandrov <nikolay@redhat.com>
---
drivers/net/bonding/bond_main.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 05e638b..486e041 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -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;
--
1.8.1.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net-next 3/5] bonding: simplify bond_3ad_update_lacp_rate and use RTNL for sync
2013-09-02 11:51 [PATCH net-next 0/5] bonding: locking simplifications and cleanup Nikolay Aleksandrov
2013-09-02 11:51 ` [PATCH net-next 1/5] bonding: simplify and fix peer notification Nikolay Aleksandrov
2013-09-02 11:51 ` [PATCH net-next 2/5] bonding: trivial: remove outdated comment and braces Nikolay Aleksandrov
@ 2013-09-02 11:51 ` Nikolay Aleksandrov
2013-09-02 11:51 ` [PATCH net-next 4/5] bonding: drop read_lock in bond_fix_features Nikolay Aleksandrov
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Nikolay Aleksandrov @ 2013-09-02 11:51 UTC (permalink / raw)
To: netdev; +Cc: andy, fubar, davem
We 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.
Signed-off-by: Nikolay Aleksandrov <nikolay@redhat.com>
---
drivers/net/bonding/bond_3ad.c | 8 +-------
drivers/net/bonding/bond_sysfs.c | 7 ++++++-
2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c
index 9010265..0d8f427 100644
--- a/drivers/net/bonding/bond_3ad.c
+++ b/drivers/net/bonding/bond_3ad.c
@@ -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);
}
diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
index 0f539de..ce46776 100644
--- a/drivers/net/bonding/bond_sysfs.c
+++ b/drivers/net/bonding/bond_sysfs.c
@@ -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,
--
1.8.1.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net-next 4/5] bonding: drop read_lock in bond_fix_features
2013-09-02 11:51 [PATCH net-next 0/5] bonding: locking simplifications and cleanup Nikolay Aleksandrov
` (2 preceding siblings ...)
2013-09-02 11:51 ` [PATCH net-next 3/5] bonding: simplify bond_3ad_update_lacp_rate and use RTNL for sync Nikolay Aleksandrov
@ 2013-09-02 11:51 ` Nikolay Aleksandrov
2013-09-02 11:51 ` [PATCH net-next 5/5] bonding: drop read_lock in bond_compute_features Nikolay Aleksandrov
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Nikolay Aleksandrov @ 2013-09-02 11:51 UTC (permalink / raw)
To: netdev; +Cc: andy, fubar, davem
We're protected by RTNL so nothing can happen and we can safely drop the
read bond->lock.
Signed-off-by: Nikolay Aleksandrov <nikolay@redhat.com>
---
drivers/net/bonding/bond_main.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 486e041..c5ebdc5 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -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;
}
--
1.8.1.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net-next 5/5] bonding: drop read_lock in bond_compute_features
2013-09-02 11:51 [PATCH net-next 0/5] bonding: locking simplifications and cleanup Nikolay Aleksandrov
` (3 preceding siblings ...)
2013-09-02 11:51 ` [PATCH net-next 4/5] bonding: drop read_lock in bond_fix_features Nikolay Aleksandrov
@ 2013-09-02 11:51 ` Nikolay Aleksandrov
2013-09-03 1:48 ` [PATCH net-next 0/5] bonding: locking simplifications and cleanup Ding Tianhong
2013-09-04 4:52 ` David Miller
6 siblings, 0 replies; 8+ messages in thread
From: Nikolay Aleksandrov @ 2013-09-02 11:51 UTC (permalink / raw)
To: netdev; +Cc: andy, fubar, davem
bond_compute_features is always called with RTNL held, so we can safely
drop the read bond->lock.
Signed-off-by: Nikolay Aleksandrov <nikolay@redhat.com>
---
drivers/net/bonding/bond_main.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index c5ebdc5..39e5b1c 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -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);
}
--
1.8.1.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH net-next 0/5] bonding: locking simplifications and cleanup
2013-09-02 11:51 [PATCH net-next 0/5] bonding: locking simplifications and cleanup Nikolay Aleksandrov
` (4 preceding siblings ...)
2013-09-02 11:51 ` [PATCH net-next 5/5] bonding: drop read_lock in bond_compute_features Nikolay Aleksandrov
@ 2013-09-03 1:48 ` Ding Tianhong
2013-09-04 4:52 ` David Miller
6 siblings, 0 replies; 8+ messages in thread
From: Ding Tianhong @ 2013-09-03 1:48 UTC (permalink / raw)
To: Nikolay Aleksandrov; +Cc: netdev, andy, fubar, davem
On 2013/9/2 19:51, Nikolay Aleksandrov wrote:
> 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(-)
>
Reviewed-by: Ding Tianhong <dingtianhong@huawei.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH net-next 0/5] bonding: locking simplifications and cleanup
2013-09-02 11:51 [PATCH net-next 0/5] bonding: locking simplifications and cleanup Nikolay Aleksandrov
` (5 preceding siblings ...)
2013-09-03 1:48 ` [PATCH net-next 0/5] bonding: locking simplifications and cleanup Ding Tianhong
@ 2013-09-04 4:52 ` David Miller
6 siblings, 0 replies; 8+ messages in thread
From: David Miller @ 2013-09-04 4:52 UTC (permalink / raw)
To: nikolay; +Cc: netdev, andy, fubar
From: Nikolay Aleksandrov <nikolay@redhat.com>
Date: Mon, 2 Sep 2013 13:51:37 +0200
> 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.
Series applied.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2013-09-04 4:52 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-02 11:51 [PATCH net-next 0/5] bonding: locking simplifications and cleanup Nikolay Aleksandrov
2013-09-02 11:51 ` [PATCH net-next 1/5] bonding: simplify and fix peer notification Nikolay Aleksandrov
2013-09-02 11:51 ` [PATCH net-next 2/5] bonding: trivial: remove outdated comment and braces Nikolay Aleksandrov
2013-09-02 11:51 ` [PATCH net-next 3/5] bonding: simplify bond_3ad_update_lacp_rate and use RTNL for sync Nikolay Aleksandrov
2013-09-02 11:51 ` [PATCH net-next 4/5] bonding: drop read_lock in bond_fix_features Nikolay Aleksandrov
2013-09-02 11:51 ` [PATCH net-next 5/5] bonding: drop read_lock in bond_compute_features Nikolay Aleksandrov
2013-09-03 1:48 ` [PATCH net-next 0/5] bonding: locking simplifications and cleanup Ding Tianhong
2013-09-04 4:52 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).