bonding: no longer rely on RTNL in bond_fill_info()
Subsystems (3)
PATCH v4 1/1 bonding: no longer rely on RTNL in bond_fill_info()
Add READ_ONCE()/WRITE_ONCE() annotations on port->is_enabled. While this field is written under bond->mode_lock protection, is is read without this lock being held.
Change bond_fill_info() to acquire RCU and use READ_ONCE() to read bond->params fields that can be updated concurrently from sysfs/procfs/rtnetlink.
Add const qualifiers to bond_uses_primary(), __agg_active_ports(), bond_option_active_slave_get_rcu(), bond_3ad_get_active_agg_info(), __bond_3ad_get_active_agg_info() helpers.
---
v4: addressed Sashiko/Jakub feedback
drivers/net/bonding/bond_3ad.c | 24 ++++--- drivers/net/bonding/bond_netlink.c | 109 ++++++++++++++++------------- drivers/net/bonding/bond_options.c | 8 +-- include/net/bond_3ad.h | 4 +- include/net/bonding.h | 8 +-- 5 files changed, 85 insertions(+), 68 deletions(-)
drivers/net/bonding/bond_3ad.c +14 -10
@@ -760,14 +760,14 @@ static int __agg_usable_ports(struct aggregator *agg)return valid; } -static int __agg_active_ports (struct aggregator *agg) +static int __agg_active_ports (const struct aggregator *agg) { -struct port *port; +const struct port *port;int active =0 ;for (port = agg->lag_ports; port; port = port->next_port_in_aggregator) { -if (port->is_enabled) +if (READ_ONCE (port->is_enabled)) active++; }
@@ -2801,11 +2801,11 @@ void bond_3ad_handle_link_change(struct slave *slave, char link)* some of he adaptors(ce1000.lan) report. */ if (link ==BOND_LINK_UP ) { - port->is_enabled = true; +WRITE_ONCE (port->is_enabled, true);ad_update_actor_keys (port, false); }else {/* link has failed */ - port->is_enabled = false; +WRITE_ONCE (port->is_enabled, false);ad_update_actor_keys (port, true); } agg =__get_first_agg (port);
@@ -2878,16 +2878,20 @@ int bond_3ad_set_carrier(struct bonding *bond)* Returns: 0 on success * < 0 on error */ -int __bond_3ad_get_active_agg_info (struct bonding *bond, +int __bond_3ad_get_active_agg_info (const struct bonding *bond,struct ad_info *ad_info) { -struct aggregator *aggregator =NULL , *tmp; +const struct aggregator *aggregator =NULL , *tmp; +struct ad_slave_info *ad_slave_info; +const struct port *port;struct list_head *iter;struct slave *slave; -struct port *port;bond_for_each_slave_rcu (bond, slave, iter) { - port = &(SLAVE_AD_INFO (slave)->port); + ad_slave_info =SLAVE_AD_INFO (slave); +if (!ad_slave_info) +continue ; + port = &ad_slave_info->port; tmp =rcu_dereference (port->aggregator);if (tmp && tmp->is_active) { aggregator = tmp;
@@ -2907,7 +2911,7 @@ int __bond_3ad_get_active_agg_info(struct bonding *bond,return 0 ; } -int bond_3ad_get_active_agg_info (struct bonding *bond,struct ad_info *ad_info) +int bond_3ad_get_active_agg_info (const struct bonding *bond,struct ad_info *ad_info) {int ret;
drivers/net/bonding/bond_netlink.c +61 -48
245 lines not on this page · raw message
drivers/net/bonding/bond_options.c +4 -4
@@ -934,14 +934,14 @@ static int bond_option_mode_set(struct bonding *bond,/* don't cache arp_validate between modes */ WRITE_ONCE (bond->params.arp_validate,BOND_ARP_VALIDATE_NONE ); - bond->params.mode = newval->value; +WRITE_ONCE (bond->params.mode, newval->value);/* When changing mode, the bond device is down, we may reduce * the bond_bcast_neigh_enabled in bond_close() if broadcast_neighbor * enabled in 8023ad mode. Therefore, only clear broadcast_neighbor * to 0. */ - bond->params.broadcast_neighbor =0 ; +WRITE_ONCE (bond->params.broadcast_neighbor,0 );if (bond->dev->reg_state ==NETREG_REGISTERED ) {bool update = false;
@@ -1706,7 +1706,7 @@ static int bond_option_lacp_strict_set(struct bonding *bond, {netdev_dbg (bond->dev,"Setting LACP fallback to %s (%llu)\n" , newval->string, newval->value); - bond->params.lacp_strict = newval->value; +WRITE_ONCE (bond->params.lacp_strict, newval->value);bond_3ad_set_carrier (bond);return 0 ;
@@ -1927,7 +1927,7 @@ static int bond_option_broadcast_neigh_set(struct bonding *bond,if (bond->params.broadcast_neighbor == newval->value)return 0 ; - bond->params.broadcast_neighbor = newval->value; +WRITE_ONCE (bond->params.broadcast_neighbor, newval->value);if (bond->dev->flags &IFF_UP ) {if (bond->params.broadcast_neighbor)static_branch_inc (&bond_bcast_neigh_enabled);
include/net/bond_3ad.h +2 -2
@@ -302,8 +302,8 @@ void bond_3ad_state_machine_handler(struct work_struct *);void bond_3ad_initiate_agg_selection (struct bonding *bond,int timeout);void bond_3ad_adapter_speed_duplex_changed (struct slave *slave);void bond_3ad_handle_link_change (struct slave *slave,char link); -int bond_3ad_get_active_agg_info (struct bonding *bond,struct ad_info *ad_info); -int __bond_3ad_get_active_agg_info (struct bonding *bond, +int bond_3ad_get_active_agg_info (const struct bonding *bond,struct ad_info *ad_info); +int __bond_3ad_get_active_agg_info (const struct bonding *bond,struct ad_info *ad_info);int bond_3ad_lacpdu_recv (const struct sk_buff *skb,struct bonding *bond,struct slave *slave);
include/net/bonding.h +4 -4
@@ -345,14 +345,14 @@ static inline bool bond_mode_uses_primary(int mode) mode ==BOND_MODE_ALB ; } -static inline bool bond_uses_primary (struct bonding *bond) +static inline bool bond_uses_primary (const struct bonding *bond) {return bond_mode_uses_primary (BOND_MODE (bond)); } -static inline struct net_device *bond_option_active_slave_get_rcu (struct bonding *bond) +static inline struct net_device *bond_option_active_slave_get_rcu (const struct bonding *bond) { -struct slave *slave =rcu_dereference_rtnl (bond->curr_active_slave); +const struct slave *slave =rcu_dereference_rtnl (bond->curr_active_slave);return bond_uses_primary (bond) && slave ? slave->dev :NULL ; }
@@ -703,7 +703,7 @@ void bond_setup(struct net_device *bond_dev);unsigned int bond_get_num_tx_queues (void );int bond_netlink_init (void );void bond_netlink_fini (void ); -struct net_device *bond_option_active_slave_get_rcu (struct bonding *bond); +struct net_device *bond_option_active_slave_get_rcu (const struct bonding *bond);const char *bond_slave_link_status (s8 link); struct bond_vlan_tag *bond_verify_device_path(struct net_device *start_dev, struct net_device *end_dev,
Signature · 1 line
2.55.0.rc0.799.gd6f94ed593-goog
Quoted 18 lines · Eric Dumazet
Add READ_ONCE()/WRITE_ONCE() annotations on
port->is_enabled. While this field is written underbond->mode_lockprotection, is is read without this lock being held.Change
bond_fill_info()to acquire RCU and useREAD_ONCE()to readbond->paramsfields that can be updated concurrently from sysfs/procfs/rtnetlink.Add const qualifiers to
bond_uses_primary(),__agg_active_ports(),bond_option_active_slave_get_rcu(),bond_3ad_get_active_agg_info(),__bond_3ad_get_active_agg_info()helpers.Signed-off-by Eric Dumazet <[email protected]>Cc Jay Vosburgh <[email protected]>Cc Andrew Lunn <[email protected]>---
v4: addressed Sashiko/Jakub feedback
Quoted 7 lines
drivers/net/bonding/bond_3ad.c | 24 ++++--- drivers/net/bonding/bond_netlink.c | 109 ++++++++++++++++------------- drivers/net/bonding/bond_options.c | 8 +-- include/net/bond_3ad.h | 4 +- include/net/bonding.h | 8 +-- 5 files changed, 85 insertions(+), 68 deletions(-)
A bit late to the party but fwiw:
Cheers,
Nik
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Mon, 29 Jun 2026 17:32:00 +0000 you wrote:
Add READ_ONCE()/WRITE_ONCE() annotations on
port->is_enabled. While this field is written underbond->mode_lockprotection, is is read without this lock being held.Change
bond_fill_info()to acquire RCU and useREAD_ONCE()to readbond->paramsfields that can be updated concurrently from sysfs/procfs/rtnetlink.[...]
Here is the summary with links:
- [v4,net-next] bonding: no longer rely on RTNL in bond_fill_info()
https://git.kernel.org/netdev/net-next/c/317cefdcaacc
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html