From: Jay Vosburgh <jv@jvosburgh.net>
To: Tonghao Zhang <tonghao@bamaicloud.com>
Cc: netdev@vger.kernel.org, "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>, Jonathan Corbet <corbet@lwn.net>,
Andrew Lunn <andrew+netdev@lunn.ch>,
Nikolay Aleksandrov <razor@blackwall.org>,
Hangbin Liu <liuhangbin@gmail.com>
Subject: Re: [PATCH net-next] net: bonding: use workqueue to make sure peer notify updated
Date: Tue, 21 Oct 2025 19:02:59 -0700 [thread overview]
Message-ID: <955201.1761098579@famine> (raw)
In-Reply-To: <20251021052249.47250-1-tonghao@bamaicloud.com>
Tonghao Zhang <tonghao@bamaicloud.com> wrote:
>The RTNL might be locked, preventing ad_cond_set_peer_notif from acquiring
>the lock and updating send_peer_notif. This patch addresses the issue by
>using a workqueue. Since updating send_peer_notif does not require high
>real-time performance, such delayed updates are entirely acceptable.
Would it be less complicated overall to convert send_peer_notif
to an atomic_t, and handle updates via atomic_inc/dec/etc instead of
messing with workqueues and RTNL just to change one variable?
As you say, it's not performance critical, and, despite your
previous patch that moves some send_peer_notif code inside an RTNL
block, if using atomic makes the code less complicated that may be
better in the long run.
-J
>Cc: Jay Vosburgh <jv@jvosburgh.net>
>Cc: "David S. Miller" <davem@davemloft.net>
>Cc: Eric Dumazet <edumazet@google.com>
>Cc: Jakub Kicinski <kuba@kernel.org>
>Cc: Paolo Abeni <pabeni@redhat.com>
>Cc: Simon Horman <horms@kernel.org>
>Cc: Jonathan Corbet <corbet@lwn.net>
>Cc: Andrew Lunn <andrew+netdev@lunn.ch>
>Cc: Nikolay Aleksandrov <razor@blackwall.org>
>Cc: Hangbin Liu <liuhangbin@gmail.com>
>Suggested-by: Hangbin Liu <liuhangbin@gmail.com>
>Signed-off-by: Tonghao Zhang <tonghao@bamaicloud.com>
>---
> drivers/net/bonding/bond_3ad.c | 7 ++-----
> drivers/net/bonding/bond_main.c | 27 +++++++++++++++++++++++++++
> include/net/bonding.h | 2 ++
> 3 files changed, 31 insertions(+), 5 deletions(-)
>
>diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c
>index 2fca8e84ab10..1db2e34a351f 100644
>--- a/drivers/net/bonding/bond_3ad.c
>+++ b/drivers/net/bonding/bond_3ad.c
>@@ -986,11 +986,8 @@ static void ad_cond_set_peer_notif(struct port *port)
> {
> struct bonding *bond = port->slave->bond;
>
>- if (bond->params.broadcast_neighbor && rtnl_trylock()) {
>- bond->send_peer_notif = bond->params.num_peer_notif *
>- max(1, bond->params.peer_notif_delay);
>- rtnl_unlock();
>- }
>+ if (bond->params.broadcast_neighbor)
>+ bond_peer_notify_work_rearm(bond, 0);
> }
>
> /**
>diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
>index 2d6883296e32..5791c3e39baa 100644
>--- a/drivers/net/bonding/bond_main.c
>+++ b/drivers/net/bonding/bond_main.c
>@@ -3990,6 +3990,31 @@ static void bond_arp_monitor(struct work_struct *work)
> bond_loadbalance_arp_mon(bond);
> }
>
>+/* Use this to update send_peer_notif when RTNL may be held in other places. */
>+void bond_peer_notify_work_rearm(struct bonding *bond, unsigned long delay)
>+{
>+ queue_delayed_work(bond->wq, &bond->peer_notify_work, delay);
>+}
>+
>+/* Peer notify update handler. Holds only RTNL */
>+static void bond_peer_notify_handler(struct work_struct *work)
>+{
>+ struct bonding *bond = container_of(work, struct bonding,
>+ peer_notify_work.work);
>+
>+ if (!rtnl_trylock())
>+ goto rearm;
>+
>+ bond->send_peer_notif = bond->params.num_peer_notif *
>+ max(1, bond->params.peer_notif_delay);
>+
>+ rtnl_unlock();
>+ return;
>+
>+rearm:
>+ bond_peer_notify_work_rearm(bond, 1);
>+}
>+
> /*-------------------------- netdev event handling --------------------------*/
>
> /* Change device name */
>@@ -4412,6 +4437,7 @@ void bond_work_init_all(struct bonding *bond)
> INIT_DELAYED_WORK(&bond->arp_work, bond_arp_monitor);
> INIT_DELAYED_WORK(&bond->ad_work, bond_3ad_state_machine_handler);
> INIT_DELAYED_WORK(&bond->slave_arr_work, bond_slave_arr_handler);
>+ INIT_DELAYED_WORK(&bond->peer_notify_work, bond_peer_notify_handler);
> }
>
> static void bond_work_cancel_all(struct bonding *bond)
>@@ -4422,6 +4448,7 @@ static void bond_work_cancel_all(struct bonding *bond)
> cancel_delayed_work_sync(&bond->ad_work);
> cancel_delayed_work_sync(&bond->mcast_work);
> cancel_delayed_work_sync(&bond->slave_arr_work);
>+ cancel_delayed_work_sync(&bond->peer_notify_work);
> }
>
> static int bond_open(struct net_device *bond_dev)
>diff --git a/include/net/bonding.h b/include/net/bonding.h
>index e06f0d63b2c1..4ce530371416 100644
>--- a/include/net/bonding.h
>+++ b/include/net/bonding.h
>@@ -255,6 +255,7 @@ struct bonding {
> struct delayed_work ad_work;
> struct delayed_work mcast_work;
> struct delayed_work slave_arr_work;
>+ struct delayed_work peer_notify_work;
> #ifdef CONFIG_DEBUG_FS
> /* debugging support via debugfs */
> struct dentry *debug_dir;
>@@ -710,6 +711,7 @@ struct bond_vlan_tag *bond_verify_device_path(struct net_device *start_dev,
> int level);
> int bond_update_slave_arr(struct bonding *bond, struct slave *skipslave);
> void bond_slave_arr_work_rearm(struct bonding *bond, unsigned long delay);
>+void bond_peer_notify_work_rearm(struct bonding *bond, unsigned long delay);
> void bond_work_init_all(struct bonding *bond);
>
> #ifdef CONFIG_PROC_FS
>--
>2.34.1
>
>
---
-Jay Vosburgh, jv@jvosburgh.net
next prev parent reply other threads:[~2025-10-22 2:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-21 5:22 [PATCH net-next] net: bonding: use workqueue to make sure peer notify updated Tonghao Zhang
2025-10-21 11:21 ` Simon Horman
2025-10-22 2:02 ` Jay Vosburgh [this message]
2025-10-26 9:59 ` Tonghao Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=955201.1761098579@famine \
--to=jv@jvosburgh.net \
--cc=andrew+netdev@lunn.ch \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=liuhangbin@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=razor@blackwall.org \
--cc=tonghao@bamaicloud.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.