🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #23868

Re: [PATCH net 1/2] net: dsa: realtek: rtl8365mb: reset SerDes data path when conduit comes up

#23868
From: netdev-bot+sashiko
Date: Sat, 28 Nov 2026 13:21
192 lines
14953 bytes
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 2 · 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] rtl8365mb_conduit_state_change()
  (drivers/net/dsa/realtek/rtl8365mb_main.c) resets the port-6 SerDes…
- [Medium] The patch adds a caller of the SerDes indirect-access window
  that is not serialised against the existing ones.
- [Low] rtl8365mb_conduit_state_change() reads the plain bool
  mb->sds_in_use under rtnl only, with no READ_ONCE and no shared lock,…

--

net: dsa: realtek: rtl8365mb: reset SerDes data path when conduit comes up

This patch moves the SerDes data path reset out of rtl8365mb_pcs_config()
into a new helper, rtl8365mb_sds_reset_datapath(). The helper is called
again from a new .conduit_state_change() callback when the conduit becomes
operational. This fixes the FCS errors seen on the CPU port of an RTL8367S
connected to an IPQ5018 over HSGMII.

> diff --git a/drivers/net/dsa/realtek/rtl8365mb_main.c b/drivers/net/dsa/realtek/rtl8365mb_main.c
> index da06f952a053d..54d90121ecd26 100644
> --- a/drivers/net/dsa/realtek/rtl8365mb_main.c
> +++ b/drivers/net/dsa/realtek/rtl8365mb_main.c

[ ... ]

> @@ -1492,7 +1501,13 @@ static int rtl8365mb_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode,
>  	val &= ~RTL8365MB_SDS_NWAY_EN_MASK;
>  	val |= RTL8365MB_SDS_NWAY_RESTART_MASK;
>  
> -	return rtl8365mb_sds_write(priv, RTL8365MB_SDS_REG_NWAY, val);
> +	ret = rtl8365mb_sds_write(priv, RTL8365MB_SDS_REG_NWAY, val);
> +	if (ret)
> +		return ret;
> +
> +	mb->sds_in_use = true;

[Severity: Low]
mb->sds_in_use is written here under the phylink state_mutex. The new
rtl8365mb_conduit_state_change() reads it with only rtnl held, with no
READ_ONCE() and no shared lock, and then touches the SerDes:

	if (!operational || !mb->sds_in_use)
		return;

	ret = rtl8365mb_sds_reset_datapath(priv);

Once set, the flag stays true until the next rtl8365mb_setup(). So it does
not exclude a later rtl8365mb_pcs_config() reprogramming the SerDes from
the phylink_resolve() worker.

Isn't this the flag-as-gate pattern, where a flag decides whether to touch
shared hardware state without a lock held?

On its own the effect is small. A stale read only skips one extra reset or
lets one through. A fix for the SDS window race described below would need
to do the sds_in_use check and the data path reset under the same lock that
rtl8365mb_pcs_config() and rtl8365mb_pcs_get_state() hold. Locking each SDS
access separately would not be enough.

The final patch in the series keeps the same lockless check.

> +
> +	return 0;
>  }

[ ... ]

> @@ -3079,6 +3094,29 @@ static int rtl8365mb_reset_chip(struct realtek_priv *priv)

[ ... ]

> +static void rtl8365mb_conduit_state_change(struct dsa_switch *ds,
> +					   const struct net_device *conduit,
> +					   bool operational)
> +{
> +	struct realtek_priv *priv = ds->priv;
> +	struct rtl8365mb *mb = priv->chip_data;
> +	int ret;
> +
> +	if (!operational || !mb->sds_in_use)
> +		return;

[Severity: Medium]
Should this check which conduit changed state? The conduit argument is
not used. Nothing checks that port 6 is a CPU port, or that it is the CPU
port behind this conduit.

The DSA core does not filter these calls either.
dsa_switch_conduit_state_change() forwards every conduit's change:

net/dsa/switch.c:dsa_switch_conduit_state_change() {
    ...
	ds->ops->conduit_state_change(ds, info->conduit, info->operational);
    ...
}

The SerDes PCS is not limited to CPU ports. For any SerDes interface,
rtl8365mb_phylink_mac_select_pcs() returns it:

	if (rtl8365mb_interface_is_serdes(interface))
		return &mb->pcs;

and rtl8365mb_pcs_config() sets sds_in_use whatever role port 6 has.

RTL8367S/RTL8367SB also have a second external interface, RGMII on port 7:

	{ 6, 1, PHY_INTF(SGMII) | PHY_INTF(HSGMII) },
	{ 7, 2, PHY_INTF(MII) | PHY_INTF(TMII) | PHY_INTF(RMII) | PHY_INTF(RGMII) },

This matters in two setups: port 7 is the CPU port and port 6 is an
SGMII/HSGMII user port, or ports 6 and 7 are both CPU ports. In either
case, if the port 7 conduit comes up or its carrier flaps (NETDEV_CHANGE),
won't this write DPRST_PHASE1/PHASE2 to the port 6 SerDes BMCR? That
would flush the FIFOs and resync the PLL on a port 6 link that may be
carrying traffic.

The later patch "net: dsa: realtek: rtl8365mb: soft reset switch core
after conduit comes up" keeps the same unfiltered check
(if (!mb->sds_in_use) return;). It also schedules a soft reset of the
whole switch core 3 seconds after any conduit becomes operational. By the
end of the series this would affect every switch port.

> +
> +	ret = rtl8365mb_sds_reset_datapath(priv);

[Severity: Medium]
Can this race with the phylink_resolve() worker on the SerDes indirect
access window?

rtl8365mb_conduit_state_change() runs from the conduit netdev notifier
with only rtnl_lock held. Each rtl8365mb_sds_write() is three separate
regmap transactions: DATA, ADR, then CMD=RUN|WR. rtl8365mb_sds_read() is
ADR, CMD=RUN, a busy poll, then DATA. priv->map_lock only covers one
transaction at a time.

Before this patch, every SDS access came from the port 6 PCS ops, and
phylink serialises those with pl->state_mutex. phylink_resolve() takes
state_mutex but not rtnl. It can reach the SDS window two ways:

phylink_resolve()
  rtl8365mb_pcs_get_state()
    rtl8365mb_sds_read(priv, RTL8365MB_SDS_REG_LINK_STATUS, &status)

This path is polled, because rtl8365mb_setup() sets mb->pcs.poll = true
for in-band mode.

phylink_resolve()
  phylink_major_config()
    rtl8365mb_pcs_config()

This path runs when a PHY switches between SGMII and 2500BASE-X.

One possible interleaving:

conduit path                         resolve worker
DATA = DPRST_PHASE1
ADR = BMCR
                                     ADR = LINK_STATUS
CMD = RUN | WR

Here PHASE1 would land in the link status register instead of BMCR.

Other interleavings are possible too. If a read is in flight, a concurrent
CMD=RUN|WR could write the read result into BMCR. The jam table writes and
the NWAY read-modify-write in rtl8365mb_pcs_config() could also be
corrupted.

The OCP PHY window in rtl8365mb_phy_ocp_read() and
rtl8365mb_phy_ocp_write() uses rtl83xx_lock() and priv->map_nolock for
this reason. Does the SDS window need a similar lock? As far as I can
tell, the final patch in the series does not add one.

> +	if (ret)
> +		dev_err(priv->dev, "failed to reset SerDes data path: %pe\n",
> +			ERR_PTR(ret));
> +}

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261127-rtl8365mb-hsgmii-fix-v1-0-f2827126aa6a%40littleit.sk
Technical Details
Message-ID: <179587210150.3135.11248119595029474130@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373124-linux-kernel-netdev=dewy.ru
References: <20261127-rtl8365mb-hsgmii-fix-v1-1-f2827126aa6a@littleit.sk>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373124-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net 1/2] net: dsa: realtek: rtl8365mb: reset SerDes data
 path when conduit comes up
Date: Sat, 28 Nov 2026 13:21:41 +0000
Organization: Usenet Network
Message-ID: <179587210150.3135.11248119595029474130@kernel.org>
References: <20261127-rtl8365mb-hsgmii-fix-v1-1-f2827126aa6a@littleit.sk>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="954343"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:pBTzwdQ7CohGdnmFZEUyNxy2wgk= sha256:WYKjFEOlbyjSWedBwiuhFtPPfumTXvVGWckSNazRD70=
	sha1:i4RnliV+rPq7hZWT9TNoZrqwScs= sha256:Li6OkIVaC11wHkQDfuKe7cxLkp6L3dtJOPYD73KkeFQ=
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 CF906125F80; Sat, 28 Nov 2026 16:22:01 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.5
X-Spam-Status: No, score=-3.5 tagged_above=-9999 required=6.31
	tests=[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 h1Z-6ulWfvDL;
	Sat, 28 Nov 2026 16:21:56 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-373124-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 6509D125F77; Sat, 28 Nov 2026 16:21:45 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 94D2C29B61; Sat, 28 Nov 2026 13:21:44 +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=1795872104;
	b=XUaRU+y84Q2F6UGHJ7P/Ihl/+KRdYLdCxS1S4tUv81zKO6kh4pNSlFMn4s1mFTIffXzU
	 mE5lfHeFKfCqfmRwYD+oG5SqXmlXnMjaCzbZ/E4NXjSxSi782BUwI/Utx0xf8C7sWDx9K
	 ps8X6f+sfo4q9w3J8dlz5Gu76iqGYTiY5abb8h73UqZd909Cr9vDHXXtqjPdPmQn0hem9
	 99hbWOZ2tnG4qtuau7RzThiulNhXaoulo+IbPG2FwV3k6Exge7DB0xbct1HqgrQk3LBvN
	 GoJZXvgxYYn/1qWgfCs/qwFBmOMKzYtTr/VJ87KSEWrK12OJGnJrwz7/vrNW3rQXekQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795872104;
	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=mO4qUhdZZZgqvziVcMAjaWJozOiYG28GexeiFi/jFBs=;
	b=WX762w8ILfJHNDk07BKbObJo0hgW21tYGiLEiSonRSrm9qrWhwOfnErFP/fGYaypzshx
	 hgnhqKIHCAHbEHzIC/yUL5k7tVB83PjxylWPfjJuKgSFcR0mE7Qm4tQ0eJL3CZ/EITscm
	 B601kUe4/w93WOOZvADnUFTagjW8Nqb916TzKLUNxRk19nrI2rP04oMZ5sLX4GiZbze/8
	 PVrR0JhxAvNGuFaSaoQs4XrnghpL3baCKdZ9u8O5FeHndAKMdNj8H1SfJuI/NEBZzWXlK
	 ZBH10nb30ry0pFbgFTJ98lDi/0lKL21vdq3PnMXMMrvG7BnK0z6Xaxecg3hPQirxBdg==
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="omjZRf/Q";
	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 EA9B2606A326;
	Sat, 28 Nov 2026 13:21:43 +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=omjZRf/Q
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=1795872103;
	b=OQlxD/7fM3nHr0dJUS9w1iI+MPkoR1uf9M8fKGRlpKUFH8oNd0CWXURkO7dAACRboBEN
	 EkC6ly4rRdUXxLGbidruh0MfBsMMzfrFU+3ui3Ur+H2PjrumdzzSqbBw96sk6d8JpUa3f
	 u3bIJj+zZ8nW7+LBg/+SEDFDn9AM8z93HRS1dMwOY2feP3P6yyukvxozFFfLdoEBEoATc
	 GtLI8QO4nOt+2xkGF34MUw6WnOrWEb8C1dE2Fed89rxXoU228a8oj+l+jvtVy1SxYcd8V
	 pSfUF58aSRR/zuhvXmq8kB01QGN2akNE/CXnVua8f5ZYh3KhBb+IsRP52AQJC+n90Dg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795872103;
	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=mO4qUhdZZZgqvziVcMAjaWJozOiYG28GexeiFi/jFBs=;
	b=fUGyjnN0n1tfwTDSV8uED4VRLGd70vl3BIuEi0zmsLo4D6O0m3XiYfbmDeNiaNnNxOMl
	 qkuRME9lySjil/5BcuztIiVUclI6lVIJN0QpolRf5YGPuSRc7FS11YQzVg1kPDT3m+aUn
	 4flxItA2dy/b+7CLRlOeP1pOngJnSDuimp9nkq74kABUzrk/b4EQXikUCsc9uPdG60LMr
	 JQwDpUBrH8Aru9xZOT2lL2dqV+SNNL/sjE9UmXLD0eW4mRkch7AedecdF5JIUgy4OzC7L
	 WWLP2UCYfj5ap2b7okZC8bbxQLd81broXXZoJJnKjTIHqwsEnifsYTFI2W7YpFcLf3Q==
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="omjZRf/Q";
	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 10339606A31C
	for <netdev@vger.kernel.org>; Sat, 28 Nov 2026 13:21:42 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id E91A51F000C1;
	Sat, 28 Nov 2026 13:21:41 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795872102;
	bh=mO4qUhdZZZgqvziVcMAjaWJozOiYG28GexeiFi/jFBs=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=omjZRf/QmnkOc2Slc8jm5FHNzT0fkPU3eYAHSaouCYa5p644hrmlwQor+jBGkZkow
	 TQPhm0hK0ba2ogBoSEawCfuNgtJdfY6ggQsUcvkt7XSdImH3+MaLdRK2bxK72d5BRW
	 qQJPACooeltQ0p+Nn2KSPhO0sL2nvVvWsMnLnsgdFlTRqKLx9Bk59R3tWR4yZTqbF0
	 CA4K6JmSdHJ658fROYgfjTbWznLknMTydsYflY/66A0Whjfm+8fAncGRuWkZxYEIav
	 DklNUAXIpGPVTiSFGLZYxSV+ahJH1NdvOUW1I0b82XCdThmUBi9rs9mROb2h+IfYQX
	 9OhMt6PsO0OyQ==
X-Cc: linusw@kernel.org, luizluca@gmail.com, alvin.sipraga@analog.com,
 andrew@lunn.ch, olteanv@gmail.com, davem@davemloft.net, edumazet@kernel.org,
 kuba@kernel.org, pabeni@redhat.com, linux@armlinux.org.uk, contact@c127.dev,
 netdev@vger.kernel.org
X-In-Reply-To: <20261127-rtl8365mb-hsgmii-fix-v1-1-f2827126aa6a@littleit.sk>
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