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=1796468932; b=KSigQIv0LLuA9idpk8A0Oeo+jyU7Vyb8NLk2VXn+B66tl99KnAIF0qLvgku7jUKxDR1Y B1TccZsRl7Gy6uRyqcdIHw+HO8TFgJoM8DzZBKIYB6H0Z/2RjvN8/PWSCmivN3cDeHYQG F1bzSsAIN7DiutuBHf6lpuXmYIL/ALFQtq6lalcJQSHL5rwngZBIXu9LDPj7t/ahVM4jF eJTCXIJiiQzgNX1FJiA3QF4GicK4OErX22cO83uLrcugjLX3jhJkwm3GhAC4Y2qrMUdb5 hzxUZ0i4x0nyzRtd7/WLcjcfPTockTzw8e0rv3rBBbCQEO0A4n8nscvNpFCrGdtiiMQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796468932; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=EDYn1qzAjPrusUO8hhflgQv9GhV0uci00IZ43H5SZ9E=; b=uIZSTxg2l0OTs8394rMRXZY6jez7tUZle6v1/C5grdVhDQUHeGNU9umhe/jx2Udie+F0 pZQgjneeOTcIjb0RkxPDoNko958VDNP9nIw6FFYQp5eTF1WqIPxJvbeDGqvo73LLdRGzD cnPB7GWVzwITFAinNNXxVCzpJsFJvpvBP5iSNYV/QFMiRtv15ptzUs15Kgx4sbP3UShh9 rT3G6+5kaqprHUi+QutCLIT9bhPvqNr5W6co9V7/tGPamw0p9MnWVo6Y38MibORaJX/9k K79J5rxI1grv2blrQ5UpgwddlDHzP6XQtbSM79fSzs87jIUSjkfaHyElhwKjyaXrgoA== 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=hbH1KWrx; 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 F0767606A335 for ; Sat, 5 Dec 2026 11:08:51 +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=hbH1KWrx Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE2561F0092B; Sat, 5 Dec 2026 11:08:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796468931; bh=EDYn1qzAjPrusUO8hhflgQv9GhV0uci00IZ43H5SZ9E=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=hbH1KWrxZmL36YxyGPBpLKXFtnWKe/KPdJ6Be0TkEianOU6kuwSuM4fnCMq9XeHy1 mmbou4rc6MqFPF2sX2f5Y0BhR+7t9AE9R69l5S1vateAZUs+mEN0b/uEP9YOQEmg8a ZYaUUnJM2RPShyMS7vi2cBW2517egh+PaKDUXoVdGjYBa3nXJJH3kEmCFvIzf/b9ex cl9YMVUKQgKrew67y6QZJdpGaTis3qU5Ch3dOsrAowDkOWHgyYR5JAAvO/F5wuJQkS +V3AJ2+etrFF6pknO6vgTQUekYIQxQDjYDPsV+MrmP8SATnENZvOhYlJ6nKMREyMYs /azZ3vVdpq5hA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH net-next 10/12] net: phylink: Support an SFP cage behind a phy_mux Reply-To: sashiko-reviews@lists.linux.dev To: "Maxime Chevallier" Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261204110622.1106492-11-maxime.chevallier@bootlin.com> References: <20261204110622.1106492-1-maxime.chevallier@bootlin.com> <20261204110622.1106492-11-maxime.chevallier@bootlin.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 11:08:51 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 7 potential issues to consider: - [Medium] net: phylink: stale sfp_link_down after stop/remove/detach breaks LOS gating - [Medium] net: phylink: phylink_start() runs resolve before mux selects SFP port - [Medium] net: phylink: phylink_mux_select() clears DISABLE_LINK before reconfiguring - [Medium] net: phylink: missing sfp_mod_present rollback on may_have_phy module failures - [Medium] net: phylink: phylink_mux_deselect() does not bring down active SFP link - [Medium] net: phylink: data race on mux_sfp_port in phylink_mux_attach() - [Medium] net: phylink: missing rtnl_lock() in phylink_destroy() mux detach -- commit 0d6f64bddfb5d3b2e43faf1b89e62b3654b6ad2b Author: Maxime Chevallier net: phylink: Support an SFP cage behind a phy_mux This commit teaches phylink to discover an SFP cage described on a phy_mux port, report module availability to the mux, and handle selecting and deselecting the SFP port. > diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c > index 702614adcb945..6d62bd37f95a6 100644 > --- a/drivers/net/phy/phylink.c > +++ b/drivers/net/phy/phylink.c [ ... ] > @@ -2150,6 +2179,7 @@ static void phylink_detach_mux(struct phylink *pl) > =20 > phy_mux_detach(pl->mux); > pl->mux =3D NULL; > + pl->mux_sfp_port =3D NULL; > } [Severity: Medium] Can phylink_destroy() race with phy_mux_state_machine() and cause a use-after-free of pl when calling phylink_detach_mux(pl) without rtnl_lock()? phylink_destroy() runs without rtnl_lock() and calls sfp_bus_del_upstream(pl->sfp_bus) followed by phylink_detach_mux(pl) and kfree(pl). With this patch, phylink_sfp_detach() calls phy_mux_port_set_available(pl->mux_sfp_port, false), which queues mux->state_work right before sfp_bus_del_upstream() drops rtnl_lock(). Because phy_mux_stop() inside phy_mux_detach() uses cancel_work() rather than cancel_work_sync(), phylink_destroy() can free pl while the worker is still running: CPU0 CPU1 (kworker) phylink_destroy() sfp_bus_del_upstream() rtnl_lock() phylink_sfp_detach() phy_mux_port_set_available(..., false) phy_mux_trigger(mux) rtnl_unlock() phy_mux_state_machine() rtnl_lock() phylink_detach_mux(pl) phy_mux_select(...) phy_mux_detach(pl->mux) phy_mux_stop(mux) cancel_work(&mux->state_work) kfree(pl) mux->pops->select(..., pl) <-- use-after-free of pl Drivers such as ucc_geth (ucc_geth_remove()) or lan743x (error path in lan743x_netdev_open()) can reach phylink_destroy() with pl->mux still attached. Independently, phy_mux_unregister() can also run phylink_detach_mux(pl) concurrently under rtnl_lock(), risking double phy_detach() / device_link_del() or use-after-free. Wrapping phylink_detach_mux(pl) in rtnl_lock() / rtnl_unlock() inside phylink_destroy() would serialize both paths before kfree(pl). [ ... ] > @@ -2766,6 +2796,9 @@ void phylink_start(struct phylink *pl) > phy_start(pl->phydev); > if (pl->sfp_bus) > sfp_upstream_start(pl->sfp_bus); > + if (pl->mux_sfp_port) > + phy_mux_port_set_available(pl->mux_sfp_port, > + pl->sfp_mod_present); > if (pl->mux) > phy_mux_start(pl->mux); > } [Severity: Medium] Can phylink_resolve() bring the link up prematurely here before the mux selects the SFP port? Earlier in phylink_start(), phylink_enable_and_run_resolve(pl, PHYLINK_DISABLE_STOPPED) clears PHYLINK_DISABLE_STOPPED and schedules pl->resolve. Because phylink_sfp_link_down() returns early without setting PHYLINK_DISABLE_LINK while !pl->sfp_selected, pl->phylink_disable_state becomes 0. When an SFP module is already inserted with pl->sfp_link_down true, phy_mux_port_set_available() runs while mux->state is still PHY_MUX_STOPPED, so phy_mux_start() defers port selection to phy_mux_state_machine(). That worker must wait for rtnl_lock(), whereas phylink_resolve() does not: CPU0 (under rtnl_lock) CPU1 (kworker) phylink_start() phylink_enable_and_run_resolve( pl, PHYLINK_DISABLE_STOPPED) phy_mux_port_set_available(...) phy_mux_start(pl->mux) phy_mux_trigger(mux) phylink_resolve() phylink_disable_state =3D=3D 0 <-- premature link-up rtnl_unlock() phy_mux_state_machine() rtnl_lock() phylink_mux_select(SFP) set PHYLINK_DISABLE_LINK This allows a spurious carrier-up and flap before SFP startup and LOS checks complete. [ ... ] > @@ -4096,18 +4143,27 @@ static int phylink_sfp_module_insert(void *upstre= am, > pl->sfp_may_have_phy =3D caps->may_have_phy; > pl->sfp_port =3D caps->port; > =20 > + phylink_sfp_set_present(pl, true); > + > /* If this module may have a PHY connecting later, defer until later */ > if (pl->sfp_may_have_phy) > return 0; > =20 > - return phylink_sfp_config_optical(pl); > + ret =3D phylink_sfp_config_optical(pl); > + if (ret) > + phylink_sfp_set_present(pl, false); > + > + return ret; > } [Severity: Medium] Does this leave pl->sfp_mod_present and pl->mux_sfp_port->available stuck true when a may_have_phy module fails deferred setup? For copper or other may_have_phy modules, validation is deferred to phylink_sfp_connect_phy() or phylink_sfp_module_start(). Neither function calls phylink_sfp_set_present(pl, false) on failure (for example when !phy->drv or phylink_sfp_config_optical() fails), and sfp_sm_main() transitions straight to SFP_S_FAIL without calling sfp_module_remove(). That leaves the mux stuck on the rejected SFP port until the module is physically removed. Also, calling phylink_sfp_set_present(pl, true) before phylink_sfp_config_optical() synchronously switches the mux and stops an active PHY port before discovering that an optical module is unsupported, causing an unnecessary link bounce when it rolls back. [ ... ] > @@ -4268,6 +4332,7 @@ static void phylink_mux_attach(struct phy_mux *mux,= void *priv) > phy_mux_set_mac_managed_pm(mux); > =20 > pl->mux =3D mux; > + pl->mux_sfp_port =3D phy_mux_get_sfp_port(mux); > } [Severity: Medium] Is there a data race on pl->mux_sfp_port between phylink_mux_attach() and the SFP callbacks? phylink_create() registers the SFP upstream before phylink_of_phy_connect() attaches the mux, and probe-time callers such as dsa_user_create() and ocelot_port_phylink_create() call phylink_of_phy_connect() without holding rtnl_lock(). In that window, phylink_mux_attach() writes pl->mux_sfp_port under phy_mux_mutex while phylink_sfp_set_present() and phylink_sfp_detach() read it under rtnl_lock(): CPU0 (probe, phy_mux_mutex) CPU1 (SFP work, rtnl_lock) phylink_of_phy_connect() phylink_attach_mux() phylink_mux_attach() pl->mux_sfp_port =3D ... phylink_sfp_module_insert() phylink_sfp_set_present() if (pl->mux_sfp_port) <-- data race > @@ -4277,6 +4342,19 @@ static int phylink_mux_select(struct phy_mux *mux,= struct phy_mux_port *port, > struct phy_device *phy; > int ret; > =20 > + if (port->type =3D=3D PHY_MUX_PORT_SFP) { > + if (!pl->sfp_bus) > + return -ENODEV; > + > + pl->sfp_selected =3D true; > + if (pl->sfp_link_down) > + phylink_run_resolve_and_disable(pl, PHYLINK_DISABLE_LINK); > + else > + phylink_enable_and_run_resolve(pl, PHYLINK_DISABLE_LINK); > + > + return 0; > + } > + > if (port->type !=3D PHY_MUX_PORT_PHY) > return -EOPNOTSUPP; [Severity: Medium] Can pl->sfp_link_down stay stale false after phylink_stop(), phylink_sfp_module_remove(), or phylink_sfp_detach(), bypassing SFP LOS link gating? Once an SFP link comes up, phylink_sfp_link_up() clears pl->sfp_link_down. When phylink_stop() calls sfp_upstream_stop(), sfp_sm_device() changes sm_dev_state to SFP_DEV_DOWN before sfp_sm_main() runs, so sfp_sm_main() skips sfp_sm_link_down() (which is gated on sm_dev_state =3D=3D SFP_DEV_UP) while resetting sm_state to SFP_S_DOWN. Neither phylink_stop(), phylink_sfp_module_remove(), nor phylink_sfp_detach() resets pl->sfp_link_down =3D true. If the interface is later reopened with RX_LOS asserted or a new module inserted, phylink_mux_select() sees stale pl->sfp_link_down =3D=3D false and clears PHYLINK_DISABLE_LINK. Because sfp_sm_link_check_los() moves straight to SFP_S_WAIT_LOS without calling sfp_sm_link_down(), PHYLINK_DISABLE_LINK remains cleared and carrier can come up while LOS is asserted. > @@ -4291,7 +4369,10 @@ static int phylink_mux_select(struct phy_mux *mux,= struct phy_mux_port *port, > return ret; > } > =20 > + clear_bit(PHYLINK_DISABLE_LINK, &pl->phylink_disable_state); > + > pl->link_config.interface =3D port->interface; > + pl->req_link_an_mode =3D pl->cfg_link_an_mode; > phylink_mac_initial_config(pl, false); > phy_start(phy); [Severity: Medium] Should PHYLINK_DISABLE_LINK be cleared after phylink_mac_initial_config() rather than before it? Once PHYLINK_DISABLE_LINK is cleared here, any MAC, PCS, or PHY interrupt can schedule phylink_resolve() on another CPU without rtnl_lock(). Because pl->link_config.interface and pl->req_link_an_mode are updated without pl->state_mutex, phylink_resolve() can race with those writes and poll the PCS under stale SFP act_link_an_mode and interface settings before phylink_mac_initial_config() reconfigures the MAC/PCS. Updating the config under pl->state_mutex and clearing PHYLINK_DISABLE_LINK after phylink_mac_initial_config(pl, false) would close this window. > @@ -4304,7 +4385,10 @@ static void phylink_mux_deselect(struct phy_mux *m= ux, > struct phy_device *phy; > =20 > - if (pl->phydev !=3D port->phydev) > + if (port->type =3D=3D PHY_MUX_PORT_SFP) > + pl->sfp_selected =3D false; > + > + if (port->type !=3D PHY_MUX_PORT_PHY || pl->phydev !=3D port->phydev) > return; [Severity: Medium] Should phylink_mux_deselect() bring the link down when deselecting PHY_MUX_PORT_SFP? Unbinding the phy_mux driver while the SFP link is up calls phy_mux_unregister() -> phylink_mux_detach() -> phy_mux_stop() -> phylink_mux_deselect() without stopping the netdev. Because phylink_mux_deselect() only clears pl->sfp_selected without calling phylink_run_resolve_and_disable(pl, PHYLINK_DISABLE_LINK), the link stays up and later phylink_sfp_link_down() calls return early while pl->sfp_behind_mux && !pl->sfp_selected, leaving carrier stuck up. Unbinding the sfp driver while an optical link is up similarly leaves the link up across the mux switch, so phylink_mux_select() calls phylink_mac_initial_config() without mac_link_down() first. Also, if a copper SFP PHY is still attached when deselected, pl->phydev remains populated and selecting a PHY port fails with -EBUSY. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204110622.1106= 492-1-maxime.chevallier@bootlin.com?part=3D10