Skip to contentSkip to conversation

net: sleepable ndo_set_rx_mode

PATCH Superseded Stanislav Fomichev 6 participants 36 messages Mar 20 – Mar 25

Subsystems (12)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover net: sleepable ndo_set_rx_mode

This series adds a new ndo_set_rx_mode_async callback that enables drivers to handle address list updates in a sleepable context. The current ndo_set_rx_mode is called under the netif_addr_lock spinlock with BHs disabled, which prevents drivers from sleeping. This is problematic for ops-locked drivers that need to sleep.

The approach:
1. Add snapshot/reconcile infrastructure for address lists
2. Introduce dev_rx_mode_work that takes snapshots under the lock, drops the lock, calls the driver, then reconciles changes back
3. Move promiscuity handling into the scheduled work as well
4. Convert existing ops-locked drivers to ndo_set_rx_mode_async
5. Add a warning for ops-locked drivers still using ndo_set_rx_mode
6. Add a selftest exercising the team+bridge+macvlan topology that triggers the addr_lock -> ops_lock ordering issue

v3:
- module_export(__rtnl_unlock) (nipa)
- s/netdev_uc_count/netdev_hw_addr_list_count/ in bnxt (Aleksandr)

v2:
- wifi: cfg80211: use __rtnl_unlock in nl80211_pre_doit (syzbot)
- simplify mlx5e_sync_netdev_addr for !uc (Cosmin)
- switch to snapshot in bnxt_cfg_rx_mode (Michael)
- add team to net/config (Jakub)

Stanislav Fomichev (13):
net: add address list snapshot and reconciliation infrastructure
wifi: cfg80211: use __rtnl_unlock in nl80211_pre_doit
net: introduce ndo_set_rx_mode_async and dev_rx_mode_work
net: move promiscuity handling into dev_rx_mode_work
fbnic: convert to ndo_set_rx_mode_async
mlx5: convert to ndo_set_rx_mode_async
bnxt: convert to ndo_set_rx_mode_async
bnxt: use snapshot in bnxt_cfg_rx_mode
iavf: convert to ndo_set_rx_mode_async
netdevsim: convert to ndo_set_rx_mode_async
dummy: convert to ndo_set_rx_mode_async
net: warn ops-locked drivers still using ndo_set_rx_mode
selftests: net: add team_bridge_macvlan rx_mode test

 Documentation/networking/netdevices.rst       |  12 +
 drivers/net/dummy.c                           |   6 +-
 drivers/net/ethernet/broadcom/bnxt/bnxt.c     |  55 +--
 drivers/net/ethernet/intel/iavf/iavf_main.c   |  14 +-
 .../net/ethernet/mellanox/mlx5/core/en/fs.h   |   5 +-
 .../net/ethernet/mellanox/mlx5/core/en_fs.c   |  30 +-
 .../net/ethernet/mellanox/mlx5/core/en_main.c |  16 +-
 .../net/ethernet/meta/fbnic/fbnic_netdev.c    |  20 +-
 .../net/ethernet/meta/fbnic/fbnic_netdev.h    |   4 +-
 drivers/net/ethernet/meta/fbnic/fbnic_pci.c   |   4 +-
 drivers/net/ethernet/meta/fbnic/fbnic_rpc.c   |   2 +-
 drivers/net/netdevsim/netdev.c                |   8 +-
 include/linux/netdevice.h                     |  26 ++
 net/core/dev.c                                | 176 ++++++++--
 net/core/dev.h                                |   1 +
 net/core/dev_addr_lists.c                     | 110 +++++-
 net/core/dev_addr_lists_test.c                | 321 +++++++++++++++++-
 net/core/rtnetlink.c                          |   1 +
 net/wireless/core.c                           |   1 +
 net/wireless/nl80211.c                        |   2 +-
 tools/testing/selftests/net/config            |   1 +
 tools/testing/selftests/net/rtnetlink.sh      |  44 +++
 22 files changed, 765 insertions(+), 94 deletions(-)
Signature · 1 line
2.53.0
#1 lore raw

PATCH v3 1/13 net: add address list snapshot and reconciliation infrastructure

Introduce __hw_addr_list_snapshot() and __hw_addr_list_reconcile() for use by the upcoming ndo_set_rx_mode_async callback.

The async rx_mode path needs to snapshot the device's unicast and multicast address lists under the addr_lock, hand those snapshots to the driver (which may sleep), and then propagate any sync_cnt changes back to the real lists. Two identical snapshots are taken:
a work copy for the driver to pass to __hw_addr_sync_dev() and a reference copy to compute deltas against.

__hw_addr_list_reconcile() walks the reference snapshot comparing each entry against the work snapshot to determine what the driver synced or unsynced. It then applies those deltas to the real list, handling concurrent modifications:

- If the real entry was concurrently removed but the driver synced it to hardware (delta > 0), re-insert a stale entry so the next work run properly unsyncs it from hardware.
- If the entry still exists, apply the delta normally. An entry whose refcount drops to zero is removed.

---
 include/linux/netdevice.h      |   6 +
 net/core/dev.h                 |   1 +
 net/core/dev_addr_lists.c      | 110 ++++++++++-
 net/core/dev_addr_lists_test.c | 321 ++++++++++++++++++++++++++++++++-
 4 files changed, 435 insertions(+), 3 deletions(-)
include/linux/netdevice.h +6 -0
index ae269a2e7f4d..469b7cdb3237 100644
@@ -4985,6 +4985,12 @@ void __hw_addr_unsync_dev(struct netdev_hw_addr_list *list,
 			  int (*unsync)(struct net_device *,
 					const unsigned char *));
 void __hw_addr_init(struct netdev_hw_addr_list *list);
+int __hw_addr_list_snapshot(struct netdev_hw_addr_list *snap,
+			    const struct netdev_hw_addr_list *list,
+			    int addr_len);
+void __hw_addr_list_reconcile(struct netdev_hw_addr_list *real_list,
+			      struct netdev_hw_addr_list *work,
+			      struct netdev_hw_addr_list *ref, int addr_len);
 
 /* Functions used for device addresses handling */
 void dev_addr_mod(struct net_device *dev, unsigned int offset,
net/core/dev.h +1 -0
index 781619e76b3e..acc925b7b337 100644
@@ -69,6 +69,7 @@ void linkwatch_run_queue(void);
 void dev_addr_flush(struct net_device *dev);
 int dev_addr_init(struct net_device *dev);
 void dev_addr_check(struct net_device *dev);
+void __hw_addr_flush(struct netdev_hw_addr_list *list);
 
 #if IS_ENABLED(CONFIG_NET_SHAPER)
 void net_shaper_flush_netdev(struct net_device *dev);
net/core/dev_addr_lists.c +109 -1

122 lines not on this page · raw message

net/core/dev_addr_lists_test.c +319 -2

358 lines not on this page · raw message

Signature · 1 line
2.53.0
maintainer
#2 lore raw

Re: [PATCH net-next v3 01/13] net: add address list snapshot and reconciliation infrastructure

Review

Quoted 2 lines · On Thu, 19 Mar 2026 18:24:49 -0700 Stanislav Fomichev wrote:
(quoted diff) +2 -0
+EXPORT_SYMBOL(__hw_addr_list_snapshot);
+EXPORT_SYMBOL(__hw_addr_list_reconcile);

Why? For the kunit tests?

#3 lore raw

Re: [PATCH net-next v3 01/13] net: add address list snapshot and reconciliation infrastructure

Quoted 5 lines · Jakub Kicinski

Review

Quoted 2 lines · On Thu, 19 Mar 2026 18:24:49 -0700 Stanislav Fomichev wrote:
(quoted diff) +2 -0
+EXPORT_SYMBOL(__hw_addr_list_snapshot);
+EXPORT_SYMBOL(__hw_addr_list_reconcile);

Why? For the kunit tests?

Yeah, no good reason, will remove!

#4 lore raw

PATCH v3 2/13 wifi: cfg80211: use __rtnl_unlock in nl80211_pre_doit

In reply to Stanislav Fomichev

nl80211_pre_doit acquires rtnl_lock and then wiphy_lock, releasing rtnl while keeping wiphy_lock held until post_doit. With the introduction of rx_mode_wq and its flush in netdev_run_todo, calling rtnl_unlock here creates a circular lock dependency:

  Chain exists of:
    (wq_completion)rx_mode_wq --> rtnl_mutex --> &rdev->wiphy.mtx

   Possible unsafe locking scenario:
         CPU0                    CPU1
         ----                    ----
    lock(&rdev->wiphy.mtx);
                                 lock(rtnl_mutex);
                                 lock(&rdev->wiphy.mtx);
    lock((wq_completion)rx_mode_wq);

Switch to __rtnl_unlock to skip netdev_run_todo in nl80211_pre_doit. This seems safe because we run before the op.

---
 net/core/rtnetlink.c   | 1 +
 net/wireless/core.c    | 1 +
 net/wireless/nl80211.c | 2 +-
 3 files changed, 3 insertions(+), 1 deletion(-)
net/core/rtnetlink.c +1 -0
index dad4b1054955..b1bfb4a4aedd 100644
@@ -150,6 +150,7 @@ void __rtnl_unlock(void)
 		head = next;
 	}
 }
+EXPORT_SYMBOL_NS_GPL(__rtnl_unlock, "NETDEV_INTERNAL");
 
 void rtnl_unlock(void)
 {
net/wireless/core.c +1 -0
index 23afc250bc10..a78a9b613c94 100644
@@ -41,6 +41,7 @@ MODULE_AUTHOR("Johannes Berg");
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("wireless configuration support");
 MODULE_ALIAS_GENL_FAMILY(NL80211_GENL_NAME);
+MODULE_IMPORT_NS("NETDEV_INTERNAL");
 
 /* RCU-protected (and RTNL for writers) */
 LIST_HEAD(cfg80211_rdev_list);
net/wireless/nl80211.c +1 -1
index e15cd26f3a79..f8ed8730cf1c 100644
@@ -18203,7 +18203,7 @@ static int nl80211_pre_doit(const struct genl_split_ops *ops,
 		__release(&rdev->wiphy.mtx);
 	}
 	if (!(internal_flags & NL80211_FLAG_NEED_RTNL))
-		rtnl_unlock();
+		__rtnl_unlock();
 
 	return 0;
 out_unlock:
Signature · 1 line
2.53.0
#5 lore raw

PATCH v3 3/13 net: introduce ndo_set_rx_mode_async and dev_rx_mode_work

In reply to Stanislav Fomichev

Add ndo_set_rx_mode_async callback that drivers can implement instead of the legacy ndo_set_rx_mode. The legacy callback runs under the netif_addr_lock spinlock with BHs disabled, preventing drivers from sleeping. The async variant runs from a work queue with rtnl_lock and netdev_lock_ops held, in fully sleepable context.

When __dev_set_rx_mode() sees ndo_set_rx_mode_async, it schedules dev_rx_mode_work instead of calling the driver inline. The work function takes two snapshots of each address list (uc/mc) under the addr_lock, then drops the lock and calls the driver with the work copies. After the driver returns, it reconciles the snapshots back to the real lists under the lock.

---
 Documentation/networking/netdevices.rst |  8 +++
 include/linux/netdevice.h               | 20 ++++++
 net/core/dev.c                          | 95 +++++++++++++++++++++++--
 3 files changed, 116 insertions(+), 7 deletions(-)
Documentation/networking/netdevices.rst +8 -0
index 35704d115312..dc83d78d3b27 100644
@@ -289,6 +289,14 @@ struct net_device synchronization rules
 ndo_set_rx_mode:
 	Synchronization: netif_addr_lock spinlock.
 	Context: BHs disabled
+	Notes: Deprecated in favor of sleepable ndo_set_rx_mode_async.
+
+ndo_set_rx_mode_async:
+	Synchronization: rtnl_lock() semaphore. In addition, netdev instance
+	lock if the driver implements queue management or shaper API.
+	Context: process (from a work queue)
+	Notes: Sleepable version of ndo_set_rx_mode. Receives snapshots
+	of the unicast and multicast address lists.
 
 ndo_setup_tc:
 	``TC_SETUP_BLOCK`` and ``TC_SETUP_FT`` are running under NFT locks
include/linux/netdevice.h +20 -0
index 469b7cdb3237..b05bdd67b807 100644
@@ -1117,6 +1117,16 @@ struct netdev_net_notifier {
  *	This function is called device changes address list filtering.
  *	If driver handles unicast address filtering, it should set
  *	IFF_UNICAST_FLT in its priv_flags.
+ *	Cannot sleep, called with netif_addr_lock_bh held.
+ *	Deprecated in favor of sleepable ndo_set_rx_mode_async.
+ *
+ * void (*ndo_set_rx_mode_async)(struct net_device *dev,
+ *				 struct netdev_hw_addr_list *uc,
+ *				 struct netdev_hw_addr_list *mc);
+ *	Sleepable version of ndo_set_rx_mode. Called from a work queue
+ *	with rtnl_lock and netdev_lock_ops(dev) held. The uc/mc parameters
+ *	are snapshots of the address lists - iterate with
+ *	netdev_hw_addr_list_for_each(ha, uc).
  *
  * int (*ndo_set_mac_address)(struct net_device *dev, void *addr);
  *	This function  is called when the Media Access Control address
@@ -1437,6 +1447,9 @@ struct net_device_ops {
 	void			(*ndo_change_rx_flags)(struct net_device *dev,
 						       int flags);
 	void			(*ndo_set_rx_mode)(struct net_device *dev);
+	void			(*ndo_set_rx_mode_async)(struct net_device *dev,
+							 struct netdev_hw_addr_list *uc,
+							 struct netdev_hw_addr_list *mc);
 	int			(*ndo_set_mac_address)(struct net_device *dev,
 						       void *addr);
 	int			(*ndo_validate_addr)(struct net_device *dev);
@@ -1903,6 +1916,7 @@ enum netdev_reg_state {
  *				has been enabled due to the need to listen to
  *				additional unicast addresses in a device that
  *				does not implement ndo_set_rx_mode()
+ *	@rx_mode_work:		Work queue entry for ndo_set_rx_mode_async()
  *	@uc:			unicast mac addresses
  *	@mc:			multicast mac addresses
  *	@dev_addrs:		list of device hw addresses
@@ -2293,6 +2307,7 @@ struct net_device {
 	unsigned int		promiscuity;
 	unsigned int		allmulti;
 	bool			uc_promisc;
+	struct work_struct	rx_mode_work;
 #ifdef CONFIG_LOCKDEP
 	unsigned char		nested_level;
 #endif
@@ -4661,6 +4676,11 @@ static inline bool netif_device_present(const struct net_device *dev)
 	return test_bit(__LINK_STATE_PRESENT, &dev->state);
 }
 
+static inline bool netif_up_and_present(const struct net_device *dev)
+{
+	return (dev->flags & IFF_UP) && netif_device_present(dev);
+}
+
 void netif_device_detach(struct net_device *dev);
 
 void netif_device_attach(struct net_device *dev);
net/core/dev.c +88 -7

140 lines not on this page · raw message

Signature · 1 line
2.53.0
#6 lore raw

RE: [Intel-wired-lan] [PATCH net-next v3 03/13] net: introduce ndo_set_rx_mode_async and dev_rx_mode_work

Quoted 57 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Stanislav Fomichev
Sent: Friday, March 20, 2026 2:25 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Keller, Jacob E <[email protected]>; [email protected]; [email protected]; [email protected]; Loktionov, Aleksandr <[email protected]>; [email protected]; linux- [email protected]; [email protected]; intel-wired- [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: [Intel-wired-lan] [PATCH net-next v3 03/13] net: introduce ndo_set_rx_mode_async and dev_rx_mode_work

Add ndo_set_rx_mode_async callback that drivers can implement instead of the legacy ndo_set_rx_mode. The legacy callback runs under the netif_addr_lock spinlock with BHs disabled, preventing drivers from sleeping. The async variant runs from a work queue with rtnl_lock and netdev_lock_ops held, in fully sleepable context.

When __dev_set_rx_mode() sees ndo_set_rx_mode_async, it schedules dev_rx_mode_work instead of calling the driver inline. The work function takes two snapshots of each address list (uc/mc) under the addr_lock, then drops the lock and calls the driver with the work copies. After the driver returns, it reconciles the snapshots back to the real lists under the lock.

---
 Documentation/networking/netdevices.rst |  8 +++
 include/linux/netdevice.h               | 20 ++++++
 net/core/dev.c                          | 95 +++++++++++++++++++++++-
(quoted diff) +0 -1
-
 3 files changed, 116 insertions(+), 7 deletions(-)
Documentation/networking/netdevices.rst +0 -0
index 35704d115312..dc83d78d3b27 100644
@@ -289,6 +289,14 @@ struct net_device synchronization rules
 ndo_set_rx_mode:
 	Synchronization: netif_addr_lock spinlock.
 	Context: BHs disabled

...

Quoted 14 lines

to

Documentation/networking/netdevices.rst +7 -0
+device
+ * and configure RX filtering.
+ * @dev: device
+ *
+ * When the device doesn't support unicast filtering it is put in
+promiscuous
+ * mode while unicast addresses are present.
  */
 void __dev_set_rx_mode(struct net_device *dev)  {
 	const struct net_device_ops *ops = dev->netdev_ops;
 
 	/* dev_open will call this function so the list will stay sane.

*/

Documentation/networking/netdevices.rst

Quoted 8 lines
Documentation/networking/netdevices.rst +3 -2
-	if (!(dev->flags&IFF_UP))
+	if (!netif_up_and_present(dev))
 		return;
 
-	if (!netif_device_present(dev))
+	if (ops->ndo_set_rx_mode_async) {
+		queue_work(rx_mode_wq, &dev->rx_mode_work);
 		return;

This early return skips the legacy core fallback below. Before this patch, __dev_set_rx_mode() continued into the existing unicast-filter handling when the device did not advertise IFF_UNICAST_FLT.

After this patch, any driver that implements ndo_set_rx_mode_async but does not set IFF_UNICAST_FLT will never hit that fallback path.

+ }

Quoted 7 lines
Documentation/networking/netdevices.rst +0 -0
 	if (!(dev->priv_flags & IFF_UNICAST_FLT)) {
 		/* Unicast addresses changes may only happen under the

rtnl, @@ -11708,6 +11772,16 @@ void netdev_run_todo(void)

__rtnl_unlock();

...

Quoted 5 lines
Documentation/networking/netdevices.rst +0 -1
 	open_softirq(NET_TX_SOFTIRQ, net_tx_action);
 	open_softirq(NET_RX_SOFTIRQ, net_rx_action);
 
--

2.53.0

#7 lore raw

Re: [Intel-wired-lan] [PATCH net-next v3 03/13] net: introduce ndo_set_rx_mode_async and dev_rx_mode_work

Quoted 87 lines · Aleksandr
Quoted 57 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Stanislav Fomichev
Sent: Friday, March 20, 2026 2:25 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Keller, Jacob E <[email protected]>; [email protected]; [email protected]; [email protected]; Loktionov, Aleksandr <[email protected]>; [email protected]; linux- [email protected]; [email protected]; intel-wired- [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: [Intel-wired-lan] [PATCH net-next v3 03/13] net: introduce ndo_set_rx_mode_async and dev_rx_mode_work

Add ndo_set_rx_mode_async callback that drivers can implement instead of the legacy ndo_set_rx_mode. The legacy callback runs under the netif_addr_lock spinlock with BHs disabled, preventing drivers from sleeping. The async variant runs from a work queue with rtnl_lock and netdev_lock_ops held, in fully sleepable context.

When __dev_set_rx_mode() sees ndo_set_rx_mode_async, it schedules dev_rx_mode_work instead of calling the driver inline. The work function takes two snapshots of each address list (uc/mc) under the addr_lock, then drops the lock and calls the driver with the work copies. After the driver returns, it reconciles the snapshots back to the real lists under the lock.

---
 Documentation/networking/netdevices.rst |  8 +++
 include/linux/netdevice.h               | 20 ++++++
 net/core/dev.c                          | 95 +++++++++++++++++++++++-
(quoted diff) +0 -1
-
 3 files changed, 116 insertions(+), 7 deletions(-)
Documentation/networking/netdevices.rst +0 -0
index 35704d115312..dc83d78d3b27 100644
@@ -289,6 +289,14 @@ struct net_device synchronization rules
 ndo_set_rx_mode:
 	Synchronization: netif_addr_lock spinlock.
 	Context: BHs disabled

...

Quoted 14 lines

to

Documentation/networking/netdevices.rst +7 -0
+device
+ * and configure RX filtering.
+ * @dev: device
+ *
+ * When the device doesn't support unicast filtering it is put in
+promiscuous
+ * mode while unicast addresses are present.
  */
 void __dev_set_rx_mode(struct net_device *dev)  {
 	const struct net_device_ops *ops = dev->netdev_ops;
 
 	/* dev_open will call this function so the list will stay sane.

*/

Documentation/networking/netdevices.rst

Quoted 8 lines
Documentation/networking/netdevices.rst +3 -2
-	if (!(dev->flags&IFF_UP))
+	if (!netif_up_and_present(dev))
 		return;
 
-	if (!netif_device_present(dev))
+	if (ops->ndo_set_rx_mode_async) {
+		queue_work(rx_mode_wq, &dev->rx_mode_work);
 		return;

This early return skips the legacy core fallback below. Before this patch, __dev_set_rx_mode() continued into the existing unicast-filter handling when the device did not advertise IFF_UNICAST_FLT.

Quoted 3 lines

After this patch, any driver that implements ndo_set_rx_mode_async but does not set IFF_UNICAST_FLT will never hit that fallback path.

I believe this is addressed later in "net: move promiscuity handling into dev_rx_mode_work"? That should take care of doing __dev_set_promiscuity for !IFF_UNICAST_FLT+ndo_set_rx_mode_async. Not sure if there is a better way to rearrange the chunks in the patches.

        if (ops->ndo_set_rx_mode_async) {
                ...

+ promisc_inc = dev_uc_promisc_update(dev);
+
+ netif_addr_unlock_bh(dev);
+ } else {
+ netif_addr_lock_bh(dev);
+ promisc_inc = dev_uc_promisc_update(dev);
+ netif_addr_unlock_bh(dev);
+ }
+
+ if (promisc_inc)
+ __dev_set_promiscuity(dev, promisc_inc, false);
+

maintainer
#8 lore raw

Re: [PATCH net-next v3 03/13] net: introduce ndo_set_rx_mode_async and dev_rx_mode_work

In reply to Stanislav Fomichev
Quoted 5 lines · On Thu, 19 Mar 2026 18:24:51 -0700 Stanislav Fomichev wrote:
Documentation/networking/netdevices.rst +0 -0
index 35704d115312..dc83d78d3b27 100644

Documentation/networking/netdevices.rst struct net_device synchronization rules · line 298

Quoted 10 lines
Documentation/networking/netdevices.rst +6 -0
@@ -289,6 +289,14 @@ struct net_device synchronization rules
 ndo_set_rx_mode:
 	Synchronization: netif_addr_lock spinlock.
 	Context: BHs disabled
+	Notes: Deprecated in favor of sleepable ndo_set_rx_mode_async.
 
+ndo_set_rx_mode_async:
+	Synchronization: rtnl_lock() semaphore. In addition, netdev instance
+	lock if the driver implements queue management or shaper API.
+	Context: process (from a work queue)
+	Notes: Sleepable version of ndo_set_rx_mode. Receives snapshots

It's probably just my weirdness but I find creating adjectives out of random nouns by adding "-able" to be in poor taste. "sleepable" took root in certain three letter subsystems but I hope it won't in netdev.

Please use your words:

Notes: Async version of ndo_set_rx_mode which runs in process context. Receives snapshots f the unicast and multicast address lists.

Quoted 52 lines
Documentation/networking/netdevices.rst +1 -0
+	of the unicast and multicast address lists.
 
 ndo_setup_tc:
 	``TC_SETUP_BLOCK`` and ``TC_SETUP_FT`` are running under NFT locks
include/linux/netdevice.h +15 -0
index 469b7cdb3237..b05bdd67b807 100644
@@ -1117,6 +1117,16 @@ struct netdev_net_notifier {
  *	This function is called device changes address list filtering.
  *	If driver handles unicast address filtering, it should set
  *	IFF_UNICAST_FLT in its priv_flags.
+ *	Cannot sleep, called with netif_addr_lock_bh held.
+ *	Deprecated in favor of sleepable ndo_set_rx_mode_async.
+ *
+ * void (*ndo_set_rx_mode_async)(struct net_device *dev,
+ *				 struct netdev_hw_addr_list *uc,
+ *				 struct netdev_hw_addr_list *mc);
+ *	Sleepable version of ndo_set_rx_mode. Called from a work queue
+ *	with rtnl_lock and netdev_lock_ops(dev) held. The uc/mc parameters
+ *	are snapshots of the address lists - iterate with
+ *	netdev_hw_addr_list_for_each(ha, uc).
  *
  * int (*ndo_set_mac_address)(struct net_device *dev, void *addr);
  *	This function  is called when the Media Access Control address
@@ -1437,6 +1447,9 @@ struct net_device_ops {
 	void			(*ndo_change_rx_flags)(struct net_device *dev,
 						       int flags);
 	void			(*ndo_set_rx_mode)(struct net_device *dev);
+	void			(*ndo_set_rx_mode_async)(struct net_device *dev,
+							 struct netdev_hw_addr_list *uc,
+							 struct netdev_hw_addr_list *mc);
 	int			(*ndo_set_mac_address)(struct net_device *dev,
 						       void *addr);
 	int			(*ndo_validate_addr)(struct net_device *dev);
@@ -1903,6 +1916,7 @@ enum netdev_reg_state {
  *				has been enabled due to the need to listen to
  *				additional unicast addresses in a device that
  *				does not implement ndo_set_rx_mode()
+ *	@rx_mode_work:		Work queue entry for ndo_set_rx_mode_async()
  *	@uc:			unicast mac addresses
  *	@mc:			multicast mac addresses
  *	@dev_addrs:		list of device hw addresses
@@ -2293,6 +2307,7 @@ struct net_device {
 	unsigned int		promiscuity;
 	unsigned int		allmulti;
 	bool			uc_promisc;
+	struct work_struct	rx_mode_work;
 #ifdef CONFIG_LOCKDEP
 	unsigned char		nested_level;
 #endif

include/linux/netdevice.h static inline bool netif_device_present(const struct net_device *dev) · line 4681

Quoted 6 lines
include/linux/netdevice.h +3 -0
@@ -4661,6 +4676,11 @@ static inline bool netif_device_present(const struct net_device *dev)
 	return test_bit(__LINK_STATE_PRESENT, &dev->state);
 }
 
+static inline bool netif_up_and_present(const struct net_device *dev)
+{
+	return (dev->flags & IFF_UP) && netif_device_present(dev);

Is this really worth a dedicated helper? What are you trying to express here semantically?

Quoted 36 lines
include/linux/netdevice.h +1 -0
+
 void netif_device_detach(struct net_device *dev);
 
 void netif_device_attach(struct net_device *dev);
net/core/dev.c +12 -5
index 200d44883fc1..fedc423306fc 100644
@@ -2381,6 +2381,8 @@ static void netstamp_clear(struct work_struct *work)
 static DECLARE_WORK(netstamp_work, netstamp_clear);
 #endif
 
+static struct workqueue_struct *rx_mode_wq;
+
 void net_enable_timestamp(void)
 {
 #ifdef CONFIG_JUMP_LABEL
@@ -9669,22 +9671,84 @@ int netif_set_allmulti(struct net_device *dev, int inc, bool notify)
 	return 0;
 }
 
-/*
- *	Upload unicast and multicast address lists to device and
- *	configure RX filtering. When the device doesn't support unicast
- *	filtering it is put in promiscuous mode while unicast addresses
- *	are present.
+static void dev_rx_mode_work(struct work_struct *work)
+{
+	struct net_device *dev = container_of(work, struct net_device,
+					      rx_mode_work);
+	struct netdev_hw_addr_list uc_snap, mc_snap, uc_ref, mc_ref;
+	const struct net_device_ops *ops = dev->netdev_ops;
+	int err;
+
+	__hw_addr_init(&uc_snap);
+	__hw_addr_init(&mc_snap);

net/core/dev.c int netif_set_allmulti(struct net_device *dev, int inc, bool notify) · line 9693

Quoted 10 lines
net/core/dev.c +10 -0
+	__hw_addr_init(&uc_ref);
+	__hw_addr_init(&mc_ref);
+
+	rtnl_lock();
+	netdev_lock_ops(dev);
+
+	if (!netif_up_and_present(dev))
+		goto out;
+
+	if (ops->ndo_set_rx_mode_async) {

How did we get here if we don't have this op?
Are you planning to plumb more code thru this work in the future? If yes the whole rx_mode handling should be in a dedicated helper rather than indenting most of the function.

net/core/dev.c int netif_set_allmulti(struct net_device *dev, int inc, bool notify) · line 9706

Quoted 13 lines
net/core/dev.c +13 -0
+		netif_addr_lock_bh(dev);
+
+		err = __hw_addr_list_snapshot(&uc_snap, &dev->uc,
+					      dev->addr_len);
+		if (!err)
+			err = __hw_addr_list_snapshot(&uc_ref, &dev->uc,
+						      dev->addr_len);
+		if (!err)
+			err = __hw_addr_list_snapshot(&mc_snap, &dev->mc,
+						      dev->addr_len);
+		if (!err)
+			err = __hw_addr_list_snapshot(&mc_ref, &dev->mc,
+						      dev->addr_len);

This doesn't get slow with a few thousands of addresses?

Quoted 53 lines
net/core/dev.c +36 -2
+		netif_addr_unlock_bh(dev);
+
+		if (err) {
+			netdev_WARN(dev, "failed to sync uc/mc addresses\n");
+			__hw_addr_flush(&uc_snap);
+			__hw_addr_flush(&uc_ref);
+			__hw_addr_flush(&mc_snap);
+			goto out;
+		}
+
+		ops->ndo_set_rx_mode_async(dev, &uc_snap, &mc_snap);
+
+		netif_addr_lock_bh(dev);
+		__hw_addr_list_reconcile(&dev->uc, &uc_snap,
+					 &uc_ref, dev->addr_len);
+		__hw_addr_list_reconcile(&dev->mc, &mc_snap,
+					 &mc_ref, dev->addr_len);
+		netif_addr_unlock_bh(dev);
+	}
+
+out:
+	netdev_unlock_ops(dev);
+	rtnl_unlock();
+}
+
+/**
+ * __dev_set_rx_mode() - upload unicast and multicast address lists to device
+ * and configure RX filtering.
+ * @dev: device
+ *
+ * When the device doesn't support unicast filtering it is put in promiscuous
+ * mode while unicast addresses are present.
  */
 void __dev_set_rx_mode(struct net_device *dev)
 {
 	const struct net_device_ops *ops = dev->netdev_ops;
 
 	/* dev_open will call this function so the list will stay sane. */
-	if (!(dev->flags&IFF_UP))
+	if (!netif_up_and_present(dev))
 		return;
 
-	if (!netif_device_present(dev))
+	if (ops->ndo_set_rx_mode_async) {
+		queue_work(rx_mode_wq, &dev->rx_mode_work);
 		return;
+	}
 
 	if (!(dev->priv_flags & IFF_UNICAST_FLT)) {
 		/* Unicast addresses changes may only happen under the rtnl,
@@ -11708,6 +11772,16 @@ void netdev_run_todo(void)
 
 	__rtnl_unlock();

net/core/dev.c void netdev_run_todo(void) · line 11783

Quoted 10 lines
net/core/dev.c +9 -0
 
+	/* Make sure all pending rx_mode work completes before returning.
+	 *
+	 * rx_mode_wq may be NULL during early boot:
+	 * core_initcall(netlink_proto_init) vs subsys_initcall(net_dev_init).
+	 *
+	 * Check current_work() to avoid flushing from the wq.
+	 */
+	if (rx_mode_wq && !current_work())
+		flush_workqueue(rx_mode_wq);

Can we give the work a reference on the netdev (at init time) and cancel + release it here instead of flushing / waiting?

Quoted 12 lines
net/core/dev.c +1 -0
 	/* Wait for rcu callbacks to finish before next phase */
 	if (!list_empty(&list))
 		rcu_barrier();
@@ -12099,6 +12173,7 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
 #endif
 
 	mutex_init(&dev->lock);
+	INIT_WORK(&dev->rx_mode_work, dev_rx_mode_work);
 
 	dev->priv_flags = IFF_XMIT_DST_RELEASE | IFF_XMIT_DST_RELEASE_PERM;
 	setup(dev);

net/core/dev.c void free_netdev(struct net_device *dev) · line 12281

Quoted 4 lines
net/core/dev.c +1 -0
@@ -12203,6 +12278,8 @@ void free_netdev(struct net_device *dev)
 
 	kfree(rcu_dereference_protected(dev->ingress_queue, 1));
 
+	cancel_work_sync(&dev->rx_mode_work);

Should never happen so maybe wrap it in a WARN ?

Quoted 14 lines
net/core/dev.c +4 -0
 	/* Flush device addresses */
 	dev_addr_flush(dev);
 
@@ -13296,6 +13373,10 @@ static int __init net_dev_init(void)
 	if (register_pernet_device(&default_device_ops))
 		goto out;
 
+	rx_mode_wq = alloc_ordered_workqueue("rx_mode_wq", 0);
+	if (!rx_mode_wq)
+		goto out;
+
 	open_softirq(NET_TX_SOFTIRQ, net_tx_action);
 	open_softirq(NET_RX_SOFTIRQ, net_rx_action);
 
#9 lore raw

Re: [PATCH net-next v3 03/13] net: introduce ndo_set_rx_mode_async and dev_rx_mode_work

Quoted 22 lines · Jakub Kicinski
Quoted 5 lines · On Thu, 19 Mar 2026 18:24:51 -0700 Stanislav Fomichev wrote:
Documentation/networking/netdevices.rst +0 -0
index 35704d115312..dc83d78d3b27 100644

Documentation/networking/netdevices.rst struct net_device synchronization rules · line 298

Quoted 10 lines
Documentation/networking/netdevices.rst +6 -0
@@ -289,6 +289,14 @@ struct net_device synchronization rules
 ndo_set_rx_mode:
 	Synchronization: netif_addr_lock spinlock.
 	Context: BHs disabled
+	Notes: Deprecated in favor of sleepable ndo_set_rx_mode_async.
 
+ndo_set_rx_mode_async:
+	Synchronization: rtnl_lock() semaphore. In addition, netdev instance
+	lock if the driver implements queue management or shaper API.
+	Context: process (from a work queue)
+	Notes: Sleepable version of ndo_set_rx_mode. Receives snapshots

It's probably just my weirdness but I find creating adjectives out of random nouns by adding "-able" to be in poor taste. "sleepable" took root in certain three letter subsystems but I hope it won't in netdev.

Quoted 4 lines

Please use your words:

Notes: Async version of ndo_set_rx_mode which runs in process context. Receives snapshots f the unicast and multicast address lists.

SG, will do!

Quoted 55 lines
Quoted 55 lines
Documentation/networking/netdevices.rst +1 -0
+	of the unicast and multicast address lists.
 
 ndo_setup_tc:
 	``TC_SETUP_BLOCK`` and ``TC_SETUP_FT`` are running under NFT locks
include/linux/netdevice.h +15 -0
index 469b7cdb3237..b05bdd67b807 100644
@@ -1117,6 +1117,16 @@ struct netdev_net_notifier {
  *	This function is called device changes address list filtering.
  *	If driver handles unicast address filtering, it should set
  *	IFF_UNICAST_FLT in its priv_flags.
+ *	Cannot sleep, called with netif_addr_lock_bh held.
+ *	Deprecated in favor of sleepable ndo_set_rx_mode_async.
+ *
+ * void (*ndo_set_rx_mode_async)(struct net_device *dev,
+ *				 struct netdev_hw_addr_list *uc,
+ *				 struct netdev_hw_addr_list *mc);
+ *	Sleepable version of ndo_set_rx_mode. Called from a work queue
+ *	with rtnl_lock and netdev_lock_ops(dev) held. The uc/mc parameters
+ *	are snapshots of the address lists - iterate with
+ *	netdev_hw_addr_list_for_each(ha, uc).
  *
  * int (*ndo_set_mac_address)(struct net_device *dev, void *addr);
  *	This function  is called when the Media Access Control address
@@ -1437,6 +1447,9 @@ struct net_device_ops {
 	void			(*ndo_change_rx_flags)(struct net_device *dev,
 						       int flags);
 	void			(*ndo_set_rx_mode)(struct net_device *dev);
+	void			(*ndo_set_rx_mode_async)(struct net_device *dev,
+							 struct netdev_hw_addr_list *uc,
+							 struct netdev_hw_addr_list *mc);
 	int			(*ndo_set_mac_address)(struct net_device *dev,
 						       void *addr);
 	int			(*ndo_validate_addr)(struct net_device *dev);
@@ -1903,6 +1916,7 @@ enum netdev_reg_state {
  *				has been enabled due to the need to listen to
  *				additional unicast addresses in a device that
  *				does not implement ndo_set_rx_mode()
+ *	@rx_mode_work:		Work queue entry for ndo_set_rx_mode_async()
  *	@uc:			unicast mac addresses
  *	@mc:			multicast mac addresses
  *	@dev_addrs:		list of device hw addresses
@@ -2293,6 +2307,7 @@ struct net_device {
 	unsigned int		promiscuity;
 	unsigned int		allmulti;
 	bool			uc_promisc;
+	struct work_struct	rx_mode_work;
 #ifdef CONFIG_LOCKDEP
 	unsigned char		nested_level;
 #endif
@@ -4661,6 +4676,11 @@ static inline bool netif_device_present(const struct net_device *dev)
 	return test_bit(__LINK_STATE_PRESENT, &dev->state);
 }
 
Quoted 6 lines

include/linux/netdevice.h static inline bool netif_device_present(const struct net_device *dev) · line 4681

Quoted 3 lines
include/linux/netdevice.h +3 -0
+static inline bool netif_up_and_present(const struct net_device *dev)
+{
+	return (dev->flags & IFF_UP) && netif_device_present(dev);

Is this really worth a dedicated helper? What are you trying to express here semantically?

I mostly added it to avoid repeating the same present & UP check. Will undo.

Quoted 43 lines
Quoted 43 lines
include/linux/netdevice.h +1 -0
+
 void netif_device_detach(struct net_device *dev);
 
 void netif_device_attach(struct net_device *dev);
net/core/dev.c +19 -5
index 200d44883fc1..fedc423306fc 100644
@@ -2381,6 +2381,8 @@ static void netstamp_clear(struct work_struct *work)
 static DECLARE_WORK(netstamp_work, netstamp_clear);
 #endif
 
+static struct workqueue_struct *rx_mode_wq;
+
 void net_enable_timestamp(void)
 {
 #ifdef CONFIG_JUMP_LABEL
@@ -9669,22 +9671,84 @@ int netif_set_allmulti(struct net_device *dev, int inc, bool notify)
 	return 0;
 }
 
-/*
- *	Upload unicast and multicast address lists to device and
- *	configure RX filtering. When the device doesn't support unicast
- *	filtering it is put in promiscuous mode while unicast addresses
- *	are present.
+static void dev_rx_mode_work(struct work_struct *work)
+{
+	struct net_device *dev = container_of(work, struct net_device,
+					      rx_mode_work);
+	struct netdev_hw_addr_list uc_snap, mc_snap, uc_ref, mc_ref;
+	const struct net_device_ops *ops = dev->netdev_ops;
+	int err;
+
+	__hw_addr_init(&uc_snap);
+	__hw_addr_init(&mc_snap);
+	__hw_addr_init(&uc_ref);
+	__hw_addr_init(&mc_ref);
+
+	rtnl_lock();
+	netdev_lock_ops(dev);
+
+	if (!netif_up_and_present(dev))
Quoted 8 lines

net/core/dev.c int netif_set_allmulti(struct net_device *dev, int inc, bool notify) · line 9693

Quoted 3 lines
net/core/dev.c +3 -0
+		goto out;
+
+	if (ops->ndo_set_rx_mode_async) {

How did we get here if we don't have this op?
Are you planning to plumb more code thru this work in the future? If yes the whole rx_mode handling should be in a dedicated helper rather than indenting most of the function.

I do expand this, yes, in the subsequent patches. With promisc handling (ndo_change_rx_flags) and ndo_set_rx_mode fallback. Let me try to see if I can add some helper+struct to manage a set of snapshots to make it a bit more clear.

Quoted 7 lines
Quoted 7 lines
net/core/dev.c +7 -0
+		netif_addr_lock_bh(dev);
+
+		err = __hw_addr_list_snapshot(&uc_snap, &dev->uc,
+					      dev->addr_len);
+		if (!err)
+			err = __hw_addr_list_snapshot(&uc_ref, &dev->uc,
+						      dev->addr_len);
Quoted 8 lines

net/core/dev.c int netif_set_allmulti(struct net_device *dev, int inc, bool notify) · line 9706

Quoted 6 lines
net/core/dev.c +6 -0
+		if (!err)
+			err = __hw_addr_list_snapshot(&mc_snap, &dev->mc,
+						      dev->addr_len);
+		if (!err)
+			err = __hw_addr_list_snapshot(&mc_ref, &dev->mc,
+						      dev->addr_len);

This doesn't get slow with a few thousands of addresses?

I can add kunit benchmark and attach the output? Although not sure where to go from that. The alternative to this is allocating an array of entries. I started with that initially but __hw_addr_sync_dev wants to kfree the individual entries and I decided not to have a separate helpers to manage the snapshots.

Quoted 54 lines
Quoted 54 lines
net/core/dev.c +36 -2
+		netif_addr_unlock_bh(dev);
+
+		if (err) {
+			netdev_WARN(dev, "failed to sync uc/mc addresses\n");
+			__hw_addr_flush(&uc_snap);
+			__hw_addr_flush(&uc_ref);
+			__hw_addr_flush(&mc_snap);
+			goto out;
+		}
+
+		ops->ndo_set_rx_mode_async(dev, &uc_snap, &mc_snap);
+
+		netif_addr_lock_bh(dev);
+		__hw_addr_list_reconcile(&dev->uc, &uc_snap,
+					 &uc_ref, dev->addr_len);
+		__hw_addr_list_reconcile(&dev->mc, &mc_snap,
+					 &mc_ref, dev->addr_len);
+		netif_addr_unlock_bh(dev);
+	}
+
+out:
+	netdev_unlock_ops(dev);
+	rtnl_unlock();
+}
+
+/**
+ * __dev_set_rx_mode() - upload unicast and multicast address lists to device
+ * and configure RX filtering.
+ * @dev: device
+ *
+ * When the device doesn't support unicast filtering it is put in promiscuous
+ * mode while unicast addresses are present.
  */
 void __dev_set_rx_mode(struct net_device *dev)
 {
 	const struct net_device_ops *ops = dev->netdev_ops;
 
 	/* dev_open will call this function so the list will stay sane. */
-	if (!(dev->flags&IFF_UP))
+	if (!netif_up_and_present(dev))
 		return;
 
-	if (!netif_device_present(dev))
+	if (ops->ndo_set_rx_mode_async) {
+		queue_work(rx_mode_wq, &dev->rx_mode_work);
 		return;
+	}
 
 	if (!(dev->priv_flags & IFF_UNICAST_FLT)) {
 		/* Unicast addresses changes may only happen under the rtnl,
@@ -11708,6 +11772,16 @@ void netdev_run_todo(void)
 
 	__rtnl_unlock();
 
Quoted 12 lines

net/core/dev.c void netdev_run_todo(void) · line 11783

Quoted 9 lines
net/core/dev.c +9 -0
+	/* Make sure all pending rx_mode work completes before returning.
+	 *
+	 * rx_mode_wq may be NULL during early boot:
+	 * core_initcall(netlink_proto_init) vs subsys_initcall(net_dev_init).
+	 *
+	 * Check current_work() to avoid flushing from the wq.
+	 */
+	if (rx_mode_wq && !current_work())
+		flush_workqueue(rx_mode_wq);

Can we give the work a reference on the netdev (at init time) and cancel + release it here instead of flushing / waiting?

Not sure why cancel+release, maybe you're thinking about the unregister path? This is rtnl_unlock -> netdev_run_todo -> __rtnl_unlock + some extras.

And the flush is here to plumb the addresses to the real devices before we return to the callers. Mostly because of the following things we have in the tests:

# TEST: team cleanup mode lacp [FAIL]
# macvlan unicast address not found on a slave

Can you explain a bit more on the suggestion?

Quoted 13 lines
Quoted 13 lines
net/core/dev.c +1 -0
 	/* Wait for rcu callbacks to finish before next phase */
 	if (!list_empty(&list))
 		rcu_barrier();
@@ -12099,6 +12173,7 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
 #endif
 
 	mutex_init(&dev->lock);
+	INIT_WORK(&dev->rx_mode_work, dev_rx_mode_work);
 
 	dev->priv_flags = IFF_XMIT_DST_RELEASE | IFF_XMIT_DST_RELEASE_PERM;
 	setup(dev);
@@ -12203,6 +12278,8 @@ void free_netdev(struct net_device *dev)
 
Quoted 5 lines

net/core/dev.c void free_netdev(struct net_device *dev) · line 12281

Quoted 3 lines
net/core/dev.c +1 -0
 	kfree(rcu_dereference_protected(dev->ingress_queue, 1));
 
+	cancel_work_sync(&dev->rx_mode_work);

Should never happen so maybe wrap it in a WARN ?

Or maybe just flush_workqueue here as well? To signal the intent that we are mostly waiting for the wq entry to be unused to be able to kfree it?

maintainer
#10 lore raw

Re: [PATCH net-next v3 03/13] net: introduce ndo_set_rx_mode_async and dev_rx_mode_work

Quoted 16 lines · On Tue, 24 Mar 2026 11:13:04 -0700 Stanislav Fomichev wrote:
Quoted 7 lines
Quoted 7 lines
net/core/dev.c +7 -0
+		netif_addr_lock_bh(dev);
+
+		err = __hw_addr_list_snapshot(&uc_snap, &dev->uc,
+					      dev->addr_len);
+		if (!err)
+			err = __hw_addr_list_snapshot(&uc_ref, &dev->uc,
+						      dev->addr_len);
Quoted 8 lines

net/core/dev.c int netif_set_allmulti(struct net_device *dev, int inc, bool notify) · line 9706

Quoted 6 lines
net/core/dev.c +6 -0
+		if (!err)
+			err = __hw_addr_list_snapshot(&mc_snap, &dev->mc,
+						      dev->addr_len);
+		if (!err)
+			err = __hw_addr_list_snapshot(&mc_ref, &dev->mc,
+						      dev->addr_len);  

This doesn't get slow with a few thousands of addresses?

Quoted 5 lines

I can add kunit benchmark and attach the output? Although not sure where to go from that. The alternative to this is allocating an array of entries. I started with that initially but __hw_addr_sync_dev wants to kfree the individual entries and I decided not to have a separate helpers to manage the snapshots.

Let's see what the benchmark says. Hopefully it's fast enough and we don't have to worry. Is keeping these lists around between the invocations of the work tricky?

Quoted 7 lines
Quoted 2 lines

Can we give the work a reference on the netdev (at init time) and cancel + release it here instead of flushing / waiting?

Not sure why cancel+release, maybe you're thinking about the unregister path? This is rtnl_unlock -> netdev_run_todo -> __rtnl_unlock + some extras.

Quoted 8 lines

And the flush is here to plumb the addresses to the real devices before we return to the callers. Mostly because of the following things we have in the tests:

# TEST: team cleanup mode lacp [FAIL]
# macvlan unicast address not found on a slave

Can you explain a bit more on the suggestion?

Oh, I thought it's here for unregister! Feels like it'd be cleaner to add the flush in dev_*c_add() and friends? How hard would it be to identify the callers in atomic context?

Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
net/core/dev.c +1 -0
 	/* Wait for rcu callbacks to finish before next phase */
 	if (!list_empty(&list))
 		rcu_barrier();
@@ -12099,6 +12173,7 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
 #endif
 
 	mutex_init(&dev->lock);
+	INIT_WORK(&dev->rx_mode_work, dev_rx_mode_work);
 
 	dev->priv_flags = IFF_XMIT_DST_RELEASE | IFF_XMIT_DST_RELEASE_PERM;
 	setup(dev);
@@ -12203,6 +12278,8 @@ void free_netdev(struct net_device *dev)
 
Quoted 5 lines

net/core/dev.c void free_netdev(struct net_device *dev) · line 12281

Quoted 3 lines
net/core/dev.c +1 -0
 	kfree(rcu_dereference_protected(dev->ingress_queue, 1));
 
+	cancel_work_sync(&dev->rx_mode_work);  

Should never happen so maybe wrap it in a WARN ?

Or maybe just flush_workqueue here as well? To signal the intent that we are mostly waiting for the wq entry to be unused to be able to kfree it?

#11 lore raw

Re: [PATCH net-next v3 03/13] net: introduce ndo_set_rx_mode_async and dev_rx_mode_work

Quoted 23 lines · Jakub Kicinski
Quoted 16 lines · On Tue, 24 Mar 2026 11:13:04 -0700 Stanislav Fomichev wrote:
Quoted 7 lines
Quoted 7 lines
net/core/dev.c +7 -0
+		netif_addr_lock_bh(dev);
+
+		err = __hw_addr_list_snapshot(&uc_snap, &dev->uc,
+					      dev->addr_len);
+		if (!err)
+			err = __hw_addr_list_snapshot(&uc_ref, &dev->uc,
+						      dev->addr_len);
Quoted 8 lines

net/core/dev.c int netif_set_allmulti(struct net_device *dev, int inc, bool notify) · line 9706

Quoted 6 lines
net/core/dev.c +6 -0
+		if (!err)
+			err = __hw_addr_list_snapshot(&mc_snap, &dev->mc,
+						      dev->addr_len);
+		if (!err)
+			err = __hw_addr_list_snapshot(&mc_ref, &dev->mc,
+						      dev->addr_len);  

This doesn't get slow with a few thousands of addresses?

Quoted 5 lines

I can add kunit benchmark and attach the output? Although not sure where to go from that. The alternative to this is allocating an array of entries. I started with that initially but __hw_addr_sync_dev wants to kfree the individual entries and I decided not to have a separate helpers to manage the snapshots.

Quoted 3 lines

Let's see what the benchmark says. Hopefully it's fast enough and we don't have to worry. Is keeping these lists around between the invocations of the work tricky?

Yeah, that sounds doable, don't think it's too tricky, just extra list_head on net_device + change the alloc/free to use it.
And then we keep this cache around until unregister? I will try to add it as a separate patch to cache these entries to keep it simple for review..

Quoted 11 lines
Quoted 11 lines
Quoted 2 lines

Can we give the work a reference on the netdev (at init time) and cancel + release it here instead of flushing / waiting?

Not sure why cancel+release, maybe you're thinking about the unregister path? This is rtnl_unlock -> netdev_run_todo -> __rtnl_unlock + some extras.

And the flush is here to plumb the addresses to the real devices before we return to the callers. Mostly because of the following things we have in the tests:

Quoted 8 lines
Quoted 4 lines

# TEST: team cleanup mode lacp [FAIL]
# macvlan unicast address not found on a slave

Can you explain a bit more on the suggestion?

Oh, I thought it's here for unregister! Feels like it'd be cleaner to add the flush in dev_*c_add() and friends? How hard would it be to identify the callers in atomic context?

Not sure we can do it in dev_xc_add because it runs under rtnl :-( I currently do flush in netdev_run_todo because that's the place that doesn't hold rtnl. Otherwise flush will get stuck because the work handler grabs it...

maintainer
#12 lore raw

Re: [PATCH net-next v3 03/13] net: introduce ndo_set_rx_mode_async and dev_rx_mode_work

Quoted 13 lines · On Tue, 24 Mar 2026 15:49:27 -0700 Stanislav Fomichev wrote:
Quoted 13 lines
Quoted 12 lines

Not sure why cancel+release, maybe you're thinking about the unregister path? This is rtnl_unlock -> netdev_run_todo -> __rtnl_unlock + some extras.

And the flush is here to plumb the addresses to the real devices before we return to the callers. Mostly because of the following things we have in the tests:

# TEST: team cleanup mode lacp [FAIL]
# macvlan unicast address not found on a slave

Can you explain a bit more on the suggestion?

Quoted 8 lines
Quoted 3 lines

Oh, I thought it's here for unregister! Feels like it'd be cleaner to add the flush in dev_*c_add() and friends? How hard would it be to identify the callers in atomic context?

Not sure we can do it in dev_xc_add because it runs under rtnl :-( I currently do flush in netdev_run_todo because that's the place that doesn't hold rtnl. Otherwise flush will get stuck because the work handler grabs it...

I was thinking of something a'la linkwatch. We can "steal" / "flush" the pending work inline. I guess linkwatch is a major source of races over the years...

Does the macvlan + team problem still happens with the current implementation minus the flush? We are only flushing once so only pushing the addresses thru one layer of async callbacks.

#13 lore raw

Re: [PATCH net-next v3 03/13] net: introduce ndo_set_rx_mode_async and dev_rx_mode_work

Quoted 23 lines · Jakub Kicinski
Quoted 13 lines · On Tue, 24 Mar 2026 15:49:27 -0700 Stanislav Fomichev wrote:
Quoted 13 lines
Quoted 12 lines

Not sure why cancel+release, maybe you're thinking about the unregister path? This is rtnl_unlock -> netdev_run_todo -> __rtnl_unlock + some extras.

And the flush is here to plumb the addresses to the real devices before we return to the callers. Mostly because of the following things we have in the tests:

# TEST: team cleanup mode lacp [FAIL]
# macvlan unicast address not found on a slave

Can you explain a bit more on the suggestion?

Quoted 8 lines
Quoted 3 lines

Oh, I thought it's here for unregister! Feels like it'd be cleaner to add the flush in dev_*c_add() and friends? How hard would it be to identify the callers in atomic context?

Not sure we can do it in dev_xc_add because it runs under rtnl :-( I currently do flush in netdev_run_todo because that's the place that doesn't hold rtnl. Otherwise flush will get stuck because the work handler grabs it...

Quoted 7 lines

I was thinking of something a'la linkwatch. We can "steal" / "flush" the pending work inline. I guess linkwatch is a major source of races over the years...

Does the macvlan + team problem still happens with the current implementation minus the flush? We are only flushing once so only pushing the addresses thru one layer of async callbacks.

Yes, it does happen consistently when I remove the flush. It also happens with my internal v4, so I need to look again at what's going on. Not sure whether it's my internal regression or I was just sloppy/lucky (since you're correct in pointing out that we flush only once).

Before I went down the workqueue route, I had a simple net_todo_list-like approach: list_add_tail on enqueue and while(!list_empty) run_work() on rtnl_unlock. This had a nice properly of tracking re-submissions (by checking whether the device's list_head is linked into the list or not) and it was relatively easy to do the recursive flush. Let me try get back to this approach and see whether it solves the flush? Not sure what wq buys us at this point.

#14 lore raw

Re: [PATCH net-next v3 03/13] net: introduce ndo_set_rx_mode_async and dev_rx_mode_work

Quoted 28 lines · Stanislav Fomichev
Quoted 27 lines · Jakub Kicinski
Quoted 13 lines · On Tue, 24 Mar 2026 15:49:27 -0700 Stanislav Fomichev wrote:
Quoted 13 lines
Quoted 12 lines

Not sure why cancel+release, maybe you're thinking about the unregister path? This is rtnl_unlock -> netdev_run_todo -> __rtnl_unlock + some extras.

And the flush is here to plumb the addresses to the real devices before we return to the callers. Mostly because of the following things we have in the tests:

# TEST: team cleanup mode lacp [FAIL]
# macvlan unicast address not found on a slave

Can you explain a bit more on the suggestion?

Quoted 8 lines
Quoted 3 lines

Oh, I thought it's here for unregister! Feels like it'd be cleaner to add the flush in dev_*c_add() and friends? How hard would it be to identify the callers in atomic context?

Not sure we can do it in dev_xc_add because it runs under rtnl :-( I currently do flush in netdev_run_todo because that's the place that doesn't hold rtnl. Otherwise flush will get stuck because the work handler grabs it...

I was thinking of something a'la linkwatch. We can "steal" / "flush" the pending work inline. I guess linkwatch is a major source of races over the years...

Quoted 8 lines
Quoted 3 lines

Does the macvlan + team problem still happens with the current implementation minus the flush? We are only flushing once so only pushing the addresses thru one layer of async callbacks.

Yes, it does happen consistently when I remove the flush. It also happens with my internal v4, so I need to look again at what's going on. Not sure whether it's my internal regression or I was just sloppy/lucky (since you're correct in pointing out that we flush only once).

Hmm, the test does 'team -d' in the background. That's why it works for bonding, but not the teaming. I'll update the test to a bunch of 'ip' commands instead of starting a daemon..

Quoted 7 lines

Before I went down the workqueue route, I had a simple net_todo_list-like approach: list_add_tail on enqueue and while(!list_empty) run_work() on rtnl_unlock. This had a nice properly of tracking re-submissions (by checking whether the device's list_head is linked into the list or not) and it was relatively easy to do the recursive flush. Let me try get back to this approach and see whether it solves the flush? Not sure what wq buys us at this point.

Will still look into that, maybe something similar to the linkwatch as you mentioned.

#15 lore raw

PATCH v3 4/13 net: move promiscuity handling into dev_rx_mode_work

In reply to Stanislav Fomichev

Move unicast promiscuity tracking into dev_rx_mode_work so it runs under netdev_ops_lock instead of under the addr_lock spinlock. This is required because __dev_set_promiscuity calls dev_change_rx_flags and __dev_notify_flags, both of which may need to sleep.

Change ASSERT_RTNL() to netdev_ops_assert_locked() in __dev_set_promiscuity, netif_set_allmulti and __dev_change_flags since these are now called from the work queue under the ops lock.

---
 Documentation/networking/netdevices.rst |  4 ++
 net/core/dev.c                          | 79 +++++++++++++++++--------
 2 files changed, 57 insertions(+), 26 deletions(-)
Documentation/networking/netdevices.rst +4 -0
index dc83d78d3b27..5cdaa1a3dcc8 100644
@@ -298,6 +298,10 @@ struct net_device synchronization rules
 	Notes: Sleepable version of ndo_set_rx_mode. Receives snapshots
 	of the unicast and multicast address lists.
 
+ndo_change_rx_flags:
+	Synchronization: rtnl_lock() semaphore. In addition, netdev instance
+	lock if the driver implements queue management or shaper API.
+
 ndo_setup_tc:
 	``TC_SETUP_BLOCK`` and ``TC_SETUP_FT`` are running under NFT locks
 	(i.e. no ``rtnl_lock`` and no device instance lock). The rest of
net/core/dev.c +53 -26

152 lines not on this page · raw message

Signature · 1 line
2.53.0
#16 lore raw

RE: [PATCH net-next v3 04/13] net: move promiscuity handling into dev_rx_mode_work

Quoted 65 lines

-----Original Message-----
From: Stanislav Fomichev <[email protected]>
Sent: Friday, March 20, 2026 2:25 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Keller, Jacob E <[email protected]>; [email protected]; [email protected]; [email protected]; Loktionov, Aleksandr <[email protected]>; [email protected]; linux- [email protected]; [email protected]; intel-wired- [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: [PATCH net-next v3 04/13] net: move promiscuity handling into dev_rx_mode_work

Move unicast promiscuity tracking into dev_rx_mode_work so it runs under netdev_ops_lock instead of under the addr_lock spinlock. This is required because __dev_set_promiscuity calls dev_change_rx_flags and __dev_notify_flags, both of which may need to sleep.

Change ASSERT_RTNL() to netdev_ops_assert_locked() in __dev_set_promiscuity, netif_set_allmulti and __dev_change_flags since these are now called from the work queue under the ops lock.

---
 Documentation/networking/netdevices.rst |  4 ++
 net/core/dev.c                          | 79 +++++++++++++++++-------
(quoted diff) +0 -1
-
 2 files changed, 57 insertions(+), 26 deletions(-)
Documentation/networking/netdevices.rst +2 -0
index dc83d78d3b27..5cdaa1a3dcc8 100644
@@ -298,6 +298,10 @@ struct net_device synchronization rules
 	Notes: Sleepable version of ndo_set_rx_mode. Receives snapshots
 	of the unicast and multicast address lists.
 
+ndo_change_rx_flags:
+	Synchronization: rtnl_lock() semaphore. In addition, netdev

instance

Documentation/networking/netdevices.rst +2 -0
+	lock if the driver implements queue management or shaper API.
+
 ndo_setup_tc:
 	``TC_SETUP_BLOCK`` and ``TC_SETUP_FT`` are running under NFT

locks
(i.e. no ``rtnl_lock`` and no device instance lock). The rest
of diff --git a/net/core/dev.c b/net/core/dev.c index fedc423306fc..fc5c9b14faa0 100644

net/core/dev.c static int __dev_set_promiscuity(struct · line 9578

Quoted 6 lines
net/core/dev.c +1 -1
@@ -9574,7 +9574,7 @@ static int __dev_set_promiscuity(struct
 net_device *dev, int inc, bool notify)
 	kuid_t uid;
 	kgid_t gid;
 
-	ASSERT_RTNL();
+	netdev_ops_assert_locked(dev);

Can you explain why do you add new hard precondition of ops lock must be held?

Quoted 8 lines
net/core/dev.c +0 -0
 	promiscuity = dev->promiscuity + inc;
 	if (promiscuity == 0) {
@@ -9610,16 +9610,8 @@ static int __dev_set_promiscuity(struct
 net_device *dev, int inc, bool notify)
 
 		dev_change_rx_flags(dev, IFF_PROMISC);
 	}

...

Quoted 19 lines
net/core/dev.c +2 -1
 	__hw_addr_init(&uc_snap);
@@ -9704,16 +9720,29 @@ static void dev_rx_mode_work(struct
 work_struct *work)
 		if (!err)
 			err = __hw_addr_list_snapshot(&mc_ref, &dev->mc,
 						      dev->addr_len);
-		netif_addr_unlock_bh(dev);
 
 		if (err) {
 			netdev_WARN(dev, "failed to sync uc/mc
 addresses\n");
 			__hw_addr_flush(&uc_snap);
 			__hw_addr_flush(&uc_ref);
 			__hw_addr_flush(&mc_snap);
+			netif_addr_unlock_bh(dev);
 			goto out;
 		}
 
+		promisc_inc = dev_uc_promisc_update(dev);

net/core/dev.c static void dev_rx_mode_work(struct · line 9745

Quoted 10 lines
net/core/dev.c +10 -0
+
+		netif_addr_unlock_bh(dev);
+	} else {
+		netif_addr_lock_bh(dev);
+		promisc_inc = dev_uc_promisc_update(dev);
+		netif_addr_unlock_bh(dev);
+	}
+
+	if (promisc_inc)
+		__dev_set_promiscuity(dev, promisc_inc, false);

But it's being called here without any netdev_lock_ops(dev) ?

Quoted 15 lines
net/core/dev.c +2 -0
+
+	if (ops->ndo_set_rx_mode_async) {
 		ops->ndo_set_rx_mode_async(dev, &uc_snap, &mc_snap);
net/core/dev.c +4 -0
 		netif_addr_lock_bh(dev);
@@ -9722,6 +9751,10 @@ static void dev_rx_mode_work(struct work_struct
 *work)
 		__hw_addr_list_reconcile(&dev->mc, &mc_snap,
 					 &mc_ref, dev->addr_len);
 		netif_addr_unlock_bh(dev);
+	} else if (ops->ndo_set_rx_mode) {
+		netif_addr_lock_bh(dev);
+		ops->ndo_set_rx_mode(dev);
+		netif_addr_unlock_bh(dev);
 	}

...

Quoted 2 lines

--
2.53.0

#17 lore raw

Re: [PATCH net-next v3 04/13] net: move promiscuity handling into dev_rx_mode_work

Quoted 69 lines · Aleksandr
Quoted 69 lines

-----Original Message-----
From: Stanislav Fomichev <[email protected]>
Sent: Friday, March 20, 2026 2:25 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Keller, Jacob E <[email protected]>; [email protected]; [email protected]; [email protected]; Loktionov, Aleksandr <[email protected]>; [email protected]; linux- [email protected]; [email protected]; intel-wired- [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: [PATCH net-next v3 04/13] net: move promiscuity handling into dev_rx_mode_work

Move unicast promiscuity tracking into dev_rx_mode_work so it runs under netdev_ops_lock instead of under the addr_lock spinlock. This is required because __dev_set_promiscuity calls dev_change_rx_flags and __dev_notify_flags, both of which may need to sleep.

Change ASSERT_RTNL() to netdev_ops_assert_locked() in __dev_set_promiscuity, netif_set_allmulti and __dev_change_flags since these are now called from the work queue under the ops lock.

---
 Documentation/networking/netdevices.rst |  4 ++
 net/core/dev.c                          | 79 +++++++++++++++++-------
(quoted diff) +0 -1
-
 2 files changed, 57 insertions(+), 26 deletions(-)
Documentation/networking/netdevices.rst +2 -0
index dc83d78d3b27..5cdaa1a3dcc8 100644
@@ -298,6 +298,10 @@ struct net_device synchronization rules
 	Notes: Sleepable version of ndo_set_rx_mode. Receives snapshots
 	of the unicast and multicast address lists.
 
+ndo_change_rx_flags:
+	Synchronization: rtnl_lock() semaphore. In addition, netdev

instance

Documentation/networking/netdevices.rst +2 -0
+	lock if the driver implements queue management or shaper API.
+
 ndo_setup_tc:
 	``TC_SETUP_BLOCK`` and ``TC_SETUP_FT`` are running under NFT

locks
(i.e. no ``rtnl_lock`` and no device instance lock). The rest
of diff --git a/net/core/dev.c b/net/core/dev.c index fedc423306fc..fc5c9b14faa0 100644

net/core/dev.c +0 -0
@@ -9574,7 +9574,7 @@ static int __dev_set_promiscuity(struct
 net_device *dev, int inc, bool notify)
 	kuid_t uid;
 	kgid_t gid;
 
Quoted 3 lines

net/core/dev.c static int __dev_set_promiscuity(struct · line 9578

Quoted 2 lines
net/core/dev.c +1 -1
-	ASSERT_RTNL();
+	netdev_ops_assert_locked(dev);

Can you explain why do you add new hard precondition of ops lock must be held?

The context is that in f792709e0baa ("selftests: net: validate team flags propagation") I had to add locking around NETDEV_CHANGE notifiers and add that ugly if (notify) netdev_ops_assert_locked check. After this patch I believe we are consistently calling __dev_set_promiscuity with the ops lock (for ops locked netdev), so we can cleanup this enforcement part.

Quoted 28 lines
Quoted 7 lines
net/core/dev.c +0 -0
 	promiscuity = dev->promiscuity + inc;
 	if (promiscuity == 0) {
@@ -9610,16 +9610,8 @@ static int __dev_set_promiscuity(struct
 net_device *dev, int inc, bool notify)
 
 		dev_change_rx_flags(dev, IFF_PROMISC);
 	}

...

Quoted 18 lines
net/core/dev.c +1 -1
 	__hw_addr_init(&uc_snap);
@@ -9704,16 +9720,29 @@ static void dev_rx_mode_work(struct
 work_struct *work)
 		if (!err)
 			err = __hw_addr_list_snapshot(&mc_ref, &dev->mc,
 						      dev->addr_len);
-		netif_addr_unlock_bh(dev);
 
 		if (err) {
 			netdev_WARN(dev, "failed to sync uc/mc
 addresses\n");
 			__hw_addr_flush(&uc_snap);
 			__hw_addr_flush(&uc_ref);
 			__hw_addr_flush(&mc_snap);
+			netif_addr_unlock_bh(dev);
 			goto out;
 		}
 
Quoted 12 lines

net/core/dev.c static void dev_rx_mode_work(struct work_struct *work) · line 9743

Quoted 11 lines
net/core/dev.c +11 -0
+		promisc_inc = dev_uc_promisc_update(dev);
+
+		netif_addr_unlock_bh(dev);
+	} else {
+		netif_addr_lock_bh(dev);
+		promisc_inc = dev_uc_promisc_update(dev);
+		netif_addr_unlock_bh(dev);
+	}
+
+	if (promisc_inc)
+		__dev_set_promiscuity(dev, promisc_inc, false);

But it's being called here without any netdev_lock_ops(dev) ?

We have the following at the start of dev_rx_mode_work:
rtnl_lock();
netdev_lock_ops(dev);

Or am I looking at something else?

#18 lore raw

PATCH v3 5/13 fbnic: convert to ndo_set_rx_mode_async

In reply to Stanislav Fomichev

Convert fbnic from ndo_set_rx_mode to ndo_set_rx_mode_async. The driver's __fbnic_set_rx_mode() now takes explicit uc/mc list parameters and uses __hw_addr_sync_dev() on the snapshots instead of __dev_uc_sync/__dev_mc_sync on the netdev directly.

Update callers in fbnic_up, fbnic_fw_config_after_crash, fbnic_bmc_rpc_check and fbnic_set_mac to pass the real address lists calling __fbnic_set_rx_mode outside the async work path.

---
 .../net/ethernet/meta/fbnic/fbnic_netdev.c    | 20 ++++++++++++-------
 .../net/ethernet/meta/fbnic/fbnic_netdev.h    |  4 +++-
 drivers/net/ethernet/meta/fbnic/fbnic_pci.c   |  4 ++--
 drivers/net/ethernet/meta/fbnic/fbnic_rpc.c   |  2 +-
 4 files changed, 19 insertions(+), 11 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic_netdev.c +13 -7
index b4b396ca9bce..c406a3b56b37 100644
@@ -183,7 +183,9 @@ static int fbnic_mc_unsync(struct net_device *netdev, const unsigned char *addr)
 	return ret;
 }
 
-void __fbnic_set_rx_mode(struct fbnic_dev *fbd)
+void __fbnic_set_rx_mode(struct fbnic_dev *fbd,
+			 struct netdev_hw_addr_list *uc,
+			 struct netdev_hw_addr_list *mc)
 {
 	bool uc_promisc = false, mc_promisc = false;
 	struct net_device *netdev = fbd->netdev;
@@ -213,10 +215,10 @@ void __fbnic_set_rx_mode(struct fbnic_dev *fbd)
 	}
 
 	/* Synchronize unicast and multicast address lists */
-	err = __dev_uc_sync(netdev, fbnic_uc_sync, fbnic_uc_unsync);
+	err = __hw_addr_sync_dev(uc, netdev, fbnic_uc_sync, fbnic_uc_unsync);
 	if (err == -ENOSPC)
 		uc_promisc = true;
-	err = __dev_mc_sync(netdev, fbnic_mc_sync, fbnic_mc_unsync);
+	err = __hw_addr_sync_dev(mc, netdev, fbnic_mc_sync, fbnic_mc_unsync);
 	if (err == -ENOSPC)
 		mc_promisc = true;
 
@@ -238,18 +240,21 @@ void __fbnic_set_rx_mode(struct fbnic_dev *fbd)
 	fbnic_write_tce_tcam(fbd);
 }
 
-static void fbnic_set_rx_mode(struct net_device *netdev)
+static void fbnic_set_rx_mode(struct net_device *netdev,
+			      struct netdev_hw_addr_list *uc,
+			      struct netdev_hw_addr_list *mc)
 {
 	struct fbnic_net *fbn = netdev_priv(netdev);
 	struct fbnic_dev *fbd = fbn->fbd;
 
 	/* No need to update the hardware if we are not running */
 	if (netif_running(netdev))
-		__fbnic_set_rx_mode(fbd);
+		__fbnic_set_rx_mode(fbd, uc, mc);
 }
 
 static int fbnic_set_mac(struct net_device *netdev, void *p)
 {
+	struct fbnic_net *fbn = netdev_priv(netdev);
 	struct sockaddr *addr = p;
 
 	if (!is_valid_ether_addr(addr->sa_data))
@@ -257,7 +262,8 @@ static int fbnic_set_mac(struct net_device *netdev, void *p)
 
 	eth_hw_addr_set(netdev, addr->sa_data);
 
-	fbnic_set_rx_mode(netdev);
+	if (netif_running(netdev))
+		__fbnic_set_rx_mode(fbn->fbd, &netdev->uc, &netdev->mc);
 
 	return 0;
 }
@@ -551,7 +557,7 @@ static const struct net_device_ops fbnic_netdev_ops = {
 	.ndo_features_check	= fbnic_features_check,
 	.ndo_set_mac_address	= fbnic_set_mac,
 	.ndo_change_mtu		= fbnic_change_mtu,
-	.ndo_set_rx_mode	= fbnic_set_rx_mode,
+	.ndo_set_rx_mode_async	= fbnic_set_rx_mode,
 	.ndo_get_stats64	= fbnic_get_stats64,
 	.ndo_bpf		= fbnic_bpf,
 	.ndo_hwtstamp_get	= fbnic_hwtstamp_get,
drivers/net/ethernet/meta/fbnic/fbnic_netdev.h +3 -1
index 9129a658f8fa..eded20b0e9e4 100644
@@ -97,7 +97,9 @@ void fbnic_time_init(struct fbnic_net *fbn);
 int fbnic_time_start(struct fbnic_net *fbn);
 void fbnic_time_stop(struct fbnic_net *fbn);
 
-void __fbnic_set_rx_mode(struct fbnic_dev *fbd);
+void __fbnic_set_rx_mode(struct fbnic_dev *fbd,
+			 struct netdev_hw_addr_list *uc,
+			 struct netdev_hw_addr_list *mc);
 void fbnic_clear_rx_mode(struct fbnic_dev *fbd);
 
 void fbnic_phylink_get_pauseparam(struct net_device *netdev,
drivers/net/ethernet/meta/fbnic/fbnic_pci.c +2 -2
index e3aebbe3656d..6b139cf54256 100644
@@ -135,7 +135,7 @@ void fbnic_up(struct fbnic_net *fbn)
 
 	fbnic_rss_reinit_hw(fbn->fbd, fbn);
 
-	__fbnic_set_rx_mode(fbn->fbd);
+	__fbnic_set_rx_mode(fbn->fbd, &fbn->netdev->uc, &fbn->netdev->mc);
 
 	/* Enable Tx/Rx processing */
 	fbnic_napi_enable(fbn);
@@ -180,7 +180,7 @@ static int fbnic_fw_config_after_crash(struct fbnic_dev *fbd)
 	}
 
 	fbnic_rpc_reset_valid_entries(fbd);
-	__fbnic_set_rx_mode(fbd);
+	__fbnic_set_rx_mode(fbd, &fbd->netdev->uc, &fbd->netdev->mc);
 
 	return 0;
 }
drivers/net/ethernet/meta/fbnic/fbnic_rpc.c +1 -1
index 42a186db43ea..fe95b6f69646 100644
@@ -244,7 +244,7 @@ void fbnic_bmc_rpc_check(struct fbnic_dev *fbd)
 
 	if (fbd->fw_cap.need_bmc_tcam_reinit) {
 		fbnic_bmc_rpc_init(fbd);
-		__fbnic_set_rx_mode(fbd);
+		__fbnic_set_rx_mode(fbd, &fbd->netdev->uc, &fbd->netdev->mc);
 		fbd->fw_cap.need_bmc_tcam_reinit = false;
 	}
 
Signature · 1 line
2.53.0
#19 lore raw

PATCH v3 6/13 mlx5: convert to ndo_set_rx_mode_async

In reply to Stanislav Fomichev

Convert mlx5 from ndo_set_rx_mode to ndo_set_rx_mode_async. The driver's mlx5e_set_rx_mode now receives uc/mc snapshots and calls mlx5e_fs_set_rx_mode_work directly instead of queueing work.

mlx5e_sync_netdev_addr and mlx5e_handle_netdev_addr now take explicit uc/mc list parameters and iterate with netdev_hw_addr_list_for_each instead of netdev_for_each_{uc,mc}_addr.

Fallback to netdev's uc/mc in a few places and grab addr lock.

---
 .../net/ethernet/mellanox/mlx5/core/en/fs.h   |  5 +++-
 .../net/ethernet/mellanox/mlx5/core/en_fs.c   | 30 ++++++++++++-------
 .../net/ethernet/mellanox/mlx5/core/en_main.c | 16 +++++++---
 3 files changed, 36 insertions(+), 15 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/fs.h +4 -1
index c3408b3f7010..091b80a67189 100644
@@ -201,7 +201,10 @@ int mlx5e_add_vlan_trap(struct mlx5e_flow_steering *fs, int  trap_id, int tir_nu
 void mlx5e_remove_vlan_trap(struct mlx5e_flow_steering *fs);
 int mlx5e_add_mac_trap(struct mlx5e_flow_steering *fs, int  trap_id, int tir_num);
 void mlx5e_remove_mac_trap(struct mlx5e_flow_steering *fs);
-void mlx5e_fs_set_rx_mode_work(struct mlx5e_flow_steering *fs, struct net_device *netdev);
+void mlx5e_fs_set_rx_mode_work(struct mlx5e_flow_steering *fs,
+			       struct net_device *netdev,
+			       struct netdev_hw_addr_list *uc,
+			       struct netdev_hw_addr_list *mc);
 int mlx5e_fs_vlan_rx_add_vid(struct mlx5e_flow_steering *fs,
 			     struct net_device *netdev,
 			     __be16 proto, u16 vid);
drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +20 -10
index 55255fe6e415..a9daefbd8f8f 100644
@@ -609,20 +609,26 @@ static void mlx5e_execute_l2_action(struct mlx5e_flow_steering *fs,
 }
 
 static void mlx5e_sync_netdev_addr(struct mlx5e_flow_steering *fs,
-				   struct net_device *netdev)
+				   struct net_device *netdev,
+				   struct netdev_hw_addr_list *uc,
+				   struct netdev_hw_addr_list *mc)
 {
 	struct netdev_hw_addr *ha;
 
-	netif_addr_lock_bh(netdev);
+	if (!uc || !mc) {
+		netif_addr_lock_bh(netdev);
+		mlx5e_sync_netdev_addr(fs, netdev, &netdev->uc, &netdev->mc);
+		netif_addr_unlock_bh(netdev);
+		return;
+	}
 
 	mlx5e_add_l2_to_hash(fs->l2.netdev_uc, netdev->dev_addr);
-	netdev_for_each_uc_addr(ha, netdev)
+
+	netdev_hw_addr_list_for_each(ha, uc)
 		mlx5e_add_l2_to_hash(fs->l2.netdev_uc, ha->addr);
 
-	netdev_for_each_mc_addr(ha, netdev)
+	netdev_hw_addr_list_for_each(ha, mc)
 		mlx5e_add_l2_to_hash(fs->l2.netdev_mc, ha->addr);
-
-	netif_addr_unlock_bh(netdev);
 }
 
 static void mlx5e_fill_addr_array(struct mlx5e_flow_steering *fs, int list_type,
@@ -724,7 +730,9 @@ static void mlx5e_apply_netdev_addr(struct mlx5e_flow_steering *fs)
 }
 
 static void mlx5e_handle_netdev_addr(struct mlx5e_flow_steering *fs,
-				     struct net_device *netdev)
+				     struct net_device *netdev,
+				     struct netdev_hw_addr_list *uc,
+				     struct netdev_hw_addr_list *mc)
 {
 	struct mlx5e_l2_hash_node *hn;
 	struct hlist_node *tmp;
@@ -736,7 +744,7 @@ static void mlx5e_handle_netdev_addr(struct mlx5e_flow_steering *fs,
 		hn->action = MLX5E_ACTION_DEL;
 
 	if (fs->state_destroy)
-		mlx5e_sync_netdev_addr(fs, netdev);
+		mlx5e_sync_netdev_addr(fs, netdev, uc, mc);
 
 	mlx5e_apply_netdev_addr(fs);
 }
@@ -820,7 +828,9 @@ static void mlx5e_destroy_promisc_table(struct mlx5e_flow_steering *fs)
 }
 
 void mlx5e_fs_set_rx_mode_work(struct mlx5e_flow_steering *fs,
-			       struct net_device *netdev)
+			       struct net_device *netdev,
+			       struct netdev_hw_addr_list *uc,
+			       struct netdev_hw_addr_list *mc)
 {
 	struct mlx5e_l2_table *ea = &fs->l2;
 
@@ -850,7 +860,7 @@ void mlx5e_fs_set_rx_mode_work(struct mlx5e_flow_steering *fs,
 	if (enable_broadcast)
 		mlx5e_add_l2_flow_rule(fs, &ea->broadcast, MLX5E_FULLMATCH);
 
-	mlx5e_handle_netdev_addr(fs, netdev);
+	mlx5e_handle_netdev_addr(fs, netdev, uc, mc);
 
 	if (disable_broadcast)
 		mlx5e_del_l2_flow_rule(fs, &ea->broadcast);
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +12 -4
index f7009da94f0b..e86cf1ee108d 100644
@@ -4108,11 +4108,16 @@ static void mlx5e_nic_set_rx_mode(struct mlx5e_priv *priv)
 	queue_work(priv->wq, &priv->set_rx_mode_work);
 }
 
-static void mlx5e_set_rx_mode(struct net_device *dev)
+static void mlx5e_set_rx_mode(struct net_device *dev,
+			      struct netdev_hw_addr_list *uc,
+			      struct netdev_hw_addr_list *mc)
 {
 	struct mlx5e_priv *priv = netdev_priv(dev);
 
-	mlx5e_nic_set_rx_mode(priv);
+	if (mlx5e_is_uplink_rep(priv))
+		return; /* no rx mode for uplink rep */
+
+	mlx5e_fs_set_rx_mode_work(priv->fs, dev, uc, mc);
 }
 
 static int mlx5e_set_mac(struct net_device *netdev, void *addr)
@@ -5287,7 +5292,7 @@ const struct net_device_ops mlx5e_netdev_ops = {
 	.ndo_setup_tc            = mlx5e_setup_tc,
 	.ndo_select_queue        = mlx5e_select_queue,
 	.ndo_get_stats64         = mlx5e_get_stats,
-	.ndo_set_rx_mode         = mlx5e_set_rx_mode,
+	.ndo_set_rx_mode_async   = mlx5e_set_rx_mode,
 	.ndo_set_mac_address     = mlx5e_set_mac,
 	.ndo_vlan_rx_add_vid     = mlx5e_vlan_rx_add_vid,
 	.ndo_vlan_rx_kill_vid    = mlx5e_vlan_rx_kill_vid,
@@ -6272,8 +6277,11 @@ void mlx5e_set_rx_mode_work(struct work_struct *work)
 {
 	struct mlx5e_priv *priv = container_of(work, struct mlx5e_priv,
 					       set_rx_mode_work);
+	struct net_device *dev = priv->netdev;
 
-	return mlx5e_fs_set_rx_mode_work(priv->fs, priv->netdev);
+	netdev_lock_ops(dev);
+	mlx5e_fs_set_rx_mode_work(priv->fs, dev, NULL, NULL);
+	netdev_unlock_ops(dev);
 }
 
 /* mlx5e generic netdev management API (move to en_common.c) */
Signature · 1 line
2.53.0
#20 lore raw

Re: [PATCH net-next v3 06/13] mlx5: convert to ndo_set_rx_mode_async

Quoted 145 lines · Stanislav Fomichev

Convert mlx5 from ndo_set_rx_mode to ndo_set_rx_mode_async. The driver's mlx5e_set_rx_mode now receives uc/mc snapshots and calls mlx5e_fs_set_rx_mode_work directly instead of queueing work.

mlx5e_sync_netdev_addr and mlx5e_handle_netdev_addr now take explicit uc/mc list parameters and iterate with netdev_hw_addr_list_for_each instead of netdev_for_each_{uc,mc}_addr.

Fallback to netdev's uc/mc in a few places and grab addr lock.

---
 .../net/ethernet/mellanox/mlx5/core/en/fs.h   |  5 +++- .../net/ethernet/mellanox/mlx5/core/en_fs.c   | 30 ++++++++++++----- --
 .../net/ethernet/mellanox/mlx5/core/en_main.c | 16 +++++++---

 3 files changed, 36 insertions(+), 15 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/fs.h +0 -0
index c3408b3f7010..091b80a67189 100644
@@ -201,7 +201,10 @@ int mlx5e_add_vlan_trap(struct

mlx5e_flow_steering *fs, int  trap_id, int tir_nu
 void mlx5e_remove_vlan_trap(struct mlx5e_flow_steering *fs); int mlx5e_add_mac_trap(struct mlx5e_flow_steering *fs, int  trap_id, int tir_num);
 void mlx5e_remove_mac_trap(struct mlx5e_flow_steering *fs); -void mlx5e_fs_set_rx_mode_work(struct mlx5e_flow_steering *fs, struct net_device *netdev);

drivers/net/ethernet/mellanox/mlx5/core/en/fs.h +4 -0
+void mlx5e_fs_set_rx_mode_work(struct mlx5e_flow_steering *fs,
+			       struct net_device *netdev,
+			       struct netdev_hw_addr_list *uc,
+			       struct netdev_hw_addr_list *mc);

 int mlx5e_fs_vlan_rx_add_vid(struct mlx5e_flow_steering *fs, struct net_device *netdev, __be16 proto, u16 vid);

drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +0 -0
index 55255fe6e415..a9daefbd8f8f 100644
@@ -609,20 +609,26 @@ static void mlx5e_execute_l2_action(struct
 mlx5e_flow_steering *fs,
  }


 static void mlx5e_sync_netdev_addr(struct mlx5e_flow_steering *fs,

drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +3 -1
-				   struct net_device *netdev)
+				   struct net_device *netdev,
+				   struct netdev_hw_addr_list *uc,
+				   struct netdev_hw_addr_list *mc)

 {
  struct netdev_hw_addr *ha;

drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +3 -1
-	netif_addr_lock_bh(netdev);
+	if (!uc || !mc) {
+		netif_addr_lock_bh(netdev);
+		mlx5e_sync_netdev_addr(fs, netdev, &netdev->uc,

&netdev->mc);

drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +3 -0
+		netif_addr_unlock_bh(netdev);
+		return;
+	}


  mlx5e_add_l2_to_hash(fs->l2.netdev_uc, netdev->dev_addr);

drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +2 -1
-	netdev_for_each_uc_addr(ha, netdev)
+
+	netdev_hw_addr_list_for_each(ha, uc)

  mlx5e_add_l2_to_hash(fs->l2.netdev_uc, ha->addr);

drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +1 -1
-	netdev_for_each_mc_addr(ha, netdev)
+	netdev_hw_addr_list_for_each(ha, mc)

  mlx5e_add_l2_to_hash(fs->l2.netdev_mc, ha->addr);

drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +0 -2
-
-	netif_addr_unlock_bh(netdev);

 }

 static void mlx5e_fill_addr_array(struct mlx5e_flow_steering *fs, int list_type,

drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +0 -0
@@ -724,7 +730,9 @@ static void mlx5e_apply_netdev_addr(struct
 mlx5e_flow_steering *fs)
  }


 static void mlx5e_handle_netdev_addr(struct mlx5e_flow_steering *fs,

drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +3 -1
-				     struct net_device *netdev)
+				     struct net_device *netdev,
+				     struct netdev_hw_addr_list *uc,
+				     struct netdev_hw_addr_list *mc)

 {
  struct mlx5e_l2_hash_node *hn;
  struct hlist_node *tmp;

drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +0 -0
@@ -736,7 +744,7 @@ static void mlx5e_handle_netdev_addr(struct
 mlx5e_flow_steering *fs,
  		hn->action = MLX5E_ACTION_DEL;


  if (fs->state_destroy)

drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +1 -1
-		mlx5e_sync_netdev_addr(fs, netdev);
+		mlx5e_sync_netdev_addr(fs, netdev, uc, mc);


  mlx5e_apply_netdev_addr(fs);
 }

drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +0 -0
@@ -820,7 +828,9 @@ static void mlx5e_destroy_promisc_table(struct
 mlx5e_flow_steering *fs)
  }


 void mlx5e_fs_set_rx_mode_work(struct mlx5e_flow_steering *fs,

drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +3 -1
-			       struct net_device *netdev)
+			       struct net_device *netdev,
+			       struct netdev_hw_addr_list *uc,
+			       struct netdev_hw_addr_list *mc)

 {
  struct mlx5e_l2_table *ea = &fs->l2;

drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +0 -0
@@ -850,7 +860,7 @@ void mlx5e_fs_set_rx_mode_work(struct
 mlx5e_flow_steering *fs,
  	if (enable_broadcast)
  		mlx5e_add_l2_flow_rule(fs, &ea->broadcast,
 MLX5E_FULLMATCH);

drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +1 -1
-	mlx5e_handle_netdev_addr(fs, netdev);
+	mlx5e_handle_netdev_addr(fs, netdev, uc, mc);


  if (disable_broadcast) mlx5e_del_l2_flow_rule(fs, &ea->broadcast);

drivers/net/ethernet/mellanox/mlx5/core/en_main.c +0 -0
index f7009da94f0b..e86cf1ee108d 100644
@@ -4108,11 +4108,16 @@ static void mlx5e_nic_set_rx_mode(struct
 mlx5e_priv *priv)
  	queue_work(priv->wq, &priv->set_rx_mode_work);
  }

drivers/net/ethernet/mellanox/mlx5/core/en_main.c +3 -1
-static void mlx5e_set_rx_mode(struct net_device *dev)
+static void mlx5e_set_rx_mode(struct net_device *dev,
+			      struct netdev_hw_addr_list *uc,
+			      struct netdev_hw_addr_list *mc)

 {
  struct mlx5e_priv *priv = netdev_priv(dev);

drivers/net/ethernet/mellanox/mlx5/core/en_main.c static void mlx5e_nic_set_rx_mode(struct mlx5e_priv *priv) · line 4120

Quoted 5 lines
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +4 -1
-	mlx5e_nic_set_rx_mode(priv);
+	if (mlx5e_is_uplink_rep(priv))
+		return; /* no rx mode for uplink rep */
+
+	mlx5e_fs_set_rx_mode_work(priv->fs, dev, uc, mc);

While this chunk is correct, I think there's a logical conflict waiting to happen with Saeed's pending patch touching this area ([1]).

You have inlined mlx5e_nic_set_rx_mode here, but after Saeed's patch the mlx5e_is_uplink_rep condition added here should be dropped.

Not sure the automatic merge will do that.

[1]
https://lore.kernel.org/netdev/[email protected]/T/#u

Quoted 28 lines

 }

 static int mlx5e_set_mac(struct net_device *netdev, void *addr)

drivers/net/ethernet/mellanox/mlx5/core/en_main.c +1 -1
@@ -5287,7 +5292,7 @@ const struct net_device_ops mlx5e_netdev_ops =
 {
  	.ndo_setup_tc            = mlx5e_setup_tc,
  	.ndo_select_queue        = mlx5e_select_queue,
  	.ndo_get_stats64         = mlx5e_get_stats,
-	.ndo_set_rx_mode         = mlx5e_set_rx_mode,
+	.ndo_set_rx_mode_async   = mlx5e_set_rx_mode,
  	.ndo_set_mac_address     = mlx5e_set_mac,
  	.ndo_vlan_rx_add_vid     = mlx5e_vlan_rx_add_vid,

  .ndo_vlan_rx_kill_vid    = mlx5e_vlan_rx_kill_vid,

drivers/net/ethernet/mellanox/mlx5/core/en_main.c +0 -0
@@ -6272,8 +6277,11 @@ void mlx5e_set_rx_mode_work(struct work_struct
 *work)
  {

  struct mlx5e_priv *priv = container_of(work, struct mlx5e_priv,
         set_rx_mode_work);

drivers/net/ethernet/mellanox/mlx5/core/en_main.c +1 -0
+	struct net_device *dev = priv->netdev;

drivers/net/ethernet/mellanox/mlx5/core/en_main.c +3 -1
-	return mlx5e_fs_set_rx_mode_work(priv->fs, priv->netdev);
+	netdev_lock_ops(dev);
+	mlx5e_fs_set_rx_mode_work(priv->fs, dev, NULL, NULL);
+	netdev_unlock_ops(dev);

 }

 /* mlx5e generic netdev management API (move to en_common.c) */

#21 lore raw

Re: [PATCH net-next v3 06/13] mlx5: convert to ndo_set_rx_mode_async

Quoted 155 lines · Cosmin Ratiu
Quoted 145 lines · Stanislav Fomichev

Convert mlx5 from ndo_set_rx_mode to ndo_set_rx_mode_async. The driver's mlx5e_set_rx_mode now receives uc/mc snapshots and calls mlx5e_fs_set_rx_mode_work directly instead of queueing work.

mlx5e_sync_netdev_addr and mlx5e_handle_netdev_addr now take explicit uc/mc list parameters and iterate with netdev_hw_addr_list_for_each instead of netdev_for_each_{uc,mc}_addr.

Fallback to netdev's uc/mc in a few places and grab addr lock.

---
 .../net/ethernet/mellanox/mlx5/core/en/fs.h   |  5 +++- .../net/ethernet/mellanox/mlx5/core/en_fs.c   | 30 ++++++++++++----- --
 .../net/ethernet/mellanox/mlx5/core/en_main.c | 16 +++++++---

 3 files changed, 36 insertions(+), 15 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/fs.h +0 -0
index c3408b3f7010..091b80a67189 100644
@@ -201,7 +201,10 @@ int mlx5e_add_vlan_trap(struct

mlx5e_flow_steering *fs, int  trap_id, int tir_nu
 void mlx5e_remove_vlan_trap(struct mlx5e_flow_steering *fs); int mlx5e_add_mac_trap(struct mlx5e_flow_steering *fs, int  trap_id, int tir_num);
 void mlx5e_remove_mac_trap(struct mlx5e_flow_steering *fs); -void mlx5e_fs_set_rx_mode_work(struct mlx5e_flow_steering *fs, struct net_device *netdev);

drivers/net/ethernet/mellanox/mlx5/core/en/fs.h +4 -0
+void mlx5e_fs_set_rx_mode_work(struct mlx5e_flow_steering *fs,
+			       struct net_device *netdev,
+			       struct netdev_hw_addr_list *uc,
+			       struct netdev_hw_addr_list *mc);

 int mlx5e_fs_vlan_rx_add_vid(struct mlx5e_flow_steering *fs, struct net_device *netdev, __be16 proto, u16 vid);

drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +0 -0
index 55255fe6e415..a9daefbd8f8f 100644
@@ -609,20 +609,26 @@ static void mlx5e_execute_l2_action(struct
 mlx5e_flow_steering *fs,
  }


 static void mlx5e_sync_netdev_addr(struct mlx5e_flow_steering *fs,

drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +3 -1
-				   struct net_device *netdev)
+				   struct net_device *netdev,
+				   struct netdev_hw_addr_list *uc,
+				   struct netdev_hw_addr_list *mc)

 {
  struct netdev_hw_addr *ha;

drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +3 -1
-	netif_addr_lock_bh(netdev);
+	if (!uc || !mc) {
+		netif_addr_lock_bh(netdev);
+		mlx5e_sync_netdev_addr(fs, netdev, &netdev->uc,

&netdev->mc);

drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +3 -0
+		netif_addr_unlock_bh(netdev);
+		return;
+	}


  mlx5e_add_l2_to_hash(fs->l2.netdev_uc, netdev->dev_addr);

drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +2 -1
-	netdev_for_each_uc_addr(ha, netdev)
+
+	netdev_hw_addr_list_for_each(ha, uc)

  mlx5e_add_l2_to_hash(fs->l2.netdev_uc, ha->addr);

drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +1 -1
-	netdev_for_each_mc_addr(ha, netdev)
+	netdev_hw_addr_list_for_each(ha, mc)

  mlx5e_add_l2_to_hash(fs->l2.netdev_mc, ha->addr);

drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +0 -2
-
-	netif_addr_unlock_bh(netdev);

 }

 static void mlx5e_fill_addr_array(struct mlx5e_flow_steering *fs, int list_type,

drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +0 -0
@@ -724,7 +730,9 @@ static void mlx5e_apply_netdev_addr(struct
 mlx5e_flow_steering *fs)
  }


 static void mlx5e_handle_netdev_addr(struct mlx5e_flow_steering *fs,

drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +3 -1
-				     struct net_device *netdev)
+				     struct net_device *netdev,
+				     struct netdev_hw_addr_list *uc,
+				     struct netdev_hw_addr_list *mc)

 {
  struct mlx5e_l2_hash_node *hn;
  struct hlist_node *tmp;

drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +0 -0
@@ -736,7 +744,7 @@ static void mlx5e_handle_netdev_addr(struct
 mlx5e_flow_steering *fs,
  		hn->action = MLX5E_ACTION_DEL;


  if (fs->state_destroy)

drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +1 -1
-		mlx5e_sync_netdev_addr(fs, netdev);
+		mlx5e_sync_netdev_addr(fs, netdev, uc, mc);


  mlx5e_apply_netdev_addr(fs);
 }

drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +0 -0
@@ -820,7 +828,9 @@ static void mlx5e_destroy_promisc_table(struct
 mlx5e_flow_steering *fs)
  }


 void mlx5e_fs_set_rx_mode_work(struct mlx5e_flow_steering *fs,

drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +3 -1
-			       struct net_device *netdev)
+			       struct net_device *netdev,
+			       struct netdev_hw_addr_list *uc,
+			       struct netdev_hw_addr_list *mc)

 {
  struct mlx5e_l2_table *ea = &fs->l2;

drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +0 -0
@@ -850,7 +860,7 @@ void mlx5e_fs_set_rx_mode_work(struct
 mlx5e_flow_steering *fs,
  	if (enable_broadcast)
  		mlx5e_add_l2_flow_rule(fs, &ea->broadcast,
 MLX5E_FULLMATCH);

drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +1 -1
-	mlx5e_handle_netdev_addr(fs, netdev);
+	mlx5e_handle_netdev_addr(fs, netdev, uc, mc);


  if (disable_broadcast) mlx5e_del_l2_flow_rule(fs, &ea->broadcast);

drivers/net/ethernet/mellanox/mlx5/core/en_main.c +0 -0
index f7009da94f0b..e86cf1ee108d 100644
@@ -4108,11 +4108,16 @@ static void mlx5e_nic_set_rx_mode(struct
 mlx5e_priv *priv)
  	queue_work(priv->wq, &priv->set_rx_mode_work);
  }

drivers/net/ethernet/mellanox/mlx5/core/en_main.c +3 -1
-static void mlx5e_set_rx_mode(struct net_device *dev)
+static void mlx5e_set_rx_mode(struct net_device *dev,
+			      struct netdev_hw_addr_list *uc,
+			      struct netdev_hw_addr_list *mc)

 {
  struct mlx5e_priv *priv = netdev_priv(dev);

drivers/net/ethernet/mellanox/mlx5/core/en_main.c static void mlx5e_nic_set_rx_mode(struct mlx5e_priv *priv) · line 4120

Quoted 5 lines
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +4 -1
-	mlx5e_nic_set_rx_mode(priv);
+	if (mlx5e_is_uplink_rep(priv))
+		return; /* no rx mode for uplink rep */
+
+	mlx5e_fs_set_rx_mode_work(priv->fs, dev, uc, mc);

While this chunk is correct, I think there's a logical conflict waiting to happen with Saeed's pending patch touching this area ([1]).

Quoted 7 lines

You have inlined mlx5e_nic_set_rx_mode here, but after Saeed's patch the mlx5e_is_uplink_rep condition added here should be dropped.

Not sure the automatic merge will do that.

[1]
https://lore.kernel.org/netdev/[email protected]/T/#u

Thanks for the heads up, will try to wait for this to be pulled before reposting!

#22 lore raw

PATCH v3 7/13 bnxt: convert to ndo_set_rx_mode_async

In reply to Stanislav Fomichev

Convert bnxt from ndo_set_rx_mode to ndo_set_rx_mode_async. bnxt_set_rx_mode, bnxt_mc_list_updated and bnxt_uc_list_updated now take explicit uc/mc list parameters and iterate with netdev_hw_addr_list_for_each instead of netdev_for_each_{uc,mc}_addr.

The bnxt_cfg_rx_mode internal caller passes the real lists under netif_addr_lock_bh.

BNXT_RX_MASK_SP_EVENT is still used here, next patch converts to the direct call.

---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 31 +++++++++++++----------
 1 file changed, 17 insertions(+), 14 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +17 -14
index c982aac714d1..225217b32e4b 100644
@@ -11040,7 +11040,8 @@ static int bnxt_setup_nitroa0_vnic(struct bnxt *bp)
 }
 
 static int bnxt_cfg_rx_mode(struct bnxt *);
-static bool bnxt_mc_list_updated(struct bnxt *, u32 *);
+static bool bnxt_mc_list_updated(struct bnxt *, u32 *,
+				 const struct netdev_hw_addr_list *);
 
 static int bnxt_init_chip(struct bnxt *bp, bool irq_re_init)
 {
@@ -11130,7 +11131,7 @@ static int bnxt_init_chip(struct bnxt *bp, bool irq_re_init)
 	} else if (bp->dev->flags & IFF_MULTICAST) {
 		u32 mask = 0;
 
-		bnxt_mc_list_updated(bp, &mask);
+		bnxt_mc_list_updated(bp, &mask, &bp->dev->mc);
 		vnic->rx_mask |= mask;
 	}
 
@@ -13519,17 +13520,17 @@ void bnxt_get_ring_drv_stats(struct bnxt *bp,
 		bnxt_get_one_ring_drv_stats(bp, stats, &bp->bnapi[i]->cp_ring);
 }
 
-static bool bnxt_mc_list_updated(struct bnxt *bp, u32 *rx_mask)
+static bool bnxt_mc_list_updated(struct bnxt *bp, u32 *rx_mask,
+				 const struct netdev_hw_addr_list *mc)
 {
 	struct bnxt_vnic_info *vnic = &bp->vnic_info[BNXT_VNIC_DEFAULT];
-	struct net_device *dev = bp->dev;
 	struct netdev_hw_addr *ha;
 	u8 *haddr;
 	int mc_count = 0;
 	bool update = false;
 	int off = 0;
 
-	netdev_for_each_mc_addr(ha, dev) {
+	netdev_hw_addr_list_for_each(ha, mc) {
 		if (mc_count >= BNXT_MAX_MC_ADDRS) {
 			*rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST;
 			vnic->mc_list_count = 0;
@@ -13553,17 +13554,17 @@ static bool bnxt_mc_list_updated(struct bnxt *bp, u32 *rx_mask)
 	return update;
 }
 
-static bool bnxt_uc_list_updated(struct bnxt *bp)
+static bool bnxt_uc_list_updated(struct bnxt *bp,
+				 const struct netdev_hw_addr_list *uc)
 {
-	struct net_device *dev = bp->dev;
 	struct bnxt_vnic_info *vnic = &bp->vnic_info[BNXT_VNIC_DEFAULT];
 	struct netdev_hw_addr *ha;
 	int off = 0;
 
-	if (netdev_uc_count(dev) != (vnic->uc_filter_count - 1))
+	if (netdev_hw_addr_list_count(uc) != (vnic->uc_filter_count - 1))
 		return true;
 
-	netdev_for_each_uc_addr(ha, dev) {
+	netdev_hw_addr_list_for_each(ha, uc) {
 		if (!ether_addr_equal(ha->addr, vnic->uc_list + off))
 			return true;
 
@@ -13572,7 +13573,9 @@ static bool bnxt_uc_list_updated(struct bnxt *bp)
 	return false;
 }
 
-static void bnxt_set_rx_mode(struct net_device *dev)
+static void bnxt_set_rx_mode(struct net_device *dev,
+			     struct netdev_hw_addr_list *uc,
+			     struct netdev_hw_addr_list *mc)
 {
 	struct bnxt *bp = netdev_priv(dev);
 	struct bnxt_vnic_info *vnic;
@@ -13593,7 +13596,7 @@ static void bnxt_set_rx_mode(struct net_device *dev)
 	if (dev->flags & IFF_PROMISC)
 		mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
 
-	uc_update = bnxt_uc_list_updated(bp);
+	uc_update = bnxt_uc_list_updated(bp, uc);
 
 	if (dev->flags & IFF_BROADCAST)
 		mask |= CFA_L2_SET_RX_MASK_REQ_MASK_BCAST;
@@ -13601,7 +13604,7 @@ static void bnxt_set_rx_mode(struct net_device *dev)
 		mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST;
 		vnic->mc_list_count = 0;
 	} else if (dev->flags & IFF_MULTICAST) {
-		mc_update = bnxt_mc_list_updated(bp, &mask);
+		mc_update = bnxt_mc_list_updated(bp, &mask, mc);
 	}
 
 	if (mask != vnic->rx_mask || uc_update || mc_update) {
@@ -13620,7 +13623,7 @@ static int bnxt_cfg_rx_mode(struct bnxt *bp)
 	bool uc_update;
 
 	netif_addr_lock_bh(dev);
-	uc_update = bnxt_uc_list_updated(bp);
+	uc_update = bnxt_uc_list_updated(bp, &dev->uc);
 	netif_addr_unlock_bh(dev);
 
 	if (!uc_update)
@@ -15871,7 +15874,7 @@ static const struct net_device_ops bnxt_netdev_ops = {
 	.ndo_start_xmit		= bnxt_start_xmit,
 	.ndo_stop		= bnxt_close,
 	.ndo_get_stats64	= bnxt_get_stats64,
-	.ndo_set_rx_mode	= bnxt_set_rx_mode,
+	.ndo_set_rx_mode_async	= bnxt_set_rx_mode,
 	.ndo_eth_ioctl		= bnxt_ioctl,
 	.ndo_validate_addr	= eth_validate_addr,
 	.ndo_set_mac_address	= bnxt_change_mac_addr,
Signature · 1 line
2.53.0
maintainer Reviewed-by on v3 7/13
#23 lore raw

Re: [PATCH net-next v3 07/13] bnxt: convert to ndo_set_rx_mode_async

Quoted 9 lines · Stanislav Fomichev

Convert bnxt from ndo_set_rx_mode to ndo_set_rx_mode_async. bnxt_set_rx_mode, bnxt_mc_list_updated and bnxt_uc_list_updated now take explicit uc/mc list parameters and iterate with netdev_hw_addr_list_for_each instead of netdev_for_each_{uc,mc}_addr.

The bnxt_cfg_rx_mode internal caller passes the real lists under netif_addr_lock_bh.

Quoted 7 lines

BNXT_RX_MASK_SP_EVENT is still used here, next patch converts to the direct call.

#24 lore raw

PATCH v3 8/13 bnxt: use snapshot in bnxt_cfg_rx_mode

In reply to Stanislav Fomichev

With the introduction of ndo_set_rx_mode_async (as discussed in [0]) we can call bnxt_cfg_rx_mode directly. Convert bnxt_cfg_rx_mode to use uc/mc snapshots and move its call in bnxt_sp_task to the section that resets BNXT_STATE_IN_SP_TASK. Switch to direct call in bnxt_set_rx_mode.

0: https://lore.kernel.org/netdev/CACKFLi=5vj8hPqEUKDd8RTw3au5G+zRgQEqjF+6NZnyoNm90KA@mail.gmail.com/

Cc Michael Chan <[email protected]>
Cc Pavan Chebbi <[email protected]>
---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 26 ++++++++++++++---------
 1 file changed, 16 insertions(+), 10 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +16 -10
index 225217b32e4b..12265bd7fda4 100644
@@ -11039,7 +11039,8 @@ static int bnxt_setup_nitroa0_vnic(struct bnxt *bp)
 	return rc;
 }
 
-static int bnxt_cfg_rx_mode(struct bnxt *);
+static int bnxt_cfg_rx_mode(struct bnxt *, struct netdev_hw_addr_list *,
+			    struct netdev_hw_addr_list *);
 static bool bnxt_mc_list_updated(struct bnxt *, u32 *,
 				 const struct netdev_hw_addr_list *);
 
@@ -11135,7 +11136,7 @@ static int bnxt_init_chip(struct bnxt *bp, bool irq_re_init)
 		vnic->rx_mask |= mask;
 	}
 
-	rc = bnxt_cfg_rx_mode(bp);
+	rc = bnxt_cfg_rx_mode(bp, &bp->dev->uc, &bp->dev->mc);
 	if (rc)
 		goto err_out;
 
@@ -13610,11 +13611,12 @@ static void bnxt_set_rx_mode(struct net_device *dev,
 	if (mask != vnic->rx_mask || uc_update || mc_update) {
 		vnic->rx_mask = mask;
 
-		bnxt_queue_sp_work(bp, BNXT_RX_MASK_SP_EVENT);
+		bnxt_cfg_rx_mode(bp, uc, mc);
 	}
 }
 
-static int bnxt_cfg_rx_mode(struct bnxt *bp)
+static int bnxt_cfg_rx_mode(struct bnxt *bp, struct netdev_hw_addr_list *uc,
+			    struct netdev_hw_addr_list *mc)
 {
 	struct net_device *dev = bp->dev;
 	struct bnxt_vnic_info *vnic = &bp->vnic_info[BNXT_VNIC_DEFAULT];
@@ -13623,7 +13625,7 @@ static int bnxt_cfg_rx_mode(struct bnxt *bp)
 	bool uc_update;
 
 	netif_addr_lock_bh(dev);
-	uc_update = bnxt_uc_list_updated(bp, &dev->uc);
+	uc_update = bnxt_uc_list_updated(bp, uc);
 	netif_addr_unlock_bh(dev);
 
 	if (!uc_update)
@@ -13639,10 +13641,10 @@ static int bnxt_cfg_rx_mode(struct bnxt *bp)
 	vnic->uc_filter_count = 1;
 
 	netif_addr_lock_bh(dev);
-	if (netdev_uc_count(dev) > (BNXT_MAX_UC_ADDRS - 1)) {
+	if (netdev_hw_addr_list_count(uc) > (BNXT_MAX_UC_ADDRS - 1)) {
 		vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
 	} else {
-		netdev_for_each_uc_addr(ha, dev) {
+		netdev_hw_addr_list_for_each(ha, uc) {
 			memcpy(vnic->uc_list + off, ha->addr, ETH_ALEN);
 			off += ETH_ALEN;
 			vnic->uc_filter_count++;
@@ -14600,6 +14602,7 @@ static void bnxt_ulp_restart(struct bnxt *bp)
 static void bnxt_sp_task(struct work_struct *work)
 {
 	struct bnxt *bp = container_of(work, struct bnxt, sp_task);
+	struct net_device *dev = bp->dev;
 
 	set_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
 	smp_mb__after_atomic();
@@ -14613,9 +14616,6 @@ static void bnxt_sp_task(struct work_struct *work)
 		bnxt_reenable_sriov(bp);
 	}
 
-	if (test_and_clear_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event))
-		bnxt_cfg_rx_mode(bp);
-
 	if (test_and_clear_bit(BNXT_RX_NTP_FLTR_SP_EVENT, &bp->sp_event))
 		bnxt_cfg_ntp_filters(bp);
 	if (test_and_clear_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT, &bp->sp_event))
@@ -14680,6 +14680,12 @@ static void bnxt_sp_task(struct work_struct *work)
 	/* These functions below will clear BNXT_STATE_IN_SP_TASK.  They
 	 * must be the last functions to be called before exiting.
 	 */
+	if (test_and_clear_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event)) {
+		bnxt_lock_sp(bp);
+		bnxt_cfg_rx_mode(bp, &dev->uc, &dev->mc);
+		bnxt_unlock_sp(bp);
+	}
+
 	if (test_and_clear_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event))
 		bnxt_reset(bp, false);
 
Signature · 1 line
2.53.0
Reviewed-by on v3 8/13
#25 lore raw

RE: [PATCH net-next v3 08/13] bnxt: use snapshot in bnxt_cfg_rx_mode

Quoted 144 lines

-----Original Message-----
From: Stanislav Fomichev <[email protected]>
Sent: Friday, March 20, 2026 2:25 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Keller, Jacob E <[email protected]>; [email protected]; [email protected]; [email protected]; Loktionov, Aleksandr <[email protected]>; [email protected]; linux- [email protected]; [email protected]; intel-wired- [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: [PATCH net-next v3 08/13] bnxt: use snapshot in bnxt_cfg_rx_mode

With the introduction of ndo_set_rx_mode_async (as discussed in [0]) we can call bnxt_cfg_rx_mode directly. Convert bnxt_cfg_rx_mode to use uc/mc snapshots and move its call in bnxt_sp_task to the section that resets BNXT_STATE_IN_SP_TASK. Switch to direct call in bnxt_set_rx_mode.

0:
https://lore.kernel.org/netdev/CACKFLi=5vj8hPqEUKDd8RTw3au5G+zRgQEqjF+
[email protected]/

Cc Michael Chan <[email protected]>
Cc Pavan Chebbi <[email protected]>
---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 26 ++++++++++++++--------
(quoted diff) +0 -1
-
 1 file changed, 16 insertions(+), 10 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +2 -1
index 225217b32e4b..12265bd7fda4 100644
@@ -11039,7 +11039,8 @@ static int bnxt_setup_nitroa0_vnic(struct bnxt
 *bp)
 	return rc;
 }
 
-static int bnxt_cfg_rx_mode(struct bnxt *);
+static int bnxt_cfg_rx_mode(struct bnxt *, struct netdev_hw_addr_list
 *,
+			    struct netdev_hw_addr_list *);
 static bool bnxt_mc_list_updated(struct bnxt *, u32 *,
drivers/net/ethernet/broadcom/bnxt/bnxt.c +4 -3
 				 const struct netdev_hw_addr_list *);
@@ -11135,7 +11136,7 @@ static int bnxt_init_chip(struct bnxt *bp,
 bool irq_re_init)
 		vnic->rx_mask |= mask;
 	}
 
-	rc = bnxt_cfg_rx_mode(bp);
+	rc = bnxt_cfg_rx_mode(bp, &bp->dev->uc, &bp->dev->mc);
 	if (rc)
 		goto err_out;
@@ -13610,11 +13611,12 @@ static void bnxt_set_rx_mode(struct
 net_device *dev,
 	if (mask != vnic->rx_mask || uc_update || mc_update) {
 		vnic->rx_mask = mask;
 
-		bnxt_queue_sp_work(bp, BNXT_RX_MASK_SP_EVENT);
+		bnxt_cfg_rx_mode(bp, uc, mc);
 	}
 }
 
-static int bnxt_cfg_rx_mode(struct bnxt *bp)
+static int bnxt_cfg_rx_mode(struct bnxt *bp, struct
 netdev_hw_addr_list *uc,
+			    struct netdev_hw_addr_list *mc)
 {
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0 -0
 	struct net_device *dev = bp->dev;
 	struct bnxt_vnic_info *vnic = &bp-
Quoted 1 line

vnic_info[BNXT_VNIC_DEFAULT];

drivers/net/ethernet/broadcom/bnxt/bnxt.c +3 -3
@@ -13623,7 +13625,7 @@ static int bnxt_cfg_rx_mode(struct bnxt *bp)
 	bool uc_update;
 
 	netif_addr_lock_bh(dev);
-	uc_update = bnxt_uc_list_updated(bp, &dev->uc);
+	uc_update = bnxt_uc_list_updated(bp, uc);
 	netif_addr_unlock_bh(dev);
 
 	if (!uc_update)
@@ -13639,10 +13641,10 @@ static int bnxt_cfg_rx_mode(struct bnxt *bp)
 	vnic->uc_filter_count = 1;
 
 	netif_addr_lock_bh(dev);
-	if (netdev_uc_count(dev) > (BNXT_MAX_UC_ADDRS - 1)) {
+	if (netdev_hw_addr_list_count(uc) > (BNXT_MAX_UC_ADDRS - 1)) {
 		vnic->rx_mask |=
 CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS;
 	} else {
-		netdev_for_each_uc_addr(ha, dev) {
+		netdev_hw_addr_list_for_each(ha, uc) {
 			memcpy(vnic->uc_list + off, ha->addr, ETH_ALEN);
 			off += ETH_ALEN;
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -3
 			vnic->uc_filter_count++;
@@ -14600,6 +14602,7 @@ static void bnxt_ulp_restart(struct bnxt *bp)
 static void bnxt_sp_task(struct work_struct *work)  {
 	struct bnxt *bp = container_of(work, struct bnxt, sp_task);
+	struct net_device *dev = bp->dev;
 
 	set_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
 	smp_mb__after_atomic();
@@ -14613,9 +14616,6 @@ static void bnxt_sp_task(struct work_struct
 *work)
 		bnxt_reenable_sriov(bp);
 	}
 
-	if (test_and_clear_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event))
-		bnxt_cfg_rx_mode(bp);
-
 	if (test_and_clear_bit(BNXT_RX_NTP_FLTR_SP_EVENT, &bp-
 >sp_event))
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0 -0
 		bnxt_cfg_ntp_filters(bp);
 	if (test_and_clear_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT, &bp-
Quoted 1 line

sp_event)) @@ -14680,6 +14680,12 @@ static void bnxt_sp_task(struct

work_struct *work)
/* These functions below will clear BNXT_STATE_IN_SP_TASK.
They

drivers/net/ethernet/broadcom/bnxt/bnxt.c +6 -0
 	 * must be the last functions to be called before exiting.
 	 */
+	if (test_and_clear_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event)) {
+		bnxt_lock_sp(bp);
+		bnxt_cfg_rx_mode(bp, &dev->uc, &dev->mc);
+		bnxt_unlock_sp(bp);
+	}
+
 	if (test_and_clear_bit(BNXT_RESET_TASK_SP_EVENT, &bp-
Quoted 1 line

sp_event))

Quoted 4 lines

bnxt_reset(bp, false);

--
2.53.0

maintainer
#26 lore raw

Re: [PATCH net-next v3 08/13] bnxt: use snapshot in bnxt_cfg_rx_mode

In reply to Stanislav Fomichev
Quoted 55 lines · Stanislav Fomichev

With the introduction of ndo_set_rx_mode_async (as discussed in [0]) we can call bnxt_cfg_rx_mode directly. Convert bnxt_cfg_rx_mode to use uc/mc snapshots and move its call in bnxt_sp_task to the section that resets BNXT_STATE_IN_SP_TASK. Switch to direct call in bnxt_set_rx_mode.

0: https://lore.kernel.org/netdev/CACKFLi=5vj8hPqEUKDd8RTw3au5G+zRgQEqjF+6NZnyoNm90KA@mail.gmail.com/

Cc Michael Chan <[email protected]>
Cc Pavan Chebbi <[email protected]>
---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 26 ++++++++++++++---------
 1 file changed, 16 insertions(+), 10 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +6 -4
index 225217b32e4b..12265bd7fda4 100644
@@ -11039,7 +11039,8 @@ static int bnxt_setup_nitroa0_vnic(struct bnxt *bp)
        return rc;
 }
 
-static int bnxt_cfg_rx_mode(struct bnxt *);
+static int bnxt_cfg_rx_mode(struct bnxt *, struct netdev_hw_addr_list *,
+                           struct netdev_hw_addr_list *);
 static bool bnxt_mc_list_updated(struct bnxt *, u32 *,
                                 const struct netdev_hw_addr_list *);
 
@@ -11135,7 +11136,7 @@ static int bnxt_init_chip(struct bnxt *bp, bool irq_re_init)
                vnic->rx_mask |= mask;
        }
 
-       rc = bnxt_cfg_rx_mode(bp);
+       rc = bnxt_cfg_rx_mode(bp, &bp->dev->uc, &bp->dev->mc);
        if (rc)
                goto err_out;
 
@@ -13610,11 +13611,12 @@ static void bnxt_set_rx_mode(struct net_device *dev,
        if (mask != vnic->rx_mask || uc_update || mc_update) {
                vnic->rx_mask = mask;
 
-               bnxt_queue_sp_work(bp, BNXT_RX_MASK_SP_EVENT);
+               bnxt_cfg_rx_mode(bp, uc, mc);
        }
 }
 
-static int bnxt_cfg_rx_mode(struct bnxt *bp)
+static int bnxt_cfg_rx_mode(struct bnxt *bp, struct netdev_hw_addr_list *uc,
+                           struct netdev_hw_addr_list *mc)
 {
        struct net_device *dev = bp->dev;
        struct bnxt_vnic_info *vnic = &bp->vnic_info[BNXT_VNIC_DEFAULT];

drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_cfg_rx_mode(struct bnxt *bp) · line 13628

Quoted 5 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -1
@@ -13623,7 +13625,7 @@ static int bnxt_cfg_rx_mode(struct bnxt *bp)
        bool uc_update;
 
        netif_addr_lock_bh(dev);
-       uc_update = bnxt_uc_list_updated(bp, &dev->uc);
+       uc_update = bnxt_uc_list_updated(bp, uc);

Will the uc list snapshot change between bnxt_set_rx_mode() and bnxt_cfg_rx_mode() with the direct call now? In the original deferred update implementation, the uc list can change and that's why we check in both functions.

#27 lore raw

Re: [PATCH net-next v3 08/13] bnxt: use snapshot in bnxt_cfg_rx_mode

Quoted 58 lines · Michael Chan
Quoted 57 lines · Stanislav Fomichev

With the introduction of ndo_set_rx_mode_async (as discussed in [0]) we can call bnxt_cfg_rx_mode directly. Convert bnxt_cfg_rx_mode to use uc/mc snapshots and move its call in bnxt_sp_task to the section that resets BNXT_STATE_IN_SP_TASK. Switch to direct call in bnxt_set_rx_mode.

0: https://lore.kernel.org/netdev/CACKFLi=5vj8hPqEUKDd8RTw3au5G+zRgQEqjF+6NZnyoNm90KA@mail.gmail.com/

Cc Michael Chan <[email protected]>
Cc Pavan Chebbi <[email protected]>
---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 26 ++++++++++++++---------
 1 file changed, 16 insertions(+), 10 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +6 -4
index 225217b32e4b..12265bd7fda4 100644
@@ -11039,7 +11039,8 @@ static int bnxt_setup_nitroa0_vnic(struct bnxt *bp)
        return rc;
 }
 
-static int bnxt_cfg_rx_mode(struct bnxt *);
+static int bnxt_cfg_rx_mode(struct bnxt *, struct netdev_hw_addr_list *,
+                           struct netdev_hw_addr_list *);
 static bool bnxt_mc_list_updated(struct bnxt *, u32 *,
                                 const struct netdev_hw_addr_list *);
 
@@ -11135,7 +11136,7 @@ static int bnxt_init_chip(struct bnxt *bp, bool irq_re_init)
                vnic->rx_mask |= mask;
        }
 
-       rc = bnxt_cfg_rx_mode(bp);
+       rc = bnxt_cfg_rx_mode(bp, &bp->dev->uc, &bp->dev->mc);
        if (rc)
                goto err_out;
 
@@ -13610,11 +13611,12 @@ static void bnxt_set_rx_mode(struct net_device *dev,
        if (mask != vnic->rx_mask || uc_update || mc_update) {
                vnic->rx_mask = mask;
 
-               bnxt_queue_sp_work(bp, BNXT_RX_MASK_SP_EVENT);
+               bnxt_cfg_rx_mode(bp, uc, mc);
        }
 }
 
-static int bnxt_cfg_rx_mode(struct bnxt *bp)
+static int bnxt_cfg_rx_mode(struct bnxt *bp, struct netdev_hw_addr_list *uc,
+                           struct netdev_hw_addr_list *mc)
 {
        struct net_device *dev = bp->dev;
        struct bnxt_vnic_info *vnic = &bp->vnic_info[BNXT_VNIC_DEFAULT];
@@ -13623,7 +13625,7 @@ static int bnxt_cfg_rx_mode(struct bnxt *bp)
        bool uc_update;
 
Quoted 8 lines

drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_cfg_rx_mode(struct bnxt *bp) · line 13628

Quoted 3 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -1
        netif_addr_lock_bh(dev);
-       uc_update = bnxt_uc_list_updated(bp, &dev->uc);
+       uc_update = bnxt_uc_list_updated(bp, uc);

Will the uc list snapshot change between bnxt_set_rx_mode() and bnxt_cfg_rx_mode() with the direct call now? In the original deferred update implementation, the uc list can change and that's why we check in both functions.

The snapshot is gonna be the same for bnxt_set_rx_mode->bnxt_cfg_rx_mode path.

So you're saying that it's ok to remove the one in bnxt_cfg_rx_mode because it's called either from bnxt_set_rx_mode (with a new list) or, explicitly, via the BNXT_RX_MASK_SP_EVENT retry mechanism (where we know that we need to redo the updates anyway)?

This makes me wonder whether I need to push the retrying mechanism to the core stack... Right now, if some of the allocations in wq handler fail, we just give up, maybe I should handle it better. And I can plug the signal from the driver (make ndo_set_rx_mode_async return int) in the same retry mechanism.

#28 lore raw

PATCH v3 9/13 iavf: convert to ndo_set_rx_mode_async

In reply to Stanislav Fomichev

Convert iavf from ndo_set_rx_mode to ndo_set_rx_mode_async. iavf_set_rx_mode now takes explicit uc/mc list parameters and uses __hw_addr_sync_dev on the snapshots instead of __dev_uc_sync and __dev_mc_sync.

The iavf_configure internal caller passes the real lists directly.

Cc Tony Nguyen <[email protected]>
Cc Przemek Kitszel <[email protected]>
---
 drivers/net/ethernet/intel/iavf/iavf_main.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/iavf/iavf_main.c +9 -5
index 7925ee152c76..6632d35ad0fe 100644
@@ -1147,14 +1147,18 @@ bool iavf_promiscuous_mode_changed(struct iavf_adapter *adapter)
 /**
  * iavf_set_rx_mode - NDO callback to set the netdev filters
  * @netdev: network interface device structure
+ * @uc: snapshot of uc address list
+ * @mc: snapshot of mc address list
  **/
-static void iavf_set_rx_mode(struct net_device *netdev)
+static void iavf_set_rx_mode(struct net_device *netdev,
+			     struct netdev_hw_addr_list *uc,
+			     struct netdev_hw_addr_list *mc)
 {
 	struct iavf_adapter *adapter = netdev_priv(netdev);
 
 	spin_lock_bh(&adapter->mac_vlan_list_lock);
-	__dev_uc_sync(netdev, iavf_addr_sync, iavf_addr_unsync);
-	__dev_mc_sync(netdev, iavf_addr_sync, iavf_addr_unsync);
+	__hw_addr_sync_dev(uc, netdev, iavf_addr_sync, iavf_addr_unsync);
+	__hw_addr_sync_dev(mc, netdev, iavf_addr_sync, iavf_addr_unsync);
 	spin_unlock_bh(&adapter->mac_vlan_list_lock);
 
 	spin_lock_bh(&adapter->current_netdev_promisc_flags_lock);
@@ -1207,7 +1211,7 @@ static void iavf_configure(struct iavf_adapter *adapter)
 	struct net_device *netdev = adapter->netdev;
 	int i;
 
-	iavf_set_rx_mode(netdev);
+	iavf_set_rx_mode(netdev, &netdev->uc, &netdev->mc);
 
 	iavf_configure_tx(adapter);
 	iavf_configure_rx(adapter);
@@ -5150,7 +5154,7 @@ static const struct net_device_ops iavf_netdev_ops = {
 	.ndo_open		= iavf_open,
 	.ndo_stop		= iavf_close,
 	.ndo_start_xmit		= iavf_xmit_frame,
-	.ndo_set_rx_mode	= iavf_set_rx_mode,
+	.ndo_set_rx_mode_async	= iavf_set_rx_mode,
 	.ndo_validate_addr	= eth_validate_addr,
 	.ndo_set_mac_address	= iavf_set_mac,
 	.ndo_change_mtu		= iavf_change_mtu,
Signature · 1 line
2.53.0
Reviewed-by on v3 9/13
#29 lore raw

RE: [PATCH net-next v3 09/13] iavf: convert to ndo_set_rx_mode_async

Quoted 88 lines

-----Original Message-----
From: Stanislav Fomichev <[email protected]>
Sent: Friday, March 20, 2026 2:25 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Keller, Jacob E <[email protected]>; [email protected]; [email protected]; [email protected]; Loktionov, Aleksandr <[email protected]>; [email protected]; linux- [email protected]; [email protected]; intel-wired- [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: [PATCH net-next v3 09/13] iavf: convert to ndo_set_rx_mode_async

Convert iavf from ndo_set_rx_mode to ndo_set_rx_mode_async. iavf_set_rx_mode now takes explicit uc/mc list parameters and uses __hw_addr_sync_dev on the snapshots instead of __dev_uc_sync and __dev_mc_sync.

The iavf_configure internal caller passes the real lists directly.

Cc Tony Nguyen <[email protected]>
Cc Przemek Kitszel <[email protected]>
---
 drivers/net/ethernet/intel/iavf/iavf_main.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/iavf/iavf_main.c +7 -3
index 7925ee152c76..6632d35ad0fe 100644
@@ -1147,14 +1147,18 @@ bool iavf_promiscuous_mode_changed(struct
 iavf_adapter *adapter)
 /**
  * iavf_set_rx_mode - NDO callback to set the netdev filters
  * @netdev: network interface device structure
+ * @uc: snapshot of uc address list
+ * @mc: snapshot of mc address list
  **/
-static void iavf_set_rx_mode(struct net_device *netdev)
+static void iavf_set_rx_mode(struct net_device *netdev,
+			     struct netdev_hw_addr_list *uc,
+			     struct netdev_hw_addr_list *mc)
 {
 	struct iavf_adapter *adapter = netdev_priv(netdev);
 
 	spin_lock_bh(&adapter->mac_vlan_list_lock);
-	__dev_uc_sync(netdev, iavf_addr_sync, iavf_addr_unsync);
-	__dev_mc_sync(netdev, iavf_addr_sync, iavf_addr_unsync);
+	__hw_addr_sync_dev(uc, netdev, iavf_addr_sync,
 iavf_addr_unsync);
+	__hw_addr_sync_dev(mc, netdev, iavf_addr_sync,
 iavf_addr_unsync);
drivers/net/ethernet/intel/iavf/iavf_main.c +1 -1
 	spin_unlock_bh(&adapter->mac_vlan_list_lock);
 
 	spin_lock_bh(&adapter->current_netdev_promisc_flags_lock);
@@ -1207,7 +1211,7 @@ static void iavf_configure(struct iavf_adapter
 *adapter)
 	struct net_device *netdev = adapter->netdev;
 	int i;
 
-	iavf_set_rx_mode(netdev);
+	iavf_set_rx_mode(netdev, &netdev->uc, &netdev->mc);
 
 	iavf_configure_tx(adapter);
drivers/net/ethernet/intel/iavf/iavf_main.c +1 -1
 	iavf_configure_rx(adapter);
@@ -5150,7 +5154,7 @@ static const struct net_device_ops
 iavf_netdev_ops = {
 	.ndo_open		= iavf_open,
 	.ndo_stop		= iavf_close,
 	.ndo_start_xmit		= iavf_xmit_frame,
-	.ndo_set_rx_mode	= iavf_set_rx_mode,
+	.ndo_set_rx_mode_async	= iavf_set_rx_mode,
 	.ndo_validate_addr	= eth_validate_addr,
 	.ndo_set_mac_address	= iavf_set_mac,
Quoted 3 lines

.ndo_change_mtu = iavf_change_mtu,
--
2.53.0

#30 lore raw

PATCH v3 10/13 netdevsim: convert to ndo_set_rx_mode_async

In reply to Stanislav Fomichev

Convert netdevsim from ndo_set_rx_mode to ndo_set_rx_mode_async. The callback is a no-op stub so just update the signature and ops struct wiring.

---
 drivers/net/netdevsim/netdev.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/net/netdevsim/netdev.c +5 -3
index 5ec028a00c62..9c9217792125 100644
@@ -182,7 +182,9 @@ static netdev_tx_t nsim_start_xmit(struct sk_buff *skb, struct net_device *dev)
 	return NETDEV_TX_OK;
 }
 
-static void nsim_set_rx_mode(struct net_device *dev)
+static void nsim_set_rx_mode(struct net_device *dev,
+			     struct netdev_hw_addr_list *uc,
+			     struct netdev_hw_addr_list *mc)
 {
 }
 
@@ -641,7 +643,7 @@ static const struct net_shaper_ops nsim_shaper_ops = {
 
 static const struct net_device_ops nsim_netdev_ops = {
 	.ndo_start_xmit		= nsim_start_xmit,
-	.ndo_set_rx_mode	= nsim_set_rx_mode,
+	.ndo_set_rx_mode_async	= nsim_set_rx_mode,
 	.ndo_set_mac_address	= eth_mac_addr,
 	.ndo_validate_addr	= eth_validate_addr,
 	.ndo_change_mtu		= nsim_change_mtu,
@@ -664,7 +666,7 @@ static const struct net_device_ops nsim_netdev_ops = {
 
 static const struct net_device_ops nsim_vf_netdev_ops = {
 	.ndo_start_xmit		= nsim_start_xmit,
-	.ndo_set_rx_mode	= nsim_set_rx_mode,
+	.ndo_set_rx_mode_async	= nsim_set_rx_mode,
 	.ndo_set_mac_address	= eth_mac_addr,
 	.ndo_validate_addr	= eth_validate_addr,
 	.ndo_change_mtu		= nsim_change_mtu,
Signature · 1 line
2.53.0
#31 lore raw

PATCH v3 11/13 dummy: convert to ndo_set_rx_mode_async

In reply to Stanislav Fomichev

Convert dummy driver from ndo_set_rx_mode to ndo_set_rx_mode_async. The dummy driver's set_multicast_list is a no-op, so the conversion is straightforward: update the signature and the ops assignment.

---
 drivers/net/dummy.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/dummy.c +4 -2
index d6bdad4baadd..f8a4eb365c3d 100644
@@ -47,7 +47,9 @@
 static int numdummies = 1;
 
 /* fake multicast ability */
-static void set_multicast_list(struct net_device *dev)
+static void set_multicast_list(struct net_device *dev,
+			       struct netdev_hw_addr_list *uc,
+			       struct netdev_hw_addr_list *mc)
 {
 }
 
@@ -87,7 +89,7 @@ static const struct net_device_ops dummy_netdev_ops = {
 	.ndo_init		= dummy_dev_init,
 	.ndo_start_xmit		= dummy_xmit,
 	.ndo_validate_addr	= eth_validate_addr,
-	.ndo_set_rx_mode	= set_multicast_list,
+	.ndo_set_rx_mode_async	= set_multicast_list,
 	.ndo_set_mac_address	= eth_mac_addr,
 	.ndo_get_stats64	= dummy_get_stats64,
 	.ndo_change_carrier	= dummy_change_carrier,
Signature · 1 line
2.53.0
Reviewed-by on v3 11/13
#32 lore raw

RE: [PATCH net-next v3 11/13] dummy: convert to ndo_set_rx_mode_async

Quoted 58 lines

-----Original Message-----
From: Stanislav Fomichev <[email protected]>
Sent: Friday, March 20, 2026 2:25 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Keller, Jacob E <[email protected]>; [email protected]; [email protected]; [email protected]; Loktionov, Aleksandr <[email protected]>; [email protected]; linux- [email protected]; [email protected]; intel-wired- [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: [PATCH net-next v3 11/13] dummy: convert to ndo_set_rx_mode_async

Convert dummy driver from ndo_set_rx_mode to ndo_set_rx_mode_async. The dummy driver's set_multicast_list is a no-op, so the conversion is
straightforward: update the signature and the ops assignment.

---
 drivers/net/dummy.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/dummy.c index renamed from drivers/net/dummy.c +0 -0

d6bdad4baadd..f8a4eb365c3d 100644

drivers/net/dummy.c +4 -2
@@ -47,7 +47,9 @@
 static int numdummies = 1;
 
 /* fake multicast ability */
-static void set_multicast_list(struct net_device *dev)
+static void set_multicast_list(struct net_device *dev,
+			       struct netdev_hw_addr_list *uc,
+			       struct netdev_hw_addr_list *mc)
 {
 }
 
@@ -87,7 +89,7 @@ static const struct net_device_ops dummy_netdev_ops
 = {
 	.ndo_init		= dummy_dev_init,
 	.ndo_start_xmit		= dummy_xmit,
 	.ndo_validate_addr	= eth_validate_addr,
-	.ndo_set_rx_mode	= set_multicast_list,
+	.ndo_set_rx_mode_async	= set_multicast_list,
 	.ndo_set_mac_address	= eth_mac_addr,
 	.ndo_get_stats64	= dummy_get_stats64,
Quoted 3 lines

.ndo_change_carrier = dummy_change_carrier,
--
2.53.0

#33 lore raw

PATCH v3 12/13 net: warn ops-locked drivers still using ndo_set_rx_mode

In reply to Stanislav Fomichev

Now that all in-tree ops-locked drivers have been converted to ndo_set_rx_mode_async, add a warning in register_netdevice to catch any remaining or newly added drivers that use ndo_set_rx_mode with ops locking. This ensures future driver authors are guided toward the async path.

Also route ops-locked devices through dev_rx_mode_work even if they lack rx_mode NDOs, to ensure netdev_ops_assert_locked() does not fire on the legacy path where only RTNL is held.

---
 net/core/dev.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
net/core/dev.c +7 -1
index fc5c9b14faa0..f38ab254708b 100644
@@ -9779,7 +9779,8 @@ void __dev_set_rx_mode(struct net_device *dev)
 	if (!netif_up_and_present(dev))
 		return;
 
-	if (ops->ndo_set_rx_mode_async || ops->ndo_change_rx_flags) {
+	if (ops->ndo_set_rx_mode_async || ops->ndo_change_rx_flags ||
+	    netdev_need_ops_lock(dev)) {
 		queue_work(rx_mode_wq, &dev->rx_mode_work);
 		return;
 	}
@@ -11471,6 +11472,11 @@ int register_netdevice(struct net_device *dev)
 		goto err_uninit;
 	}
 
+	if (netdev_need_ops_lock(dev) &&
+	    dev->netdev_ops->ndo_set_rx_mode &&
+	    !dev->netdev_ops->ndo_set_rx_mode_async)
+		netdev_WARN(dev, "ops-locked drivers should use ndo_set_rx_mode_async\n");
+
 	ret = netdev_do_alloc_pcpu_stats(dev);
 	if (ret)
 		goto err_uninit;
Signature · 1 line
2.53.0
Reviewed-by on v3 12/13
#34 lore raw

RE: [PATCH net-next v3 12/13] net: warn ops-locked drivers still using ndo_set_rx_mode

Quoted 69 lines

-----Original Message-----
From: Stanislav Fomichev <[email protected]>
Sent: Friday, March 20, 2026 2:25 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Keller, Jacob E <[email protected]>; [email protected]; [email protected]; [email protected]; Loktionov, Aleksandr <[email protected]>; [email protected]; linux- [email protected]; [email protected]; intel-wired- [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: [PATCH net-next v3 12/13] net: warn ops-locked drivers still using ndo_set_rx_mode

Now that all in-tree ops-locked drivers have been converted to ndo_set_rx_mode_async, add a warning in register_netdevice to catch any remaining or newly added drivers that use ndo_set_rx_mode with ops locking. This ensures future driver authors are guided toward the async path.

Also route ops-locked devices through dev_rx_mode_work even if they lack rx_mode NDOs, to ensure netdev_ops_assert_locked() does not fire on the legacy path where only RTNL is held.

---
 net/core/dev.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
net/core/dev.c index renamed from net/core/dev.c +0 -0

fc5c9b14faa0..f38ab254708b 100644

net/core/dev.c +8 -2
@@ -9779,7 +9779,8 @@ void __dev_set_rx_mode(struct net_device *dev)
 	if (!netif_up_and_present(dev))
 		return;
 
-	if (ops->ndo_set_rx_mode_async || ops->ndo_change_rx_flags) {
+	if (ops->ndo_set_rx_mode_async || ops->ndo_change_rx_flags ||
+	    netdev_need_ops_lock(dev)) {
 		queue_work(rx_mode_wq, &dev->rx_mode_work);
 		return;
 	}
@@ -11471,6 +11472,11 @@ int register_netdevice(struct net_device
 *dev)
 		goto err_uninit;
 	}
 
+	if (netdev_need_ops_lock(dev) &&
+	    dev->netdev_ops->ndo_set_rx_mode &&
+	    !dev->netdev_ops->ndo_set_rx_mode_async)
+		netdev_WARN(dev, "ops-locked drivers should use
+ndo_set_rx_mode_async\n");
+
 	ret = netdev_do_alloc_pcpu_stats(dev);
 	if (ret)
 		goto err_uninit;
--
Quoted 1 line

2.53.0

#35 lore raw

PATCH v3 13/13 selftests: net: add team_bridge_macvlan rx_mode test

In reply to Stanislav Fomichev

Add a test that exercises the ndo_change_rx_flags path through a macvlan -> bridge -> team -> dummy stack. This triggers dev_uc_add under addr_list_lock which flips promiscuity on the lower device. With the new work queue approach, this must not deadlock.

---
 tools/testing/selftests/net/config       |  1 +
 tools/testing/selftests/net/rtnetlink.sh | 44 ++++++++++++++++++++++++
 2 files changed, 45 insertions(+)
tools/testing/selftests/net/config +1 -0
index 2a390cae41bf..94d722770420 100644
@@ -101,6 +101,7 @@ CONFIG_NET_SCH_HTB=m
 CONFIG_NET_SCH_INGRESS=m
 CONFIG_NET_SCH_NETEM=y
 CONFIG_NET_SCH_PRIO=m
+CONFIG_NET_TEAM=y
 CONFIG_NET_VRF=y
 CONFIG_NF_CONNTRACK=m
 CONFIG_NF_CONNTRACK_OVS=y
tools/testing/selftests/net/rtnetlink.sh +44 -0

56 lines not on this page · raw message

Signature · 1 line
2.53.0