Re: [PATCH net-next v4 2/3] net: phy: acx00: report receive statistics
From: netdev-bot+sashiko
Date: Tue Nov 17 2026 - 13:51:30 EST
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] The receive-statistics baseline is invalidated only inside
acx00_ephy_soft_reset() (drivers/net/phy/xpowers/acx00.c), once that…
- [Medium] In __acx00_ephy_update_stats()
(drivers/net/phy/xpowers/acx00.c), the wrap adjustment hard-codes a…
--
net: phy: acx00: report receive statistics
This commit reports the ACx00 PHY receive packet, byte and CRC-error
counters through the generic PHY statistics interface. The free-running
hardware counters are polled through the update_stats callback and added
into 64-bit totals with wrap adjustment. The baseline is invalidated on
soft reset, power-off, resume, and after long polling gaps.
> diff --git a/drivers/net/phy/xpowers/acx00.c b/drivers/net/phy/xpowers/acx00.c
> index cee6c7ff0278e..fb53bac12195c 100644
> --- a/drivers/net/phy/xpowers/acx00.c
> +++ b/drivers/net/phy/xpowers/acx00.c
[ ... ]
> @@ -110,6 +144,124 @@ static int acx00_ephy_write_page(struct phy_device *phydev, int page)
[ ... ]
> +static int __acx00_ephy_update_stats(struct phy_device *phydev)
> +{
[ ... ]
> + /* Skip unusable samples without turning a statistics miss into a link error. */
> + if (ret || counts[ACX00_STAT_RX_BYTES] >= ACX00_RX_BYTES_WRAP)
> + return 0;
> +
> + /* Include sleep and read time; complete unseen cycles cannot be recovered. */
> + if (priv->stats_valid &&
> + ktime_ms_delta(ktime_get_boottime(), priv->stats_start) >=
> + (s64)ACX00_STATS_MAX_INTERVAL_MS)
> + priv->stats_valid = false;
> +
> + for (i = 0; i < ACX00_NUM_STATS; i++) {
> + u64 count = counts[i];
> +
> + if (priv->stats_valid) {
> + if (count < priv->stats_last[i])
> + count += i == ACX00_STAT_RX_BYTES ?
> + ACX00_RX_BYTES_WRAP : BIT_ULL(32);
[Severity: Medium]
Has the 2^32 rollover been measured for the packet (0x1b/0x1c) and
CRC-error (0x1d/0x1e) counters? The commit message gives hardware
measurements for the byte counter's 4,000,000,000 modulus. For the other
two counters it only says:
"The packet and CRC-error counters wrap at 2^32."
All three counters sit next to each other in page 9 and are read the same
way. If the packet or CRC counters wrap at 4e9 like the byte counter, each
wrap adds BIT_ULL(32) instead of 4e9. That would add an extra 294,967,296
to rx_packets_total or rx_errors on every wrap.
Only the byte sample is checked against its modulus above. The packet and
CRC samples are never range-checked, so nothing here would catch a wrong
modulus.
> + priv->stats[i] += count - priv->stats_last[i];
> + }
> + priv->stats_last[i] = counts[i];
> + }
> + priv->stats_valid = true;
> + priv->stats_start = start;
[ ... ]
> @@ -350,6 +506,10 @@ static int acx00_ephy_soft_reset(struct phy_device *phydev)
>
> mutex_lock(&priv->state_lock);
>
> + /* phylib may already have reset the counters before calling us. */
> + priv->stats_active = false;
> + priv->stats_valid = false;
> +
[Severity: Medium]
Can a concurrent poll count a BMCR reset as a counter wrap before this
invalidation runs?
phy_mii_ioctl() in drivers/net/phy/phy.c writes BMCR_RESET before it
reaches the driver's soft_reset:
mdiobus_write(phydev->mdio.bus, prtad, devad, val);
if (prtad == phydev->mdio.addr &&
devad == MII_BMCR &&
val & BMCR_RESET)
return phy_init_hw(phydev);
This path runs under RTNL only. It holds neither phydev->lock nor
state_lock, and it does not stop the state machine.
Meanwhile, _phy_state_machine() in PHY_NOLINK or PHY_RUNNING calls
phy_update_stats()->acx00_ephy_update_stats().
Suppose that poll takes state_lock after the BMCR_RESET write but before
acx00_ephy_soft_reset() takes it. Then stats_active and stats_valid are
still true. __acx00_ephy_update_stats() reads the cleared page-9 counters
and sees count < stats_last[i]. It then adds ACX00_RX_BYTES_WRAP or
BIT_ULL(32) and commits the result to priv->stats[].
Clearing stats_valid here afterwards does not remove that delta.
rx_bytes_total would grow by about 4e9 minus the old byte baseline.
rx_packets_total and rx_errors would each grow by about 2^32 minus their
baselines.
The commit message says the invalidation covers the case where "phylib may
already have reset the PHY through BMCR or its reset signal". Does that
hold if a poll runs between the reset write and soft_reset?
This needs CAP_NET_ADMIN and a narrow timing window. Still, nothing in the
driver orders the reset write against the collector.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113-submit-acx00-phy-stats-v1-v4-0-986b8a4a1871%40gmail.com