Subject: Re: [PATCHv4 net-next] bonding: add software tx timestamping support

From: Jay Vosburgh <[email-masked]>
Date: Fri, 14 Apr 2023 20:43:14 -0700

Jakub Kicinski <[email-masked]> wrote:

>On Fri, 14 Apr 2023 16:35:26 +0800 Hangbin Liu wrote:
>> v4: add ASSERT_RTNL to make sure bond_ethtool_get_ts_info() called via
>>     RTNL. Only check _TX_SOFTWARE for the slaves.
>
>> +	ASSERT_RTNL();
>> +
>>  	rcu_read_lock();
>>  	real_dev = bond_option_active_slave_get_rcu(bond);
>>  	dev_hold(real_dev);
>> @@ -5707,10 +5713,36 @@ static int bond_ethtool_get_ts_info(struct net_device *bond_dev,
>>  			ret = ops->get_ts_info(real_dev, info);
>>  			goto out;
>>  		}
>> +	} else {
>> +		/* Check if all slaves support software tx timestamping */
>> +		rcu_read_lock();
>> +		bond_for_each_slave_rcu(bond, slave, iter) {
>
>> +			ret = -1;
>> +			ops = slave->dev->ethtool_ops;
>> +			phydev = slave->dev->phydev;
>> +
>> +			if (phy_has_tsinfo(phydev))
>> +				ret = phy_ts_info(phydev, &ts_info);
>> +			else if (ops->get_ts_info)
>> +				ret = ops->get_ts_info(slave->dev, &ts_info);
>
>My comment about this path being under rtnl was to point out that we
>don't need the RCU protection to iterate over the slaves. This is 
>a bit of a guess, I don't know bonding, but can we not use
>bond_for_each_slave() ?

	Ah, I missed that nuance.  And, yes, you're correct,
bond_for_each_slave() works with RTNL and we don't need RCU here if RTNL
is held.

>As a general rule we should let all driver callbacks sleep. Drivers 
>may need to consult the FW or read something over a slow asynchronous
>bus which requires process / non-atomic context. RCU lock puts us in 
>an atomic context. And ->get_ts_info() is a driver callback.

	Agreed.

>It's not a deal breaker if we can't avoid RCU, but if we can - we should
>let the drivers sleep. Sorry if I wasn't very clear previously.

	Understood; I should have remembered this, as it's been an issue
arising from the "in the middle" aspect of bonding in the past.

	-J

---
	-Jay Vosburgh, [email-masked]