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 v2 2/2] net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A
Date: Mon, 30 Nov 2026 07:41:18 +0000	[thread overview]
Message-ID: <sashiko-outbox-240609@kernel.org> (raw)
In-Reply-To: <20261129-fcs-v2-2-f60d6b105a15@birger-koblitz.de>

Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] net: usb: ax88179: missing fcs_trailer in ax88179a_rx_fixup()
  min length check
- [Medium] net: usb: ax88179: bad-FCS frames skip stats and get
  CHECKSUM_UNNECESSARY
- [Medium] net: usb: ax88179: unsynchronized rxctl updates in
  ax88179a_set_features()
- [Low] net: usb: ax88179: unchecked ax88179_write_u16() in
  ax88179a_set_features()
- [Low] net: usb: ax88179: ax88179a_set_features() starts RX while
  interface is down
--

commit 21d8e6eaf31af5eed7506d49312844c800b253bc
Author: Birger Koblitz <mail@birger-koblitz.de>

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

This commit adds NETIF_F_RXFCS and NETIF_F_RXALL support for AX88179A devices,
adjusts packet length handling in ax88179a_rx_fixup() for trailing FCS bytes,
and updates RX drop and CRC error counters.

> diff --git a/drivers/net/usb/ax88179a_devices.c b/drivers/net/usb/ax88179a_devices.c
> index 69095110e7043..21cf90d69f502 100644
> --- a/drivers/net/usb/ax88179a_devices.c
> +++ b/drivers/net/usb/ax88179a_devices.c
> @@ -717,10 +717,12 @@ static int ax88179a_mii_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
>  static int ax88179a_set_features(struct net_device *net, netdev_features_t features)
>  {
>  	struct usbnet *dev = netdev_priv(net);
> +	struct ax88179_data *ax179_data;
>  	netdev_features_t changed;
>  	int ret;
>  	u8 tmp;
>  
> +	ax179_data = dev->driver_priv;
>  	changed = net->features ^ features;
>  
>  	ret = ax88179_set_features(net, features);
> @@ -780,6 +782,18 @@ 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 = 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);
> +		ax88179_write_u16(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, rxctl);
> +	}
> +
>  	return 0;
>  }

[Severity: Medium]
Can this ax179_data->rxctl update race with ax88179_set_multicast() or
ax88179a_mac_link_up()?

__netdev_update_features() calls ndo_set_features before updating
net->features.  While ax88179_write_u16() sleeps on the USB control
transfer, ax88179_set_multicast() can run under netif_addr_lock_bh()
without rtnl_lock and recompute AX_RX_CTL_DROPCRCERR from the old
net->features value:

CPU0                                  CPU1 (<softirq>)
__netdev_update_features()
  ax88179a_set_features()
    rxctl |= AX_RX_CTL_DROPCRCERR
    WRITE_ONCE(ax179_data->rxctl, ...)
    ax88179_write_u16(..., AX_RX_CTL, ...)
                                      ax88179_set_multicast()
                                        rxctl &= ~AX_RX_CTL_DROPCRCERR
                                        if (net->features & ...)
                                          /* still false */
                                        WRITE_ONCE(data->rxctl, rxctl)
                                        ax88179_write_cmd_async(...)
  net->features = features;             <-- AX_RX_CTL_DROPCRCERR lost

That leaves hardware FCS appending disabled while net->features has
NETIF_F_RXFCS or NETIF_F_RXALL set.  ax88179a_mac_link_up() also runs in
the phylink workqueue without rtnl_lock, writes AX_RX_CTL_STOP while
configuring the link, and restores AX_RX_CTL from ax179_data->rxctl under
medium_status_mutex, so an unserialized write here can re-enable
AX_RX_CTL_START in the middle of link setup.

[Severity: Low]
Should this check and return the error from ax88179_write_u16()?  If the
control transfer fails, returning 0 lets the netdev core commit the new
feature flags to net->features while AX_RX_CTL in hardware keeps the old
AX_RX_CTL_DROPCRCERR state, so ax88179a_rx_fixup() misinterprets whether
received packets carry a 4-byte FCS trailer.

[Severity: Low]
Can this re-enable hardware reception while the interface is down?
ax88179a_stop() writes 0 to AX_RX_CTL in hardware without clearing
AX_RX_CTL_START in ax179_data->rxctl, so toggling rx-fcs or rx-all while
the interface is stopped writes AX_RX_CTL_START back to AX_RX_CTL.

[ ... ]

> @@ -1039,9 +1058,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;
> +
>  		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 +1074,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) {
>  			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;
> @@ -1063,6 +1096,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]
Should the minimum length check also account for fcs_trailer?

When NETIF_F_RXALL is enabled and NETIF_F_RXFCS is disabled, a 16- or
17-byte runt frame (including the 4-byte FCS trailer) passes
pkt_len < 2 + ETH_HLEN and then has fcs_trailer subtracted, leaving
pkt_len at 12 or 13 bytes (< ETH_HLEN).  usbnet_skb_return() then calls
eth_type_trans(), where eth_skb_pull_mac() fails to pull ETH_HLEN bytes
and eth_type_trans() reads eth->h_proto past skb_tail_pointer(ax_skb) from
uninitialized skb memory.

[Severity: Medium]
When NETIF_F_RXALL is enabled, does a frame with !(pkt_desc &
AX179A_RX_PD_RX_OK) skip rx_crc_errors accounting and still get passed to
ax88179a_rx_checksum()?

Because the error counters are inside the discard branch, bad-FCS frames
received under NETIF_F_RXALL are not counted in rx_crc_errors or
rx_errors.  They then reach ax88179a_rx_checksum(), which only checks
AX179A_RX_PD_L4_ERR and AX179A_RX_PD_L3_ERR and can mark a frame that
failed L2 CRC verification as CHECKSUM_UNNECESSARY.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261129-fcs-v2-0-f60d6b105a15@birger-koblitz.de?part=2

  reply	other threads:[~2026-11-30  7:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29  7:40 [PATCH net-next v2 0/2] net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A Birger Koblitz
2026-11-29  7:40 ` [PATCH net-next v2 1/2] net: usb: ax88179: Make receiving FCS on AX88179A configurable Birger Koblitz
2026-11-30  7:41   ` sashiko-bot
2026-11-30  8:35   ` netdev-bot+sashiko
2026-11-29  7:40 ` [PATCH net-next v2 2/2] net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A Birger Koblitz
2026-11-30  7:41   ` sashiko-bot [this message]
2026-11-30  8:35   ` netdev-bot+sashiko

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-240609@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