Linux Documentation
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: james.hilliard1@gmail.com
Cc: andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org, corbet@lwn.net,
	skhan@linuxfoundation.org, rdunlap@infradead.org,
	o.rempel@pengutronix.de, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
	stable+noautosel@kernel.org
Subject: Re: [PATCH net-next v4 2/3] net: phy: acx00: report receive statistics
Date: Tue, 17 Nov 2026 18:50:25 +0000	[thread overview]
Message-ID: <179494142597.3136.3833380345536721828@kernel.org> (raw)
In-Reply-To: <20261113-submit-acx00-phy-stats-v1-v4-2-986b8a4a1871@gmail.com>

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

  reply	other threads:[~2026-11-17 18:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13 17:12 [PATCH net-next v4 0/3] ethtool: expose PHY receive totals James Hilliard
2026-11-13 17:12 ` [PATCH net-next v4 1/3] ethtool: add PHY receive frame and byte totals James Hilliard
2026-11-13 20:55   ` Andrew Lunn
2026-11-13 17:12 ` [PATCH net-next v4 2/3] net: phy: acx00: report receive statistics James Hilliard
2026-11-17 18:50   ` netdev-bot+sashiko [this message]
2026-11-13 17:12 ` [PATCH net-next v4 3/3] net: phy: dp83tg720: report inclusive RX packet totals James Hilliard
2026-11-13 21:39   ` Oleksij Rempel

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=179494142597.3136.3833380345536721828@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew@lunn.ch \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=hkallweit1@gmail.com \
    --cc=horms@kernel.org \
    --cc=james.hilliard1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=o.rempel@pengutronix.de \
    --cc=pabeni@redhat.com \
    --cc=rdunlap@infradead.org \
    --cc=skhan@linuxfoundation.org \
    --cc=stable+noautosel@kernel.org \
    /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