Re: [PATCH net-next v6 5/7] net: add dev_addr_set_sync() for driver address updates

From: netdev-bot+sashiko

Date: Sat Dec 05 2026 - 11:28:26 EST


Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The concern: dev_addr_set_sync() is exported with
EXPORT_SYMBOL_GPL from net/core/dev_api.c and declared in…
- [Low] The concern: dev_addr_set_sync() requires RTNL held and the
device instance lock not held.
- [Low] The concern: dev_addr_set_sync() changes dev->dev_addr and the
dev->dev_addrs rbtree under RTNL and dev_addr_sem only, and it forbids…

--

net: add dev_addr_set_sync() for driver address updates

This adds an exported helper, dev_addr_set_sync(), for drivers that
publish a new primary device address while holding RTNL. It takes
dev_addr_sem for writing around dev_addr_set(), so the update is
serialized with the sysfs and SIOCGIFHWADDR readers. It also asserts
that the caller holds neither dev_addr_sem nor the device instance lock.

> diff --git a/net/core/dev_api.c b/net/core/dev_api.c
> index 437947dd08ed5..081e9cb063b69 100644
> --- a/net/core/dev_api.c
> +++ b/net/core/dev_api.c
> @@ -85,6 +85,27 @@ void dev_set_group(struct net_device *dev, int new_group)
> netdev_unlock_ops(dev);
> }
>
> +/**
> + * dev_addr_set_sync() - publish a driver-selected device address
> + * @dev: device whose address is being updated
> + * @addr: new address, with dev->addr_len bytes
> + *
> + * Serialize the update with sysfs and SIOCGIFHWADDR readers.
> + * The caller holds RTNL and must hold neither dev_addr_sem nor the
> + * device instance lock.
> + */
> +void dev_addr_set_sync(struct net_device *dev, const u8 *addr)

[Severity: Low]
This isn't a bug, but is the dev_ prefix a good fit for this helper?

Documentation/networking/netdevices.rst describes the dev_xxx/netdev_xxx
functions as the ones that take the instance lock themselves. The peer
writer dev_set_mac_address_user() does take it:

down_write(&dev_addr_sem);
netdev_lock_ops(dev);
ret = netif_set_mac_address(dev, ss, extack);

dev_addr_set_sync() instead requires that the instance lock is not held.

That said, the instance lock does not seem to cover dev->dev_addr or
dev->dev_addrs. Neither field appears in the @lock kernel-doc of struct
net_device, and dev_addr_add() already changes the same dev_addrs tree
with only RTNL held. The existing dev_addr_* helpers don't follow the
dev_xxx naming rule either. So this looks like a naming question, not
a race.

> +{
> + ASSERT_RTNL();
> + lockdep_assert_not_held(&dev_addr_sem);
> + lockdep_assert_not_held(&dev->lock);

[Severity: Low]
With this contract, can ops-locked drivers use the helper from deferred
work at all? Documentation/networking/netdevices.rst says:

ndo_work:
Synchronization: netdev instance lock for "ops locked" drivers,
rtnl_lock() semaphore for all other drivers.

An ops-locked driver running from netdev_work_proc() would hold dev->lock
and not RTNL. It would fail both ASSERT_RTNL() and the dev->lock
assertion here.

A caller that ignored the contract and held dev->lock would take
dev->lock before dev_addr_sem. That is the reverse of the order used in
dev_set_mac_address_user() and do_setlink():

/* dev_addr_sem is an outer lock, enforce proper ordering */
down_write(&dev_addr_sem);
netdev_lock_ops(dev);

Lockdep would catch this through the assertions above.

The only user in the series is enic, which isn't ops-locked. In
enic_vf_admin_mac_work() it takes RTNL with rtnl_trylock() and doesn't
hold dev->lock, so it meets the contract.

Is it intended that only non-ops-locked callers can use the helper? If
so, could the kernel-doc say so?

> +
> + down_write(&dev_addr_sem);
> + dev_addr_set(dev, addr);
> + up_write(&dev_addr_sem);
> +}
> +EXPORT_SYMBOL_GPL(dev_addr_set_sync);

[Severity: Low]
Nothing calls dev_addr_set_sync() at this commit. Could the commit
message name the intended user?

The later patch "enic: manage V2 VF station and administrative MAC"
calls it from enic_vf_admin_mac_work() and enic_vf_admin_mac_refresh().
So the export is used by the end of the series.

The commit message describes the problem in general terms:

Drivers that publish a new address in
response to firmware can bypass the write-side lock taken by the
userspace MAC setter.

Other drivers with the same pattern still update the address without
dev_addr_sem. Examples are bnxt_update_vf_mac() in bnxt_sriov.c and
drivers/net/vmxnet3/vmxnet3_drv.c. That bypass predates this patch, and
the patch doesn't claim to convert those drivers.

--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204-b4-enic-sriov-v2-vf-receive-control-v6-0-ca38950bbe07%40cisco.com