Commit 6c5d1714 authored by Eric Dumazet's avatar Eric Dumazet Committed by Jakub Kicinski

bonding: no longer use RTNL in bonding_show_bonds()

netdev structures are already RCU protected.

Change bond_init() and bond_uninit() to use RCU
enabled list_add_tail_rcu() and list_del_rcu().

Then bonding_show_bonds() can use rcu_read_lock()
while iterating through bn->dev_list.
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Acked-by: default avatarJay Vosburgh <jay.vosburgh@canonical.com>
Link: https://lore.kernel.org/r/20240408190437.2214473-2-edumazet@google.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent d034d02d
...@@ -5933,7 +5933,7 @@ static void bond_uninit(struct net_device *bond_dev) ...@@ -5933,7 +5933,7 @@ static void bond_uninit(struct net_device *bond_dev)
bond_set_slave_arr(bond, NULL, NULL); bond_set_slave_arr(bond, NULL, NULL);
list_del(&bond->bond_list); list_del_rcu(&bond->bond_list);
bond_debug_unregister(bond); bond_debug_unregister(bond);
} }
...@@ -6347,7 +6347,7 @@ static int bond_init(struct net_device *bond_dev) ...@@ -6347,7 +6347,7 @@ static int bond_init(struct net_device *bond_dev)
spin_lock_init(&bond->stats_lock); spin_lock_init(&bond->stats_lock);
netdev_lockdep_set_classes(bond_dev); netdev_lockdep_set_classes(bond_dev);
list_add_tail(&bond->bond_list, &bn->dev_list); list_add_tail_rcu(&bond->bond_list, &bn->dev_list);
bond_prepare_sysfs_group(bond); bond_prepare_sysfs_group(bond);
......
...@@ -37,12 +37,12 @@ static ssize_t bonding_show_bonds(const struct class *cls, ...@@ -37,12 +37,12 @@ static ssize_t bonding_show_bonds(const struct class *cls,
{ {
const struct bond_net *bn = const struct bond_net *bn =
container_of_const(attr, struct bond_net, class_attr_bonding_masters); container_of_const(attr, struct bond_net, class_attr_bonding_masters);
int res = 0;
struct bonding *bond; struct bonding *bond;
int res = 0;
rtnl_lock(); rcu_read_lock();
list_for_each_entry(bond, &bn->dev_list, bond_list) { list_for_each_entry_rcu(bond, &bn->dev_list, bond_list) {
if (res > (PAGE_SIZE - IFNAMSIZ)) { if (res > (PAGE_SIZE - IFNAMSIZ)) {
/* not enough space for another interface name */ /* not enough space for another interface name */
if ((PAGE_SIZE - res) > 10) if ((PAGE_SIZE - res) > 10)
...@@ -55,7 +55,7 @@ static ssize_t bonding_show_bonds(const struct class *cls, ...@@ -55,7 +55,7 @@ static ssize_t bonding_show_bonds(const struct class *cls,
if (res) if (res)
buf[res-1] = '\n'; /* eat the leftover space */ buf[res-1] = '\n'; /* eat the leftover space */
rtnl_unlock(); rcu_read_unlock();
return res; return res;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment