From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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 ; Sat, 28 Nov 2026 13:21:42 +0000 (UTC) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E91A51F000C1; Sat, 28 Nov 2026 13:21:41 +0000 (UTC) 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== Subject: Re: [PATCH net 1/2] net: dsa: realtek: rtl8365mb: reset SerDes data path when conduit comes up From: netdev-bot+sashiko@kernel.org To: juraj.sladek@littleit.sk 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 Date: Sat, 28 Nov 2026 13:21:41 +0000 Message-ID: <179587210150.3135.11248119595029474130@kernel.org> In-Reply-To: <20261127-rtl8365mb-hsgmii-fix-v1-1-f2827126aa6a@littleit.sk> References: <20261127-rtl8365mb-hsgmii-fix-v1-1-f2827126aa6a@littleit.sk> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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