Skip to content

Commit

Permalink
bonding: use rcu_dereference_rtnl when get bonding active slave
Browse files Browse the repository at this point in the history
bond_option_active_slave_get_rcu() should not be used in rtnl_mutex as it
use rcu_dereference(). Replace to rcu_dereference_rtnl() so we also can use
this function in rtnl protected context.

With this update, we can rmeove the rcu_read_lock/unlock in
bonding .ndo_eth_ioctl and .get_ts_info.

Reported-by: Vladimir Oltean <[email protected]>
Fixes: 94dd016 ("bond: pass get_ts_info and SIOC[SG]HWTSTAMP ioctl to active device")
Signed-off-by: Hangbin Liu <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
liuhangbin authored and davem330 committed Jan 24, 2022
1 parent 2148927 commit aa60346
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 5 deletions.
4 changes: 0 additions & 4 deletions drivers/net/bonding/bond_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4133,9 +4133,7 @@ static int bond_eth_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cm

fallthrough;
case SIOCGHWTSTAMP:
rcu_read_lock();
real_dev = bond_option_active_slave_get_rcu(bond);
rcu_read_unlock();
if (!real_dev)
return -EOPNOTSUPP;

Expand Down Expand Up @@ -5382,9 +5380,7 @@ static int bond_ethtool_get_ts_info(struct net_device *bond_dev,
struct net_device *real_dev;
struct phy_device *phydev;

rcu_read_lock();
real_dev = bond_option_active_slave_get_rcu(bond);
rcu_read_unlock();
if (real_dev) {
ops = real_dev->ethtool_ops;
phydev = real_dev->phydev;
Expand Down
2 changes: 1 addition & 1 deletion include/net/bonding.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ static inline bool bond_uses_primary(struct bonding *bond)

static inline struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond)
{
struct slave *slave = rcu_dereference(bond->curr_active_slave);
struct slave *slave = rcu_dereference_rtnl(bond->curr_active_slave);

return bond_uses_primary(bond) && slave ? slave->dev : NULL;
}
Expand Down

0 comments on commit aa60346

Please sign in to comment.