From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96589606A321 for ; Sun, 6 Dec 2026 14:49:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=ElfQ1+Vz; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=xFBDE07x DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=Ntaj8DJ5YXSQ8Z8lg5xN75mT/hTaGphesqUlp6LgWjM=; b=ElfQ1+VzfLFW1E fB4ZWWC/CMf/vyYFJMsz9T3UljeJ3zVfeAbW/LLjv0HtMMKktzfk7tEYphXGtx4R6f5quzDk6A50a zKJqcQX5sVg+a8qC8gUAzPDhS9njUOX7cGLUBzT0A40UjfvOymt/DVv4dXqaQwx40nsXStI9zOP+l btJgXYiDLJzj6JPiuGNAn437NzeyLryUnw6/1J1w9MZmlWNaAtZsD2S2ZYa99F+tBbXGsOkbqIgUR /FzRTj9mrUlWKBPkprMWubQuDSGmhctRzJ30eEjcjQBPgFSIOymj4tj1Pjof5pMxf/HPuFGou/3o0 6jRImes44Q704q5IBuSQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xaDYM-00000003gj7-0eic; Sun, 06 Dec 2026 14:49:26 +0000 Received: from smtpout-02.galae.net ([185.246.84.56]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xaDYJ-00000003gih-1O3k for linux-arm-kernel@lists.infradead.org; Sun, 06 Dec 2026 14:49:24 +0000 Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 5DB2E1A199A; Sun, 6 Dec 2026 14:49:21 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 2A4EA604C0; Sun, 6 Dec 2026 14:49:21 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 2066311EA178D; Sun, 06 Dec 2026 15:49:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1796568559; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:content-language:in-reply-to:references; bh=Ntaj8DJ5YXSQ8Z8lg5xN75mT/hTaGphesqUlp6LgWjM=; b=xFBDE07xGr6yQrTbGmVymU+H5f4IL8dvUYXSRRaFQJx7kgQsFbKxZKkT8/8pQGvZGdbF71 8nxc/wGwA546i3EAONhaYU+8VSr3VxHkajD/FpvzTKB2pDtYiqplQcvKixyej6o1U8bAoT SmYemik0Eeu8Sstu+0x46reReYLx1uoaSfStS9MJnCNOph9lXoZ9dwNyHCPKcXNA3RZ/V6 wdH3eOFo/evJRK+/MBbxlTuWn0t404z375yeWKKuZtYNEzjnrZk5LC0UMpRJIKw4l+8olG 4cYZO5qlljHmU+RTEb+/8E1PrmLZfl2sCMqQrUWh5TDM+bK4EF/AASmFjM++bw== Message-ID: <4759d07e-aa4b-406f-b080-09bce6af8cf3@bootlin.com> Date: Sun, 6 Dec 2026 15:49:08 +0100 X-Archived-By: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net-next 09/12] net: phylink: Support PHYs reached through a phy_mux To: netdev-bot+sashiko@kernel.org 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 References: <20261204110622.1106492-10-maxime.chevallier@bootlin.com> <179647311481.3146.4575966133992501685@kernel.org> Content-Language: en-US From: Maxime Chevallier In-Reply-To: <179647311481.3146.4575966133992501685@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Last-TLS-Session-Version: TLSv1.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261206_064923_728974_B6CC286D X-CRM114-Status: GOOD ( 50.54 ) X-Spam-Score: -2.1 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On 12/5/26 13:18, netdev-bot+sashiko@kernel.org wrote: > 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()? Ah I missed that yeah, OK this needs addressing. pw-bot: cr > > [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; >> +} > > [ ... ] >