bonding: annotate data-races arcound churn variables
Subsystems (3)
PATCH 1/1 bonding: annotate data-races arcound churn variables
These fields are updated asynchronously by the bonding state machine in ad_churn_machine() while holding bond->mode_lock.
bond_info_show_slave() and bond_fill_slave_info() read them without bond->mode_lock being held, we need to add READ_ONCE() and WRITE_ONCE() annotations.
Note that AD_CHURN_MONITOR, AD_CHURN, and AD_NO_CHURN are defined exclusively in (kernel private) include/net/bond_3ad.h header.
They should be moved to include/uapi/linux/if_bonding.h or userspace tools will have to hardcode their values.
---
Cc: Hangbin Liu <[email protected]>
Cc: Jay Vosburgh <[email protected]>
Cc: Andrew Lunn <[email protected]>
--- drivers/net/bonding/bond_3ad.c | 18 ++++++++++-------- drivers/net/bonding/bond_netlink.c | 4 ++-- drivers/net/bonding/bond_procfs.c | 8 ++++---- 3 files changed, 16 insertions(+), 14 deletions(-)
drivers/net/bonding/bond_3ad.c +10 -8
@@ -1386,8 +1386,8 @@ static void ad_churn_machine(struct port *port) {if (port->sm_vars &AD_PORT_CHURNED ) { port->sm_vars &= ~AD_PORT_CHURNED ; - port->sm_churn_actor_state =AD_CHURN_MONITOR ; - port->sm_churn_partner_state =AD_CHURN_MONITOR ; +WRITE_ONCE (port->sm_churn_actor_state,AD_CHURN_MONITOR ); +WRITE_ONCE (port->sm_churn_partner_state,AD_CHURN_MONITOR ); port->sm_churn_actor_timer_counter =__ad_timer_to_ticks (AD_ACTOR_CHURN_TIMER ,0 ); port->sm_churn_partner_timer_counter =
@@ -1398,20 +1398,22 @@ static void ad_churn_machine(struct port *port) !(--port->sm_churn_actor_timer_counter) && port->sm_churn_actor_state == AD_CHURN_MONITOR) {if (port->actor_oper_port_state &LACP_STATE_SYNCHRONIZATION ) { - port->sm_churn_actor_state =AD_NO_CHURN ; +WRITE_ONCE (port->sm_churn_actor_state,AD_NO_CHURN ); }else { - port->churn_actor_count++; - port->sm_churn_actor_state =AD_CHURN ; +WRITE_ONCE (port->churn_actor_count, + port->churn_actor_count +1 ); +WRITE_ONCE (port->sm_churn_actor_state,AD_CHURN ); } }if (port->sm_churn_partner_timer_counter && !(--port->sm_churn_partner_timer_counter) && port->sm_churn_partner_state ==AD_CHURN_MONITOR ) {if (port->partner_oper.port_state &LACP_STATE_SYNCHRONIZATION ) { - port->sm_churn_partner_state =AD_NO_CHURN ; +WRITE_ONCE (port->sm_churn_partner_state,AD_NO_CHURN ); }else { - port->churn_partner_count++; - port->sm_churn_partner_state =AD_CHURN ; +WRITE_ONCE (port->churn_partner_count, + port->churn_partner_count +1 ); +WRITE_ONCE (port->sm_churn_partner_state,AD_CHURN ); } } }
drivers/net/bonding/bond_netlink.c +2 -2
@@ -82,10 +82,10 @@ static int bond_fill_slave_info(struct sk_buff *skb, goto nla_put_failure_rcu;if (nla_put_u8 (skb,IFLA_BOND_SLAVE_AD_CHURN_ACTOR_STATE , - ad_port->sm_churn_actor_state)) +READ_ONCE (ad_port->sm_churn_actor_state))) goto nla_put_failure_rcu;if (nla_put_u8 (skb,IFLA_BOND_SLAVE_AD_CHURN_PARTNER_STATE , - ad_port->sm_churn_partner_state)) +READ_ONCE (ad_port->sm_churn_partner_state))) goto nla_put_failure_rcu; }rcu_read_unlock ();
drivers/net/bonding/bond_procfs.c +4 -4
@@ -221,13 +221,13 @@ static void bond_info_show_slave(struct seq_file *seq,seq_printf (seq,"Aggregator ID: %d\n" , agg->aggregator_identifier);seq_printf (seq,"Actor Churn State: %s\n" , -bond_3ad_churn_desc (port->sm_churn_actor_state)); +bond_3ad_churn_desc (READ_ONCE (port->sm_churn_actor_state)));seq_printf (seq,"Partner Churn State: %s\n" , -bond_3ad_churn_desc (port->sm_churn_partner_state)); +bond_3ad_churn_desc (READ_ONCE (port->sm_churn_partner_state)));seq_printf (seq,"Actor Churned Count: %d\n" , - port->churn_actor_count); +READ_ONCE (port->churn_actor_count));seq_printf (seq,"Partner Churned Count: %d\n" , - port->churn_partner_count); +READ_ONCE (port->churn_partner_count));if (capable (CAP_NET_ADMIN )) {seq_puts (seq,"details actor lacp pdu:\n" );
Signature · 1 line
2.54.0.1013.g208068f2d8-goog
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Wed, 3 Jun 2026 12:35:14 +0000 you wrote:
These fields are updated asynchronously by the bonding state machine in
ad_churn_machine()while holdingbond->mode_lock.
bond_info_show_slave()andbond_fill_slave_info()read them withoutbond->mode_lockbeing held, we need to addREAD_ONCE()andWRITE_ONCE()annotations.[...]
Here is the summary with links:
- [net] bonding: annotate data-races arcound churn variables
https://git.kernel.org/netdev/net/c/b47ff80f280e
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html