Re: [PATCH net-next v6 6/7] enic: manage V2 VF station and administrative MAC

From: netdev-bot+sashiko

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


Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 3 · Low: 2

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] In enic_vf_admin_mac_work()
(drivers/net/ethernet/cisco/enic/enic_main.c), the nonzero-policy case…
- [Medium] enic: enic_vf_station_recovery_required() blocks VF_UNREGISTER
on remove
- [Medium] enic: enic_vf_admin_mac_work() disables mailbox sends on
detached netdev
- [Low] enic: lockless READ_ONCE() on admin MAC flags races with plain
writes
- [Low] enic: missing 2-byte alignment on struct enic MAC address arrays

--

enic: manage V2 VF station and administrative MAC

The patch makes the V2 VF station address use the mailbox MAC operation,
and keeps it apart from netdev secondary-unicast sync. A replacement is
sent as one compound DEL+ADD request. The patch also adds a worker that
applies PF administrative MAC notifications, refreshes the policy after
registration, and manages the station address across open, stop, reset
and remove.

> diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c b/drivers/net/ethernet/cisco/enic/enic_main.c
> index 587c340854cb2..0ee2ea5b24682 100644
> --- a/drivers/net/ethernet/cisco/enic/enic_main.c
> +++ b/drivers/net/ethernet/cisco/enic/enic_main.c

[ ... ]

> +static void enic_vf_admin_mac_work(struct work_struct *work)
> +{

[ ... ]

> + /* A nonzero notification describes a station address the PF has already
> + * installed. Zero delegates selection to the VF, which registers the
> + * selected random address through the policy-safe replacement request.
> + */
> + if (!READ_ONCE(enic->datapath_open)) {
> + station_installed = !zero_policy &&
> + (!enic->vf_station_addr_valid ||
> + ether_addr_equal(enic->vf_station_addr, selected));
> + } else if (zero_policy) {
> + mutated = true;
> + err = enic_vf_station_addr_replace(enic, selected, NULL);
> + station_installed = !err;
> + } else if (enic->vf_station_addr_valid &&
> + !ether_addr_equal(enic->vf_station_addr, selected)) {
> + mutated = true;
> + err = enic_vf_station_addr_del(enic);
> + station_installed = !err;

[Severity: Medium]
What makes sure the new administrative MAC is actually installed at the PF
as a station filter when this branch runs?

The datapath is open and the policy is nonzero and differs from
vf_station_addr. In that case enic_vf_admin_mac_work() only sends a
mailbox DELETE for the old station through enic_vf_station_addr_del().
No ADD is sent for selected. When the DELETE succeeds, station_installed
is set to true and the code later does:

if (station_installed)
enic_vf_station_addr_set(enic, selected);
enic_vf_station_sync_reset(enic);

The only basis for treating selected as installed is the comment above
the branch. No in-tree PF sends ENIC_MBOX_PF_SET_ADMIN_MAC_NOTIF. The PF
admin MAC path, enic_set_vf_mac(), only issues a proxied
vnic_dev_set_mac_addr() (CMD_SET_MAC_ADDR) and adds no address filter.
Neither enic_mbox.h nor the commit message states this contract, and the
commit message says the PF side comes in a later series.

Suppose the PF sends the notification before it installs the address, or
never installs it as a STATION entry. Would the VF then delete its only
confirmed station filter and end up with dev_addr == selected and
vf_station_addr_valid == true, but no exact filter for its own MAC?

enic_vf_station_sync_reset() also drops the core unicast sync reference
for that address. So rx-mode sync would not install the filter either,
and unicast receive to the primary MAC could stay broken until the next
stop/open or re-registration.

The zero-policy branch and enic_vf_station_addr_open() both use
enic_vf_station_addr_replace(), whose final equal-address DEL+ADD is
confirmed by the PF reply. Could the nonzero-policy branch use the same
replacement request instead of assuming the PF has already installed the
address?

> + } else {
> + station_installed = true;
> + }
> + if (err)
> + goto unlock;

[Severity: Medium]
If the PF rejects this station DELETE, the new call to
enic_vf_station_recovery_required() goes through
enic_mbox_vf_require_reconnect() to
enic_mbox_vf_mark_reconnect_locked(), which sets mbox_send_disabled.
vf_registered stays true. mbox_tx_poisoned is false because the admin
WQ itself is fine. A partial or contradictory reply in
enic_vf_station_addr_replace() leaves the same state behind.

What clears mbox_send_disabled again after that? The intended cleanup
is the fresh registration done by vf_mbox_recovery_work. However,
enic_mbox_vf_kick_recovery() only schedules that work while
netif_running() is true, and that fails on each of these paths:

__dev_close_many() clears __LINK_STATE_START before it calls ndo_stop.
A rejected DELETE from __enic_stop() therefore schedules nothing.

On a failed enic_open(), the core clears __LINK_STATE_START before it
drops RTNL. A queued recovery worker then sees the interface down in
enic_hang_reset() and returns.

After a runtime MAC change takes the replace path, enic_remove()
cancels any pending recovery worker with disable_work_sync().

If the device is removed afterwards, enic_remove() still sees
vf_registered and calls enic_mbox_vf_unregister(). But
enic_mbox_send_msg_id() finds mbox_send_disabled set and fails
locally with -ENODEV, so VF_UNREGISTER never reaches the PF.

The commit message and the new comment in enic_remove() make
VF_UNREGISTER the cleanup boundary that removes the VF-requested
station address. In this sequence the PF keeps the VF registered after
the driver is gone. It also keeps the station filter that the recovery
request was meant to clean up.

Should enic_remove() still be able to send VF_UNREGISTER when the
channel is healthy and only a reconnect was requested? Or should a
stopped device get re-registered some other way?

[ ... ]

> + changed = !ether_addr_equal(enic->netdev->dev_addr, selected);
> + enic_vf_station_sync_reset(enic);
> + if (changed)
> + dev_addr_set_sync(enic->netdev, selected);
> + if (changed || (!zero_policy &&
> + enic->netdev->addr_assign_type == NET_ADDR_RANDOM))
> + enic->netdev->addr_assign_type = zero_policy ?
> + NET_ADDR_RANDOM : NET_ADDR_SET;
> + ether_addr_copy(enic->mac_addr, selected);
> + if (station_installed)
> + enic_vf_station_addr_set(enic, selected);
> + enic_vf_station_sync_reset(enic);

[ ... ]

> @@ -1064,6 +1067,512 @@ static int enic_set_mac_addr(struct net_device *netdev, char *addr)
> return 0;
> }
>
> +static void enic_vf_station_recovery_required(struct enic *enic)
> +{
> + enic_mbox_vf_require_reconnect(enic);
> +}
> +
> +static void enic_vf_station_addr_set(struct enic *enic, const u8 *addr)
> +{
> + ether_addr_copy(enic->vf_station_addr, addr);
> + enic->vf_station_addr_valid = true;
> +}
> +
> +static int enic_vf_keep_nonstation_sync(struct net_device *netdev,
> + const u8 *addr)
> +{
> + struct enic *enic = netdev_priv(netdev);
> +
> + if (!ether_addr_equal(addr, enic->vf_station_addr))
> + return -ENOENT;
> + if (WARN_ON_ONCE(!enic->uc_count))
> + return 0;
> + enic->uc_count--;
> +
> + return 0;
> +}
> +
> +static void enic_vf_station_sync_reset(struct enic *enic)
> +{
> + if (!enic->vf_station_addr_valid)
> + return;
> +
> + /* The PF keys its MAC ledger by address. A station entry is also the
> + * receive filter for that address and must not retain a second core
> + * synchronization reference which could later delete the station.
> + */
> + netif_addr_lock_bh(enic->netdev);
> + __dev_uc_unsync(enic->netdev, enic_vf_keep_nonstation_sync);
> + netif_addr_unlock_bh(enic->netdev);
> +}
> +
> +static int enic_vf_station_addr_del(struct enic *enic)
> +{
> + int err;
> +
> + if (!enic->vf_station_addr_valid)
> + return 0;
> +
> + err = enic_mbox_vf_add_del_mac(enic, enic->vf_station_addr,
> + false, true);
> + if (!err) {
> + enic->vf_station_addr_valid = false;
> + } else if (READ_ONCE(enic->mbox_tx_poisoned)) {
> + enic_mbox_vf_link_state_set_running(enic, false);
> + } else if (err == -EACCES) {
> + /* A definitive rejected DELETE leaves an unrequested station
> + * filter installed. Fresh registration is the cleanup boundary.
> + */
> + enic_vf_station_recovery_required(enic);
> + }
> +
> + return err;
> +}
> +
> +/* End every replacement with an equal-address DEL+ADD pair. A bare ADD could
> + * report DUPLICATE for a secondary exact filter without applying the current
> + * station-address policy. If another station is tracked, delete it first in
> + * the same compound request.
> + */
> +static int enic_vf_station_addr_replace(struct enic *enic, const u8 *addr,
> + bool *policy_rejected)
> +{
> + struct enic_mac_addr macs[3] = {};
> + bool all_deletes_skipped = true;
> + bool deletes_converged = true;
> + u16 num_macs = 0;
> + unsigned int i;
> + u16 result;
> + int err;
> +
> + if (policy_rejected)
> + *policy_rejected = false;
> +
> + if (enic->vf_station_addr_valid &&
> + !ether_addr_equal(enic->vf_station_addr, addr)) {
> + ether_addr_copy(macs[num_macs].addr, enic->vf_station_addr);
> + macs[num_macs++].flags =
> + cpu_to_le16(ENIC_MAC_ADDR_FLAG_STATION);
> + }
> + ether_addr_copy(macs[num_macs].addr, addr);
> + macs[num_macs++].flags = cpu_to_le16(ENIC_MAC_ADDR_FLAG_STATION);
> + ether_addr_copy(macs[num_macs].addr, addr);
> + macs[num_macs++].flags = cpu_to_le16(ENIC_MAC_ADDR_FLAG_ADD |
> + ENIC_MAC_ADDR_FLAG_STATION);
> +
> + err = enic_mbox_vf_add_del_macs(enic, macs, num_macs);
> + if (err) {
> + if (READ_ONCE(enic->mbox_tx_poisoned))
> + enic_mbox_vf_link_state_set_running(enic, false);
> + return err;
> + }
> +
> + for (i = 0; i < num_macs - 1; i++) {
> + result = le16_to_cpu(macs[i].flags) &
> + ENIC_MAC_ADDR_FLAG_REPLY_MASK;
> + if (result != ENIC_MAC_ADDR_FLAG_SKIPPED)
> + all_deletes_skipped = false;
> + if (result && result != ENIC_MAC_ADDR_FLAG_NOT_FOUND)
> + deletes_converged = false;
> + }
> + result = le16_to_cpu(macs[num_macs - 1].flags) &
> + ENIC_MAC_ADDR_FLAG_REPLY_MASK;
> + if (deletes_converged && !result)
> + return 0;
> +
> + /* A policy-rejected ADD can be reported with all preceding DELETEs
> + * skipped. No operation changed state in that coherent result tuple.
> + */
> + if (all_deletes_skipped && result) {
> + if (policy_rejected)
> + *policy_rejected =
> + result == ENIC_MAC_ADDR_FLAG_NOT_PERMITTED;
> + if (result & (ENIC_MAC_ADDR_FLAG_DUPLICATE |
> + ENIC_MAC_ADDR_FLAG_PERMANENT_MASK))
> + return -EACCES;
> + return -EIO;
> + }
> +
> + /* After any other partial or contradictory result, the VF does not know
> + * which station address the PF kept. Re-register before accepting traffic.
> + */
> + enic_vf_station_recovery_required(enic);
> + for (i = 0; i < num_macs; i++)
> + if (le16_to_cpu(macs[i].flags) &
> + ENIC_MAC_ADDR_FLAG_PERMANENT_MASK)
> + return -EACCES;
> +
> + return -EIO;
> +}
> +
> +static void enic_vf_admin_mac_cache_selected(struct enic *enic,
> + const u8 *addr)
> +{
> + /* A zero administrative policy delegates the operational address to
> + * the VF. Preserve a successful user selection across reconnects.
> + */
> + spin_lock_bh(&enic->vf_admin_mac_lock);
> + if (is_zero_ether_addr(enic->vf_admin_mac)) {
> + ether_addr_copy(enic->vf_admin_mac_random_addr, addr);
> + enic->vf_admin_mac_random_valid = true;
> + }
> + spin_unlock_bh(&enic->vf_admin_mac_lock);
> +}
> +
> +static void enic_vf_admin_mac_work(struct work_struct *work)
> +{
> + struct enic *enic = container_of(to_delayed_work(work), struct enic,
> + vf_admin_mac_work);
> + u8 policy[ETH_ALEN] __aligned(2);
> + u8 selected[ETH_ALEN] __aligned(2);
> + unsigned long delay = 0;
> + u32 generation = 0;
> + bool changed;
> + bool mutated = false;
> + bool reschedule = false;
> + bool station_installed = false;
> + bool stale = false;
> + bool zero_policy;
> + bool pending;
> + int err = 0;
> +
> + spin_lock_bh(&enic->vf_admin_mac_lock);
> + pending = enic->vf_admin_mac_pending &&
> + enic->vf_admin_mac_work_enabled;
> + spin_unlock_bh(&enic->vf_admin_mac_lock);
> + if (!pending)
> + return;
> +
> + /* Teardown owns RTNL while synchronously cancelling this work. Do not
> + * block that owner.
> + */
> + if (!rtnl_trylock()) {
> + spin_lock_bh(&enic->vf_admin_mac_lock);
> + if (enic->vf_admin_mac_pending &&
> + enic->vf_admin_mac_work_enabled)
> + mod_delayed_work(system_percpu_wq,
> + &enic->vf_admin_mac_work,
> + msecs_to_jiffies(10));
> + spin_unlock_bh(&enic->vf_admin_mac_lock);
> + return;
> + }
> +
> + spin_lock_bh(&enic->vf_admin_mac_lock);
> + pending = enic->vf_admin_mac_pending &&
> + enic->vf_admin_mac_work_enabled;
> + if (pending) {
> + ether_addr_copy(policy, enic->vf_admin_mac);

[Severity: Low]
vf_station_addr and the on-stack MAC buffers get __aligned(2). The
reason is that ether_addr_copy(), ether_addr_equal() and
is_zero_ether_addr() use 16-bit accesses when
CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS is not set.

vf_admin_mac and vf_admin_mac_random_addr are passed to the same
helpers but carry no alignment annotation. The callers are
enic_vf_admin_mac_work(), enic_vf_admin_mac_notify(),
enic_vf_admin_mac_refresh() and enic_set_mac_address_dynamic().

Both arrays directly follow vf_admin_mac_lock. On configurations where
spinlock_t is one byte, they land at odd offsets in struct enic. One
example is sparc32 SMP without lock debugging, where arch_spinlock_t
is a single volatile unsigned char. The helpers would then take
alignment traps.

The existing mac_addr after devcmd_lock has the same layout problem.
This patch now writes it with ether_addr_copy() in
enic_vf_admin_mac_work() and enic_vf_admin_mac_refresh().

ENIC only depends on PCI, so it builds on such configurations, even if
real VIC adapters are unlikely to appear there. Could these arrays get
__aligned(2) as well, to match vf_station_addr?

> + generation = enic->vf_admin_mac_generation;
> + zero_policy = is_zero_ether_addr(policy);
> + if (zero_policy && enic->vf_admin_mac_random_valid)
> + ether_addr_copy(selected,
> + enic->vf_admin_mac_random_addr);
> + }
> + spin_unlock_bh(&enic->vf_admin_mac_lock);
> + if (!pending)
> + goto unlock;
> +
> + if (zero_policy && !READ_ONCE(enic->vf_admin_mac_random_valid)) {
> + eth_random_addr(selected);
> + spin_lock_bh(&enic->vf_admin_mac_lock);
> + if (!enic->vf_admin_mac_pending ||
> + !enic->vf_admin_mac_work_enabled ||
> + enic->vf_admin_mac_generation != generation ||
> + !is_zero_ether_addr(enic->vf_admin_mac)) {
> + stale = true;
> + } else if (enic->vf_admin_mac_random_valid) {
> + ether_addr_copy(selected,
> + enic->vf_admin_mac_random_addr);
> + } else {
> + ether_addr_copy(enic->vf_admin_mac_random_addr, selected);
> + enic->vf_admin_mac_random_valid = true;
> + }
> + spin_unlock_bh(&enic->vf_admin_mac_lock);
> + if (stale)
> + goto unlock;
> + } else if (!zero_policy) {
> + ether_addr_copy(selected, policy);
> + }
> +
> + if (!netif_device_present(enic->netdev) ||

[Severity: Medium]
Is a detached netdev really a retryable condition here? This driver
never calls netif_device_attach() after enic_remove() or
enic_detach_after_recovery_failure() has detached the device. Yet this
check reports it as -EAGAIN.

The retry logic after the unlock label treats that like any other
failure. It reschedules up to ENIC_VF_ADMIN_MAC_MAX_RETRIES times, then
calls enic_vf_station_recovery_required(). That sets
mbox_send_disabled through enic_mbox_vf_mark_reconnect_locked() while
vf_registered stays true. Recovery cannot do anything for a detached
device.

I see two ways to get here.

First, enic_detach_after_recovery_failure() from enic_open() or
__enic_stop() leaves the device detached. The admin channel stays
live, vf_registered stays true and vf_admin_mac_work_enabled is still
true. Any later PF admin MAC notification then walks through the
retries and disables mailbox sends.

Second, enic_remove() drops RTNL after netif_device_detach() and only
later calls enic_vf_admin_mac_quiesce(). A worker that has already
used up its retries can run in that window and reach the recovery
call.

In both cases the later enic_mbox_vf_unregister() in enic_remove()
fails with -ENODEV inside enic_mbox_send_msg_id(). The PF never gets
VF_UNREGISTER and keeps the VF registration and station filter after
removal.

Should a non-present device just leave the update pending, without
counting it as a retry or triggering recovery? And could enic_remove()
quiesce the admin MAC worker before it releases RTNL after detaching?
The worker only uses rtnl_trylock(), so that should not deadlock.

> + !READ_ONCE(enic->vf_registered)) {
> + err = -EAGAIN;
> + goto unlock;
> + }
> +
> + /* A nonzero notification describes a station address the PF has already
> + * installed. Zero delegates selection to the VF, which registers the
> + * selected random address through the policy-safe replacement request.
> + */
> + if (!READ_ONCE(enic->datapath_open)) {
> + station_installed = !zero_policy &&
> + (!enic->vf_station_addr_valid ||
> + ether_addr_equal(enic->vf_station_addr, selected));
> + } else if (zero_policy) {
> + mutated = true;
> + err = enic_vf_station_addr_replace(enic, selected, NULL);
> + station_installed = !err;
> + } else if (enic->vf_station_addr_valid &&
> + !ether_addr_equal(enic->vf_station_addr, selected)) {
> + mutated = true;
> + err = enic_vf_station_addr_del(enic);
> + station_installed = !err;
> + } else {
> + station_installed = true;
> + }
> + if (err)
> + goto unlock;
> +
> + spin_lock_bh(&enic->vf_admin_mac_lock);
> + if (!enic->vf_admin_mac_pending ||
> + !enic->vf_admin_mac_work_enabled ||
> + enic->vf_admin_mac_generation != generation) {
> + stale = true;
> + /* If policy changed while the request was running, the completed
> + * station change may no longer match it. Record recovery while holding
> + * vf_admin_mac_lock, which also protects VF worker shutdown. Teardown
> + * therefore either suppresses the update or sees it first, and already
> + * uses unregister/register to clear old state.
> + */
> + if (mutated && enic->vf_admin_mac_work_enabled)
> + enic_vf_station_recovery_required(enic);
> + } else {
> + enic->vf_admin_mac_pending = false;
> + enic->vf_admin_mac_retries = 0;
> + enic->vf_admin_mac_recovery_attempted = false;
> + if (!zero_policy)
> + enic->vf_admin_mac_random_valid = false;
> + }
> + spin_unlock_bh(&enic->vf_admin_mac_lock);
> + if (stale)
> + goto unlock;
> +
> + changed = !ether_addr_equal(enic->netdev->dev_addr, selected);
> + enic_vf_station_sync_reset(enic);
> + if (changed)
> + dev_addr_set_sync(enic->netdev, selected);
> + if (changed || (!zero_policy &&
> + enic->netdev->addr_assign_type == NET_ADDR_RANDOM))
> + enic->netdev->addr_assign_type = zero_policy ?
> + NET_ADDR_RANDOM : NET_ADDR_SET;
> + ether_addr_copy(enic->mac_addr, selected);
> + if (station_installed)
> + enic_vf_station_addr_set(enic, selected);
> + enic_vf_station_sync_reset(enic);
> + if (enic->netdev->reg_state == NETREG_REGISTERED) {
> + if (changed)
> + call_netdevice_notifiers(NETDEV_CHANGEADDR,
> + enic->netdev);
> + netif_rx_mode_schedule_update(enic->netdev);
> + }
> + netdev_info(enic->netdev, "MBOX: admin MAC set to %pM\n", selected);
> +
> +unlock:
> + rtnl_unlock();
> +
> + spin_lock_bh(&enic->vf_admin_mac_lock);
> + if (err && enic->vf_admin_mac_pending &&
> + enic->vf_admin_mac_work_enabled &&
> + generation == enic->vf_admin_mac_generation &&
> + !READ_ONCE(enic->mbox_send_disabled)) {
> + if (enic->vf_admin_mac_retries <
> + ENIC_VF_ADMIN_MAC_MAX_RETRIES) {
> + enic->vf_admin_mac_retries++;
> + reschedule = true;
> + delay = msecs_to_jiffies(ENIC_VF_ADMIN_MAC_RETRY_MS);
> + } else if (!enic->vf_admin_mac_recovery_attempted) {
> + enic->vf_admin_mac_recovery_attempted = true;
> + /* vf_admin_mac_lock also protects VF worker shutdown. */
> + enic_vf_station_recovery_required(enic);
> + }
> + }
> + if (enic->vf_admin_mac_pending &&
> + enic->vf_admin_mac_work_enabled &&
> + generation != enic->vf_admin_mac_generation) {
> + reschedule = true;
> + delay = 0;
> + }
> + if (enic->vf_admin_mac_pending && reschedule)
> + mod_delayed_work(system_percpu_wq,
> + &enic->vf_admin_mac_work, delay);
> + spin_unlock_bh(&enic->vf_admin_mac_lock);
> +}
> +
> +void enic_vf_admin_mac_notify(struct enic *enic, const u8 *addr)
> +{
> + bool new_policy;
> +
> + spin_lock_bh(&enic->vf_admin_mac_lock);
> + new_policy = !enic->vf_admin_mac_pending ||
> + !ether_addr_equal(enic->vf_admin_mac, addr);
> + if (new_policy) {
> + ether_addr_copy(enic->vf_admin_mac, addr);
> + if (!is_zero_ether_addr(addr))
> + enic->vf_admin_mac_random_valid = false;
> + enic->vf_admin_mac_pending = true;
> + enic->vf_admin_mac_generation++;
> + enic->vf_admin_mac_retries = 0;
> + enic->vf_admin_mac_recovery_attempted = false;
> + }
> + if (new_policy && enic->vf_admin_mac_work_enabled)
> + mod_delayed_work(system_percpu_wq,
> + &enic->vf_admin_mac_work, 0);
> + spin_unlock_bh(&enic->vf_admin_mac_lock);
> +}
> +
> +void enic_vf_admin_mac_quiesce(struct enic *enic)
> +{
> + spin_lock_bh(&enic->vf_admin_mac_lock);
> + enic->vf_admin_mac_work_enabled = false;
> + enic->vf_admin_mac_generation++;
> + spin_unlock_bh(&enic->vf_admin_mac_lock);
> + cancel_delayed_work_sync(&enic->vf_admin_mac_work);
> +}
> +
> +void enic_vf_admin_mac_rearm(struct enic *enic)
> +{
> + spin_lock_bh(&enic->vf_admin_mac_lock);
> + enic->vf_admin_mac_work_enabled = true;
> + if (enic->vf_admin_mac_pending)
> + mod_delayed_work(system_percpu_wq,
> + &enic->vf_admin_mac_work, 0);
> + spin_unlock_bh(&enic->vf_admin_mac_lock);
> +}
> +
> +void enic_vf_admin_mac_purge(struct enic *enic)
> +{
> + enic_vf_admin_mac_quiesce(enic);
> + spin_lock_bh(&enic->vf_admin_mac_lock);
> + enic->vf_admin_mac_pending = false;
> + enic->vf_admin_mac_random_valid = false;
> + enic->vf_admin_mac_recovery_attempted = false;
> + enic->vf_admin_mac_retries = 0;
> + enic->vf_admin_mac_generation++;
> + spin_unlock_bh(&enic->vf_admin_mac_lock);
> +}
> +
> +/* CMD_GET_MAC_ADDR is the PF-owned policy store. Re-read it after REGISTER so
> + * a lost notification cannot leave the VF using stale administrative policy.
> + */
> +static int enic_vf_admin_mac_refresh(struct enic *enic)
> +{
> + u8 previous_policy[ETH_ALEN] __aligned(2);
> + u8 random_addr[ETH_ALEN] __aligned(2);
> + u8 selected[ETH_ALEN] __aligned(2);
> + u8 policy[ETH_ALEN] __aligned(2);
> + u32 generation;
> + bool apply_policy;
> + bool changed;
> + bool pending;
> + bool policy_changed;
> + bool zero_policy;
> + unsigned int attempt;
> + int err;
> +
> + for (attempt = 0; attempt < ENIC_VF_ADMIN_MAC_REFRESH_RETRIES;
> + attempt++) {
> + spin_lock_bh(&enic->vf_admin_mac_lock);
> + generation = enic->vf_admin_mac_generation;
> + pending = enic->vf_admin_mac_pending;
> + ether_addr_copy(previous_policy, enic->vf_admin_mac);
> + spin_unlock_bh(&enic->vf_admin_mac_lock);
> +
> + err = enic_dev_get_mac_addr(enic, policy);
> + if (err)
> + return err;
> + if (is_multicast_ether_addr(policy))
> + return -EADDRNOTAVAIL;
> +
> + zero_policy = is_zero_ether_addr(policy);
> + if (zero_policy)
> + eth_random_addr(random_addr);
> +
> + spin_lock_bh(&enic->vf_admin_mac_lock);
> + if (enic->vf_admin_mac_generation != generation) {
> + spin_unlock_bh(&enic->vf_admin_mac_lock);
> + continue;
> + }
> +
> + policy_changed = !ether_addr_equal(previous_policy, policy);
> + apply_policy = pending || policy_changed ||
> + !is_valid_ether_addr(enic->netdev->dev_addr) ||
> + (!zero_policy &&
> + !ether_addr_equal(enic->netdev->dev_addr, policy));
> + if (!apply_policy) {
> + ether_addr_copy(selected, enic->netdev->dev_addr);
> + if (zero_policy) {
> + ether_addr_copy(enic->vf_admin_mac_random_addr,
> + selected);
> + enic->vf_admin_mac_random_valid = true;
> + }
> + } else if (zero_policy && enic->vf_admin_mac_random_valid) {
> + ether_addr_copy(selected,
> + enic->vf_admin_mac_random_addr);
> + } else if (zero_policy) {
> + ether_addr_copy(selected, random_addr);
> + ether_addr_copy(enic->vf_admin_mac_random_addr, selected);
> + enic->vf_admin_mac_random_valid = true;
> + } else {
> + ether_addr_copy(selected, policy);
> + enic->vf_admin_mac_random_valid = false;
> + }
> + ether_addr_copy(enic->vf_admin_mac, policy);
> + enic->vf_admin_mac_pending = false;
> + enic->vf_admin_mac_recovery_attempted = false;
> + enic->vf_admin_mac_retries = 0;
> + enic->vf_admin_mac_generation++;
> + spin_unlock_bh(&enic->vf_admin_mac_lock);
> +
> + changed = !ether_addr_equal(enic->netdev->dev_addr, selected);
> + if (changed) {
> + if (enic->netdev->reg_state == NETREG_REGISTERED)
> + dev_addr_set_sync(enic->netdev, selected);
> + else
> + eth_hw_addr_set(enic->netdev, selected);
> + }
> + if (zero_policy && changed)
> + enic->netdev->addr_assign_type = NET_ADDR_RANDOM;
> + else if (!zero_policy &&
> + enic->netdev->reg_state == NETREG_REGISTERED &&
> + (changed ||
> + enic->netdev->addr_assign_type == NET_ADDR_RANDOM))
> + enic->netdev->addr_assign_type = NET_ADDR_SET;
> + ether_addr_copy(enic->mac_addr, selected);
> + if (changed && enic->netdev->reg_state == NETREG_REGISTERED)
> + call_netdevice_notifiers(NETDEV_CHANGEADDR,
> + enic->netdev);
> +
> + return 0;
> + }
> +
> + return -EAGAIN;
> +}
> +
> +static int enic_vf_station_addr_open(struct enic *enic)
> +{
> + struct net_device *netdev = enic->netdev;
> + u8 requested[ETH_ALEN] __aligned(2);
> + bool policy_rejected;
> + int err;
> +
> + ether_addr_copy(requested, netdev->dev_addr);
> + err = enic_vf_station_addr_replace(enic, requested, &policy_rejected);
> + if (!policy_rejected || !READ_ONCE(enic->vf_registered) ||
> + READ_ONCE(enic->mbox_send_disabled))
> + return err;
> +
> + /* PF policy can change after the last refresh, with its notification
> + * still in flight. A clean rejection permits one attempt at the new MAC.
> + */
> + err = enic_vf_admin_mac_refresh(enic);
> + if (err)
> + return err;
> + if (ether_addr_equal(requested, netdev->dev_addr))
> + return -EACCES;
> +
> + return enic_vf_station_addr_replace(enic, netdev->dev_addr, NULL);
> +}
> +
> static int enic_set_mac_address_dynamic(struct net_device *netdev, void *p)
> {
> struct enic *enic = netdev_priv(netdev);

[Severity: Low]
enic_vf_admin_mac_notify() runs from admin_msg_work without RTNL. It
updates vf_admin_mac_pending and vf_admin_mac_random_valid with plain
stores under vf_admin_mac_lock. The other writers of these flags are
also plain stores under the same lock: enic_vf_admin_mac_refresh(),
enic_vf_admin_mac_purge(), enic_vf_admin_mac_cache_selected() and the
worker itself.

Here the worker reads vf_admin_mac_random_valid with READ_ONCE() just
after dropping vf_admin_mac_lock. enic_open() likewise reads
vf_admin_mac_pending with READ_ONCE() without taking the lock. A
READ_ONCE() racing with an unmarked store is still a data race under
the memory model. KCSAN will report it whenever a PF notification
arrives during open or while the worker runs.

I don't see a functional failure. The worker revalidates under
vf_admin_mac_lock, and open falls back to the policy-rejected retry in
enic_vf_station_addr_open(). But the marking suggests a lockless
protocol that the writers do not follow.

The worker already holds vf_admin_mac_lock a few lines earlier, when
it copies policy and generation. Could it capture random_valid into a
local there? And could enic_open() take vf_admin_mac_lock for the
pending check? Otherwise the writers would need WRITE_ONCE() so the
lockless reads are properly paired.

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