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=1796473117; b=ZVNAcNxiK5T0m3iEiA5qfgO5NyM/wRuJ0HSoNKiNtEJ6zJPQ2sK4OEmBL9QLIgiEvU7D tZd8L6w0icuKIMrQKlAF/sl8NsqhjFUYw3/JSzLg1Sz/3HKqhZSCJ+70hTYuxbas35Qxs 0fZTwBYqN4zTQUUdN+sAs/xmdwxJ7HCxQ7CGhZiptHLX1zsNuPfKraS/KxLNcbtevI8ka 2tjosaYjyCqOAAB4MAAPDALqx+WVhUaEmFpaw4FIWqtZxGvC23KZr+M5QA2uvmmeAx19F bUW3+5M0beAaW+GrVYeI48ARWEdeikgnucjGKUESiF7J4Xt39sQPD4U0Ix2nxC6jKDA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796473117; 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=5U+ZjQL5GweLu3WrsaYF/MGb20L3lHI1JIBdmGzEKEQ=; b=TLy2lDccL4peBdzfjD6dIR/W8k48hRGtWLIzRuZjJSUXOBVJa2Ui3DDG10CWvlu+KxOw A8N12mIEjBFvqYg9hEUEbw8vgNtamjdySz8r2Cdv6B5MD4LcHlyasR9pAVHb7ccOEfuMD qH82zV/QQqbNuRKVVU3JQ/fDo0YWfwU9BqkXW2Uya9bFSuAdHzFHjM6SWv/31UECe0MEn A4nMxvC50tHnX7f2BePw4AWBdBq8GdF0dFarvqgEI3xJ29Y4rorl7Q/uzwyMJn2JPu6Pb dyp1HnmT3LP6RmfdDSbeaqCcIEpTdxiVBH1GCkNI/uAfGv8NfaUDHACd5eMDqSsUY/Q== 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=X7UNmKQG; 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 5EC7C606A680; Sat, 5 Dec 2026 12:18:37 +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=X7UNmKQG Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38AD11F0092B; Sat, 5 Dec 2026 12:18:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796473116; bh=5U+ZjQL5GweLu3WrsaYF/MGb20L3lHI1JIBdmGzEKEQ=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=X7UNmKQGc4rJ9otsPT6W14qtpRbcQ+wNZnwOB6RdsLVr914E9VEZ7B+7j4KWxac1+ 6NOVD64smCn1yGWvmMEi8vJ/L6IeXmCFmQwPb5pv7Lqhy965yLwZtKn8Sno7bJ+UdH CA0FOQeMJCARIvSdsicHw7FDzgJb9J2liBza8hTV44tpq2r8nSoBhllwQJV2pOGBqf QiA6zh7Xr+kTYw90zH+LPzv063gu3wsCyQsWaaytjEgpJVLMqFG6aBU0z6tEpov661 p/O3SOTX+2X1mIW3QPm2W03/ziWxZ6YrC6ZBkOz6wTeH/Y8vsUkdV2knfwnKo9a7dE YURz0Szv3uCoQ== Subject: Re: [PATCH net-next 09/12] net: phylink: Support PHYs reached through a phy_mux From: netdev-bot+sashiko@kernel.org To: maxime.chevallier@bootlin.com Cc: davem@davemloft.net, andrew+netdev@lunn.ch, kuba@kernel.org, edumazet@kernel.org, willemb@google.com, pabeni@redhat.com, linux@armlinux.org.uk, kabel@kernel.org, sebastian.hesselbarth@gmail.com, gregory.clement@bootlin.com, hkallweit1@gmail.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, thomas.petazzoni@bootlin.com, devicetree@vger.kernel.org, conor+dt@kernel.org, krzk+dt@kernel.org, robh@kernel.org, christophe.leroy@csgroup.eu, herve.codina@bootlin.com, f.fainelli@gmail.com, vladimir.oltean@nxp.com, kory.maincent@bootlin.com, o.rempel@pengutronix.de, nicveronese@gmail.com, horms@kernel.org, marcin.s.wojtas@gmail.com, daniel@makrotopia.org, dimitri.fedrau@liebherr.com, frank.wunderlich@linux.dev, p.ameruoso@live.it, f@lex.la Date: Sat, 05 Dec 2026 12:18:34 +0000 Message-ID: <179647311481.3146.4575966133992501685@kernel.org> In-Reply-To: <20261204110622.1106492-10-maxime.chevallier@bootlin.com> References: <20261204110622.1106492-10-maxime.chevallier@bootlin.com> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: devicetree@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 8 potential issue(s) to consider. Critical: 0 · High: 1 · Medium: 5 · Low: 2 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). - [High] net: phylink: phylink_mux_select() configures suspended PHY - [Medium] With a mux, phylink has no PHY every time the interface is down, not only before the first selection as the commit message says. - [Medium] The patch changes what phylink_fwnode_phy_connect()/phylink_of_phy_connect() guarantee on… - [Medium] On MACs that set mac_requires_rxc (stmmac sets it unconditionally), the PHYs behind a mux are left in BMCR power-down… - [Medium] With a mux, phylink_suspend() with PHY-handled WoL breaks the wake path. - [Medium] net: phylink: missing rtnl_lock() in phylink_destroy() mux detach - [Low] The kernel-doc for phylink_of_phy_connect() still says "Actions specified in phylink_connect_phy() will be performed": attach the PHY,… - [Low] phylink_mux_select() writes `pl->link_config.interface = port->interface;` with only rtnl held, after phylink_bringup_phy() has… -- net: phylink: Support PHYs reached through a phy_mux This makes phylink act as the parent of a phy_mux. When the MAC node has a mii-mux-handle property, phylink_fwnode_phy_connect() attaches to the mux instead of connecting a PHY. phylink starts and stops the mux along with the interface, and the select/deselect parent ops bring up or stop the selected port's PHY and reconfigure the MAC. > 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 [ ... ] > @@ -2494,6 +2510,34 @@ int phylink_of_phy_connect(struct phylink *pl, struct device_node *dn, > } > EXPORT_SYMBOL_GPL(phylink_of_phy_connect); > > +static const struct phy_mux_parent_ops phylink_mux_ops; > + > +static int phylink_attach_mux(struct phylink *pl, > + const struct fwnode_handle *fwnode, u32 flags) > +{ > + struct fwnode_handle *mux_fwnode; > + int ret; > + > + if (pl->mux || !IS_ENABLED(CONFIG_PHY_MUX)) > + return 0; > + > + if (pl->config->type != PHYLINK_NETDEV) > + return 0; > + > + mux_fwnode = fwnode_find_reference(fwnode, "mii-mux-handle", 0); > + if (IS_ERR(mux_fwnode)) > + return 0; > + > + if (pl->config->mac_requires_rxc) > + flags |= PHY_F_RXC_ALWAYS_ON; > + > + ret = fwnode_phy_mux_attach(mux_fwnode, pl->netdev, flags, > + &phylink_mux_ops, pl); [Severity: Medium] On MACs that set mac_requires_rxc, can the PHYs behind the mux still be powered down when the MAC runs its DMA reset? phy_mux_attach() resumes each PHY through phy_attach_direct(), but then deselects every port: drivers/net/phy/phy_mux.c:phy_mux_attach() { ... xa_for_each(&mux->ports, id, port) phy_mux_port_deselect(port); ... } For PHY ports this ends up in phy_mux_phy_power_down() -> phy_suspend(). phylink_fwnode_phy_connect() then returns with pl->phydev == NULL. phylink_prepare_resume() is the helper that guarantees RXC for these MACs, and it only looks at pl->phydev: if (pl->config->mac_requires_rxc && phydev && phydev->suspended) phy_resume(phydev); stmmac sets mac_requires_rxc unconditionally. __stmmac_open() calls phylink_prepare_resume() and then stmmac_hw_setup(), both before phylink_start(), so no PHY gets resumed. On resume, phylink_suspend() -> phylink_stop() -> phy_mux_stop() has already cleared pl->phydev, so the same thing seems to happen there. If the PHY stops RXC in power-down, wouldn't the DMA reset fail, so that open or resume fails with "Hw setup failed"? stmmac takes this path when its node has both phy-handle and mii-mux-handle. No in-tree DT pairs stmmac with a mux today. > + fwnode_handle_put(mux_fwnode); > + > + return ret == -EPROBE_DEFER ? -ENODEV : ret; > +} > + > /** > * phylink_fwnode_phy_connect() - connect the PHY specified in the fwnode. > * @pl: a pointer to a &struct phylink returned from phylink_create() > @@ -2501,7 +2545,7 @@ EXPORT_SYMBOL_GPL(phylink_of_phy_connect); > * @flags: PHY-specific flags to communicate to the PHY device driver > * > * Connect the phy specified @fwnode to the phylink instance specified > - * by @pl. > + * by @pl, or attach to the PHY multiplexer it refers to. [Severity: Low] This isn't a bug, but phylink_of_phy_connect() forwards to this function, and its kernel-doc still says: * Connect the phy specified in the device node @dn to the phylink instance * specified by @pl. Actions specified in phylink_connect_phy() will be * performed. With mii-mux-handle, none of those actions (attaching the PHY, restricting its advertisement, starting it, enabling interrupts, updating the supported/advertising masks) happen until phylink_mux_select() runs after phylink_start(). Should that comment be updated as well? It is still unchanged at the end of the series. > * > * Returns 0 on success or a negative errno. > */ > @@ -2516,6 +2560,13 @@ int phylink_fwnode_phy_connect(struct phylink *pl, > if (!phylink_expects_phy(pl)) > return 0; > > + ret = phylink_attach_mux(pl, fwnode, flags); > + if (ret) > + return ret; > + > + if (pl->mux) > + return 0; [Severity: Medium] This changes what a successful phylink_fwnode_phy_connect() or phylink_of_phy_connect() guarantees. Are the existing callers ready for pl->phydev to be NULL here? mvneta_mdio_probe() queries WoL right after connecting: drivers/net/ethernet/marvell/mvneta.c:mvneta_mdio_probe() { ... int err = phylink_of_phy_connect(pp->phylink, pp->dn, 0); ... phylink_ethtool_get_wol(pp->phylink, &wol); device_set_wakeup_capable(&pp->dev->dev, !!wol.supported); ... } The Turris Omnia WAN port is an mvneta, and the DTS change in this series gives it mii-mux-handle. There, wol.supported would be 0 and the netdev would be marked not wakeup-capable, even though the 88E1514 behind the mux supports WoL. stmmac_init_phy() also calls phylink_ethtool_get_eee()/set_eee() right after connecting, to program the PHY's tx_lpi_timer. With a mux that would silently do nothing. Also, stmmac_init_phy() only calls phylink_fwnode_phy_connect() when fwnode_get_phy_node() finds a phy-handle: if (!phy_fwnode || IS_ERR(phy_fwnode)) { int addr = priv->plat->phy_addr; So a MAC node that only has mii-mux-handle, like the mii-mux-auto.yaml example, never reaches phylink_attach_mux(). It fails with "no phy found" when phy_addr < 0. Should these callers be adapted along with this change? > + > phy_fwnode = fwnode_get_phy_node(fwnode); > if (IS_ERR(phy_fwnode)) { > /* PHY mode requires a PHY to be specified. */ [ ... ] > @@ -2727,6 +2787,8 @@ void phylink_stop(struct phylink *pl) > { > ASSERT_RTNL(); > > + if (pl->mux) > + phy_mux_stop(pl->mux); [Severity: Medium] The commit message says phylink has no PHY "between the time it attaches to the mux and the first selection". Doesn't every phylink_stop() also drop the PHY? phylink_stop() phy_mux_stop() phy_mux_select(mux, NULL) __phy_mux_deselect_port() phylink_mux_deselect() phylink_clear_phydev() After that, phy_mux_port_set_parent_phy(..., false) sets netdev->phydev to NULL. While the interface is down, phylink_ethtool_ksettings_set() with cfg_link_an_mode == MLO_AN_PHY and no PHY falls through to the branch commented "All that is left are in-band links". It stores speed, duplex and advertising in pl->link_config and returns 0. On the next open, phylink_mux_select() -> phylink_bringup_phy() overwrites pl->link_config.advertising with phy->advertising. The PHY itself was never reprogrammed. So would an ethtool -s, or a systemd .link file applied while the device is down, be accepted and then silently lost? In the same state, phylink_ethtool_set_wol() and phylink_ethtool_set_eee() return -EOPNOTSUPP, and phylink_ethtool_get_wol() reports no support. ksettings_get reports the leftover pl->supported/advertising of whichever PHY was selected last. > if (pl->sfp_bus) > sfp_upstream_stop(pl->sfp_bus); > if (pl->phydev) [ ... ] > +static int phylink_mux_select(struct phy_mux *mux, struct phy_mux_port *port, > + void *priv) > +{ > + struct phylink *pl = priv; > + struct phy_device *phy; > + int ret; > + > + if (port->type != PHY_MUX_PORT_PHY) > + return -EOPNOTSUPP; > + > + if (pl->phydev) > + return -EBUSY; > + > + phy = port->phydev; > + > + ret = phylink_bringup_phy(pl, phy, port->interface); > + if (ret) { > + phy->phylink = NULL; > + return ret; > + } > + > + pl->link_config.interface = port->interface; [Severity: High] Is the PHY still suspended when phylink_mux_select() runs? phy_mux_attach() deselects every port right after phy_attach_direct(). For PHY ports that ends in phy_mux_phy_power_down() -> phy_suspend(), and every later deselection suspends the port again. Nothing in phy_mux.c resumes the PHY before it calls pops->select(). phylink_mux_select() then calls phylink_bringup_phy() and phylink_mac_initial_config() on that suspended PHY. Only the final phy_start() goes through __phy_resume(). Before that point: - phylink_bringup_phy() does MDIO accesses through phy_support_eee(), phy_eee_tx_clock_stop_capable() and phy_eee_rx_clock_stop() - phy_request_interrupt() -> phy_enable_interrupts() calls config_intr() - phylink_major_config() calls phy_config_inband() Without a mux this ordering doesn't occur, because phy_attach_direct() resumes the PHY before phylink_bringup_phy() is called. Several in-tree drivers don't tolerate register accesses in that state: - bcm54xx_resume() notes that writes to registers other than BMCR are ignored until PDOWN is cleared, and resume can soft-reset and re-run config_init - kszphy_resume() says leaving power-down generates an internal global reset - rtl821x_suspend() gates priv->clk while suspended On those PHYs, the interrupt enable written by config_intr(), or the inband and EEE clock-stop settings, could be ignored or wiped by the resume in phy_start(). phylib would then believe interrupts are enabled and stop polling while the hardware still has them masked. The link would never come up. If config_intr() fails outright, the PHY is silently downgraded to PHY_POLL. Should the PHY be resumed before phylink_bringup_phy(), either here (and suspended again if select fails) or by phy_mux before it calls pops->select()? [Severity: Low] Can this store race with phylink_resolve()? phylink_mux_select() runs from the mux state work after phylink_start() has cleared PHYLINK_DISABLE_STOPPED. phylink_bringup_phy() has already published pl->phydev at this point. This line writes pl->link_config.interface with only rtnl held. phylink_resolve() can be queued at the same time by phylink_pcs_change(), phylink_mac_change() or phylink_phy_change(). It reads and writes the same field under state_mutex: drivers/net/phy/phylink.c:phylink_resolve() { ... if ((mac_config && link_state.interface != pl->link_config.interface) || pl->force_major_config) { ... pl->link_config.interface = link_state.interface; ... } Could resolve compare against a stale interface and run an extra major config while select is changing it? Later in the series, this same unlocked block also gets clear_bit(PHYLINK_DISABLE_LINK) and a pl->req_link_an_mode store. > + phylink_mac_initial_config(pl, false); > + phy_start(phy); > + > + return 0; > +} > + > +static void phylink_mux_deselect(struct phy_mux *mux, > + struct phy_mux_port *port, void *priv) > +{ > + struct phylink *pl = priv; > + struct phy_device *phy; > + > + if (pl->phydev != port->phydev) > + return; > + > + phy = port->phydev; > + > + if (phy_is_started(phy) || phy->state == PHY_ERROR) > + phy_stop(phy); > + > + phylink_clear_phydev(pl); > + > + if (phy_interrupt_is_valid(phy)) > + phy_free_interrupt(phy); [Severity: Medium] phylink_destroy() is called without rtnl held. Both of its neighbours here, sfp_bus_del_upstream() and phylink_destroy_sfp_cage_port(), take rtnl_lock() themselves. phylink_detach_mux() takes no lock at all, but the paths it can race with rely on rtnl: - phy_mux_unregister() takes rtnl_lock() before it checks mux->netdev and calls pops->detach(). That ends in phylink_mux_detach(), which clears pl->mux. - phy_mux_state_machine() runs phy_mux_select() under rtnl. phy_mux_stop() only does cancel_work(), not cancel_work_sync(), so rtnl is the only thing keeping the work from running alongside detach. If pl->mux is still set when phylink_destroy() runs, could phylink_destroy() and phy_mux_unregister() both detach the same mux, so that phy_detach() and device_link_del() run twice? Could a state work item that is already running still dereference pl after the kfree(pl) at the end of phylink_destroy()? If the mux was started, the chain phy_mux_detach() -> phy_mux_stop() -> phylink_mux_deselect() -> phylink_clear_phydev() also hits ASSERT_RTNL(). Most drivers call phylink_disconnect_phy() under rtnl before phylink_destroy(). So this needs a teardown or error path where the mux is still attached at destroy time. Should phylink_destroy() take rtnl_lock() around phylink_detach_mux(), and should phylink_detach_mux() get an ASSERT_RTNL()? [Severity: Medium] With a mux, does PHY-based Wake-on-LAN still work across suspend? When the PHY handles WoL, phylink_suspend() calls phylink_stop(). That now goes through phy_mux_stop() -> phylink_mux_deselect(), which reaches this phy_free_interrupt(). phy_free_interrupt() calls config_intr(PHY_INTERRUPT_DISABLED) and then frees the IRQ. Some PHYs signal WoL through their interrupt enable register: at803x writes 0 to AT803X_INTR_ENABLE, and Marvell clears the IMASK register that holds WOL_EIE. On those PHYs this disables the wake source. phy_suspend() in the port deselect returns -EBUSY because WoL is enabled. The PHY therefore stays powered but can no longer raise a wake. Without a mux, phylink_stop() only calls phy_stop(), which leaves the interrupt configuration and the IRQ in place. phylink_suspend() then does: } else { phylink_stop(pl); } if (phylink_phy_pm_speed_ctrl(pl)) phylink_speed_down(pl, false); phylink_phy_pm_speed_ctrl() needs pl->phydev, and deselect has already cleared it. When wol_phy_speed_ctrl is set, wouldn't phylink_speed_down() be skipped, leaving the PHY at full link speed during WoL suspend? > + > + phy->phylink = NULL; > +} [ ... ] -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204110622.1106492-1-maxime.chevallier%40bootlin.com