Subject: Re: [PATCH net-next v5 02/14] net: introduce ndo_set_rx_mode_async and netdev_rx_mode_work

From: Jakub Kicinski <[email-masked]>
Date: Fri, 3 Apr 2026 17:06:04 -0700

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
Subject: net: introduce ndo_set_rx_mode_async and netdev_rx_mode_work

This commit introduces an async variant of ndo_set_rx_mode that runs from a
workqueue, allowing drivers to sleep during RX mode changes. It also adds
netif_rx_mode_sync() to opportunistically flush pending updates before
returning to userspace.

> --- a/net/core/dev.c
> +++ b/net/core/dev.c
[ ... ]
> @@ -12217,6 +12178,9 @@ void free_netdev(struct net_device *dev)
>  
>  	kfree(rcu_dereference_protected(dev->ingress_queue, 1));
>  
> +	if (netif_rx_mode_clean(dev))
> +		dev_put(dev);
> +
>  	/* Flush device addresses */
>  	dev_addr_flush(dev);

Is this cleanup reachable during normal shutdown?

When a device is queued to rx_mode_list, netif_rx_mode_queue() elevates its
reference count via dev_hold(). During unregistration, netdev_wait_allrefs()
blocks the system until all references are dropped.

Because of this wait, the system shouldn't be able to reach free_netdev()
until the worker thread has already dequeued the device and called
dev_put(). It seems the device is guaranteed to not be on the list by the
time this code executes.

> --- a/net/core/dev_addr_lists.c
> +++ b/net/core/dev_addr_lists.c
[ ... ]
> +static void netdev_rx_mode_work(struct work_struct *work)
> +{
> +	struct net_device *dev;
> +
> +	rtnl_lock();
> +
> +	while (true) {
> +		spin_lock_bh(&rx_mode_lock);
> +		if (list_empty(&rx_mode_list)) {
> +			spin_unlock_bh(&rx_mode_lock);
> +			break;
> +		}
> +		dev = list_first_entry(&rx_mode_list, struct net_device,
> +				       rx_mode_node);
> +		list_del_init(&dev->rx_mode_node);
> +		spin_unlock_bh(&rx_mode_lock);
> +
> +		netdev_lock_ops(dev);

Can this while loop starve the system of the rtnl lock?

Since userspace can trigger RX mode updates via ioctls like SIOCADDMULTI
while holding only netdev_lock_ops() and not the rtnl lock, a continuous
stream of these operations could repeatedly add devices to rx_mode_list.

Because the loop releases rx_mode_lock while processing but retains the rtnl
lock, could it run indefinitely if the list is continually replenished?

Additionally, does the order of list_del_init() and netdev_lock_ops() create
a race condition with netif_rx_mode_sync()?

If the worker thread dequeues the device and drops the spinlock, it might
then block waiting for netdev_lock_ops(). Meanwhile, an ioctl thread
holding netdev_lock_ops() might call netif_rx_mode_sync().

The ioctl thread would call netif_rx_mode_clean(), which checks
list_empty(). Since the worker already removed the device from the list,
clean returns false. This causes netif_rx_mode_sync() to act as a no-op,
allowing the ioctl to return to userspace before the hardware update
actually completes.

> --- a/net/core/dev_api.c
> +++ b/net/core/dev_api.c
[ ... ]
> @@ -311,6 +313,7 @@ int dev_set_allmulti(struct net_device *dev, int inc)
>  
>  	netdev_lock_ops(dev);
>  	ret = netif_set_allmulti(dev, inc, true);
> +	netif_rx_mode_sync(dev);
>  	netdev_unlock_ops(dev);
>  
>  	return ret;

Does this correctly handle cascaded updates for stacked devices?

When operating on a stacked device like a VLAN, the RX mode update cascades
to the underlying physical device, queuing the physical device to the
rx_mode_list via __dev_set_rx_mode().

Since netif_rx_mode_sync() is only called on the stacked device here, and
the stacked device itself is not on the rx_mode_list, will the physical
device's update be left on the workqueue? This seems to bypass the
synchronous update guarantee.