Linux USB
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: mail@birger-koblitz.de
Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org,
	linux-usb@vger.kernel.org, benjamin.larsson@genexis.eu
Subject: Re: [PATCH net-next v4 2/2] net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A
Date: Sat, 05 Dec 2026 22:22:51 +0000	[thread overview]
Message-ID: <179650937129.3148.9298321111140221071@kernel.org> (raw)
In-Reply-To: <20261204-fcs-v4-2-32773b612c81@birger-koblitz.de>

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

Critical: 0 · High: 2 · Medium: 6 · Low: 5

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).

- [High] The patch adds `struct mutex rx_ctl_mutex` to `struct
  ax88179_data` (drivers/net/usb/ax88179_lib.h:295) and locks it in…
- [High] The patch adds mutex_lock(&data->rx_ctl_mutex) to
  ax88179_set_multicast() (drivers/net/usb/ax88179_lib.c:359-401).
- [Medium] The commit message only covers the RXFCS/RXALL features, FCS-
  aware length checks and new counters.
- [Medium] The preceding commit 'net: usb: ax88179: Make receiving FCS on
  AX88179A configurable', which carries a Fixes: tag, removed…
- [Medium] In ax88179a_rx_fixup(), the RXALL handling and the new error
  accounting are incomplete.
- [Medium] In ax88179_set_multicast() (drivers/net/usb/ax88179_lib.c),
  mutex_unlock(&data->rx_ctl_mutex) at line 401 comes before…
- [Medium] ax88179_set_multicast() clears AX_RX_CTL_DROPCRCERR and re-
  derives it from `net->features & (NETIF_F_RXFCS | NETIF_F_RXALL)`.
- [Medium] net: usb: ax88179: unlocked AX_RX_CTL updates in reset() and
  mac_link_up()
- [Low] The patch mainly adds new user-visible functionality:
  NETIF_F_RXFCS and NETIF_F_RXALL in hw_features for AX88179A…
- [Low] In ax88179a_set_features(), WRITE_ONCE(ax179_data->rxctl, rxctl)
  at ax88179a_devices.c:797 stores the new DROPCRCERR state before…
- [Low] Whether a frame carries an FCS is fixed by the
  AX_RX_CTL_DROPCRCERR setting at the moment the hardware receives it,…
- [Low] ax88179a_mac_link_up() writes AX_RX_CTL_STOP at
  ax88179a_devices.c:515 ('Stop RX/TX for link configuration') without…
- [Low] The new increments of dev->net->stats.rx_dropped, rx_crc_errors
  and rx_errors in ax88179a_rx_fixup() (ax88179a_devices.c:1089-1094)…

--

net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A

This patch advertises NETIF_F_RXFCS and NETIF_F_RXALL on the AX88179A. It
toggles AX_RX_CTL_DROPCRCERR so the MAC keeps the FCS, and it accounts for
the trailing FCS in the ax88179a_rx_fixup() length checks. It also counts
dropped and bad-FCS frames and adds a new rx_ctl_mutex around AX_RX_CTL
updates.

> Add NETIF_F_RXFCS and NETIF_F_RXALL features for
> the AX88179A and take a trailing FCS into account for MTU
> verification when checking packet length in rx_fixup().
>
> Count dropped packets and those with incorrect FCS.

[Severity: Medium]
Should the commit message also describe the locking changes? The patch also
does the following:

  - adds rx_ctl_mutex ("protect AX_RX_CTL") to struct ax88179_data
  - takes it in ax88179_set_multicast(), which ax88179_178a.c also uses
    for the older AX88179/AX88178A devices
  - makes the async AX_RX_CTL write use a stack copy (&rxctl) instead of
    &data->rxctl

The message doesn't say which race the mutex is meant to close. It also
doesn't say that the older driver is affected. The two locking problems
raised further down both come from this change.

> Fixes: 7d573278f9a5 ("ax88179_178a: Add HW support for AX179A-based chips")

[Severity: Low]
This isn't a bug, but is this Fixes: tag accurate? Most of the patch is new
functionality: NETIF_F_RXFCS/NETIF_F_RXALL in hw_features and new error
counters. With default features the AX88179A strips the FCS, so the old
length check in ax88179a_rx_fixup() was already correct.

The only real fix here is restoring AX_RX_CTL_DROPCRCERR for AX88279 in
ax88179a_reset(). That fixes the preceding commit in this series, not
7d573278f9a5.

Could this tag lead stable to backport the new feature toggles?

> diff --git a/drivers/net/usb/ax88179_lib.c b/drivers/net/usb/ax88179_lib.c
> index 273c5946e16a1..dc32660a23359 100644
> --- a/drivers/net/usb/ax88179_lib.c
> +++ b/drivers/net/usb/ax88179_lib.c
> @@ -356,6 +356,7 @@ void ax88179_set_multicast(struct net_device *net)
>  
>  	data = dev->driver_priv;
>  
> +	mutex_lock(&data->rx_ctl_mutex);

[Severity: High]
Can ax88179_set_multicast() sleep here? It is the .ndo_set_rx_mode callback
for both ax88179a_netdev_ops and the legacy ax88179_netdev_ops in
ax88179_178a.c. Neither sets ndo_set_rx_mode_async, so the core calls it in
atomic context:

include/linux/netdevice.h:
 * void (*ndo_set_rx_mode)(struct net_device *dev);
 ...
 *	Cannot sleep, called with netif_addr_lock_bh held.

net/core/dev_addr_lists.c:dev_set_rx_mode() {
	netif_addr_lock_bh(dev);
	__dev_set_rx_mode(dev);
	netif_addr_unlock_bh(dev);
}

mutex_lock() calls might_sleep(), so CONFIG_DEBUG_ATOMIC_SLEEP would warn
on every call.

Both ax88179a_mac_link_up() (phylink resolve worker) and
ax88179a_set_features() (ethtool -K) hold rx_ctl_mutex across synchronous
USB control transfers. If one of them holds it when the rx-mode callback
runs, mutex_lock() sleeps with a BH-disabling spinlock held. Would that end
in "scheduling while atomic"?

An unprivileged multicast join through dev_mc_add() is enough to reach this
path. That includes the older AX88179/AX88178A devices.

Would a spinlock, or a move to ndo_set_rx_mode_async, work better here?

>  	if (data->chip_version >= AX_VERSION_AX88179A) {
>  		rxctl = READ_ONCE(data->rxctl);
>  		rxctl &= ~(AX_RX_CTL_IPE | AX_RX_CTL_DROPCRCERR | AX_RX_CTL_PRO |
> @@ -397,8 +398,9 @@ void ax88179_set_multicast(struct net_device *net)
>  	}
>  
>  	WRITE_ONCE(data->rxctl, rxctl);
> +	mutex_unlock(&data->rx_ctl_mutex);
>  	ax88179_write_cmd_async(dev, AX_ACCESS_MAC, AX_RX_CTL,
> -				2, 2, &data->rxctl);
> +				2, 2, &rxctl);

[Severity: Medium]
The async write is submitted after mutex_unlock(). Does the mutex then
control the order in which values reach the hardware? Consider:

CPU0 (ax88179_set_multicast)
  computes X
  WRITE_ONCE(data->rxctl, X)
  mutex_unlock()

CPU1 (ax88179a_set_features)
  mutex_lock()
  Y = X | AX_RX_CTL_DROPCRCERR
  WRITE_ONCE(ax179_data->rxctl, Y)
  ax88179_write_u16(..., AX_RX_CTL, 2, Y)   /* synchronous */
  mutex_unlock()

CPU0
  ax88179_write_cmd_async(..., AX_RX_CTL, ..., &rxctl)  /* X */

The hardware then holds X while data->rxctl and dev->features say Y. If
DROPCRCERR differs, ax88179a_rx_fixup() gets the FCS handling wrong for
every frame until the next rx-mode change.

This callback has to stay atomic, so the write can't simply move inside the
mutex.

[ ... ]

> diff --git a/drivers/net/usb/ax88179_lib.h b/drivers/net/usb/ax88179_lib.h
> index 401c0bed3d28b..a9e688424c129 100644
> --- a/drivers/net/usb/ax88179_lib.h
> +++ b/drivers/net/usb/ax88179_lib.h
> @@ -292,6 +292,7 @@ enum ax_chip_version {
>  
>  struct ax88179_data {
>  	struct mutex medium_status_mutex;  /* protect AX_MEDIUM_STATUS_MODE */
> +	struct mutex rx_ctl_mutex;  /* protect AX_RX_CTL */

[Severity: High]
Where is rx_ctl_mutex initialized? Both bind routines allocate this struct
with kzalloc but only initialize medium_status_mutex:

drivers/net/usb/ax88179a_devices.c:ax88179a_bind() {
    ...
	dev->driver_priv = ax179_data;
	mutex_init(&ax179_data->medium_status_mutex);
    ...
}

ax88179_bind() in drivers/net/usb/ax88179_178a.c has the same single
mutex_init() call. Its ndo_set_rx_mode is ax88179_set_multicast(), so it
now locks this mutex too.

With CONFIG_DEBUG_MUTEXES, the lock->magic check fires on lock and unlock.
With lockdep, the uninitialized dep_map triggers a non-static key report and
lockdep turns itself off.

Should mutex_init(&ax179_data->rx_ctl_mutex) be added next to the
medium_status_mutex init in both ax88179a_bind() and ax88179_bind()?

>  	u8  eee_enabled;
>  	u8  eee_active;
>  	u16 rxctl;
> diff --git a/drivers/net/usb/ax88179a_devices.c b/drivers/net/usb/ax88179a_devices.c
> index 78a804203202f..9137f790ddaa6 100644
> --- a/drivers/net/usb/ax88179a_devices.c
> +++ b/drivers/net/usb/ax88179a_devices.c
> @@ -601,7 +601,9 @@ static void ax88179a_mac_link_up(struct phylink_config *config,
>  		mode |= AX_MEDIUM_JUMBO_EN;
>  	ax88179_write_u16(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 2, mode);
>  
> +	mutex_lock(&ax179_data->rx_ctl_mutex);
>  	ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, READ_ONCE(ax179_data->rxctl));
> +	mutex_unlock(&ax179_data->rx_ctl_mutex);

[Severity: Low]
Is it enough to cover only the restore write here? Earlier in the function,
RX is stopped without the mutex:

ax88179a_mac_link_up() {
	/* Stop RX/TX for link configuration */
	ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, AX_RX_CTL_STOP);
    ...
	ax88179a_bulkin_config(dev, link_sts, bulk_config_speed, !!duplex);
    ...
}

ax88179a_mac_link_up() runs from the phylink resolve worker without RTNL.
It can therefore run at the same time as ax88179a_set_features().

The new synchronous AX_RX_CTL write in ax88179a_set_features() writes the
cached rxctl, which has AX_RX_CTL_START set. If that write lands inside this
window, could it restart RX while the bulk-in/CDC parameters are only partly
programmed?

The async write in ax88179_set_multicast() could already land in this window
before this patch. This patch adds another writer.

>  	mutex_unlock(&ax179_data->medium_status_mutex);
>  
>  	ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_PATH, 1,

[ ... ]

> @@ -780,6 +784,24 @@ static int ax88179a_set_features(struct net_device *net, netdev_features_t featu
>  		if (ret < 0)
>  			return ret;
>  	}
> +
> +	if (changed & (NETIF_F_RXFCS | NETIF_F_RXALL)) {
> +		u16 rxctl;
> +
> +		mutex_lock(&ax179_data->rx_ctl_mutex);
> +		rxctl = READ_ONCE(ax179_data->rxctl);
> +		if (features & (NETIF_F_RXFCS | NETIF_F_RXALL))
> +			rxctl |= AX_RX_CTL_DROPCRCERR;
> +		else
> +			rxctl &= ~AX_RX_CTL_DROPCRCERR;
> +		WRITE_ONCE(ax179_data->rxctl, rxctl);
> +		ret = ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, rxctl);

[Severity: Low]
What happens to the cached rxctl if this USB write fails? WRITE_ONCE() has
already stored the new DROPCRCERR state. On the error return the core leaves
dev->features unchanged, but nothing rolls data->rxctl back.

On the next link flap, ax88179a_mac_link_up() writes
READ_ONCE(ax179_data->rxctl) to AX_RX_CTL unchanged. The MAC then keeps or
strips the FCS opposite to what dev->features says. This lasts until an
rx-mode change recomputes the bit.

[Severity: Medium]
Can an rx-mode update undo this change? ax88179_set_multicast() clears
AX_RX_CTL_DROPCRCERR and re-derives it from net->features:

	if (net->features & (NETIF_F_RXFCS | NETIF_F_RXALL) ||
	    data->chip_version != AX_VERSION_AX88179A)
		rxctl |= AX_RX_CTL_DROPCRCERR; /* Do not remove FCS from frame */

__netdev_update_features() only assigns dev->features after ndo_set_features
returns, and rx_ctl_mutex doesn't cover net->features.

An rx-mode update can run in that window, for example an IPv6 MLD join
calling dev_mc_add() under idev->mc_lock without RTNL. It reads the old
features and reverts DROPCRCERR. The core then commits the new features.
>From then on the hardware and ax88179a_rx_fixup() disagree on FCS presence
for every frame.

> +		mutex_unlock(&ax179_data->rx_ctl_mutex);
> +
> +		if (ret < 0)
> +			return ret;
> +	}
> +
>  	return 0;
>  }

[ ... ]

> @@ -1039,9 +1064,14 @@ static int ax88179a_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
>  	pkt_end = 0;
>  	while (pkt_cnt--) {
>  		u64 pkt_desc = get_unaligned_le64(pkt_desc_ptr);
> +		netdev_features_t features = dev->net->features;
>  		u32 pkt_len_plus_padd;
> +		u32 fcs_trailer = 0;
>  		u32 pkt_len;
>  
> +		if (features & (NETIF_F_RXFCS | NETIF_F_RXALL))
> +			fcs_trailer = ETH_FCS_LEN;

[Severity: Low]
Is the live dev->net->features a reliable indication of whether this frame
has an FCS? Whether the FCS is present depends on AX_RX_CTL_DROPCRCERR at
the time the hardware received the frame. The descriptor has no bit for it.

ax88179a_set_features() reprograms AX_RX_CTL before the core updates
dev->features, and it doesn't stop or flush RX. Several 48 KiB bulk-in URBs
can still hold frames in the old format.

During an rx-fcs/rx-all toggle, frames without an FCS could lose 4 bytes of
payload to the later pkt_len -= fcs_trailer. Frames with an FCS could have
it delivered as payload.

Would it make sense to reset or quiesce RX on these feature changes, as igb
does?

>  		pkt_len = FIELD_GET(AX179A_RX_PD_LEN, pkt_desc);
>  		pkt_len -= (ax179_data->ip_align ? 2 : 0);
>  		pkt_len_plus_padd = ((pkt_len + 7 + (ax179_data->ip_align ? 2 : 0)) & 0x7FFF8);
> @@ -1050,10 +1080,19 @@ static int ax88179a_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
>  		if (pkt_end > hdr_off || (pkt_cnt == 0 && pkt_end != hdr_off))
>  			goto err;
>  
> -		if (pkt_desc & AX179A_RX_PD_DROP || !(pkt_desc & AX179A_RX_PD_RX_OK) ||
> -		    pkt_len > (dev->hard_mtu + AX179A_RX_HW_PAD) || pkt_len < 2 + ETH_HLEN) {
> +		if (((pkt_desc & AX179A_RX_PD_DROP || !(pkt_desc & AX179A_RX_PD_RX_OK)) &&
> +		     !(features & NETIF_F_RXALL)) ||
> +		    pkt_len > dev->hard_mtu + AX179A_RX_HW_PAD + fcs_trailer ||
> +		    pkt_len < 2 + ETH_HLEN + fcs_trailer) {
>  			skb_pull(skb, pkt_len_plus_padd);
>  
> +			if (pkt_desc & AX179A_RX_PD_DROP)
> +				dev->net->stats.rx_dropped++;
> +
> +			if (!(pkt_desc & AX179A_RX_PD_RX_OK)) {
> +				dev->net->stats.rx_crc_errors++;
> +				dev->net->stats.rx_errors++;
> +			}

[Severity: Medium]
Are the error counters complete? They are only updated inside this drop
branch, which leaves two gaps:

  - With NETIF_F_RXALL enabled, a bad-FCS frame (RX_OK clear) with a valid
    length skips this branch. It goes to the stack without incrementing
    rx_crc_errors or rx_errors.
  - A frame dropped only by the pkt_len checks, with PD_DROP clear and
    RX_OK set, increments nothing.

Both seem to contradict "Count dropped packets and those with incorrect
FCS" in the commit message.

The only hardware change RXALL makes is setting AX_RX_CTL_DROPCRCERR, the
same bit RXFCS sets. The preceding commit says this bit doesn't affect
whether the adapter drops corrupt frames. Does RXALL then only skip the
software check of the descriptor error flags?

Frames let through under RXALL with PD_DROP set or RX_OK clear still go
through ax88179a_rx_checksum() and __vlan_hwaccel_put_tag() using
descriptor fields. Can those fields be trusted for errored frames?

[Severity: Low]
These dev->net->stats increments are plain non-atomic read-modify-writes,
and ax88179a_rx_fixup() runs from the usbnet BH work. usbnet's
rx_complete() also updates dev->net->stats.rx_errors from URB completion
context, which may run on another CPU. Can increments be lost here?

This follows existing usbnet practice. Would
dev_core_stats_rx_dropped_inc() or per-CPU stats be a better fit for the
new counters?

>  			/* Next RX Packet Descriptor */
>  			pkt_desc_ptr++;
>  			continue;

[ ... ]

> @@ -1221,6 +1263,9 @@ static int ax88179a_reset(struct usbnet *dev)
>  		rxctl |= AX_RX_CTL_IPE;
>  	if (dev->net->flags & IFF_PROMISC)
>  		rxctl |= AX_RX_CTL_PRO;
> +	if (dev->net->features & (NETIF_F_RXFCS | NETIF_F_RXALL) ||
> +	    ax179_data->chip_version == AX_VERSION_AX88279)
> +		rxctl |= AX_RX_CTL_DROPCRCERR;

[Severity: Medium]
Does ax88179a_reset() also need to take rx_ctl_mutex? It rebuilds
rxctl from dev->net->flags and dev->net->features, stores it with
WRITE_ONCE(ax179_data->rxctl, rxctl) and writes AX_RX_CTL, all without
the new lock.

ax88179a_resume() calls ax88179a_reset() before it takes rtnl_lock(),
and the netdev is already present again at that point. So
ax88179a_set_features() and ax88179_set_multicast() can run at the
same time as the reset:

CPU0 (ax88179a_set_features, ethtool -K rx-fcs on)
  mutex_lock(&ax179_data->rx_ctl_mutex)
  rxctl |= AX_RX_CTL_DROPCRCERR
  WRITE_ONCE(ax179_data->rxctl, rxctl)
  ax88179_write_u16(..., AX_RX_CTL, 2, rxctl)
  mutex_unlock(&ax179_data->rx_ctl_mutex)

CPU1 (ax88179a_resume -> ax88179a_reset)
  reads dev->net->features, still without NETIF_F_RXFCS
  rxctl = AX_RX_CTL_START | ...   /* no DROPCRCERR */
  WRITE_ONCE(ax179_data->rxctl, rxctl)
  ax88179_write_u16(..., AX_RX_CTL, 2, rxctl)

The core then commits NETIF_F_RXFCS to dev->features. Both the cached
rxctl and the hardware still strip the FCS. From then on
ax88179a_rx_fixup() assumes every frame carries an FCS that the MAC has
already removed. If the two writes land in the other order, an rx-mode
update is lost the same way.

The AX_RX_CTL_STOP write at the top of ax88179a_mac_link_up() has the
same gap. The lock is only taken for the final restore of the cached
value. A set_features or set_multicast write that lands between the
STOP and the restore can set AX_RX_CTL_START while the bulk-in, CDC
and medium registers are only partly programmed.

Should ax88179a_reset() hold rx_ctl_mutex while it builds and writes
rxctl? And should ax88179a_mac_link_up() hold it from the STOP write
through the restore? The second option makes the mutex cover a long run
of synchronous USB transfers, and the atomic rx-mode path can't wait on
that anyway. A different scheme may be needed there.

[Severity: Medium]
Should the AX88279 part of this go into the preceding commit, "net: usb:
ax88179: Make receiving FCS on AX88179A configurable"? That commit removed
AX_RX_CTL_DROPCRCERR from the base rxctl here for every AX179A-family chip,
including the AX88279. Its own message says "For AX88279-based adapters,
the flag must be set in order to receive complete frames".

With only that patch applied, a resume runs ax88179a_reset() and then
ax88179a_mac_link_up(). The latter writes the cached rxctl without
DROPCRCERR. Until an rx-mode change, the AX88279 can then receive incomplete
frames.

This patch quietly restores the bit. It also rewrites the ax88179a_bind()
comment that the previous patch made false. Its commit message mentions
neither change.

Since the previous patch carries a Fixes: tag, could stable pick it up
without this follow-up?

>  	WRITE_ONCE(ax179_data->rxctl, rxctl);
>  	ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, rxctl);

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204-fcs-v4-0-32773b612c81%40birger-koblitz.de

      parent reply	other threads:[~2026-12-05 22:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 21:21 [PATCH net-next v4 0/2] net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A Birger Koblitz
2026-12-04 21:21 ` [PATCH net-next v4 1/2] net: usb: ax88179: Make receiving FCS on AX88179A configurable Birger Koblitz
2026-12-05 21:22   ` sashiko-bot
2026-12-04 21:21 ` [PATCH net-next v4 2/2] net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A Birger Koblitz
2026-12-05 21:22   ` sashiko-bot
2026-12-05 22:22   ` netdev-bot+sashiko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179650937129.3148.9298321111140221071@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=benjamin.larsson@genexis.eu \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mail@birger-koblitz.de \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox