* [PATCH net-next v4 0/2] net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A
@ 2026-12-04 21:21 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-04 21:21 ` [PATCH net-next v4 2/2] net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A Birger Koblitz
0 siblings, 2 replies; 5+ messages in thread
From: Birger Koblitz @ 2026-12-04 21:21 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni
Cc: netdev, linux-usb, Benjamin Larsson, Birger Koblitz
The AX88179A-Chip family supports reception of the FCS
at the host. This is configured by enabling the AX_RX_CTL_DROPCRCERR
flag in the USB-adapters RX-controls. For AX88279-based adapters,
the flag has already been always set in order to receive
complete frames, however, the FCS is not necessarily usable, as it
is only part of the transferred up-to 8-byte padding area, and for
some frame-lengths only 2 of the 4 bytes of the FCS are transferred
to the host.
Note, that the AX_RX_CTL_DROPCRCERR flag has no influence on dropping
of corrupt frames already by the USB adapter, even corrupt frames
are always transferred to the host.
Add 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().
Also add code rx_fixup() in order to Count dropped packets and those
with incorrect checksum.
Suggested-by: Benjamin Larsson <benjamin.larsson@genexis.eu>
Signed-off-by: Birger Koblitz <mail@birger-koblitz.de>
---
Changes in v4:
- Add locking for changes in rxctl
- Include read-modify-write changes to rxctl in commit message
- Add comment to explain AX_RX_CTL_DROPCRCERR behaviour
- Link to v3: https://lore.kernel.org/r/20261201-fcs-v3-0-6c355917b17e@birger-koblitz.de
Changes in v3:
- In ax88179_set_multicast() make sure the behaviour for the older
AX88179 devices is not changed
- Improve error checking in set_features()
- Improve lower packet length check to take FCS into account
- Link to v2: https://lore.kernel.org/r/20261129-fcs-v2-0-f60d6b105a15@birger-koblitz.de
Changes in v2:
- Do not clobber rxctl in ax88179_set_multicast(): read and update it
- Use netdev_features_t for features in rx_fixup()
- Do not include FCS trailer when NETIF_F_RXFCS not set
- Count rx_errors together with crc_errors as per definition
- Link to v1: https://lore.kernel.org/r/20261127-fcs-v1-0-0c4ede015bf5@birger-koblitz.de
---
Birger Koblitz (2):
net: usb: ax88179: Make receiving FCS on AX88179A configurable
net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A
drivers/net/usb/ax88179_lib.c | 18 +++++++++---
drivers/net/usb/ax88179_lib.h | 1 +
drivers/net/usb/ax88179a_devices.c | 56 ++++++++++++++++++++++++++++++++++----
3 files changed, 65 insertions(+), 10 deletions(-)
---
base-commit: eb6d6c80d35449c27471b1874f13066c09a8964d
change-id: 20261126-fcs-afccb4a76dd1
Best regards,
--
Birger Koblitz <mail@birger-koblitz.de>
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH net-next v4 1/2] net: usb: ax88179: Make receiving FCS on AX88179A configurable 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 ` 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 1 sibling, 1 reply; 5+ messages in thread From: Birger Koblitz @ 2026-12-04 21:21 UTC (permalink / raw) To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni Cc: netdev, linux-usb, Benjamin Larsson, Birger Koblitz Make reception of FCS on AX88179A configuration-dependent. In contrast to what the name suggests, AX_RX_CTL_DROPCRCERR actually instructs the MAC to leave the FCS attached to the end of the Ethernet frame when sent by the USB-adapter to the host. This was tested for AX88179A as well as on the AX88772D, which behaves the same as the AX88179A in respect of this flag, as this refers to MAC functionality and the AX88772D is merely a AX88179A with a different integrated 100Mbit PHY. For the older AX88179, the behaviour does not change. For AX88279-based adapters, the flag must be set in order to receive complete frames, however, the FCS is not necessarily usable, as it is only part of the transferred up-to 8-byte padding area, and for some frame-lengths only 2 of the 4 bytes of the FCS are transferred to the host. The AX_RX_CTL_DROPCRCERR flag has no influence on dropping of corrupt frames already by the USB adapter. Use read-modify-write for the changes to rxctrl on AX88179A/AX88279. Fixes: 7d573278f9a5 ("ax88179_178a: Add HW support for AX179A-based chips") Signed-off-by: Birger Koblitz <mail@birger-koblitz.de> --- drivers/net/usb/ax88179_lib.c | 14 +++++++++++--- drivers/net/usb/ax88179a_devices.c | 3 +-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/net/usb/ax88179_lib.c b/drivers/net/usb/ax88179_lib.c index 821ee9cd8ded1b8f1e425bcef493fb175ed30376..273c5946e16a159f5f392b822942e0d393d5075f 100644 --- a/drivers/net/usb/ax88179_lib.c +++ b/drivers/net/usb/ax88179_lib.c @@ -352,14 +352,22 @@ void ax88179_set_multicast(struct net_device *net) struct usbnet *dev = netdev_priv(net); u8 *m_filter = ((u8 *)dev->data); struct ax88179_data *data; - u16 rxctl = 0; + u16 rxctl; data = dev->driver_priv; - rxctl = (AX_RX_CTL_START | AX_RX_CTL_AB | AX_RX_CTL_DROPCRCERR); + 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 | + AX_RX_CTL_AMALL | AX_RX_CTL_AM); + } else { + rxctl = (AX_RX_CTL_START | AX_RX_CTL_AB | AX_RX_CTL_DROPCRCERR); + } if (data->ip_align) rxctl |= AX_RX_CTL_IPE; - + 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 */ if (net->flags & IFF_PROMISC) { rxctl |= AX_RX_CTL_PRO; } else if (net->flags & IFF_ALLMULTI || diff --git a/drivers/net/usb/ax88179a_devices.c b/drivers/net/usb/ax88179a_devices.c index 69095110e70435806a99274c50d79e86016ec9a0..78a804203202f7741eb62efd10c19253043a3708 100644 --- a/drivers/net/usb/ax88179a_devices.c +++ b/drivers/net/usb/ax88179a_devices.c @@ -1216,8 +1216,7 @@ static int ax88179a_reset(struct usbnet *dev) ax88179_write_u8(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, *tmp); /* Configure RX control register => start operation */ - rxctl = AX_RX_CTL_DROPCRCERR | AX_RX_CTL_START | AX_RX_CTL_AP | - AX_RX_CTL_AMALL | AX_RX_CTL_AB; + rxctl = AX_RX_CTL_START | AX_RX_CTL_AP | AX_RX_CTL_AMALL | AX_RX_CTL_AB; if (ax179_data->ip_align) rxctl |= AX_RX_CTL_IPE; if (dev->net->flags & IFF_PROMISC) -- 2.47.3 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net-next v4 1/2] net: usb: ax88179: Make receiving FCS on AX88179A configurable 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 0 siblings, 0 replies; 5+ messages in thread From: sashiko-bot @ 2026-12-05 21:22 UTC (permalink / raw) To: Birger Koblitz; +Cc: linux-usb Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] net: usb: ax88179: unlocked rxctl RMW in ax88179_set_multicast() -- commit 92e42adb3b2a81ab9beb3f4942dd4fe939e57e19 Author: Birger Koblitz <mail@birger-koblitz.de> net: usb: ax88179: Make receiving FCS on AX88179A configurable This commit changes ax88179_set_multicast() on AX88179A and newer chips to read-modify-write data->rxctl and set AX_RX_CTL_DROPCRCERR based on NETIF_F_RXFCS and NETIF_F_RXALL. It also stops setting AX_RX_CTL_DROPCRCERR by default in ax88179a_reset(). > diff --git a/drivers/net/usb/ax88179_lib.c b/drivers/net/usb/ax88179_lib.c > index 821ee9cd8ded1..273c5946e16a1 100644 > --- a/drivers/net/usb/ax88179_lib.c > +++ b/drivers/net/usb/ax88179_lib.c > @@ -352,14 +352,22 @@ void ax88179_set_multicast(struct net_device *net) > struct usbnet *dev = netdev_priv(net); > u8 *m_filter = ((u8 *)dev->data); > struct ax88179_data *data; > - u16 rxctl = 0; > + u16 rxctl; > > data = dev->driver_priv; > > - rxctl = (AX_RX_CTL_START | AX_RX_CTL_AB | AX_RX_CTL_DROPCRCERR); > + 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 | > + AX_RX_CTL_AMALL | AX_RX_CTL_AM); > + } else { > + rxctl = (AX_RX_CTL_START | AX_RX_CTL_AB | AX_RX_CTL_DROPCRCERR); > + } > if (data->ip_align) > rxctl |= AX_RX_CTL_IPE; > - > + 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 */ > if (net->flags & IFF_PROMISC) { > rxctl |= AX_RX_CTL_PRO; > } else if (net->flags & IFF_ALLMULTI || [Severity: Medium] Can this unlocked read-modify-write of data->rxctl race with other AX_RX_CTL writers and leave data->rxctl out of sync with hardware? __dev_set_rx_mode() calls ax88179_set_multicast() in BH context holding only netif_addr_lock_bh() without RTNL. Neither ax88179a_resume() -> ax88179a_reset() (which runs while netif_device_present() stays true) nor ax88179a_mac_link_up() takes netif_addr_lock_bh(): CPU0 CPU1 ax88179a_resume() ax88179a_reset() ax88179_write_u16(..., 0) __dev_set_rx_mode() ax88179_set_multicast() rxctl = READ_ONCE(data->rxctl) WRITE_ONCE(ax179_data->rxctl, ...) ax88179_write_u16(..., rxctl) WRITE_ONCE(data->rxctl, rxctl) ax88179_write_cmd_async(...) <-- clobbers rxctl / AX_RX_CTL This allows lost updates to data->rxctl, out-of-order async and synchronous AX_RX_CTL writes, or re-enabling AX_RX_CTL_START mid-reset or during link-up. Reading net->features without RTNL also races with __netdev_update_features(), which calls ndo_set_features() before updating dev->features. With commit "net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A", a concurrent ax88179_set_multicast() can overwrite AX_RX_CTL_DROPCRCERR from stale net->features, leaving ax88179a_rx_fixup() out of sync with hardware FCS stripping. That follow-up commit does not resolve this race either, as ax88179_set_multicast() still reads net->features without RTNL, submits its async write outside rx_ctl_mutex, and ax88179a_reset() remains unlocked. Consider serializing rxctl updates with a spinlock_bh or deferring RX mode writes to workqueue context (such as ndo_set_rx_mode_async or usbnet_defer_kevent()), and avoid recomputing AX_RX_CTL_DROPCRCERR from net->features outside RTNL. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261204-fcs-v4-0-32773b612c81@birger-koblitz.de?part=1 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net-next v4 2/2] net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A 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-04 21:21 ` Birger Koblitz 2026-12-05 21:22 ` sashiko-bot 1 sibling, 1 reply; 5+ messages in thread From: Birger Koblitz @ 2026-12-04 21:21 UTC (permalink / raw) To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni Cc: netdev, linux-usb, Benjamin Larsson, Birger Koblitz 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> --- drivers/net/usb/ax88179_lib.c | 4 ++- drivers/net/usb/ax88179_lib.h | 1 + drivers/net/usb/ax88179a_devices.c | 53 +++++++++++++++++++++++++++++++++++--- 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/drivers/net/usb/ax88179_lib.c b/drivers/net/usb/ax88179_lib.c index 273c5946e16a159f5f392b822942e0d393d5075f..dc32660a2335935bc99776b68a5fd7604fa98728 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 | @@ -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); } int ax88179_set_features(struct net_device *net, netdev_features_t features) diff --git a/drivers/net/usb/ax88179_lib.h b/drivers/net/usb/ax88179_lib.h index 401c0bed3d28b4b94f0a0cad7509cd7087ef0639..a9e688424c1299f17d777b573db53c1ea81fdbfe 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; diff --git a/drivers/net/usb/ax88179a_devices.c b/drivers/net/usb/ax88179a_devices.c index 78a804203202f7741eb62efd10c19253043a3708..9137f790ddaa61f6f741ba3f59ab24628bbd92af 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); mutex_unlock(&ax179_data->medium_status_mutex); ax88179_write_u8(dev, AX_ACCESS_MAC, AX88179A_MAC_PATH, 1, @@ -717,10 +719,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 +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; } @@ -852,8 +874,8 @@ static int ax88179a_bind(struct usbnet *dev, struct usb_interface *intf) ax179_data->fw_version[2], ax179_data->fw_version[3]); /* The AX88279 requires both the AX_RX_CTL_IPE and AX_RX_CTL_DROPCRCERR - * bits set in AX_RX_CTL for creating correct RX-URBs. AX_RX_CTL_DROPCRCERR - * is anyway set for all chips, make sure AX_RX_CTL_IPE is set via ip_align. + * bits set in AX_RX_CTL for creating correct RX-URBs. Make sure + * AX_RX_CTL_IPE is set via ip_align. * Also configure eeprom access parameters. */ if (ax179_data->chip_version == AX_VERSION_AX88279) { @@ -894,6 +916,9 @@ static int ax88179a_bind(struct usbnet *dev, struct usb_interface *intf) dev->net->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM | NETIF_F_TSO; + if (ax179_data->chip_version == AX_VERSION_AX88179A) + dev->net->hw_features |= NETIF_F_RXFCS | NETIF_F_RXALL; + netif_set_tso_max_size(dev->net, 16384); /* Enable Transmission of Link Speed byte in interrupt URB */ @@ -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; + 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++; + } /* Next RX Packet Descriptor */ pkt_desc_ptr++; continue; @@ -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); @@ -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); -- 2.47.3 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net-next v4 2/2] net: usb: ax88179: Support NETIF_F_RXFCS and NETIF_F_RXALL on AX88179A 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 0 siblings, 0 replies; 5+ messages in thread From: sashiko-bot @ 2026-12-05 21:22 UTC (permalink / raw) To: Birger Koblitz; +Cc: linux-usb 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-05 21:22 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox