🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #19134

Re: [PATCH net-next v6 3/3] net: phy: acx00: report receive statistics

#19134
From: netdev-bot+sashiko
Date: Thu, 19 Nov 2026 12:00
267 lines
17576 bytes
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 3

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] Only the RX byte counter gets a plausibility check: samples >=
  ACX00_RX_BYTES_WRAP are skipped without moving the baseline.
- [Low] In __acx00_ephy_config_init() (drivers/net/phy/xpowers/acx00.c),
  the new statistics baseline snapshot goes through…
- [Low] In __acx00_ephy_update_stats(), stats_last[ACX00_STAT_RX_PACKETS]
  and stats_start[ACX00_STAT_RX_PACKETS] only advance when…
- [Low] Counter baselines are only invalidated inside
  acx00_ephy_soft_reset() (and power-off/resume), under priv->state_lock.

--

net: phy: acx00: report receive statistics

This commit adds receive statistics to the AC200/AC300 PHY driver. It
reports rx_packets, rx_errors and rx_bytes through get_phy_stats, using
counters that update_stats samples from vendor page 9 and adds into
64-bit totals with wrap handling. Baselines are invalidated across soft
reset, power-off and resume, and deltas are discarded after gaps of 320
seconds or more.

> diff --git a/drivers/net/phy/xpowers/acx00.c b/drivers/net/phy/xpowers/acx00.c
> index cee6c7ff0278e..0015816fad078 100644
> --- a/drivers/net/phy/xpowers/acx00.c
> +++ b/drivers/net/phy/xpowers/acx00.c

[ ... ]

> @@ -110,6 +138,169 @@ static int acx00_ephy_write_page(struct phy_device *phydev, int page)

[ ... ]

> +/* Return a mask of usable counters, or a negative MDIO error. */
> +static int acx00_ephy_read_counts(struct phy_device *phydev, u32 *counts)
> +{

[ ... ]

> +	/* Bracket the packet counter with an unchanged CRC count. */
> +	for (i = 0; i < ACX00_COUNTER_READ_ATTEMPTS; i++) {
> +		ret = acx00_ephy_read_counter(phydev, ACX00_PAGE9_RX_PACKETS_HIGH_REG,
> +					      &packets);
> +		if (ret < 0)
> +			return ret;
> +		if (ret)
> +			break;
> +		ret = acx00_ephy_read_counter(phydev, ACX00_PAGE9_RX_CRC_ERRORS_HIGH_REG,
> +					      &errors);
> +		if (ret < 0)
> +			return ret;
> +		if (ret)
> +			break;
> +		if (errors == counts[ACX00_STAT_RX_CRC_ERRORS]) {
> +			/* Both hardware counters and their difference wrap at 2^32. */
> +			counts[ACX00_STAT_RX_PACKETS] = packets - errors;
> +			return BIT(ACX00_STAT_RX_PACKETS) | BIT(ACX00_STAT_RX_CRC_ERRORS);
> +		}
> +		counts[ACX00_STAT_RX_CRC_ERRORS] = errors;
> +	}
> +
> +	/* Keep reporting errors even when no coherent packet sample is possible. */
> +	return BIT(ACX00_STAT_RX_CRC_ERRORS);

[Severity: Low]
When the CRC count changes during all three bracket attempts, only the CRC
bit is returned. This leaves stats_last[ACX00_STAT_RX_PACKETS] and
stats_start[ACX00_STAT_RX_PACKETS] at their old values.

On a link with a sustained high CRC-error rate, this could happen on every
poll for 320 seconds or more:

_phy_state_machine()->phy_update_stats()->acx00_ephy_update_stats()

When a coherent pair finally arrives, __acx00_ephy_update_stats() checks
the interval against the stale timestamp:

	if ((priv->stats_valid & BIT(i)) &&
	    ktime_ms_delta(ktime_get_boottime(), priv->stats_start[i]) <
	    (s64)ACX00_STATS_MAX_INTERVAL_MS) {
		...
	}
	priv->stats_last[i] = counts[i];
	priv->stats_start[i] = start;

The delta is dropped, but the baseline still moves forward. Wouldn't all
good frames received since the last coherent sample then be permanently
missing from rx_packets?

That seems to conflict with the commit message:

    A later coherent pair accounts for the intervening successful frames.

The 320 second window comes from the 4e9 byte-counter modulus. At about
148,810 frames/s at 100 Mb/s, the 32-bit packets-minus-errors value would
take hours to wrap. Could the frame counters use a longer window?

> +}

[ ... ]

> +	ret = acx00_ephy_read_counter(phydev, ACX00_PAGE9_RX_BYTES_HIGH_REG,
> +				      &counts[ACX00_STAT_RX_BYTES]);
> +	if (ret < 0)
> +		goto out_restore_page;
> +	if (!ret && counts[ACX00_STAT_RX_BYTES] < ACX00_RX_BYTES_WRAP)
> +		valid |= BIT(ACX00_STAT_RX_BYTES);
> +	ret = valid;
> +
> +out_restore_page:
> +	ret = phy_restore_page(phydev, oldpage, ret);
> +	if (ret < 0)
> +		return ret;
> +
> +	for (i = 0; i < ACX00_NUM_STATS; i++) {
> +		u64 count;
> +
> +		if (!(ret & BIT(i)))
> +			continue;
> +		count = counts[i];
> +
> +		/* Include sleep and read time; unseen cycles cannot be recovered. */
> +		if ((priv->stats_valid & BIT(i)) &&
> +		    ktime_ms_delta(ktime_get_boottime(), priv->stats_start[i]) <
> +		    (s64)ACX00_STATS_MAX_INTERVAL_MS) {
> +			if (count < priv->stats_last[i])
> +				count += i == ACX00_STAT_RX_BYTES ?
> +					ACX00_RX_BYTES_WRAP : BIT_ULL(32);
> +			priv->stats[i] += count - priv->stats_last[i];

[Severity: Medium]
Can a single non-monotonic frame or CRC sample permanently add about 2^32
to rx_packets or rx_errors?

Only the byte counter has a plausibility check: samples at or above
ACX00_RX_BYTES_WRAP are skipped. For the CRC counter and the derived
packets-minus-errors value, any sample below stats_last[] counts as a
full 2^32 wrap, and the resulting delta has no upper bound.

An all-ones read is one way this can happen. Suppose the PHY stops
responding on an MDIO controller that returns 0xffff without an error.
acx00_ephy_read_counter() then sees high == check == 0xffff and returns
0xffffffff as a valid sample.

The CRC count reads 0xffffffff on both bracket reads, so packets - errors
is 0 and rx_packets gains 2^32 - N. The next good sample wraps again, and
both totals stay around 2^32 too high.

The other way is if the hardware updates the packet and CRC counters at
different times for the same bad frame. The bracket in
acx00_ephy_read_counts() could then see the frame in packets but not yet
in errors, or the reverse:

	if (errors == counts[ACX00_STAT_RX_CRC_ERRORS]) {
		/* Both hardware counters and their difference wrap at 2^32. */
		counts[ACX00_STAT_RX_PACKETS] = packets - errors;

On the next sample, the -1 would become a jump of 2^32 - 1. Is it known
that the two counters update together?

The commit message bounds the rate at "one frame per received byte". Under
that bound, any real frame delta within the 320 second window is below
4e9. Could frame and CRC deltas in [4e9, 2^32) be rejected, the same way
out-of-range byte samples are?

> +		}
> +		priv->stats_last[i] = counts[i];
> +		priv->stats_start[i] = start;
> +		priv->stats_valid |= BIT(i);
> +	}

[ ... ]

> @@ -350,6 +545,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 = 0;
> +

[Severity: Low]
Does this invalidation happen early enough when phy_mii_ioctl() triggers
the reset?

For SIOCSMIIREG on MII_BMCR with BMCR_RESET, drivers/net/phy/phy.c does:

phy_mii_ioctl()
	mdiobus_write(phydev->mdio.bus, prtad, devad, val);

	if (prtad == phydev->mdio.addr &&
	    devad == MII_BMCR &&
	    val & BMCR_RESET)
		return phy_init_hw(phydev);

Neither call holds phydev->lock. _phy_state_machine() can therefore run
phy_update_stats()->acx00_ephy_update_stats() after the raw reset write
but before acx00_ephy_soft_reset() takes state_lock. stats_active and
stats_valid are still set at that point.

This comment assumes the reset clears the page 9 counters. If it does,
the new values are lower than stats_last[], and __acx00_ephy_update_stats()
treats them as a wrap:

	if (count < priv->stats_last[i])
		count += i == ACX00_STAT_RX_BYTES ?
			ACX00_RX_BYTES_WRAP : BIT_ULL(32);

The totals are kept across resets. Would rx_packets, rx_errors and
rx_bytes then stay inflated by about 2^32 or 4e9?

The window is narrow and needs CAP_NET_ADMIN.

[ ... ]

> @@ -475,10 +674,21 @@ static int __acx00_ephy_config_init(struct phy_device *phydev)

[ ... ]

> +	if (!priv->stats_active) {
> +		/* Establish a new baseline after reset, retaining the software total. */
> +		priv->stats_active = true;
> +		acx00_ephy_snapshot_stats(phydev);
> +	}
>  
> -	return genphy_restart_aneg(phydev);
> +	return 0;
>  }

[Severity: Low]
Should MDIO and page-restore errors from this snapshot be propagated?

acx00_ephy_snapshot_stats() drops every negative return from
__acx00_ephy_update_stats():

	ret = __acx00_ephy_update_stats(phydev);
	if (ret)
		phydev_dbg(phydev, "failed to snapshot statistics: %pe\n", ERR_PTR(ret));

That includes a phy_restore_page() failure after
phy_select_page(phydev, ACX00_PAGE_9).

__acx00_ephy_config_init() then returns 0, so acx00_ephy_config_init()
skips its power-off path. phy_init_hw() and resume report success while
the page register may still be on page 9. Later phy_select_page() calls
would then save page 9 as oldpage and restore back to it.

Every other paged access in config_init propagates the phy_restore_page()
result. The commit message also says:

    Real MDIO errors, including page-restoration failures, still propagate.

That holds for the .update_stats callback, but not for this snapshot.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116-submit-acx00-phy-stats-v1-v6-0-8feef8e76cd5%40gmail.com
Technical Details
Message-ID: <179508961966.3136.18071124735934068397@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-366992-linux-kernel-netdev=dewy.ru
References: <20261116-submit-acx00-phy-stats-v1-v6-3-8feef8e76cd5@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-366992-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v6 3/3] net: phy: acx00: report receive statistics
Date: Thu, 19 Nov 2026 12:00:19 +0000
Organization: Usenet Network
Message-ID: <179508961966.3136.18071124735934068397@kernel.org>
References: <20261116-submit-acx00-phy-stats-v1-v6-3-8feef8e76cd5@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2864997"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:i/4QcUspak8FI7Oh236woQdGoFo= sha256:aaPuQwegoMn2ewJBISeL3NZCrvj40m3hzmKUdyvoB74=
	sha1:6l+2z3FxGbWkmuu4PzfAF4kNDCE= sha256:w5ZnU2VJGxGJpwPsBIbUkotV3Zztgabp0vJaAfetsj4=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 47DE6115613; Thu, 19 Nov 2026 15:00:51 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id gh6CsGLP1PUO;
	Thu, 19 Nov 2026 15:00:45 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-366992-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 2A19B115609; Thu, 19 Nov 2026 15:00:37 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 5B7E92A4048; Thu, 19 Nov 2026 12:00:28 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795089622;
	b=fjPp0ltSRr3doIB5uuPyIMPOVhye4v9//ovyV6vYWYq9tS/fudhJc+qOGTy0j/uNim71
	 m8VKCy34dQHxvwms3Io3RE4tzsM//aihjmKKn3YmPWCwp564UjrGbST7j8+GqZ7p0oU7a
	 E1K/Bqljo00fq6POoJXO5HEWX1JKM9TNIjlExtuV0Game9qD8voNV9sfwtIpLMhfc0289
	 Y40o2zBJuXT8z233JxknbUDTQ53zH5nSBNSurY+O3vDQNfJ8pmnYdPJI1hJIJr3l1qh25
	 w0b1c9JeuOCNnGbK8Tq9vbIckhh7clDjd7bs8p9Ij81jJD60VymXJ1CZRI7RC94DctA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795089622;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=gHihami8Hw3KiT1c9S+seF0Ysxwc1soMqoPWxdiIsBk=;
	b=WBDvNMqK8fYRttR5E3wxytUZnr2fpmiy6F4f5/3jeyDiRMBnqM68lL4zTvVEYamzjMTK
	 2SNrquhPoY1XRD5Ztg1PoFtzj/LjMdNXqptXwMyo+li5+7Ib7TI32dPIMkdckBJa9krLL
	 /n+WFyjwA9CV8dwffIwJHgEF6tDOjHj+N+0+AcE9W1E3yluKvV3Pq9F9Cslmfnkky6JnV
	 IViM3Vw0p+5naXjENDyn7IkwmNHkkj24Ti5WOS/g1RIIud7iK0UIp6WVSbaZlggNlh9cj
	 ze1k2A3Hc3NNuIkFX95EjmtEXcsNPBJXfvOo9DiSe8LtibHIDS9/+/Q1+ZND9UqAedg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=k6NeyC1V;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 1B9C260A2621;
	Thu, 19 Nov 2026 12:00:22 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=k6NeyC1V
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795089621;
	b=NxZYT4Mu7TJxI4S1TkZL9R++XoXwCJmGzLHY28wQ5/2A/3ssXlPdIacO3Z+g5GDhhCK3
	 OYN5VsJYaToyjUxX/kxtWI0bTqlyLcfOu/UPtgyC/M9TLhVHmL11evimTkQKpmmJz0EiX
	 wh6yLble8LYAOeTT7OSQtfVugNiBaRrIMkxeHBOh+dNW6z3fYoV2or+krITx9634eYqMf
	 xopmRjuyi0xYGIpybaPW6jhCT9cGHvOGkiUOnLDYqvgM6/uo/wl9KebqKY+VYqCpgJkfD
	 XwQ9cpnAbOjo6uGLrz45doqcBnGuxTH/srk0luSxQpNKnlOcR26TC/bYqAIiAEoioaw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795089621;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=gHihami8Hw3KiT1c9S+seF0Ysxwc1soMqoPWxdiIsBk=;
	b=kOG0u92cL4rxmRgAzqQG7GYKZvi16mxtiWNHtbWM88D8iA0uek6W0GEDTIpGcVwaLxQY
	 gAzeue703QwPVpoxG/cypb4nVk7+j/4CddlJr28j3VW2fEHkRECdxMD++Kf2rdpHCZnGW
	 ueWj2eg379dcoX+t7SmHZLNdWQDKeXuTs7fSbSfdATPEy+Ykiso5eIR4uHwAXmviVABjQ
	 ZUg70wxruZzH8UsC6bk3YpaiQoUsW97Q/BtqKBnpLdueTwP6ufxaTlgtuMxtGGgFOl4ik
	 ttEP9Gxmw3z07RGR2cRPesdCtQJ0LbU1Z3QEI+r1f90PZgYT/BrnDu9bMPNz/NKwvlQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=k6NeyC1V;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3AEBC60A260B;
	Thu, 19 Nov 2026 12:00:21 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 147D51F000C4;
	Thu, 19 Nov 2026 12:00:20 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795089620;
	bh=gHihami8Hw3KiT1c9S+seF0Ysxwc1soMqoPWxdiIsBk=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=k6NeyC1V7QTcGlRo9j5JxTMLtcKGPG1jCO+hIPseEjsBPeOZr1+nZD5M4AY/c3QQB
	 cZ1uIr0l185IXgx5yEBBCi59vTGshn2Y1sZ3c/TM3nbuvJsKx2gla104H2G1cz3NGv
	 czUA6y/i6nOSeawwVrk4TR9nAAlStjzVa1MkYt16uE/gywoeX5ricXsclZQphOKCoL
	 /p53QMU74w1gX3h2jFsHyCfTD0mP+vCntroGpm3yvDJTiqrMfHQhm/ihQ1LoC487UC
	 3xXAiaoGUd2WyTYepQ8BO1fY702qt97vZL9SXs+djkcb8gtwkhJ8aJNcIhugHb7219
	 pZgE+TVY8GOIg==
X-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
X-In-Reply-To: <20261116-submit-acx00-phy-stats-v1-v6-3-8feef8e76cd5@gmail.com>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list