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=1796468931; b=b/+d9lTCtkV7kJAalV+sKfP6Cb33to6M8xJLDwAWjrsZOfzmLaBZHrrW3gQ9iCOckNvj P47TsVH0mwkltvf0rltxfnPsZW5GjBF3t4DTEAU4so+LxWwPZDK/uf+InrQ5JSRkqbYzf csq14Q3pmHvWG8zW85g9SfW/QqdC8TYh87KBbfYjRtVq57rsZ4XrOXvtEPcF9bny9ZqmW ppJXmc/BrqRU18VAvVG8gej4caU58V7yKT913y+L1/GO+2db+/ZSJLAToKIw32SSakd7o h1Y5sgt66TFY2D6YsM/AthR78JxEEwIjBI9gNA74bc9Y+d+DSe30RsUJPEFmWnurF3w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796468931; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=UA1nO6krFXyo7yyshJKEQqh9CeB68/l72LiIegDuVig=; b=L8sS+sUvMgwsiIYhv1AN6ZxGlPiIzkpzyAhMBKZQWYU149EP5dKEQWZFQ/69BQppsLVq D1/7W31oth0F3NcJofMVOsAkeyMaF5ug+KxhcBOYXrTBhRl8nduKX61Xx6ZeGwhDd7FsB +48Gd4O6t8s+rZXnEQgpCIwSeOyXem/5XwYtS0deFSZjxs1P9wVHI7csC8aJ0yZaAutbE plRT7NqhpiA/b44JGMZUbQwiZufIasR+uG7gScClhpYTvmE1Y+IkMOO7K6KHXvHv6Uc3C exnCuysmNYUkudnaRCubri70bjT/HfSDe+2T+RUnim4jdIGQlzspuNfy7LTT1sgcjgA== 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=d3eCCCyq; 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 6FF50606A334 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=d3eCCCyq Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A4881F0092B; 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=UA1nO6krFXyo7yyshJKEQqh9CeB68/l72LiIegDuVig=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=d3eCCCyq7gTsudobF6fQB1GpeKXYzTXO+d1PjZbmPJ1TgMkkrvNNUnIWNCh/Wgcdz VyxlJT/Z+m+cH9YpZ9FKXC67ZZwy14kyjEaA+oENbX83mtsydZPvkRhfuNk4Om8LeA j5MnEV0Jy4StIyawf84UMnO1HJ9t9jfMO1oFtCERvYUmNbjbveBv/cW3dGNdkDAQ5J CmVMPbrycQn4pFNWIW4aLNP41Ieo3Syn1UOD863BiKiYO1xDkSGGlOZgVi4ZE4Y/O7 40hGr88MAnUbk5tMhkhBT0wHx8f1oHVuZjWcC6BcTVlv70JiTQ6Z7/QRXhJHnMC9pE xnu6Wo03uML4g== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH net-next 09/12] net: phylink: Support PHYs reached through 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-10-maxime.chevallier@bootlin.com> References: <20261204110622.1106492-1-maxime.chevallier@bootlin.com> <20261204110622.1106492-10-maxime.chevallier@bootlin.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 11:08:50 +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 6 potential issues to consider: - [High] net: phylink: phylink_mux_select() configures suspended PHY - [High] net: phylink: phylink_resolve() left enabled across phy_mux port transitions - [Medium] net: phylink: missing rtnl_lock() in phylink_destroy() mux detach - [Medium] net: phylink: phy_mux_stop() in phylink_stop() breaks PM WoL and RXC resume - [Medium] net: phylink: unlocked pl->mux read in phylink_fwnode_phy_connect() - [Medium] net: phylink: armed PHY IRQ in PHY_HALTED races with mux select/deselect -- commit a4afcb522e18328b8fbf2ddefbad3fcd4d9619af Author: Maxime Chevallier net: phylink: Support PHYs reached through a phy_mux This commit adds phy_mux parent support to phylink so that MACs referencing= a mii-mux-handle attach to the mux in phylink_fwnode_phy_connect() and manage PHY port selection through phy_mux_parent_ops. > diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c > index 03e255f5ceb17..702614adcb945 100644 > --- a/drivers/net/phy/phylink.c > +++ b/drivers/net/phy/phylink.c [ ... ] > @@ -2141,6 +2143,15 @@ struct phylink *phylink_create(struct phylink_conf= ig *config, > } > EXPORT_SYMBOL_GPL(phylink_create); > =20 > +static void phylink_detach_mux(struct phylink *pl) > +{ > + if (!pl->mux) > + return; > + > + phy_mux_detach(pl->mux); > + pl->mux =3D NULL; > +} > + > /** > * phylink_destroy() - cleanup and destroy the phylink instance > * @pl: a pointer to a &struct phylink returned from phylink_create() > @@ -2153,6 +2164,7 @@ EXPORT_SYMBOL_GPL(phylink_create); > void phylink_destroy(struct phylink *pl) > { > sfp_bus_del_upstream(pl->sfp_bus); > + phylink_detach_mux(pl); > phylink_destroy_sfp_cage_port(pl); > if (pl->link_gpio) > gpiod_put(pl->link_gpio); [Severity: Medium] Can calling phylink_detach_mux() here without rtnl_lock() race with phy_mux_unregister() or phy_mux_state_machine()? phylink_destroy() is called without rtnl_lock() held, unlike both neighbori= ng calls (sfp_bus_del_upstream() and phylink_destroy_sfp_cage_port()), which acquire it internally. In drivers/net/phy/phy_mux.c, phy_mux_unregister() = and phy_mux_state_machine() rely on rtnl_lock() to serialize mux teardown (and phy_mux_stop() only calls non-synchronous cancel_work(&mux->state_work)). CPU0 CPU1 phylink_destroy() phy_mux_unregister() phylink_detach_mux() rtnl_lock() if (!pl->mux) mux->pops->detach() phylink_detach_mux() phy_mux_detach(mux) pl->mux =3D NULL phy_mux_detach(pl->mux) rtnl_unlock() <-- double detach / UAF phy_mux_free(mux) If phylink_destroy() runs while pl->mux is still attached, this can double detach or use-after-free pl or mux, and if the mux is still started, phy_mux_detach() -> phy_mux_stop() -> phylink_mux_deselect() -> phylink_clear_phydev() also hits ASSERT_RTNL(). Acquiring rtnl_lock() arou= nd phylink_detach_mux(pl) in phylink_destroy() (and asserting ASSERT_RTNL() in phylink_detach_mux()) would close this. [ ... ] > @@ -2516,6 +2560,13 @@ int phylink_fwnode_phy_connect(struct phylink *pl, > if (!phylink_expects_phy(pl)) > return 0; > =20 > + ret =3D phylink_attach_mux(pl, fwnode, flags); > + if (ret) > + return ret; > + > + if (pl->mux) > + return 0; > + > phy_fwnode =3D fwnode_get_phy_node(fwnode); > if (IS_ERR(phy_fwnode)) { > /* PHY mode requires a PHY to be specified. */ [Severity: Medium] Can this unlocked read of pl->mux race with a concurrent phy_mux_unregister= ()? Callers such as dsa_user_create() invoke phylink_fwnode_phy_connect() witho= ut rtnl_lock(). fwnode_phy_mux_attach() releases phy_mux_mutex before returni= ng: CPU0 CPU1 phylink_fwnode_phy_connect() phylink_attach_mux() fwnode_phy_mux_attach() mutex_lock(&phy_mux_mutex) pl->mux =3D mux mutex_unlock(&phy_mux_mutex) phy_mux_unregister() rtnl_lock() phylink_mux_detach() pl->mux =3D NULL rtnl_unlock() if (pl->mux) <-- sees NULL return 0; fwnode_get_phy_node() If phy_mux_unregister() clears pl->mux in that window, this falls through to fwnode_get_phy_node() as if no mux existed, returning -ENODEV in MLO_AN_PHY mode or returning 0 with neither mux nor PHY in MLO_AN_INBAND mode. [ ... ] > @@ -2708,6 +2766,8 @@ void phylink_start(struct phylink *pl) > phy_start(pl->phydev); > if (pl->sfp_bus) > sfp_upstream_start(pl->sfp_bus); > + if (pl->mux) > + phy_mux_start(pl->mux); > } > EXPORT_SYMBOL_GPL(phylink_start); [Severity: High] Does leaving phylink_resolve() enabled while no mux port is selected allow spurious link-up and unlocked reconfiguration in MLO_AN_INBAND mode? phylink_start() clears PHYLINK_DISABLE_STOPPED and queues pl->resolve before phy_mux_start() schedules mux->state_work (which blocks on rtnl_lock()). phylink_mux_deselect() also clears pl->phydev without setting a PHYLINK_DISABLE_* bit, so the retriggered resolve work runs with pl->phydev NULL. CPU0 kworker phylink_start() phylink_enable_and_run_resolve() queue_work(pl->resolve) phy_mux_start(pl->mux) schedule_work(mux->state_work) phylink_resolve() /* pl->phydev =3D=3D NULL */ phylink_mac_pcs_get_state() phylink_link_up() <-- no port selected In MLO_AN_INBAND mode, phylink_resolve() skips gating on pl->phy_state.link when pl->phydev is NULL, so a live PCS link triggers phylink_link_up() with no mux port selected. When phylink_mux_select() then runs, calling phylink_mac_initial_config() -> phylink_major_config() while pl->old_link_state is true reconfigures the MAC and PCS without a preceding phylink_link_down(). Because phylink_resolve() is still enabled, phylink_mux_select() also writes pl->link_config.interface without pl->state_mutex or phy->lock, and phylink_mac_initial_config() reads pl->req_link_an_mode, pl->phy_state, and pl->link_config before taking phy->lock, racing with a concurrent resolve. > @@ -2727,6 +2787,8 @@ void phylink_stop(struct phylink *pl) > { > ASSERT_RTNL(); > =20 > + if (pl->mux) > + phy_mux_stop(pl->mux); > if (pl->sfp_bus) > sfp_upstream_stop(pl->sfp_bus); > if (pl->phydev) [Severity: Medium] Does calling phy_mux_stop() in phylink_stop() break PHY Wake-on-LAN and mac_requires_rxc resume? phy_mux_stop() deselects the active port via phylink_mux_deselect(), which clears pl->phydev to NULL and frees the PHY interrupt. In phylink_suspend(pl, false), phylink_stop() runs before phylink_phy_pm_speed_ctrl() checks pl->phydev, so phylink_speed_down() (and phylink_speed_up() on resume) is always skipped, and freeing the PHY IRQ breaks IRQ-based PHY Wake-on-LAN wakeups. Clearing pl->phydev also turns phylink_prepare_resume() into a no-op, so MA= Cs with mac_requires_rxc (such as stmmac in __stmmac_open()) cannot wake the suspended PHY to restore RXC before DMA reset. [ ... ] > +static int phylink_mux_select(struct phy_mux *mux, struct phy_mux_port *= port, > + void *priv) > +{ > + struct phylink *pl =3D priv; > + struct phy_device *phy; > + int ret; > + > + if (port->type !=3D PHY_MUX_PORT_PHY) > + return -EOPNOTSUPP; > + > + if (pl->phydev) > + return -EBUSY; > + > + phy =3D port->phydev; > + > + ret =3D phylink_bringup_phy(pl, phy, port->interface); > + if (ret) { > + phy->phylink =3D NULL; > + return ret; > + } > + > + pl->link_config.interface =3D port->interface; > + phylink_mac_initial_config(pl, false); > + phy_start(phy); > + > + return 0; > +} [Severity: High] Isn't port->phydev still suspended when phylink_bringup_phy() and phylink_mac_initial_config() configure it here? phy_mux_attach() and port deselection both suspend PHY ports via phy_mux_phy_power_down() -> phy_suspend(), and phy_mux does not call phy_resume() on selection. phylink_bringup_phy() performs MDIO accesses for EEE and enables interrupts via phy_request_interrupt(), and phylink_major_config() calls phy_config_inband(), all before phy_start(phy) resumes the PHY. On PHY drivers that ignore non-BMCR writes in power-down or reset registers= on resume (such as bcm54xx_resume() in drivers/net/phy/broadcom.c or kszphy_resume() in drivers/net/phy/micrel.c), interrupt and EEE configurati= on can be silently discarded or fail, leaving hardware IRQs masked while polli= ng is disabled so the link never comes up. Resuming the PHY before phylink_bringup_phy() (and re-suspending on error), or resuming the port in phy_mux before pops->select(), would avoid this. > +static void phylink_mux_deselect(struct phy_mux *mux, > + struct phy_mux_port *port, void *priv) > +{ > + struct phylink *pl =3D priv; > + struct phy_device *phy; > + > + if (pl->phydev !=3D port->phydev) > + return; > + > + phy =3D port->phydev; > + > + if (phy_is_started(phy) || phy->state =3D=3D PHY_ERROR) > + phy_stop(phy); > + > + phylink_clear_phydev(pl); > + > + if (phy_interrupt_is_valid(phy)) > + phy_free_interrupt(phy); > + > + phy->phylink =3D NULL; > +} [Severity: Medium] Can a PHY or shared interrupt firing while phy->state is PHY_HALTED re-susp= end the PHY after phy_start() or race with teardown? Because a muxed PHY stays attached across port switches, phy_stop() leaves = it in PHY_HALTED rather than PHY_READY. In phylink_mux_deselect(), phy_stop() cancels phy->state_queue before phylink_clear_phydev() flushes pl->resolve = and before phy_free_interrupt() frees the IRQ, without canceling phy->state_que= ue afterward. On re-selection in phylink_mux_select(), phylink_bringup_phy() also calls phy_request_interrupt() while phy->state is still PHY_HALTED. CPU0 kworker phylink_mux_select() phylink_bringup_phy() phy_request_interrupt(phy) /* IRQ fires in PHY_HALTED */ phy_state_machine() mutex_lock(&phy->lock) _phy_state_machine() -> WORK_SUSPEND mutex_unlock(&phy->lock) phy_start(phy) mutex_lock(&phy->lock) __phy_resume(phy) phy->state =3D PHY_UP mutex_unlock(&phy->lock) phy_suspend(phy) <-- re-suspends PHY Because phy_state_machine() drops phy->lock before _phy_state_machine_post_work() calls phy_suspend(), a stale PHY_HALTED work item can re-set BMCR_PDOWN and phy->suspended after phy_start() resumes the PHY, leaving the link stuck down until another stop/start cycle. During deselection, the queued work can also race with phy_mux_phy_power_down() or phy_detach(). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204110622.1106= 492-1-maxime.chevallier@bootlin.com?part=3D9