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=H9jIwS8ZjDDmQ/wlWF+9yw7ahOILQA5HpEyxq9AWyR1F/7A/ZQUHbw6k5zxRgFJ5FBC/ tgvkovRVleXO5Wqvikd/eAKmUcHjPASTILiAtfonSEptkKnmdeAUKLtiwvlYOdc0NPH92 pDd7BBTif+xluRROartA6+KGj6eOisTHd5+Eu7h6y07GkxjJgn0GQJQXnfZnhSmozk29j 7lFOwVFe0ELJIuyK0gMg/1lYb+45WdtkCF0ozW2aQVgxcDO6xHa913qMGDpx4ShWC7JyT pxiGIzoiEeLNFFYQe8lMQNlTA+UUk8etzYgfOmDmH51xewXVxIkia0KIf2PVxDRjAbg== 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=beLRsuSTy5RU53STQqfCL5UiPzoaro6lfV6L2XFhSXs=; b=UgQ0WIQT61TfjD3dW3enHnISAJPHds/6JPOQSLZCxG/Yy7CTTmx0ZIdUuXZ2trivizVG rf4Ud59lyPXjlnA0fmLpNsVIb1moz8dtXfLkwgdgKmq7hHxKIqAobBOSi9Rp1PvMa19U7 R+UU66Yfho1YzsshUa+8KgeLX5RMeLL0HZwOFtAZkEy9IIWLqDL2ucRydE0wWbnylXyjk mMSTw2iGx/OBewdeHQuu7g1YWgruyw6DaZLWVxQ0iF633oUjRfZteZZrpKXTTUNelSlwa xjlQ5EnTCKKAdw/XilbD7onsCdaw5FD9hnt1GJG/azNV1E7Tu8AE0+rVdgaaT5EwhGg== 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=iv8EAW57; 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 EBB43606A32F for ; Sat, 5 Dec 2026 11:08:50 +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=iv8EAW57 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B0FB1F00A07; Sat, 5 Dec 2026 11:08:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796468930; bh=beLRsuSTy5RU53STQqfCL5UiPzoaro6lfV6L2XFhSXs=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=iv8EAW57Vq/DtU7Pn/VSPQWrvi2y/XrM+71OFZCAKpYkGXYfPV5cNdrJ66jprjlJI BMbQBlJCMLBqtlfWlRCA/lVP22JcC/M0V741mEo9zehNJ1z0zLf2903oO04QqwyBMa BP+AVxmT2M2MQFTnTWHE0M4lUwDqUIpb/Rc9/BAD2Os/Eq8bvso577Fp63pr3Cg2sq q9Vp062JepxnmHDyCQyUeNnUhKsz7Q+3GLxt0lrIgG/kkSYeD601Wkzvgrgdofec5n hSTBl0HM4iuhNHXn1OqFRUwVAM8vpcqpm5aX9gJNrcjYVG3lP1c84cNZ9rv0FEQ/ju r9B345ifDVScg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH net-next 06/12] net: phy: phy_mux: Support SFP cage ports 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-7-maxime.chevallier@bootlin.com> References: <20261204110622.1106492-1-maxime.chevallier@bootlin.com> <20261204110622.1106492-7-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 5 potential issues to consider: - [Medium] net: phy: phy_mux_detach() races with unregister, free, and attach - [Medium] net: phy: phy_mux_select() errors silently ignored by callers - [Medium] net: phy: phy_mux_start() defers port selection past ndo_open() and RTNL - [Low] net: phy: phy_mux_port_set_available() queues work when stopped - [Low] net: phy: commit message overstates auto-mux scope and omits design -- commit 7f7c13dd3f5d9a4be97b36f9ec7d719e76abf8ad Author: Maxime Chevallier > net: phy: phy_mux: Support SFP cage ports > > It's quite common to have combo ports where one of the ports is an SFP > cage, let's allow adding one on the mux. > > To keep things realistic, we only allow one SFP cage per combo port. > > When an SFP cage doesn't have any module inserted, it doesn't really > make sense to allow using it as the active port, so we need to keep > track of whether there's a module or not. > > There's a simple way to implement a combo port that we find on Turris > Omnia for example, that is to wire the SFP cage's mod_def0 to the > physical multiplexer. In this case, we can't select the port to use from > the host, but we can report that the port is in use and shutdown the > unused port. For that, we however need to indicate that the SFP cage > always takes precedence, as represented in the auto-mux binding. > > So, add support for attaching SFP cages to muxes, and implement the > automatic mux. > > Signed-off-by: Maxime Chevallier [Severity: Low] This isn't a bug, but the closing sentence states that this patch implements the automatic mux, whereas it only adds core phy_mux support for SFP ports and port precedence (not the mii-mux-auto driver or its DT property parsing). The commit message also omits explaining the new init_port callback in phy_mux_fwnode_add_ports(), changing phy_mux_start() to defer selection to state_work, and why phy_mux_port_set_available() selects synchronously when available is true but defers to state_work when false. > 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_po= wer_ops =3D { > .deselect =3D phy_mux_phy_power_down, > }; > =20 > +static struct phy_mux_port *phy_mux_choose_port(struct phy_mux *mux) > +{ > + struct phy_mux_port *port; > + unsigned long id; > + > + xa_for_each(&mux->ports, id, port) > + if (port->has_precedence && port->available) > + return port; > + > + xa_for_each(&mux->ports, id, port) > + if (port->available) > + return port; > + > + return NULL; > +} > + > +static void phy_mux_state_machine(struct work_struct *work) > +{ > + struct phy_mux *mux =3D 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(); > +} [Severity: Medium] Should phy_mux_state_machine() and phy_mux_port_set_available() check the return value of phy_mux_select()? phy_mux_select() deselects any active mux->current_port and sets it to NULL before calling __phy_mux_select_port(). If mux->pops->select() fails (for example, phylink_bringup_phy() failing in phy_eee_rx_clock_stop() or phylink_validate_phy()), ignoring the error leaves mux->current_port NULL and the interface up with no active port or link, without logging any error. > +void phy_mux_port_set_available(struct phy_mux_port *port, bool availabl= e) > +{ > + struct phy_mux *mux =3D port->mux; > + > + ASSERT_RTNL(); > + > + if (port->available =3D=3D available) > + return; > + > + port->available =3D available; > + > + if (available && mux->state =3D=3D PHY_MUX_STARTED) { > + phy_mux_select(mux, phy_mux_choose_port(mux)); > + return; > + } > + > + phy_mux_trigger(mux); > +} [Severity: Low] Should phy_mux_port_set_available() return early when mux->state !=3D PHY_MUX_STARTED? When the mux is stopped, falling through to phy_mux_trigger() wakes a kworker and acquires rtnl_lock() in phy_mux_state_machine() only to break out of the switch. phy_mux_stop() also returns early when already stopped, so work queued while stopped is not cancelled there either. [ ... ] > @@ -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 =3D 0; > - > mux->state =3D PHY_MUX_STARTED; > - > - port =3D xa_find(&mux->ports, &id, ULONG_MAX, XA_PRESENT); > - phy_mux_select(mux, port); > + phy_mux_trigger(mux); > } > EXPORT_SYMBOL_GPL(phy_mux_start); [Severity: Medium] Does deferring initial port selection to state_work break callers that expect a PHY to be selected when phy_mux_start() returns? Because phy_mux_state_machine() blocks on rtnl_lock(), port selection cannot run until ndo_open() releases RTNL. Drivers such as stmmac_open() and mvneta_start_dev() call phylink_speed_up() right after phylink_start() under the same RTNL lock, where pl->phydev is now guaranteed to be NULL; phy_speed_up() is silently skipped and a PHY downgraded by phylink_speed_down() remains stuck at its lowest advertised speed. Userspace ethtool calls issued immediately after ip link set up can also race ahead of state_work and see pl->phydev =3D=3D NULL. Calling phy_mux_select(mux, phy_mux_choose_port(mux)) synchronously in phy_mux_start() under the caller's held RTNL lock avoids both issues and the extra kworker wakeup. [ ... ] > @@ -502,6 +672,8 @@ void phy_mux_free(struct phy_mux *mux) > struct phy_mux_port *port; > unsigned long id; > =20 > + disable_work_sync(&mux->state_work); > + > xa_for_each(&mux->ports, id, port) > phy_mux_port_destroy(port); [Severity: Medium] Can phy_mux_detach() race with phy_mux_unregister(), phy_mux_free(), and fwnode_phy_mux_attach()? fwnode_phy_mux_attach() holds phy_mux_mutex without requiring rtnl_lock(), phy_mux_unregister() drops phy_mux_mutex and holds only rtnl_lock(), and phy_mux_detach() acquires neither lock (and is permitted without RTNL when the mux is stopped, as in phylink_destroy()). Because mux->devlink uses DL_FLAG_STATELESS and struct phy_mux has no reference count, unbinding the MAC device and mux device concurrently can interleave: CPU0 CPU1 phy_mux_detach(mux) if (!mux->netdev) -> false ... phy_mux_unregister(mux) rtnl_lock() mux->pops->detach(...) rtnl_unlock() phy_mux_free(mux) kfree(mux) mux->netdev =3D NULL <-- use-after-free Depending on timing, CPU1 can also trigger a double detach (double phy_detach() and device_link_del()), or dereference a NULL mux->pops or freed parent_priv if CPU0 clears them after CPU1 checks them. Concurrent fwnode_phy_mux_attach() and phy_mux_detach() are similarly unsynchronized on mux->netdev and port PHY bindings. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204110622.1106= 492-1-maxime.chevallier@bootlin.com?part=3D6