From: Lorenzo Bianconi <lorenzo@kernel.org>
To: sashiko-reviews@lists.linux.dev
Cc: robh@kernel.org, devicetree@vger.kernel.org, conor+dt@kernel.org,
krzk+dt@kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH net-next v6 12/12] net: airoha: Better handle MIB for GDM with multiple port attached
Date: Wed, 13 May 2026 12:46:21 +0200 [thread overview]
Message-ID: <agRWfSghLZGeMVOc@lore-desk> (raw)
In-Reply-To: <20260512233205.7CA40C2BCB0@smtp.kernel.org>
[-- Attachment #1: Type: text/plain, Size: 5471 bytes --]
> Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
> - [High] The RUNT_CNT statistic is overwritten and lost due to incorrect assignment logic.
> - [High] 32-bit free-running hardware statistics will wrap around and reset 64-bit software counters to zero.
> - [High] Torn hardware reads on 64-bit registers due to free-running counters.
> - [High] Pre-existing potential deadlock due to using `spin_lock()` instead of `spin_lock_bh()` for stats lock.
> --
>
> commit 2f0d0c633539afc37cceb4ad426afb56465e7b6d
> Author: Christian Marangi <ansuelsmth@gmail.com>
> Subject: net: airoha: Better handle MIB for GDM with multiple port attached
>
> The commit enables the split MIB feature for GDM3 and GDM4, moving stats
> from port to device, and modifying the stats update logic from clear-on-read
> to direct assignment since the MIB clear was removed.
>
> > diff --git a/drivers/net/ethernet/airoha/airoha_eth.c b/drivers/net/ethernet/airoha/airoha_eth.c
> > index 533ffe20f8333..27ccc636d8009 100644
> > --- a/drivers/net/ethernet/airoha/airoha_eth.c
> > +++ b/drivers/net/ethernet/airoha/airoha_eth.c
> > @@ -1621,143 +1621,146 @@ static void airoha_update_hw_stats(struct airoha_gdm_dev *dev)
> > struct airoha_eth *eth = dev->eth;
> > u32 val, i = 0;
> >
> > - spin_lock(&port->stats.lock);
> > - u64_stats_update_begin(&port->stats.syncp);
> > + spin_lock(&port->stats_lock);
>
> This isn't a bug introduced by this patch, but could this spin_lock()
> cause a deadlock? Since airoha_update_hw_stats() is called by
> ndo_get_stats64() (which can run in softirq context) and ethtool
> callbacks (which run in process context), a softirq could interrupt the
> process context and spin forever trying to acquire the same lock. Should
> this be spin_lock_bh()?
ndo_get_stats64() does not run in softirq context.
>
> > + u64_stats_update_begin(&dev->stats.syncp);
> > +
> > + /* Read relevant MIB for GDM with multiple port attached */
> > + if (port->id == AIROHA_GDM3_IDX || port->id == AIROHA_GDM4_IDX)
> > + airoha_fe_rmw(eth, REG_FE_GDM_MIB_CFG(port->id),
> > + FE_TX_MIB_ID_MASK | FE_RX_MIB_ID_MASK,
> > + FIELD_PREP(FE_TX_MIB_ID_MASK, dev->nbq) |
> > + FIELD_PREP(FE_RX_MIB_ID_MASK, dev->nbq));
> >
> > /* TX */
> > val = airoha_fe_rr(eth, REG_FE_GDM_TX_OK_PKT_CNT_H(port->id));
> > - port->stats.tx_ok_pkts += ((u64)val << 32);
> > + dev->stats.tx_ok_pkts = (u64)val << 32;
> > val = airoha_fe_rr(eth, REG_FE_GDM_TX_OK_PKT_CNT_L(port->id));
> > - port->stats.tx_ok_pkts += val;
>
> Now that the hardware counters are free-running (the MIB clear operation
> was removed later in the patch), can a torn read occur here? If the low
> 32-bit register overflows and increments the high 32-bit register in the
> brief window between the two reads, the resulting 64-bit value will be
> corrupted and off by ~4.29 billion.
ack, I will fit it in v7.
>
> [ ... ]
> > val = airoha_fe_rr(eth, REG_FE_GDM_TX_ETH_DROP_CNT(port->id));
> > - port->stats.tx_drops += val;
> > + dev->stats.tx_drops = val;
>
> Since TX_ETH_DROP_CNT is a 32-bit hardware register and the MIB clear
> operation is removed, the hardware counter will eventually wrap back to
> zero. By assigning it directly to dev->stats.tx_drops, won't this
> cause the 64-bit software counter to also silently drop back to zero and
> violate the monotonically increasing requirement of ndo_get_stats64?
> Does this need to calculate the delta instead of directly assigning the
> value?
ack, I will fit it in v7.
>
> [ ... ]
> > val = airoha_fe_rr(eth, REG_FE_GDM_TX_ETH_RUNT_CNT(port->id));
> > - port->stats.tx_len[i] += val;
> > + dev->stats.tx_len[i] = val;
> >
> > val = airoha_fe_rr(eth, REG_FE_GDM_TX_ETH_E64_CNT_H(port->id));
> > - port->stats.tx_len[i] += ((u64)val << 32);
> > + dev->stats.tx_len[i] = (u64)val << 32;
> > val = airoha_fe_rr(eth, REG_FE_GDM_TX_ETH_E64_CNT_L(port->id));
> > - port->stats.tx_len[i++] += val;
>
> Does this overwrite the RUNT_CNT statistic? The code assigns RUNT_CNT
> to tx_len[i] (where i=0), but immediately overwrites it with
> E64_CNT_H at the same index because i is not incremented between
> the assignments.
ack, I will fit it in v7.
>
> [ ... ]
> > i = 0;
> > val = airoha_fe_rr(eth, REG_FE_GDM_RX_ETH_RUNT_CNT(port->id));
> > - port->stats.rx_len[i] += val;
> > + dev->stats.rx_len[i] = val;
> >
> > val = airoha_fe_rr(eth, REG_FE_GDM_RX_ETH_E64_CNT_H(port->id));
> > - port->stats.rx_len[i] += ((u64)val << 32);
> > + dev->stats.rx_len[i] = (u64)val << 32;
> > val = airoha_fe_rr(eth, REG_FE_GDM_RX_ETH_E64_CNT_L(port->id));
> > - port->stats.rx_len[i++] += val;
>
> Does this also overwrite the RUNT_CNT statistic for the RX path in the
> same way?
ack, I will fit it in v7.
Regards,
Lorenzo
>
> [ ... ]
> > - /* reset mib counters */
> > - airoha_fe_set(eth, REG_FE_GDM_MIB_CLEAR(port->id),
> > - FE_GDM_MIB_RX_CLEAR_MASK | FE_GDM_MIB_TX_CLEAR_MASK);
> > + dev->stats.rx_len[i++] = val;
> >
> > - u64_stats_update_end(&port->stats.syncp);
> > - spin_unlock(&port->stats.lock);
> > + u64_stats_update_end(&dev->stats.syncp);
> > + spin_unlock(&port->stats_lock);
> > }
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20260511-airoha-eth-multi-serdes-v6-0-c899462c4f75@kernel.org?part=12
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
prev parent reply other threads:[~2026-05-13 10:46 UTC|newest]
Thread overview: 22+ 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-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
[not found] ` <20260512234745.34227C2BCB0@smtp.kernel.org>
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
[not found] ` <20260512233205.7CA40C2BCB0@smtp.kernel.org>
2026-05-13 10:46 ` Lorenzo Bianconi [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=agRWfSghLZGeMVOc@lore-desk \
--to=lorenzo@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=robh@kernel.org \
--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