diff mbox

[net-next,6/9] bonding: use RTNL instead of bond lock for bond_3ad_state_machine_handler()

Message ID 5279E74C.8070403@huawei.com
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

Ding Tianhong Nov. 6, 2013, 6:53 a.m. UTC
The bond_3ad_state_machine_handler() is a slow path, it use the bond
lock to protect the bond slave list and slave port, the slave list
could not be protect by bond lock anymore, so I need to use RTNL or
RCU instead of bond lock, but if I remove the bond lock, the
bond_3ad_state_machine_handler() may use the slave port when bond
releasing the slave, it will occur problems.

As the bond_3ad_unbind_slave() only protected by bond lock or RTNL,
so add RCU is not a good solution as it could not protect the slave
port, so RTNL is fit here.

Signed-off-by: Ding Tianhong <dingtianhong@huawei.com>
---
 drivers/net/bonding/bond_3ad.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

Comments

Sergei Shtylyov Nov. 6, 2013, 11:50 p.m. UTC | #1
Hello.

On 11/06/2013 09:53 AM, Ding Tianhong wrote:

> The bond_3ad_state_machine_handler() is a slow path, it use the bond
> lock to protect the bond slave list and slave port, the slave list
> could not be protect by bond lock anymore, so I need to use RTNL or
> RCU instead of bond lock, but if I remove the bond lock, the
> bond_3ad_state_machine_handler() may use the slave port when bond
> releasing the slave, it will occur problems.

> As the bond_3ad_unbind_slave() only protected by bond lock or RTNL,
> so add RCU is not a good solution as it could not protect the slave
> port, so RTNL is fit here.

> Signed-off-by: Ding Tianhong <dingtianhong@huawei.com>
> ---
>   drivers/net/bonding/bond_3ad.c | 15 +++++++--------
>   1 file changed, 7 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c
> index 187b1b7..a4d190e 100644
> --- a/drivers/net/bonding/bond_3ad.c
> +++ b/drivers/net/bonding/bond_3ad.c
> @@ -2068,18 +2068,19 @@ void bond_3ad_state_machine_handler(struct work_struct *work)
[...]
> -	//check if there are any slaves
>   	if (!bond_has_slaves(bond))
>   		goto re_arm;
>
> -	// check if agg_select_timer timer after initialize is timed out
> +	/* check if agg_select_timer timer after initialize is timed out */
>   	if (BOND_AD_INFO(bond).agg_select_timer && !(--BOND_AD_INFO(bond).agg_select_timer)) {
>   		slave = bond_first_slave(bond);
>   		port = slave ? &(SLAVE_AD_INFO(slave).port) : NULL;
>
> -		// select the active aggregator for the bond
>   		if (port) {
>   			if (!port->slave) {
>   				pr_warning("%s: Warning: bond's first port is uninitialized\n",
> @@ -2093,7 +2094,6 @@ void bond_3ad_state_machine_handler(struct work_struct *work)
>   		bond_3ad_set_carrier(bond);
>   	}
>
> -	// for each port run the state machines
>   	bond_for_each_slave(bond, slave, iter) {
>   		port = &(SLAVE_AD_INFO(slave).port);
>   		if (!port->slave) {
> @@ -2114,7 +2114,7 @@ void bond_3ad_state_machine_handler(struct work_struct *work)
>   		ad_mux_machine(port);
>   		ad_tx_machine(port);
>
> -		// turn off the BEGIN bit, since we already handled it
> +		/* turn off the BEGIN bit, since we already handled it */
>   		if (port->sm_vars & AD_PORT_BEGIN)
>   			port->sm_vars &= ~AD_PORT_BEGIN;
>

    These comment changes are not documented in the changelog and should most 
probably be in a separate patch.

WBR, Sergei

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Ding Tianhong Nov. 7, 2013, 1:40 a.m. UTC | #2
On 2013/11/7 7:50, Sergei Shtylyov wrote:
> Hello.
> 
> On 11/06/2013 09:53 AM, Ding Tianhong wrote:
> 
>> The bond_3ad_state_machine_handler() is a slow path, it use the bond
>> lock to protect the bond slave list and slave port, the slave list
>> could not be protect by bond lock anymore, so I need to use RTNL or
>> RCU instead of bond lock, but if I remove the bond lock, the
>> bond_3ad_state_machine_handler() may use the slave port when bond
>> releasing the slave, it will occur problems.
> 
>> As the bond_3ad_unbind_slave() only protected by bond lock or RTNL,
>> so add RCU is not a good solution as it could not protect the slave
>> port, so RTNL is fit here.
> 
>> Signed-off-by: Ding Tianhong <dingtianhong@huawei.com>
>> ---
>>   drivers/net/bonding/bond_3ad.c | 15 +++++++--------
>>   1 file changed, 7 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c
>> index 187b1b7..a4d190e 100644
>> --- a/drivers/net/bonding/bond_3ad.c
>> +++ b/drivers/net/bonding/bond_3ad.c
>> @@ -2068,18 +2068,19 @@ void bond_3ad_state_machine_handler(struct work_struct *work)
> [...]
>> -    //check if there are any slaves
>>       if (!bond_has_slaves(bond))
>>           goto re_arm;
>>
>> -    // check if agg_select_timer timer after initialize is timed out
>> +    /* check if agg_select_timer timer after initialize is timed out */
>>       if (BOND_AD_INFO(bond).agg_select_timer && !(--BOND_AD_INFO(bond).agg_select_timer)) {
>>           slave = bond_first_slave(bond);
>>           port = slave ? &(SLAVE_AD_INFO(slave).port) : NULL;
>>
>> -        // select the active aggregator for the bond
>>           if (port) {
>>               if (!port->slave) {
>>                   pr_warning("%s: Warning: bond's first port is uninitialized\n",
>> @@ -2093,7 +2094,6 @@ void bond_3ad_state_machine_handler(struct work_struct *work)
>>           bond_3ad_set_carrier(bond);
>>       }
>>
>> -    // for each port run the state machines
>>       bond_for_each_slave(bond, slave, iter) {
>>           port = &(SLAVE_AD_INFO(slave).port);
>>           if (!port->slave) {
>> @@ -2114,7 +2114,7 @@ void bond_3ad_state_machine_handler(struct work_struct *work)
>>           ad_mux_machine(port);
>>           ad_tx_machine(port);
>>
>> -        // turn off the BEGIN bit, since we already handled it
>> +        /* turn off the BEGIN bit, since we already handled it */
>>           if (port->sm_vars & AD_PORT_BEGIN)
>>               port->sm_vars &= ~AD_PORT_BEGIN;
>>
> 
>    These comment changes are not documented in the changelog and should most probably be in a separate patch.
> 
> WBR, Sergei
> 

thanks for your reply, I miss it in the changelog, it is already a big patch set, so I really do not want to add patch any more, I will add it in changelog.

Tnanks

Ding

> 
> .
> 


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c
index 187b1b7..a4d190e 100644
--- a/drivers/net/bonding/bond_3ad.c
+++ b/drivers/net/bonding/bond_3ad.c
@@ -2068,18 +2068,19 @@  void bond_3ad_state_machine_handler(struct work_struct *work)
 	struct slave *slave;
 	struct port *port;
 
-	read_lock(&bond->lock);
+	if (!rtnl_trylock()) {
+		queue_delayed_work(bond->wq, &bond->ad_work, ad_delta_in_ticks);
+		return;
+	}
 
-	//check if there are any slaves
 	if (!bond_has_slaves(bond))
 		goto re_arm;
 
-	// check if agg_select_timer timer after initialize is timed out
+	/* check if agg_select_timer timer after initialize is timed out */
 	if (BOND_AD_INFO(bond).agg_select_timer && !(--BOND_AD_INFO(bond).agg_select_timer)) {
 		slave = bond_first_slave(bond);
 		port = slave ? &(SLAVE_AD_INFO(slave).port) : NULL;
 
-		// select the active aggregator for the bond
 		if (port) {
 			if (!port->slave) {
 				pr_warning("%s: Warning: bond's first port is uninitialized\n",
@@ -2093,7 +2094,6 @@  void bond_3ad_state_machine_handler(struct work_struct *work)
 		bond_3ad_set_carrier(bond);
 	}
 
-	// for each port run the state machines
 	bond_for_each_slave(bond, slave, iter) {
 		port = &(SLAVE_AD_INFO(slave).port);
 		if (!port->slave) {
@@ -2114,7 +2114,7 @@  void bond_3ad_state_machine_handler(struct work_struct *work)
 		ad_mux_machine(port);
 		ad_tx_machine(port);
 
-		// turn off the BEGIN bit, since we already handled it
+		/* turn off the BEGIN bit, since we already handled it */
 		if (port->sm_vars & AD_PORT_BEGIN)
 			port->sm_vars &= ~AD_PORT_BEGIN;
 
@@ -2122,9 +2122,8 @@  void bond_3ad_state_machine_handler(struct work_struct *work)
 	}
 
 re_arm:
+	rtnl_unlock();
 	queue_delayed_work(bond->wq, &bond->ad_work, ad_delta_in_ticks);
-
-	read_unlock(&bond->lock);
 }
 
 /**