🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #12762

Re: [PATCH net-next 3/4] net: dsa: motorcomm: Use safe 64-bit counter reader

#12762
From: netdev-bot+sashiko
Date: Sun, 08 Nov 2026 14:22
156 lines
12973 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

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

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] yt921x_counter_read() in drivers/net/dsa/motorcomm/smi.c
  returns a false -EIO for half of the low-word wraps that race with a…
- [Low] "net: dsa: motorcomm: Use safe 64-bit counter reader" fixes a
  user-visible bug, a transient ~4 GiB jump in the 64-bit RX/TX good-…

--

net: dsa: motorcomm: Use safe 64-bit counter reader

This commit changes how yt921x_mib_read() reads the 64-bit MIB counters.
The old code read the low word and then the high word. That is replaced
with a new helper, yt921x_counter_read(), which reads the low word again
and reads the high word again if the low word wrapped. The aim is to
avoid a spurious ~4 GiB jump when the low word wraps between the two
reads.

> diff --git a/drivers/net/dsa/motorcomm/mib.c b/drivers/net/dsa/motorcomm/mib.c
> index 90b0ef670aa31..b45bc82117412 100644
> --- a/drivers/net/dsa/motorcomm/mib.c
> +++ b/drivers/net/dsa/motorcomm/mib.c
> @@ -102,29 +102,26 @@ static int yt921x_mib_read(struct yt921x_priv *priv, int port)

[ ... ]

> -		} else {
> -			u32 val1;
>  
> -			res = yt921x_reg_read(priv, reg + 4, &val1);
> +			buf[i] = val;
> +		} else {
> +			res = yt921x_counter_read(priv, reg, &buf[i]);
>  			if (res)
>  				break;
> -			val = ((u64)val1 << 32) | val0;
>  		}

[Severity: Low]
The commit fixes a user-visible problem: a transient ~4 GiB jump in the
64-bit good-bytes and bad-bytes counters. That jump shows up in ethtool -S
and rtnl_link_stats64. Should it carry a Fixes: tag?

The read removed here, which takes the low word and then the high word in
two separate transactions, has been in the driver since it was added in
drivers/net/dsa/yt921x.c. It was later moved into
drivers/net/dsa/motorcomm/mib.c by 25265e7ccdb51b. That would suggest:

Fixes: 186623f4aa72 ("net: dsa: yt921x: Add support for Motorcomm YT921x")

> diff --git a/drivers/net/dsa/motorcomm/smi.c b/drivers/net/dsa/motorcomm/smi.c
> index bf3adfd64165a..16f62409422d5 100644
> --- a/drivers/net/dsa/motorcomm/smi.c
> +++ b/drivers/net/dsa/motorcomm/smi.c
> @@ -63,6 +63,41 @@ int yt921x_reg_update_bits(struct yt921x_priv *priv, u32 reg, u32 mask, u32 val)
>  	return yt921x_reg_write(priv, reg, u);
>  }
>  
> +/* Reliably read a 64-bit counter, assuming the counter isn't that "fast" */
> +int yt921x_counter_read(struct yt921x_priv *priv, u32 reg, u64 *valp)
> +{
> +	u32 old_lo;
> +	int res;
> +	u32 hi;
> +	u32 lo;
> +
> +	res = yt921x_reg_read(priv, reg, &old_lo);
> +	if (res)
> +		return res;
> +
> +	res = yt921x_reg_read(priv, reg + 4, &hi);
> +	if (res)
> +		return res;
> +
> +	res = yt921x_reg_read(priv, reg, &lo);
> +	if (res)
> +		return res;
> +
> +	if (lo < old_lo) {
> +		u32 new_hi;
> +
> +		res = yt921x_reg_read(priv, reg + 4, &new_hi);
> +		if (res)
> +			return res;
> +		if (new_hi != hi + 1)
> +			return -EIO;

[Severity: Medium]
Can this return -EIO for a read that is actually consistent?

The reads happen in this order:

  t0: old_lo = [reg]
  t1: hi     = [reg + 4]
  t2: lo     = [reg]
  t3: new_hi = [reg + 4]   (only if lo < old_lo)

lo < old_lo only shows that the low word wrapped somewhere between t0 and
t2.

If the wrap happens between t1 and t2, then hi == H and new_hi == H + 1,
so the check passes.

If the wrap happens between t0 and t1, the carry is already in the high
word when hi is read. Then hi == H + 1 and new_hi == H + 1 == hi. The
(hi, lo) pair is a valid snapshot, but new_hi != hi + 1 rejects it with
-EIO.

The t0..t1 window is one SMI transaction, the same size as the t1..t2
window. So roughly half of the wraps that race with a read would take
this path. At 1 Gb/s the low words of the good-bytes and bad-bytes
counters wrap about every 34 seconds.

When it happens, yt921x_mib_read() breaks out of its descriptor loop, so
the remaining counters for that port are not refreshed. The partially
refreshed buffer is still published, and this message is logged:

  Failed to read stats for port N: -5

In addition, yt921x_mib_poll() backs off:

	if (res)
		delay *= 4;

That moves the poll interval from 3 seconds to 12 seconds, for a bus
error that never occurred.

The later "net: dsa: motorcomm: Prevent rx_bytes/tx_bytes underflow"
change drops the whole sample for that cycle instead. It does not touch
yt921x_counter_read(), so the false -EIO is still present after it.

Would it work to accept new_hi when it equals either hi or hi + 1 and
pair it with lo? Another option is a hi/lo/hi read that retries while
the two hi values differ.

> +		hi = new_hi;
> +	}
> +
> +	*valp = ((u64)hi << 32) | lo;
> +	return 0;
> +}

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261107132040.1066996-1-mmyangfl%40gmail.com
Technical Details
Message-ID: <179414774900.994134.836318177639068785@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-358761-linux-kernel-netdev=dewy.ru
References: <20261107132040.1066996-4-mmyangfl@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-358761-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next 3/4] net: dsa: motorcomm: Use safe 64-bit counter reader
Date: Sun, 08 Nov 2026 14:22:29 +0000
Organization: Usenet Network
Message-ID: <179414774900.994134.836318177639068785@kernel.org>
References: <20261107132040.1066996-4-mmyangfl@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="139870"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:1uHMn4ihe76UdPT9P5Q1LRE/0C8= sha256:KTxVZuuVkDjUIASwtQRshvjXNfEeIC4rum5Seyr7j5M=
	sha1:3Z+TFEigrk66LH0wKFhRzwRGTp4= sha256:9aGrhxqWh6lr4T1lRnHLsMo3YudagA9FfGOevgMgylk=
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 D048E11359A; Sun,  8 Nov 2026 17:24:26 +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 gggCZNCuyFVa;
	Sun,  8 Nov 2026 17:24:22 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-358761-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 55D62113596; Sun,  8 Nov 2026 17:24:14 +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 8AF4A61171; Sun,  8 Nov 2026 14:22:31 +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=1794147751;
	b=oo5mYTQ7y4NjgpiZwxuNw3AAP7Jv74jkFzSiRy210XnA8M0bIqP3Tsb8z+39VgJE3VHw
	 WwsUCIfBRlqlw89CBzZcrAeN8Q4M9zunrwKEnhpvoWjWF1poSMq4IzB7DuFDHpzD7tqNu
	 LoeEXXHofZRvp+o0dwujtEe7JkbuMuKXyIv8dZDx2NPENOT5EdQ+REUvfkucPZL1PkwM/
	 Vwgjl2wke3ncuH30ShQbesYSovji9N8WDzRFsU3P6NMJUewHqoFkWO99SuSYWmjbn9Rjz
	 ksKh+p40YZfEoa62kXQLt87mZnKGeTv2Rtyc0xPiiTYaoNK6ZDGp5XmKDV9qknMyGTg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794147751;
	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=8nSnyp4qIY+eMxZ+jWwWlVQJaqb6UKomcauQ+sOlv74=;
	b=1kNL9+5aszoUB7E1KaQctVKY1l19PRIL/9CcZTLGQpGBncQpHEIw80xJJ9rdKLs+3SXh
	 NAWcXEMP6wNHsXKbcPoO3bKyw+zEuLbP1OWzm4OgicAUujobSJqBTVxu84IR3fRaCrFfS
	 FdDD0e5GgWbwLQPjmg1rTSlW0vOwtz7MicL64VECrgumXggL82zQe1opyLNsRsQgKralb
	 gCGlowH0yxUa9gUAKPNoYdi3ny8ndnUr0O3BWXA9tAlZxxzN6vT+R3FYwUDNoY3m94XqJ
	 5x+bR7QXwCM8jsELh9zifUFEDdihgHnh7PLTAvdfWWqA01fDxLWwFtVlimfqj2MzHfg==
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=BR6d+siC;
	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 63A4C606A338;
	Sun,  8 Nov 2026 14:22:31 +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=BR6d+siC
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=1794147750;
	b=t6nBxBCSHaI5mywXb/QjTqqEPVl3gZItVqS57FosR61Mr2J5fBuMgiiwJ2qpGMEov9ol
	 BffYBROCX6PpkLLE2xHb52pf5uabTc+wukbMCdvVeiNh6meBckh5V65PjqOw1k+RnFP8+
	 DQiaI0zFEg1FuhtR/2eIwb2IRYrVOTw4DrMVRuSGOVI0O+52b48Q2lXpX4TJxgnjCbg2O
	 DY0pIFrrvfktdkVea4/EQSRWTprP19Ll2e1uGV0r36/PBMDz1pTafEoREWyoq1Ky+YZNE
	 V8W11Eu8OuSThFiV9Tny7qI3XBkESexXOIvPluURX+iB8DXnS/3w34YLmoQLA0otIYg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794147750;
	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=8nSnyp4qIY+eMxZ+jWwWlVQJaqb6UKomcauQ+sOlv74=;
	b=mz9VcawaIUXe4NQUKbvI1KY/vpNN4rYaxqCMKRdwHkWBhPDtnhygiIIf/PhwSz1QcJN1
	 QVJ69REEGshLDFe2ZST3kMhCPvHEkjcpli8OgHy8waTfNQ/YAJYcnh3QspM8ZvqhhPcn5
	 Buc44CnaL040bhaYO5JvwUh/2JG2FuTPvKkRVC9psxpLrNZORfLX7hOJhj2tUGuZD/iN2
	 DkEoNwi3uU9yqBtIbMeUrEN0PRQ1SbQVbeE0d24x3Hv4SrrBe5TuT5sF+O0IQNL/E7bQL
	 1B7YDvfRTr7PwOQqQG0jJG6or8SUX2lhOXYMEYu/4YWI654DJdodclmqOVZ6yH0hekg==
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=BR6d+siC;
	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 3F965606A331;
	Sun,  8 Nov 2026 14:22:30 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6720C1F0089F;
	Sun,  8 Nov 2026 14:22:29 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794147749;
	bh=8nSnyp4qIY+eMxZ+jWwWlVQJaqb6UKomcauQ+sOlv74=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=BR6d+siCVXoHe+4BaQgvXxUzZKyolUL4fCaEOmHQuNmqygG+idw61mbvLKmiyxX9A
	 5iyZg9dRKtZTo3J6mV9F9zhEsvysqNOvQwveT1o2nSqmUzI6pbOe6Ta6Rf5v5nZeMc
	 mfWsgb0wcJt/0HPbEf4K5YptCnnWeEriaSBgzcIGxd7i8adg0RgzrJkqd9VxUkNNsy
	 LdJVPw2n72R9d0whtwE8Yyv8/fo9r4NZxfVciO8ck/S2WaAtMz5ICSj6vZHx1E2xIC
	 IB59w4T/7aIQMIMESwAr1VrMRNJx512GnptBeEjnufF1R26lH35jirI7klk7aw15h9
	 IMFZ41N1FIW7Q==
X-Cc: netdev@vger.kernel.org, andrew@lunn.ch, olteanv@gmail.com,
 davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
 linux-kernel@vger.kernel.org
X-In-Reply-To: <20261107132040.1066996-4-mmyangfl@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