Linux USB
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Birger Koblitz" <mail@birger-koblitz.de>
Cc: linux-usb@vger.kernel.org
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 21:22:13 +0000	[thread overview]
Message-ID: <sashiko-outbox-251904@kernel.org> (raw)
In-Reply-To: <20261204-fcs-v4-2-32773b612c81@birger-koblitz.de>

Thank you for your contribution! Sashiko AI review found 11 potential
issues to consider:
- [High] net: usb: ax88179: missing mutex_init() for rx_ctl_mutex in
  bind paths
- [High] net: usb: ax88179: sleeping mutex_lock() in atomic
  ax88179_set_multicast()
- [Medium] net: usb: ax88179: out-of-order async AX_RX_CTL writes in
  set_multicast()
- [Medium] net: usb: ax88179: stale net->features read reverts
  AX_RX_CTL_DROPCRCERR
- [Medium] net: usb: ax88179: unlocked AX_RX_CTL updates in reset() and
  mac_link_up()
- [Medium] net: usb: ax88179: cached rxctl updated before USB write
  check succeeds
- [Medium] net: usb: ax88179: live RXFCS/RXALL toggle races with
  ax88179a_rx_fixup()
- [Medium] net: usb: ax88179: incomplete RX error/drop stats in
  ax88179a_rx_fixup()
- [Medium] net: usb: ax88179: ax88179a_rx_checksum() skips RX_OK/DROP
  check on RXALL
- [Low] net: usb: ax88179: ax88179a_set_features() writes
  AX_RX_CTL_START when down
- [Low] net: usb: ax88179: inappropriate Fixes trailer and incomplete
  changelog
--

commit 5e000501a479ed67d43879d36a716e17523931f9
Author: Birger Koblitz <mail@birger-koblitz.de>

> net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A
>
> 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.
>
> Fixes: 7d573278f9a5 ("ax88179_178a: Add HW support for AX179A-based chips")
> Suggested-by: Benjamin Larsson <benjamin.larsson@genexis.eu>
> Signed-off-by: Birger Koblitz <mail@birger-koblitz.de>

[Severity: Low]
Should this commit drop the Fixes: trailer?  It adds new user-visible
features (NETIF_F_RXFCS and NETIF_F_RXALL) and depends on commit
"net: usb: ax88179: Make receiving FCS on AX88179A configurable", so
carrying Fixes: queues a non-standalone feature commit for automated
-stable backporting.

Restoring AX_RX_CTL_DROPCRCERR for AX88279 in ax88179a_reset() fixes a
bisection regression from commit "net: usb: ax88179: Make receiving FCS
on AX88179A configurable" and belongs in that patch instead.  Also, the
commit message does not mention adding rx_ctl_mutex or the
ax88179a_reset() change.

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

[Severity: High]
Can ax88179_set_multicast() sleep here?  It is registered as
ndo_set_rx_mode, which the networking core invokes via dev_set_rx_mode()
under netif_addr_lock_bh() with a spinlock held and softirqs disabled.

Because ax88179a_set_features() and ax88179a_mac_link_up() hold
rx_ctl_mutex across blocking USB control transfers, acquiring it here
trips sleeping-in-atomic checks and can panic or self-deadlock on
contention.

[Severity: Medium]
Can clearing AX_RX_CTL_DROPCRCERR and recomputing it from net->features
here revert a concurrent feature update?

CPU0                                CPU1
__netdev_update_features()
  ax88179a_set_features()
    rxctl |= AX_RX_CTL_DROPCRCERR
    ax88179_write_u16(..., rxctl)
    mutex_unlock(&rx_ctl_mutex)
                                    __dev_mc_add() (no rtnl_lock)
                                      ax88179_set_multicast()
                                        reads stale net->features
                                        clears AX_RX_CTL_DROPCRCERR
                                        writes stale rxctl to hw
  dev->features = features          <-- hw and dev->features diverge

Once dev->features and hardware AX_RX_CTL_DROPCRCERR disagree,
ax88179a_rx_fixup() either truncates 4 payload bytes per frame or leaves
4 FCS bytes attached and drops full-MTU frames.  Preserving
AX_RX_CTL_DROPCRCERR in data->rxctl instead of recomputing it from
net->features avoids this race.

[ ... ]

> @@ -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]
Can this asynchronous AX_RX_CTL write land after a newer synchronous
write from ax88179a_set_features()?

CPU0                                CPU1
ax88179_set_multicast()
  WRITE_ONCE(data->rxctl, old)
  mutex_unlock(&rx_ctl_mutex)
                                    ax88179a_set_features()
                                      mutex_lock(&rx_ctl_mutex)
                                      WRITE_ONCE(data->rxctl, new)
                                      ax88179_write_u16(..., new)
                                      mutex_unlock(&rx_ctl_mutex)
  ax88179_write_cmd_async(..., old) <-- overwrites hw with stale rxctl

If the older async URB executes on EP0 after the synchronous write,
hardware AX_RX_CTL_DROPCRCERR disagrees with dev->net->features, causing
ax88179a_rx_fixup() to miscalculate FCS length on subsequent frames.

> 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 */
>  	u8  eee_enabled;
>  	u8  eee_active;
>  	u16 rxctl;

[Severity: High]
Is rx_ctl_mutex ever initialized?  Both ax88179a_bind() and
ax88179_bind() allocate ax88179_data with kzalloc_obj() and call
mutex_init() on medium_status_mutex, but neither calls
mutex_init(&ax179_data->rx_ctl_mutex).

Locking a zero-filled mutex on interface bring-up violates the mutex
API, tripping lockdep and mutex/spinlock debug checks and risking
corruption or lockup on CONFIG_PREEMPT_RT.

> 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

[ ... ]

> @@ -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);
> +		mutex_unlock(&ax179_data->rx_ctl_mutex);
> +
> +		if (ret < 0)
> +			return ret;
> +	}
> +
>  	return 0;
>  }

[Severity: Medium]
Should ax179_data->rxctl only be updated after ax88179_write_u16()
succeeds?  If the USB write fails, __netdev_update_features() keeps
dev->features at the old value while ax179_data->rxctl retains the new
AX_RX_CTL_DROPCRCERR bit, which the next ax88179a_mac_link_up() then
programs into hardware out of sync with dev->features.

[Severity: Low]
Does this write AX_RX_CTL_START back to hardware when the interface is
down?  ax88179a_stop() clears hardware AX_RX_CTL to 0 without clearing
AX_RX_CTL_START in ax179_data->rxctl, and ax88179a_set_features() does
not check netif_running(net) before writing AX_RX_CTL.

[ ... ]

> @@ -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++;
> +			}
>  			/* Next RX Packet Descriptor */
>  			pkt_desc_ptr++;
>  			continue;

[Severity: Medium]
Does placing the error counters inside the discard block break RX
accounting when NETIF_F_RXALL is enabled?  Valid-length frames with
!(pkt_desc & AX179A_RX_PD_RX_OK) bypass this block completely and stop
incrementing rx_crc_errors and rx_errors.

In addition, frames with AX179A_RX_PD_RX_OK set and AX179A_RX_PD_DROP
clear that fail the oversize or runt length checks are dropped without
incrementing rx_length_errors, rx_errors, or rx_dropped, and usbnet's
rx_process() does not count them because ax88179a_rx_fixup() returns 1.
It is also unclear whether !AX179A_RX_PD_RX_OK exclusively indicates CRC
errors rather than other receive errors.

[Severity: Medium]
Can L2-errored frames admitted under NETIF_F_RXALL be falsely marked
CHECKSUM_UNNECESSARY?  When NETIF_F_RXALL and NETIF_F_RXCSUM are both
enabled, frames with AX179A_RX_PD_DROP set or AX179A_RX_PD_RX_OK clear
now reach ax88179a_rx_checksum(), which only checks negative error bits
(AX179A_RX_PD_L3_ERR and AX179A_RX_PD_L4_ERR) without a positive
checksum-verified flag.

If the hardware skips L3/L4 checksum validation on failed L2 frames, the
stack will skip software verification on corrupted TCP/UDP payloads.
Gating ax88179a_rx_checksum() on (pkt_desc & AX179A_RX_PD_RX_OK) &&
!(pkt_desc & AX179A_RX_PD_DROP) avoids this.

> @@ -1063,6 +1102,9 @@ static int ax88179a_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
>  		if (!ax_skb)
>  			goto err;
>  
> +		if (!(features & NETIF_F_RXFCS))
> +			pkt_len -= fcs_trailer;
> +
>  		skb_put(ax_skb, pkt_len);
>  		memcpy(ax_skb->data, skb->data + (ax179_data->ip_align ? AX179A_RX_HW_PAD : 0),
>  		       pkt_len);

[Severity: Medium]
Can toggling NETIF_F_RXFCS or NETIF_F_RXALL on a live interface corrupt
in-flight frames in ax88179a_rx_fixup()?

CPU0                                CPU1
__netdev_update_features()
  ax88179a_set_features()
    clears AX_RX_CTL_DROPCRCERR
    (hw stops appending FCS)
                                    usbnet_bh() -> ax88179a_rx_fixup()
                                      reads old dev->net->features
                                      fcs_trailer = ETH_FCS_LEN
                                      pkt_len -= fcs_trailer  <-- truncates
  dev->features = features                                        payload

Because ax88179a_set_features() changes AX_RX_CTL live without draining
in-flight RX URBs and __netdev_update_features() updates dev->features
only after ndo_set_features() returns, frames captured across the
transition either lose 4 bytes of payload or keep 4 trailing FCS bytes
(and full-MTU frames get dropped as oversized).

[ ... ]

> @@ -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;
>  	WRITE_ONCE(ax179_data->rxctl, rxctl);
>  	ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, rxctl);

[Severity: Medium]
Should ax88179a_reset() hold rx_ctl_mutex around updating
ax179_data->rxctl and writing AX_RX_CTL?  ax88179a_resume() calls
ax88179a_reset() before taking rtnl_lock(), so a concurrent
ax88179a_set_features() or ax88179_set_multicast() can race and lose
AX_RX_CTL updates.

Similarly, ax88179a_mac_link_up() writes AX_RX_CTL_STOP without holding
rx_ctl_mutex across link reconfiguration, allowing a concurrent
ax88179a_set_features() to write AX_RX_CTL_START back to hardware while
MAC and bulk-in registers are still being reprogrammed.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-fcs-v4-0-32773b612c81@birger-koblitz.de?part=2

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

Thread overview: 5+ 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 [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=sashiko-outbox-251904@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mail@birger-koblitz.de \
    --cc=sashiko-reviews@lists.linux.dev \
    /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