bonding: no longer rely on RTNL in bond_fill_info()
Subsystems (3)
PATCH v2 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.
---
v2: addressed sashiko.dev feedback.
drivers/net/bonding/bond_3ad.c | 18 ++--- drivers/net/bonding/bond_netlink.c | 107 ++++++++++++++++------------- drivers/net/bonding/bond_options.c | 6 +- include/net/bond_3ad.h | 4 +- include/net/bonding.h | 8 +-- 5 files changed, 78 insertions(+), 65 deletions(-)
drivers/net/bonding/bond_3ad.c +9 -9
@@ -745,14 +745,14 @@ static void __set_agg_ports_ready(struct aggregator *aggregator, int val) } } -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++; }
@@ -2782,11 +2782,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);
@@ -2857,13 +2857,13 @@ 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; +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);
@@ -2886,7 +2886,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 +60 -47
240 lines not on this page · raw message
drivers/net/bonding/bond_options.c +3 -3
@@ -918,14 +918,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;
@@ -1900,7 +1900,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
@@ -344,14 +344,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 ; }
@@ -702,7 +702,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.54.0.1032.g2f8565e1d1-goog
Jakub Kicinski
maintainerQuoted 1 line · On Mon, 8 Jun 2026 13:50:51 +0000 Eric Dumazet wrote:
Subject: [PATCH v2 net] bonding: no longer rely on RTNL in
bond_fill_info()
This one does not apply
Signature · 1 line
pw-bot: cr
Quoted 7 lines · Jakub Kicinski
Quoted 1 line · On Mon, 8 Jun 2026 13:50:51 +0000 Eric Dumazet wrote:
Subject: [PATCH v2 net] bonding: no longer rely on RTNL in
bond_fill_info()This one does not apply
--
pw-bot: cr
Wrong prefix, this should have been net-next., sorry for the confusion.
V3 is coming,