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 0978B606A339 for ; Sat, 5 Dec 2026 12:19:12 +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=HYl/z82Q; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=KTjeCklN 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:MIME-Version: Content-Transfer-Encoding:Content-Type:References:In-Reply-To:Message-ID:Date :Cc:To:From:Subject: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=LEsfm/OHxUh2aFpHim5+USgchKPib/KDXMcIPoPFhQo=; b=HYl/z82QcOtBr7kzTCWC6j5hQW kALQYNv4xsQdknBNRnegynZ86I6lBOZXNMF1VluES6x+lWrP7rgcFxa+EaToxcgabucUyaQeQwg+p VPqTdJA7kCWZVJZWBpOW60B/UfnT9SB9Gt0v0LUGP9IETpYxvW8X/tWgrzSMYTpP4Npml5fW/te0i 4Iwt+WXsTttOXH5OgrQRGF4pID2qcjA7Vdp4KcTKWlVmtMHLUmr6tqZ2LNLDU0+pv+kUJqWwh9ALF lAvvwbQIh2woj5mYXxeBaCHkW6o8KeVS9X0U2pV7DQSkMDTQHUQoFoXikFOvq5yFi3GIU8Q/gLnVo wFlon5aA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZojF-00000002PDC-2Q2S; Sat, 05 Dec 2026 12:19:01 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZoiu-00000002P2J-1CUx for linux-arm-kernel@lists.infradead.org; Sat, 05 Dec 2026 12:18:42 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id AB8F061CEF; Sat, 5 Dec 2026 12:18:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8359B1F0092B; Sat, 5 Dec 2026 12:18:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796473119; bh=LEsfm/OHxUh2aFpHim5+USgchKPib/KDXMcIPoPFhQo=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=KTjeCklN4tSZCNbKV+cOC/obrWun7lSox2m5smVQxPMA0zP3ze28AcDhk2oWh5etk jG5bZiNT8Hv7xdm3sVq0/yHpth2NYQ32gy7vsYWUDvlblFlA96TPJhp80Jv7ScLIMO A8R7vORaQmZfAGgFb0plw6KbBrW/vMBUeZe9A4zzlewttFXY8bu4KTcbFGgm1aYP3I xYquOZ+W3ludj2/PUumLcrJp0IDZNgCvHIJyUZEOtaVFDQBL2XubY+o3ddLZLsPYpp qWpKx5PJ0Zij5aCxQLZNzGDH/ZQxhCXr9GZesr9dFQ8vIIwtidQGCvXViM7l828msG aM4TKKiIA5mMQ== Subject: Re: [PATCH net-next 10/12] net: phylink: Support an SFP cage behind 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:37 +0000 Message-ID: <179647311708.3146.9182940426072971501@kernel.org> In-Reply-To: <20261204110622.1106492-11-maxime.chevallier@bootlin.com> References: <20261204110622.1106492-11-maxime.chevallier@bootlin.com> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Archived-By: MIME-Version: 1.0 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=-11.2 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 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 Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider. Critical: 0 · High: 0 · 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). - [Medium] phylink_sfp_module_insert() (drivers/net/phy/phylink.c) calls phylink_sfp_set_present(pl, true) before it has accepted the module. - [Medium] phylink_register_mux_sfp() sets pl->sfp_behind_mux = true and pl->sfp_link_down = true inside phylink_create(). - [Medium] net: phylink: phylink_start() runs resolve before mux selects SFP port - [Medium] net: phylink: phylink_mux_deselect() does not bring down active SFP link - [Medium] net: phylink: missing rtnl_lock() in phylink_destroy() mux detach - [Low] phylink_speed_down() and phylink_speed_up() change from `!pl->sfp_bus && pl->phydev` to `pl->phydev && (!pl->sfp_bus ||… - [Low] On the PHY-port path, phylink_mux_select() calls clear_bit(PHYLINK_DISABLE_LINK, &pl->phylink_disable_state) first,… -- net: phylink: Support an SFP cage behind a phy_mux This patch lets phylink find an SFP cage that is described in one of the ports of a phy_mux referenced by mii-mux-handle, and register as its upstream. Module presence is reported to the mux with phy_mux_port_set_available() so the mux can switch between the SFP and PHY ports. SFP link events are gated on whether the SFP port is selected. > 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 [ ... ] > @@ -1876,6 +1881,30 @@ static int phylink_register_sfp(struct phylink *pl, > return ret; > } > > +static int phylink_register_mux_sfp(struct phylink *pl, > + const struct fwnode_handle *fwnode) > +{ > + struct fwnode_handle *mux_fwnode, *sfp_fwnode; > + int ret; > + > + mux_fwnode = fwnode_find_reference(fwnode, "mii-mux-handle", 0); > + if (IS_ERR(mux_fwnode)) > + return phylink_register_sfp(pl, fwnode); > + > + sfp_fwnode = fwnode_phy_mux_find_sfp_port(mux_fwnode); > + fwnode_handle_put(mux_fwnode); > + if (!sfp_fwnode) > + return phylink_register_sfp(pl, fwnode); > + > + pl->sfp_behind_mux = true; > + pl->sfp_link_down = true; [Severity: Medium] Should deselecting the SFP port also take the link down? For an SFP port, phylink_mux_deselect() only clears sfp_selected. It does not set PHYLINK_DISABLE_LINK. It also leaves an SFP module PHY in pl->phydev if one is attached. Take a mux driver unbind while the SFP link is up. The device link created by phy_mux_attach() is DL_FLAG_STATELESS, so the netdev stays open: phy_mux_unregister() phylink_mux_detach() phylink_detach_mux() phy_mux_detach() phy_mux_stop() phy_mux_select(mux, NULL) phylink_mux_deselect() The link is left up. sfp_behind_mux stays true while sfp_selected is now false, so every later phylink_sfp_link_down() takes the early return. Wouldn't the carrier then stay up even after the fibre or the module is pulled? Removing the SFP socket has a similar problem. sfp_unregister_bus() calls phylink_sfp_detach() first, which marks the mux port unavailable and queues mux->state_work. It then calls socket_ops->stop(), which moves sm_dev_state to SFP_DEV_DOWN. As a result sfp_sm_main() skips sfp_sm_link_down(): if (sfp->sm_state == SFP_S_LINK_UP && sfp->sm_dev_state == SFP_DEV_UP) sfp_sm_link_down(sfp); When the mux work runs, phylink_mux_deselect() leaves the link up. phylink_mux_select() for the PHY port then calls phylink_mac_initial_config() -> phylink_major_config(), and mac_link_down() has never been called. Is the MAC/PCS expected to cope with a major reconfiguration while the link is up? Also, a copper module's PHY may still be in pl->phydev when the SFP port is deselected. In that case the following phylink_mux_select() for the PHY port would fail with -EBUSY. Would calling phylink_run_resolve_and_disable(pl, PHYLINK_DISABLE_LINK) from the SFP branch of phylink_mux_deselect() be enough here? And what should happen to an attached module PHY? [Severity: Medium] Can phylink_resolve() bring the link up here before the mux has selected the SFP port? While sfp_selected is false, phylink_sfp_link_down() only records sfp_link_down. It returns without setting PHYLINK_DISABLE_LINK. Suppose a module is already in the cage when the interface is opened. By the time phylink_start() runs, the only bit left in phylink_disable_state is PHYLINK_DISABLE_STOPPED. phylink_enable_and_run_resolve(pl, PHYLINK_DISABLE_STOPPED) clears that bit. The state drops to zero and pl->resolve is queued. Only after that does phylink_start() call phy_mux_port_set_available() and phy_mux_start(). At that point mux->state is still PHY_MUX_STOPPED, so the port is not selected synchronously. The selection is deferred to mux->state_work, and phy_mux_state_machine() has to take rtnl_lock(). The caller of phylink_start() still holds it: rtnl_lock(); switch (mux->state) { ... case PHY_MUX_STARTED: phy_mux_select(mux, phy_mux_choose_port(mux)); break; } phylink_resolve() does not need RTNL. It can run first, with phylink_disable_state == 0 even though sfp_link_down is still true. That is before the SFP state machine has finished its LOS checks. When phylink_mux_select() finally runs for the SFP port, it calls phylink_run_resolve_and_disable(). Could the carrier come up and then drop straight away? Would it make sense to set PHYLINK_DISABLE_LINK up front when sfp_behind_mux is set? phylink_mux_select() could then clear it for whichever port ends up selected. Or should the mux be started before the resolve is enabled? [Severity: Medium] sfp_behind_mux is set here in phylink_create() based only on the firmware description. The mux itself is attached later, through phylink_fwnode_phy_connect() -> phylink_attach_mux(). What happens if that attach never takes place? phylink_attach_mux() returns 0 without attaching anything for non-netdev users: if (pl->config->type != PHYLINK_NETDEV) return 0; There are other ways to end up without a mux: - phylink_fwnode_phy_connect() returns early for fixed-link. - A MAC driver may call phylink_connect_phy() directly when there is no phy-handle. - If the mux driver is unbound, phylink_detach_mux() clears pl->mux and pl->mux_sfp_port but leaves sfp_behind_mux set. In all of these cases sfp_selected never becomes true, so phylink_sfp_link_up() always takes the new early return: pl->sfp_link_down = false; if (pl->sfp_behind_mux && !pl->sfp_selected) return; Would the module then be detected and configured while PHYLINK_DISABLE_LINK is never cleared? That would leave the carrier down with no error reported. > + > + ret = phylink_register_sfp(pl, sfp_fwnode); > + fwnode_handle_put(sfp_fwnode); > + > + return ret; > +} [ ... ] > @@ -3842,7 +3875,8 @@ int phylink_speed_down(struct phylink *pl, bool sync) > > ASSERT_RTNL(); > > - if (!pl->sfp_bus && pl->phydev) > + if (pl->phydev && > + (!pl->sfp_bus || (pl->sfp_behind_mux && !pl->sfp_selected))) > ret = phy_speed_down(pl->phydev, sync); [Severity: Low] Does !sfp_selected reliably mean that pl->phydev is the mux's copper PHY? phylink_mux_deselect() clears sfp_selected for an SFP port, but it only clears pl->phydev for PHY_MUX_PORT_PHY ports: if (port->type == PHY_MUX_PORT_SFP) pl->sfp_selected = false; if (port->type != PHY_MUX_PORT_PHY || pl->phydev != port->phydev) return; Suppose the mux is detached while a copper SFP module's PHY is attached, for example on mux driver unbind: phy_mux_unregister() phylink_mux_detach() phy_mux_detach() phy_mux_stop() pl->phydev is then still the SFP module PHY, and sfp_selected is false. A later phylink_speed_down() would call phy_speed_down() on that SFP module PHY. Both the kernel-doc ("set the non-SFP PHY to lowest speed") and the old check rule that out. The same applies to phylink_speed_up(). The commit message also doesn't mention this change to the WoL/suspend behaviour. > > return ret; [ ... ] > @@ -4096,18 +4143,27 @@ static int phylink_sfp_module_insert(void *upstream, > pl->sfp_may_have_phy = caps->may_have_phy; > pl->sfp_port = caps->port; > > + 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; [Severity: Medium] The port is reported as available here before phylink has accepted the module. The commit message says: "we only report the modules that phylink accepted" and: "with an unsupported module we're left with the PHY port selected" Does the code match that? When the mux is started, phy_mux_port_set_available(port, true) selects the port synchronously: if (available && mux->state == PHY_MUX_STARTED) { phy_mux_select(mux, phy_mux_choose_port(mux)); return; } phy_mux_trigger(mux); That deselects the copper port before phylink_sfp_config_optical() has run. phylink_mux_deselect() stops the PHY, clears pl->phydev and frees the interrupt, and then the mux powers the PHY down. For an unsupported optical module, the rollback to false only queues phy_mux_trigger(). Would every such insertion drop and renegotiate the copper link? For modules with sfp_may_have_phy set, this returns 0 with the port still available, and nothing later seems to undo it. phylink_sfp_connect_phy() can fail: if (!phy->drv) { ... return -EINVAL; } ... return phylink_sfp_config_phy(pl, phy); phylink_sfp_module_start() can also fail in phylink_sfp_config_optical(), and that path only removes the mod port: ret = phylink_sfp_config_optical(pl); if (ret) goto del_mod_port; In sfp_sm_main(), both failures go to SFP_S_FAIL without calling module_remove. That would leave the SFP mux port selected, the copper PHY suspended with pl->phydev NULL, and PHYLINK_DISABLE_LINK set. Is there then no link on either medium until the module is pulled out? > - return phylink_sfp_config_optical(pl); > + ret = phylink_sfp_config_optical(pl); > + if (ret) > + phylink_sfp_set_present(pl, false); > + > + return ret; > } [Severity: Medium] This gives the mux a new way to be touched while phylink_destroy() is tearing things down without RTNL. phylink_destroy() calls sfp_bus_del_upstream(), which takes RTNL and ends up in phylink_sfp_detach(). With this patch, that now calls phy_mux_port_set_available(pl->mux_sfp_port, false). If a module was present, this goes through phy_mux_trigger() and queues mux->state_work. As soon as sfp_bus_del_upstream() drops RTNL, phy_mux_state_machine() can take it. It then calls phylink_mux_select() or phylink_mux_deselect() with pl as the private pointer. Meanwhile phylink_destroy() runs phylink_detach_mux() -> phy_mux_detach() -> phy_mux_stop() without RTNL, although both of those expect it to be held. phy_mux_stop() only does cancel_work() on mux->state_work. Nothing waits for a running phy_mux_state_machine() before kfree(pl). Can that lead to a use-after-free of pl? The same unlocked phylink_detach_mux() can also race with phy_mux_unregister(). On mux driver unbind, that calls phylink_mux_detach() under RTNL. Both sides could then run phy_mux_detach() at the same time, calling phy_detach() and device_link_del() twice. This needs phylink_destroy() to be entered with pl->mux still set. That happens when the MAC driver doesn't call phylink_disconnect_phy() first: - ucc_geth_remove() calls phylink_destroy() before devres unregisters the netdev. - The error paths in lan743x_netdev_open() and mvpp2_open() skip the disconnect after the PHY was connected. The unlocked call was added earlier in the series. Should phylink_destroy() take RTNL around phylink_detach_mux(), or detach the mux before sfp_bus_del_upstream()? Note that phy_mux_stop() can't simply switch to cancel_work_sync() while it is called under RTNL, since the work itself takes rtnl_lock(). [ ... ] > @@ -4291,7 +4369,10 @@ static int phylink_mux_select(struct phy_mux *mux, struct phy_mux_port *port, > return ret; > } > > + clear_bit(PHYLINK_DISABLE_LINK, &pl->phylink_disable_state); > + > pl->link_config.interface = port->interface; > + pl->req_link_an_mode = pl->cfg_link_an_mode; > phylink_mac_initial_config(pl, false); [Severity: Low] Can clearing PHYLINK_DISABLE_LINK before these stores race with phylink_resolve()? When switching back from the SFP port after the module is removed, phylink_sfp_link_down() has set DISABLE_LINK. This clear_bit() can bring phylink_disable_state back to 0. A resolve queued by phylink_pcs_change() or phylink_mac_change() can then run from the workqueue. phylink_resolve() reads, and may write, pl->link_config while holding phydev_mutex, phy->lock and state_mutex. Here pl->link_config.interface and pl->req_link_an_mode are written under RTNL only. The link should be down during that window, so the practical impact may be small. Would moving the clear_bit() after phylink_mac_initial_config() avoid the race? > phy_start(phy); [ ... ] -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204110622.1106492-1-maxime.chevallier%40bootlin.com