From: Lorenzo Bianconi <lorenzo@kernel.org>
To: sashiko@lists.linux.dev
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org, robh@kernel.org,
krzk+dt@kernel.org
Subject: Re: [PATCH net-next v6 09/12] net: airoha: Do not stop GDM port if it is shared
Date: Wed, 13 May 2026 11:43:51 +0200 [thread overview]
Message-ID: <agRH12v6OeetUmtJ@lore-desk> (raw)
In-Reply-To: <20260512213116.7414FC2BCB0@smtp.kernel.org>
[-- Attachment #1: Type: text/plain, Size: 4832 bytes --]
> Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
> - [High] Stopping a net_device leaves its packets in the shared QDMA hardware TX ring, causing a BUG_ON kernel panic or Use-After-Free when the hardware later transmits them.
> - [Medium] When decreasing the MTU on a shared GDM port with multiple active users, the hardware MTU is not reduced to match the new global maximum.
> - [Low] The function parameter `netdev` is overwritten in a loop within `airoha_dev_stop()`.
> --
>
> commit 30071ffd90f181adfa0fb1ab6717d5d5cfa7e0e8
> Author: Lorenzo Bianconi <lorenzo@kernel.org>
>
> net: airoha: Do not stop GDM port if it is shared
>
> Theoretically, in the current codebase, two independent net_devices can
> be connected to the same GDM port so we need to check the GDM port is not
> used by any other running net_device before setting the forward
> configuration to FE_PSE_PORT_DROP.
>
> > diff --git a/drivers/net/ethernet/airoha/airoha_eth.c b/drivers/net/ethernet/airoha/airoha_eth.c
> > index 4efd36779453e..aed182c7a5e17 100644
> > --- a/drivers/net/ethernet/airoha/airoha_eth.c
> > +++ b/drivers/net/ethernet/airoha/airoha_eth.c
> [ ... ]
> > @@ -1759,6 +1769,7 @@ static int airoha_dev_stop(struct net_device *netdev)
> > struct airoha_gdm_dev *dev = netdev_priv(netdev);
> > struct airoha_gdm_port *port = dev->port;
> > struct airoha_qdma *qdma = dev->qdma;
> > + u32 len = 0;
> > int i;
> >
> > netif_tx_disable(netdev);
> > @@ -1766,8 +1777,23 @@ static int airoha_dev_stop(struct net_device *netdev)
> > for (i = 0; i < netdev->num_tx_queues; i++)
> > netdev_tx_reset_subqueue(netdev, i);
>
> If another device is still using the QDMA (qdma->users > 1), the hardware TX
> ring is not cleaned up. NAPI polling is bound to a dummy device and continues
> running.
>
> When NAPI later processes the stopped device's pending TX completions, it
> unconditionally calls netdev_tx_completed_queue() which invokes
> dql_completed().
>
> Since BQL was reset here, will this trigger a BUG_ON in
> lib/dynamic_queue_limits.c? Furthermore, if the device was unregistered,
> would the skb->dev access in the completion handler result in a
> use-after-free?
This issue is not introduced in this patch.
>
> >
> > - airoha_set_gdm_port_fwd_cfg(qdma->eth, REG_GDM_FWD_CFG(port->id),
> > - FE_PSE_PORT_DROP);
> > + for (i = 0; i < ARRAY_SIZE(port->devs); i++) {
> > + if (!port->devs[i])
> > + continue;
> > +
> > + netdev = port->devs[i]->dev;
>
> This isn't a bug, but this loop reassigns the local parameter netdev. While
> it might be functionally harmless right now because netdev isn't dereferenced
> later in this function, could this create issues for future modifications
> expecting netdev to still point to the device being stopped?
ack, I will fix it in v7.
>
> > + if (netif_running(netdev))
> > + len = max_t(u32, len, netdev->mtu);
> > + }
> > + len += ETH_HLEN + ETH_FCS_LEN;
> > + airoha_fe_rmw(qdma->eth, REG_GDM_LEN_CFG(port->id),
> > + GDM_LONG_LEN_MASK,
> > + FIELD_PREP(GDM_LONG_LEN_MASK, len));
> > +
> [ ... ]
> > @@ -1919,13 +1945,18 @@ static void airoha_dev_get_stats64(struct net_device *netdev,
> > static int airoha_dev_change_mtu(struct net_device *netdev, int mtu)
> > {
> > struct airoha_gdm_dev *dev = netdev_priv(netdev);
> > + u32 cur_len, len = ETH_HLEN + mtu + ETH_FCS_LEN;
> > struct airoha_gdm_port *port = dev->port;
> > - u32 len = ETH_HLEN + mtu + ETH_FCS_LEN;
> > struct airoha_eth *eth = dev->eth;
> >
> > - airoha_fe_rmw(eth, REG_GDM_LEN_CFG(port->id),
> > - GDM_LONG_LEN_MASK,
> > - FIELD_PREP(GDM_LONG_LEN_MASK, len));
> > + cur_len = airoha_fe_get(eth, REG_GDM_LEN_CFG(port->id),
> > + GDM_LONG_LEN_MASK);
> > + if (len > cur_len || !port->users ||
> > + (port->users == 1 && netif_running(netdev)))
> > + airoha_fe_rmw(eth, REG_GDM_LEN_CFG(port->id),
> > + GDM_LONG_LEN_MASK,
> > + FIELD_PREP(GDM_LONG_LEN_MASK, len));
>
> If there are multiple running devices on the shared port and they all lower
> their MTU, this condition prevents the hardware MTU from being updated to
> match the new global maximum. Should this iterate over port->devs to compute
> the actual maximum MTU of all running devices, similar to how it is handled
> in airoha_dev_stop()?
According to my understanding, airoha_dev_change_mtu() is running with RTNL
lock held so we will always have the max configured mtu in cur_len.
Regards,
Lorenzo
>
> > +
> > WRITE_ONCE(netdev->mtu, mtu);
> >
> > return 0;
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20260511-airoha-eth-multi-serdes-v6-0-c899462c4f75@kernel.org?part=9
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2026-05-13 9:43 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-11 10:49 [PATCH net-next v6 00/12] net: airoha: Support multiple net_devices connected to the same GDM port Lorenzo Bianconi
2026-05-11 10:49 ` [PATCH net-next v6 01/12] dt-bindings: net: airoha: Add EN7581 ethernet-ports properties Lorenzo Bianconi
2026-05-11 10:49 ` [PATCH net-next v6 02/12] net: airoha: Reserve RX headroom to avoid skb reallocation Lorenzo Bianconi
2026-05-12 20:31 ` Lorenzo Bianconi
2026-05-11 10:49 ` [PATCH net-next v6 03/12] net: airoha: Introduce airoha_gdm_dev struct Lorenzo Bianconi
2026-05-12 20:55 ` Lorenzo Bianconi
2026-05-11 10:49 ` [PATCH net-next v6 04/12] net: airoha: Move airoha_qdma pointer in " Lorenzo Bianconi
2026-05-13 8:45 ` Lorenzo Bianconi
2026-05-11 10:49 ` [PATCH net-next v6 05/12] net: airoha: Rely on airoha_gdm_dev pointer in airhoa_is_lan_gdm_port() Lorenzo Bianconi
2026-05-11 10:49 ` [PATCH net-next v6 06/12] net: airoha: Move qos_sq_bmap in airoha_gdm_dev struct Lorenzo Bianconi
2026-05-11 10:49 ` [PATCH net-next v6 07/12] net: airoha: Move {cpu,fwd}_tx_packets " Lorenzo Bianconi
2026-05-11 10:49 ` [PATCH net-next v6 08/12] net: airoha: Support multiple net_devices for a single FE GDM port Lorenzo Bianconi
2026-05-13 9:26 ` Lorenzo Bianconi
2026-05-11 10:49 ` [PATCH net-next v6 09/12] net: airoha: Do not stop GDM port if it is shared Lorenzo Bianconi
2026-05-12 21:31 ` sashiko-bot
2026-05-13 9:43 ` Lorenzo Bianconi [this message]
2026-05-11 10:49 ` [PATCH net-next v6 10/12] net: airoha: Introduce WAN device flag Lorenzo Bianconi
2026-05-11 10:49 ` [PATCH net-next v6 11/12] net: airoha: Support multiple LAN/WAN interfaces for hw MAC address configuration Lorenzo Bianconi
2026-05-12 17:49 ` Benjamin Larsson
2026-05-12 20:58 ` Lorenzo Bianconi
2026-05-13 12:26 ` Benjamin Larsson
2026-05-12 23:47 ` sashiko-bot
2026-05-13 10:35 ` Lorenzo Bianconi
2026-05-11 10:49 ` [PATCH net-next v6 12/12] net: airoha: Better handle MIB for GDM with multiple port attached Lorenzo Bianconi
2026-05-12 23:32 ` sashiko-bot
2026-05-13 10:46 ` Lorenzo Bianconi
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=agRH12v6OeetUmtJ@lore-desk \
--to=lorenzo@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=robh@kernel.org \
--cc=sashiko@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