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=1796473115; b=brtHkD15TMvPnmz9hgAK1Z4u0oLKVBC59sAHeyc3nr87CAkmqEpJ5OQUFGIAlOk2/Brz hUfbWcU9S2cq6f0ZnBhRKjx6E5Z4NtA90AsC3vbXhgRHlPZWXni/krcBWUSmcksbsFUN8 V+RRG3RXsXq6Gk1md+fSo57uVmohYq6WzulII/EiYKYrutAd/S14fLHj49xXbh320SBA2 ushjmeCYT3MFvSK2LDo7Mwosxj9IQTxWxCwCCpdFTvCKe2RaHd2U9JCrvYWzoX1OUIhtv iMRsGhH1M8Fdqcjl4Kcz16xZ4cHyosG4jkWr2R3nVG+T3AjCV5a0eE88CVE2YbPKVXA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796473115; 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=nL7199qu4KhLqXPhUGywa0akk4OhDmXvVcIBrJM8o5g=; b=DHX65sCLeSPGSuKLXOSFkq+M9SzrUA4tJ+kaxl7fGoetywgkSsES8rA1veWdbxGzvAUw Zf2a0+Zauejhd3jP0MJzWRx2sFGf/d4zhVH1bkYgNrzTHWUz3DWdT1lHHoV49a/wf9jaS YpKDiuIVyf/Ie6wHlYPHAuCaGGXjuFUENeLOBR+e9UnQcVrjpZ/vZyVR1ORKRBvpODuwg tT9YFjl0W+e2grZsJt5bqR4XN3RurLcETHgmQp8T/fhSjrNRQLtSd7ea8rf/IixTWlQ/d QQoBW9tF7vGjpF+yYYoia9pH0KFdberF6r4cPUfmr/81qNDwPWcqaJ+f8Vh8R0K/WSg== 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=fKyMWgLR; 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 02917606A6B6; Sat, 5 Dec 2026 12:18:34 +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=fKyMWgLR Received: by smtp.kernel.org (Postfix) with ESMTPSA id D04911F00A25; Sat, 5 Dec 2026 12:18:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796473114; bh=nL7199qu4KhLqXPhUGywa0akk4OhDmXvVcIBrJM8o5g=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=fKyMWgLRkYzDJkeQduDv/nRjjemT+1kfPMgYtb+ATHwhjhFQ616R55FJZwMa/EZRP 2b/jZ1RRvqmO5HxY0RLQxcGqkW61aumRogia6i+XRyFnKeNPinejMoKwAGZ6OziUDm 5mQVpkI7zstv1/UtpY82bIDA6zp6XyRKXy1MJCzHAr8UlBZKhDJklwF5oUH6czaskd Vf4vHIHOjDkrgxH6IoSsdC2n7rLDujqdD1kIpiHEJHCEyrag+A/cMQlfyDdlf3X25b epdOGzKXkNTPChmin/pSkLx7exoGtTyr5eK6UdXcMJ3huLGYYviHziWusW2nQWb7QD nAuo90fomUiww== Subject: Re: [PATCH net-next 06/12] net: phy: phy_mux: Support SFP cage ports 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:32 +0000 Message-ID: <179647311238.3146.3730324098600663207@kernel.org> In-Reply-To: <20261204110622.1106492-7-maxime.chevallier@bootlin.com> References: <20261204110622.1106492-7-maxime.chevallier@bootlin.com> X-sashiko-severity: Medium 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 5 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 2 · Low: 3 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] When a port switch fails, nothing is selected and the mux core never retries. - [Medium] net: phy: phy_mux_detach() races with unregister, free, and attach - [Low] This patch changes phy_mux_start() from synchronous to deferred selection without saying so. - [Low] In include/linux/phy_mux.h, the kernel-doc for struct phy_mux_port::interface says "The MII mode the link runs in when this… - [Low] net: phy: commit message overstates auto-mux scope and omits design -- net: phy: phy_mux: Support SFP cage ports This adds SFP cage ports to the phy_mux core, with at most one SFP cage per mux. It tracks whether each port is available and lets a port take precedence over the others. Port selection moves into a work item, and phy_mux_port_set_available() switches ports when a module is inserted or removed. > diff --git a/drivers/net/phy/phy_mux.c b/drivers/net/phy/phy_mux.c > index 407269980edc1..de3336970bd9b 100644 > --- a/drivers/net/phy/phy_mux.c > +++ b/drivers/net/phy/phy_mux.c [ ... ] > @@ -122,6 +129,109 @@ static const struct phy_mux_port_ops phy_mux_phy_power_ops = { [ ... ] > +static void phy_mux_state_machine(struct work_struct *work) > +{ > + struct phy_mux *mux = container_of(work, struct phy_mux, state_work); > + > + rtnl_lock(); > + > + switch (mux->state) { > + case PHY_MUX_STOPPED: > + break; > + > + case PHY_MUX_STARTED: > + phy_mux_select(mux, phy_mux_choose_port(mux)); > + break; > + } > + > + rtnl_unlock(); > +} [ ... ] > +void phy_mux_port_set_available(struct phy_mux_port *port, bool available) > +{ > + struct phy_mux *mux = port->mux; > + > + ASSERT_RTNL(); > + > + if (port->available == available) > + return; > + > + port->available = available; > + > + if (available && mux->state == PHY_MUX_STARTED) { > + phy_mux_select(mux, phy_mux_choose_port(mux)); > + return; > + } > + > + phy_mux_trigger(mux); > +} [Severity: Low] The last sentence of the changelog says this patch implements the automatic mux, but only the core side is here. The mii-mux-auto driver and the parsing of the takes-precedence property only arrive later in the series, in drivers/net/phy/mux/mii_mux_auto.c. Nothing in this patch sets port->has_precedence either; phy_mux_choose_port() reads it, and setting it is left to an init_port callback. Could the changelog say this adds what an auto-mux driver needs, rather than the auto-mux itself? It also doesn't explain the split in phy_mux_port_set_available(). When a port becomes available on a started mux, phy_mux_select() runs synchronously, under the caller's rtnl, and the parent's select and deselect ops are called from inside phy_mux_port_set_available(). When a port becomes unavailable, the selection is deferred to state_work, which takes rtnl again later from system_freezable_power_efficient_wq. So for the SFP port, a module insertion switches the mux before the call returns, while after a module removal the SFP port stays current_port until the worker runs. Is there a reason the two directions need to differ? Either way, could the commit message and a comment above that branch explain it, so parent drivers know which of their callbacks can run from within phy_mux_port_set_available()? [Severity: Medium] This isn't introduced here, but since phy_mux_free() is touched: what serializes phy_mux_detach() against phy_mux_unregister() and phy_mux_free()? phy_mux_detach() takes neither phy_mux_mutex nor rtnl, and its kernel-doc allows calling it without rtnl when the mux is stopped. phylink_destroy() does that later in this series. phy_mux_unregister() drops phy_mux_mutex right after list_del(), then only takes rtnl before testing mux->netdev and mux->pops and calling mux->pops->detach(mux, mux->parent_priv). fwnode_phy_mux_attach() serializes phy_mux_attach() with phy_mux_mutex only. So with the MAC driver and the mux driver unbound at the same time: CPU0 (MAC unbind) CPU1 (mux unbind) phylink_destroy() phy_mux_detach() mux->netdev is set phy_mux_unregister() rtnl_lock() mux->pops->detach() phy_mux_detach() rtnl_unlock() phy_mux_free() kfree(mux) phy_mux_detach_phys(mux) mux->pops = NULL Both sides can run phy_mux_detach_phys() and device_link_del(), giving a double phy_detach()/put_device(). CPU1 can also see mux->pops set and then call through it after CPU0 has cleared it, or pass a parent_priv the parent already freed. struct phy_mux has no refcount, so phy_mux_free() can destroy the ports and kfree(mux) while CPU0 is still writing to them. The disable_work_sync() added here only waits for state_work. The device link from phy_mux_attach() is DL_FLAG_STATELESS, so it does not make the driver core unbind the MAC before the mux either. Attach vs detach has the same problem, since the two paths hold different locks (or none) while updating mux->netdev, mux->pops, mux->devlink, port->attached, port->phydev and phydev->mux_port. This needs root to unbind both devices, but nothing later in the series adds locking or a refcount. Should phy_mux_detach() and phy_mux_unregister() share a lock held across the whole teardown, or should struct phy_mux be refcounted while a parent is attached? Would a managed device link be enough to guarantee the unbind ordering? [Severity: Medium] What happens when the switch to the new port fails? phy_mux_state_machine() and phy_mux_port_set_available() both ignore the return value of phy_mux_select(). phy_mux_select() deselects the old port before it tries the new one, and nothing is rolled back: phy_mux_select() { ... if (mux->current_port) { __phy_mux_deselect_port(mux, mux->current_port); mux->current_port = NULL; } ... ret = __phy_mux_select_port(mux, port); if (ret) return ret; ... } For a PHY port, __phy_mux_deselect_port() also calls phy_suspend() through phy_mux_phy_power_down() and clears netdev->phydev. The phylink parent added later in this series makes the switch back to copper after an SFP module removal reachable: phylink_sfp_module_remove() phy_mux_port_set_available(sfp, false) phy_mux_trigger() phy_mux_state_machine() phy_mux_select() __phy_mux_deselect_port(SFP) __phy_mux_select_port(PHY) phylink_mux_select() phylink_bringup_phy() phylink_bringup_phy() can fail in phylink_validate_phy(). It can also fail when phy_eee_rx_clock_stop() hits an MDIO error, or return -EBUSY if pl->phydev is still set. A PHY port's available flag is set once in phy_mux_register_port() and never changes. A repeated phy_mux_port_set_available() call with the same value returns early. Can this leave current_port NULL, with no port selected while the copper cable is still connected, and nothing retrying until ifdown/ifup or the next SFP event? Should the error at least be logged, or should phy_mux_choose_port() fall back to another available port? Before this patch, phy_mux_select() was only called with current_port NULL from phy_mux_start(), or with port NULL from phy_mux_stop(). A deselect followed by a failed select could not happen then. [ ... ] > @@ -312,13 +422,8 @@ EXPORT_SYMBOL_GPL(phy_mux_detach); > */ > void phy_mux_start(struct phy_mux *mux) > { > - struct phy_mux_port *port; > - unsigned long id = 0; > - > mux->state = PHY_MUX_STARTED; > - > - port = xa_find(&mux->ports, &id, ULONG_MAX, XA_PRESENT); > - phy_mux_select(mux, port); > + phy_mux_trigger(mux); > } [Severity: Low] This changes phy_mux_start() from synchronous to deferred selection for every mux, PHY-only ones included. The commit message doesn't mention it. Before, pops->select() had run and netdev->phydev was set by the time phy_mux_start() returned. Now the work is queued on system_freezable_power_efficient_wq, and phy_mux_state_machine() takes rtnl_lock(). Callers of phy_mux_start() already hold rtnl, so selection only happens after the caller drops rtnl. On resume paths it also waits for the freezable workqueue to thaw. The kernel-doc above phy_mux_start() still says: * To be called when the parent is ready to use the PHY of the selected * port, typically when the interface is brought up. Caller must hold rtnl. Could the kernel-doc of phy_mux_start() and struct phy_mux_parent_ops say that select/deselect may now run later from a worker, or synchronously from phy_mux_port_set_available()? The later commit "net: phylink: Support PHYs reached through a phy_mux" documents this for phylink ("the first selection, which only happens after phylink_start()"). The core API documentation in this patch says nothing about it. The commit message also doesn't mention three other changes: - the new init_port parameter of the exported phy_mux_fwnode_add_ports() - the new selection policy: the precedence port first, then the first available port - the deferred start described above Could those be described as well? [ ... ] > diff --git a/include/linux/phy_mux.h b/include/linux/phy_mux.h > index 6a42ffff02b7b..77cf389b8c776 100644 > --- a/include/linux/phy_mux.h > +++ b/include/linux/phy_mux.h [ ... ] > @@ -30,9 +31,14 @@ enum phy_mux_port_type { > * @type: What sits behind that port > * @phydev: For PHY_MUX_PORT_PHY, the PHY device behind the port, while the > * mux is attached > - * @fwnode: For PHY_MUX_PORT_PHY, the firmware node of that PHY > + * @fwnode: For PHY_MUX_PORT_PHY, the firmware node of that PHY. For > + * PHY_MUX_PORT_SFP, the port's own firmware node, carrying the sfp > + * property. > * @ops: How to drive that port > * @interface: The MII mode the link runs in when this port is selected [Severity: Low] Is this description still accurate for SFP ports? phy_mux_add_sfp_port() never sets port->interface, so it stays at the kzalloc_obj() value of 0 (PHY_INTERFACE_MODE_NA). The mii-mux binding forbids phy-mode on sfp ports, so there is nothing to parse. The real mode depends on the inserted module and isn't tracked by the mux. Should @interface be limited to PHY_MUX_PORT_PHY, like @phydev and @attached? > + * @available: The port can be used (e.g. an SFP module is plugged) > + * @has_precedence: The port is selected as soon as it is available, whatever > + * the other ports do. > * @attached: For PHY_MUX_PORT_PHY, the PHY is attached to the mux's netdev > * @selected: The port currently drives the MII > */ [ ... ] -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204110622.1106492-1-maxime.chevallier%40bootlin.com