Skip to content

Commit

Permalink
Merge branch 'bonding-next'
Browse files Browse the repository at this point in the history
Nikolay Aleksandrov says:

====================
bonding: get rid of curr_slave_lock

This is the second patch-set dealing with bond locking and the purpose here
is to convert curr_slave_lock into a spinlock called "mode_lock" which can
be used in the various modes for their specific needs. The first three
patches cleanup the use of curr_slave_lock and prepare it for the
conversion which is done in patch 4 and then the modes that were using
their own locks are converted to use the new "mode_lock" giving us the
opportunity to remove their locks.
This patch-set has been tested in each mode by running enslave/release of
slaves in parallel with traffic transmission and miimon=1 i.e. running
all the time. In fact this lead to the discovery of a subtle bug related to
RCU which will be fixed in -net.
Also did an allmodconfig test just in case :-)

v2: fix bond_3ad_state_machine_handler's use of mode_lock and
    curr_slave_lock
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Sep 13, 2014
2 parents b25bd25 + 8c0bc55 commit 8801d48
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 274 deletions.
84 changes: 26 additions & 58 deletions drivers/net/bonding/bond_3ad.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,24 +233,6 @@ static inline int __check_agg_selection_timer(struct port *port)
return BOND_AD_INFO(bond).agg_select_timer ? 1 : 0;
}

/**
* __get_state_machine_lock - lock the port's state machines
* @port: the port we're looking at
*/
static inline void __get_state_machine_lock(struct port *port)
{
spin_lock_bh(&(SLAVE_AD_INFO(port->slave)->state_machine_lock));
}

/**
* __release_state_machine_lock - unlock the port's state machines
* @port: the port we're looking at
*/
static inline void __release_state_machine_lock(struct port *port)
{
spin_unlock_bh(&(SLAVE_AD_INFO(port->slave)->state_machine_lock));
}

/**
* __get_link_speed - get a port's speed
* @port: the port we're looking at
Expand Down Expand Up @@ -341,16 +323,6 @@ static u8 __get_duplex(struct port *port)
return retval;
}

/**
* __initialize_port_locks - initialize a port's STATE machine spinlock
* @port: the slave of the port we're looking at
*/
static inline void __initialize_port_locks(struct slave *slave)
{
/* make sure it isn't called twice */
spin_lock_init(&(SLAVE_AD_INFO(slave)->state_machine_lock));
}

/* Conversions */

/**
Expand Down Expand Up @@ -1843,7 +1815,6 @@ void bond_3ad_bind_slave(struct slave *slave)

ad_initialize_port(port, bond->params.lacp_fast);

__initialize_port_locks(slave);
port->slave = slave;
port->actor_port_number = SLAVE_AD_INFO(slave)->id;
/* key is determined according to the link speed, duplex and user key(which
Expand Down Expand Up @@ -1899,14 +1870,16 @@ void bond_3ad_unbind_slave(struct slave *slave)
struct slave *slave_iter;
struct list_head *iter;

/* Sync against bond_3ad_state_machine_handler() */
spin_lock_bh(&bond->mode_lock);
aggregator = &(SLAVE_AD_INFO(slave)->aggregator);
port = &(SLAVE_AD_INFO(slave)->port);

/* if slave is null, the whole port is not initialized */
if (!port->slave) {
netdev_warn(bond->dev, "Trying to unbind an uninitialized port on %s\n",
slave->dev->name);
return;
goto out;
}

netdev_dbg(bond->dev, "Unbinding Link Aggregation Group %d\n",
Expand Down Expand Up @@ -2032,6 +2005,9 @@ void bond_3ad_unbind_slave(struct slave *slave)
}
}
port->slave = NULL;

out:
spin_unlock_bh(&bond->mode_lock);
}

/**
Expand All @@ -2057,7 +2033,11 @@ void bond_3ad_state_machine_handler(struct work_struct *work)
struct port *port;
bool should_notify_rtnl = BOND_SLAVE_NOTIFY_LATER;

read_lock(&bond->curr_slave_lock);
/* Lock to protect data accessed by all (e.g., port->sm_vars) and
* against running with bond_3ad_unbind_slave. ad_rx_machine may run
* concurrently due to incoming LACPDU as well.
*/
spin_lock_bh(&bond->mode_lock);
rcu_read_lock();

/* check if there are any slaves */
Expand Down Expand Up @@ -2093,12 +2073,6 @@ void bond_3ad_state_machine_handler(struct work_struct *work)
goto re_arm;
}

/* Lock around state machines to protect data accessed
* by all (e.g., port->sm_vars). ad_rx_machine may run
* concurrently due to incoming LACPDU.
*/
__get_state_machine_lock(port);

ad_rx_machine(NULL, port);
ad_periodic_machine(port);
ad_port_selection_logic(port);
Expand All @@ -2108,8 +2082,6 @@ void bond_3ad_state_machine_handler(struct work_struct *work)
/* turn off the BEGIN bit, since we already handled it */
if (port->sm_vars & AD_PORT_BEGIN)
port->sm_vars &= ~AD_PORT_BEGIN;

__release_state_machine_lock(port);
}

re_arm:
Expand All @@ -2120,7 +2092,7 @@ void bond_3ad_state_machine_handler(struct work_struct *work)
}
}
rcu_read_unlock();
read_unlock(&bond->curr_slave_lock);
spin_unlock_bh(&bond->mode_lock);

if (should_notify_rtnl && rtnl_trylock()) {
bond_slave_state_notify(bond);
Expand Down Expand Up @@ -2161,9 +2133,9 @@ static int bond_3ad_rx_indication(struct lacpdu *lacpdu, struct slave *slave,
netdev_dbg(slave->bond->dev, "Received LACPDU on port %d\n",
port->actor_port_number);
/* Protect against concurrent state machines */
__get_state_machine_lock(port);
spin_lock(&slave->bond->mode_lock);
ad_rx_machine(lacpdu, port);
__release_state_machine_lock(port);
spin_unlock(&slave->bond->mode_lock);
break;

case AD_TYPE_MARKER:
Expand Down Expand Up @@ -2213,7 +2185,7 @@ void bond_3ad_adapter_speed_changed(struct slave *slave)
return;
}

__get_state_machine_lock(port);
spin_lock_bh(&slave->bond->mode_lock);

port->actor_admin_port_key &= ~AD_SPEED_KEY_BITS;
port->actor_oper_port_key = port->actor_admin_port_key |=
Expand All @@ -2224,7 +2196,7 @@ void bond_3ad_adapter_speed_changed(struct slave *slave)
*/
port->sm_vars |= AD_PORT_BEGIN;

__release_state_machine_lock(port);
spin_unlock_bh(&slave->bond->mode_lock);
}

/**
Expand All @@ -2246,7 +2218,7 @@ void bond_3ad_adapter_duplex_changed(struct slave *slave)
return;
}

__get_state_machine_lock(port);
spin_lock_bh(&slave->bond->mode_lock);

port->actor_admin_port_key &= ~AD_DUPLEX_KEY_BITS;
port->actor_oper_port_key = port->actor_admin_port_key |=
Expand All @@ -2257,7 +2229,7 @@ void bond_3ad_adapter_duplex_changed(struct slave *slave)
*/
port->sm_vars |= AD_PORT_BEGIN;

__release_state_machine_lock(port);
spin_unlock_bh(&slave->bond->mode_lock);
}

/**
Expand All @@ -2280,7 +2252,7 @@ void bond_3ad_handle_link_change(struct slave *slave, char link)
return;
}

__get_state_machine_lock(port);
spin_lock_bh(&slave->bond->mode_lock);
/* on link down we are zeroing duplex and speed since
* some of the adaptors(ce1000.lan) report full duplex/speed
* instead of N/A(duplex) / 0(speed).
Expand Down Expand Up @@ -2311,7 +2283,7 @@ void bond_3ad_handle_link_change(struct slave *slave, char link)
*/
port->sm_vars |= AD_PORT_BEGIN;

__release_state_machine_lock(port);
spin_unlock_bh(&slave->bond->mode_lock);
}

/**
Expand Down Expand Up @@ -2476,20 +2448,16 @@ int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev)
int bond_3ad_lacpdu_recv(const struct sk_buff *skb, struct bonding *bond,
struct slave *slave)
{
int ret = RX_HANDLER_ANOTHER;
struct lacpdu *lacpdu, _lacpdu;

if (skb->protocol != PKT_TYPE_LACPDU)
return ret;
return RX_HANDLER_ANOTHER;

lacpdu = skb_header_pointer(skb, 0, sizeof(_lacpdu), &_lacpdu);
if (!lacpdu)
return ret;
return RX_HANDLER_ANOTHER;

read_lock(&bond->curr_slave_lock);
ret = bond_3ad_rx_indication(lacpdu, slave, skb->len);
read_unlock(&bond->curr_slave_lock);
return ret;
return bond_3ad_rx_indication(lacpdu, slave, skb->len);
}

/**
Expand All @@ -2499,7 +2467,7 @@ int bond_3ad_lacpdu_recv(const struct sk_buff *skb, struct bonding *bond,
* When modify lacp_rate parameter via sysfs,
* update actor_oper_port_state of each port.
*
* Hold slave->state_machine_lock,
* Hold bond->mode_lock,
* so we can modify port->actor_oper_port_state,
* no matter bond is up or down.
*/
Expand All @@ -2511,13 +2479,13 @@ void bond_3ad_update_lacp_rate(struct bonding *bond)
int lacp_fast;

lacp_fast = bond->params.lacp_fast;
spin_lock_bh(&bond->mode_lock);
bond_for_each_slave(bond, slave, iter) {
port = &(SLAVE_AD_INFO(slave)->port);
__get_state_machine_lock(port);
if (lacp_fast)
port->actor_oper_port_state |= AD_STATE_LACP_TIMEOUT;
else
port->actor_oper_port_state &= ~AD_STATE_LACP_TIMEOUT;
__release_state_machine_lock(port);
}
spin_unlock_bh(&bond->mode_lock);
}
1 change: 0 additions & 1 deletion drivers/net/bonding/bond_3ad.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ struct ad_bond_info {
struct ad_slave_info {
struct aggregator aggregator; /* 802.3ad aggregator structure */
struct port port; /* 802.3ad port structure */
spinlock_t state_machine_lock; /* mutex state machines vs. incoming LACPDU */
u16 id;
};

Expand Down
Loading

0 comments on commit 8801d48

Please sign in to comment.