* [PATCH net] net: bonding: annotate lockless writes with WRITE_ONCE()
@ 2026-08-31 8:10 Eric Dumazet
2026-08-31 9:43 ` Xuanqiang Luo
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Eric Dumazet @ 2026-08-31 8:10 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski, Paolo Abeni
Cc: Simon Horman, Andrew Lunn, netdev, eric.dumazet, Eric Dumazet,
Jay Vosburgh
Several fields in bonding are read locklessly using READ_ONCE()
(or ACCESS_ONCE() previously) but have corresponding writes that
do not use WRITE_ONCE().
Add WRITE_ONCE() annotations to:
- bond->send_peer_notif decrements in bond_peer_notify_may_events()
and reset in bond_close().
- bond->slave_cnt increments and decrements in bond_enslave() and
__bond_release_one().
- bond->recv_probe updates in bond_open(), bond_option_arp_interval_set()
and rlb_initialize().
- slaves->count decrement in bond_skip_slave().
Fixes: 4d97480b1806 ("bonding: use local function pointer of bond->recv_probe in bond_handle_frame")
Fixes: 9a72c2da690d ("bonding: fix div by zero while enslaving and transmitting")
Fixes: ee6377147409 ("bonding: Simplify the xmit function for modes that use xmit_hash")
Fixes: 429208aab9db ("net: bonding: add the READ_ONCE/WRITE_ONCE for outside lock accessing")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Jay Vosburgh <jv@jvosburgh.net>
---
drivers/net/bonding/bond_alb.c | 2 +-
drivers/net/bonding/bond_main.c | 14 +++++++-------
drivers/net/bonding/bond_options.c | 4 ++--
3 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c
index 839f7482dc1823b12a13437a4b6639e3b63d46ec..d2fb67a47cf99651423602c39a3c89a5f5379913 100644
--- a/drivers/net/bonding/bond_alb.c
+++ b/drivers/net/bonding/bond_alb.c
@@ -875,7 +875,7 @@ static int rlb_initialize(struct bonding *bond)
spin_unlock_bh(&bond->mode_lock);
/* register to receive ARPs */
- bond->recv_probe = rlb_arp_recv;
+ WRITE_ONCE(bond->recv_probe, rlb_arp_recv);
return 0;
}
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index ef9eb0c53c661fddc48bea03f8091f239dd0f3e8..947d92a669b676524ce7a3786bc8acbc8d36fb3c 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1245,7 +1245,7 @@ static void bond_peer_notify_may_events(struct bonding *bond, bool force)
}
if (notified || force)
- bond->send_peer_notif--;
+ WRITE_ONCE(bond->send_peer_notif, bond->send_peer_notif - 1);
}
/**
@@ -2284,7 +2284,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
}
}
- bond->slave_cnt++;
+ WRITE_ONCE(bond->slave_cnt, bond->slave_cnt + 1);
netdev_compute_master_upper_features(bond->dev, true);
bond_set_carrier(bond);
@@ -2533,7 +2533,7 @@ static int __bond_release_one(struct net_device *bond_dev,
unblock_netpoll_tx();
synchronize_rcu();
- bond->slave_cnt--;
+ WRITE_ONCE(bond->slave_cnt, bond->slave_cnt - 1);
if (!bond_has_slaves(bond)) {
call_netdevice_notifiers(NETDEV_CHANGEADDR, bond->dev);
@@ -4385,13 +4385,13 @@ static int bond_open(struct net_device *bond_dev)
if (bond->params.arp_interval) { /* arp interval, in milliseconds. */
queue_delayed_work(bond->wq, &bond->arp_work, 0);
- bond->recv_probe = bond_rcv_validate;
+ WRITE_ONCE(bond->recv_probe, bond_rcv_validate);
}
if (BOND_MODE(bond) == BOND_MODE_8023AD) {
queue_delayed_work(bond->wq, &bond->ad_work, 0);
/* register to receive LACPDUs */
- bond->recv_probe = bond_3ad_lacpdu_recv;
+ WRITE_ONCE(bond->recv_probe, bond_3ad_lacpdu_recv);
bond_3ad_initiate_agg_selection(bond, 1);
bond_for_each_slave(bond, slave, iter)
@@ -4413,7 +4413,7 @@ static int bond_close(struct net_device *bond_dev)
struct slave *slave;
bond_work_cancel_all(bond);
- bond->send_peer_notif = 0;
+ WRITE_ONCE(bond->send_peer_notif, 0);
WRITE_ONCE(bond->recv_probe, NULL);
/* Wait for any in-flight RX handlers */
@@ -5118,7 +5118,7 @@ static void bond_skip_slave(struct bond_up_slave *slaves,
if (skipslave == slaves->arr[idx]) {
slaves->arr[idx] =
slaves->arr[slaves->count - 1];
- slaves->count--;
+ WRITE_ONCE(slaves->count, slaves->count - 1);
break;
}
}
diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c
index 36b8d89387ee5d67a51087fa2c6edd0de579ab3f..9efadeff6a2238960828a0604e304108ad9c2dc7 100644
--- a/drivers/net/bonding/bond_options.c
+++ b/drivers/net/bonding/bond_options.c
@@ -1147,11 +1147,11 @@ static int bond_option_arp_interval_set(struct bonding *bond,
*/
if (!newval->value) {
if (bond->params.arp_validate)
- bond->recv_probe = NULL;
+ WRITE_ONCE(bond->recv_probe, NULL);
cancel_delayed_work_sync(&bond->arp_work);
} else {
/* arp_validate can be set only in active-backup mode */
- bond->recv_probe = bond_rcv_validate;
+ WRITE_ONCE(bond->recv_probe, bond_rcv_validate);
cancel_delayed_work_sync(&bond->mii_work);
queue_delayed_work(bond->wq, &bond->arp_work, 0);
}
--
2.55.0.897.gb25b4bd76c-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net] net: bonding: annotate lockless writes with WRITE_ONCE()
2026-08-31 8:10 [PATCH net] net: bonding: annotate lockless writes with WRITE_ONCE() Eric Dumazet
@ 2026-08-31 9:43 ` Xuanqiang Luo
2026-08-31 9:44 ` Hangbin Liu
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Xuanqiang Luo @ 2026-08-31 9:43 UTC (permalink / raw)
To: Eric Dumazet
Cc: Simon Horman, Andrew Lunn, netdev, eric.dumazet, Jay Vosburgh,
David S . Miller, Jakub Kicinski, Paolo Abeni
在 2026/8/31 16:10, Eric Dumazet 写道:
> Several fields in bonding are read locklessly using READ_ONCE()
> (or ACCESS_ONCE() previously) but have corresponding writes that
> do not use WRITE_ONCE().
>
> Add WRITE_ONCE() annotations to:
> - bond->send_peer_notif decrements in bond_peer_notify_may_events()
> and reset in bond_close().
> - bond->slave_cnt increments and decrements in bond_enslave() and
> __bond_release_one().
> - bond->recv_probe updates in bond_open(), bond_option_arp_interval_set()
> and rlb_initialize().
> - slaves->count decrement in bond_skip_slave().
>
> Fixes: 4d97480b1806 ("bonding: use local function pointer of bond->recv_probe in bond_handle_frame")
> Fixes: 9a72c2da690d ("bonding: fix div by zero while enslaving and transmitting")
> Fixes: ee6377147409 ("bonding: Simplify the xmit function for modes that use xmit_hash")
> Fixes: 429208aab9db ("net: bonding: add the READ_ONCE/WRITE_ONCE for outside lock accessing")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Jay Vosburgh <jv@jvosburgh.net>
Reviewed-by: Xuanqiang Luo<luoxuanqiang@kylinos.cn>
Thanks,
Xuanqiang
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] net: bonding: annotate lockless writes with WRITE_ONCE()
2026-08-31 8:10 [PATCH net] net: bonding: annotate lockless writes with WRITE_ONCE() Eric Dumazet
2026-08-31 9:43 ` Xuanqiang Luo
@ 2026-08-31 9:44 ` Hangbin Liu
2026-09-01 10:26 ` Paolo Abeni
2026-09-01 10:30 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: Hangbin Liu @ 2026-08-31 9:44 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, Simon Horman,
Andrew Lunn, netdev, eric.dumazet, Jay Vosburgh
On Mon, Aug 31, 2026 at 08:10:27AM +0000, Eric Dumazet wrote:
> Several fields in bonding are read locklessly using READ_ONCE()
> (or ACCESS_ONCE() previously) but have corresponding writes that
> do not use WRITE_ONCE().
>
> Add WRITE_ONCE() annotations to:
> - bond->send_peer_notif decrements in bond_peer_notify_may_events()
> and reset in bond_close().
> - bond->slave_cnt increments and decrements in bond_enslave() and
> __bond_release_one().
> - bond->recv_probe updates in bond_open(), bond_option_arp_interval_set()
> and rlb_initialize().
> - slaves->count decrement in bond_skip_slave().
>
> Fixes: 4d97480b1806 ("bonding: use local function pointer of bond->recv_probe in bond_handle_frame")
> Fixes: 9a72c2da690d ("bonding: fix div by zero while enslaving and transmitting")
> Fixes: ee6377147409 ("bonding: Simplify the xmit function for modes that use xmit_hash")
> Fixes: 429208aab9db ("net: bonding: add the READ_ONCE/WRITE_ONCE for outside lock accessing")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Jay Vosburgh <jv@jvosburgh.net>
Reviewed-by: Hangbin Liu <liuhangbin@kylinos.cn>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] net: bonding: annotate lockless writes with WRITE_ONCE()
2026-08-31 8:10 [PATCH net] net: bonding: annotate lockless writes with WRITE_ONCE() Eric Dumazet
2026-08-31 9:43 ` Xuanqiang Luo
2026-08-31 9:44 ` Hangbin Liu
@ 2026-09-01 10:26 ` Paolo Abeni
2026-09-01 10:30 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: Paolo Abeni @ 2026-09-01 10:26 UTC (permalink / raw)
To: Eric Dumazet, David S . Miller, Jakub Kicinski
Cc: Simon Horman, Andrew Lunn, netdev, eric.dumazet, Jay Vosburgh
On 8/31/26 10:10 AM, Eric Dumazet wrote:
> Several fields in bonding are read locklessly using READ_ONCE()
> (or ACCESS_ONCE() previously) but have corresponding writes that
> do not use WRITE_ONCE().
>
> Add WRITE_ONCE() annotations to:
> - bond->send_peer_notif decrements in bond_peer_notify_may_events()
> and reset in bond_close().
> - bond->slave_cnt increments and decrements in bond_enslave() and
> __bond_release_one().
> - bond->recv_probe updates in bond_open(), bond_option_arp_interval_set()
> and rlb_initialize().
> - slaves->count decrement in bond_skip_slave().
>
> Fixes: 4d97480b1806 ("bonding: use local function pointer of bond->recv_probe in bond_handle_frame")
> Fixes: 9a72c2da690d ("bonding: fix div by zero while enslaving and transmitting")
> Fixes: ee6377147409 ("bonding: Simplify the xmit function for modes that use xmit_hash")
> Fixes: 429208aab9db ("net: bonding: add the READ_ONCE/WRITE_ONCE for outside lock accessing")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Jay Vosburgh <jv@jvosburgh.net>
Clashiko noted there is still a missing READ_ONCE annotation for
`usable_slaves->count` in bond_miimon_inspect(), but I think that is
better handled with a separate patch.
/P
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] net: bonding: annotate lockless writes with WRITE_ONCE()
2026-08-31 8:10 [PATCH net] net: bonding: annotate lockless writes with WRITE_ONCE() Eric Dumazet
` (2 preceding siblings ...)
2026-09-01 10:26 ` Paolo Abeni
@ 2026-09-01 10:30 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-09-01 10:30 UTC (permalink / raw)
To: Eric Dumazet
Cc: davem, kuba, pabeni, horms, andrew+netdev, netdev, eric.dumazet,
jv
Hello:
This patch was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:
On Mon, 31 Aug 2026 08:10:27 +0000 you wrote:
> Several fields in bonding are read locklessly using READ_ONCE()
> (or ACCESS_ONCE() previously) but have corresponding writes that
> do not use WRITE_ONCE().
>
> Add WRITE_ONCE() annotations to:
> - bond->send_peer_notif decrements in bond_peer_notify_may_events()
> and reset in bond_close().
> - bond->slave_cnt increments and decrements in bond_enslave() and
> __bond_release_one().
> - bond->recv_probe updates in bond_open(), bond_option_arp_interval_set()
> and rlb_initialize().
> - slaves->count decrement in bond_skip_slave().
>
> [...]
Here is the summary with links:
- [net] net: bonding: annotate lockless writes with WRITE_ONCE()
https://git.kernel.org/netdev/net/c/bc93419130bb
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-09-01 10:31 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-31 8:10 [PATCH net] net: bonding: annotate lockless writes with WRITE_ONCE() Eric Dumazet
2026-08-31 9:43 ` Xuanqiang Luo
2026-08-31 9:44 ` Hangbin Liu
2026-09-01 10:26 ` Paolo Abeni
2026-09-01 10:30 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox