Article View: linux.kernel.netdev
Article #27374Re: [PATCH net-next 04/12] net: phy: phy_mux: Allow attaching a mux to a net_device
From: netdev-bot+sashiko
Date: Sat, 05 Dec 2026 12:18
Date: Sat, 05 Dec 2026 12:18
292 lines
19213 bytes
19213 bytes
Thank you for your contribution! Sashiko AI review found 6 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 3 · 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] Only the parent's optional pops->detach can undo an attach.
- [Medium] At this commit phy_mux_detach() takes no lock and asserts
none, yet it clears mux->pops, mux->parent_priv and mux->netdev and…
- [Medium] net: phy: phy_mux: phy_mux_attach() clobbers dev->sfp_bus
- [Low] The commit message and kernel-doc describe things this commit
does not contain.
- [Low] The patch deletes the still-accurate kernel-doc line "The mux
still has to be freed with phy_mux_free()" from phy_mux_unregister().
- [Low] fwnode_phy_mux_attach() holds the global phy_mux_mutex across
phy_attach_direct() for every muxed PHY, across device_link_add(), and…
--
net: phy: phy_mux: Allow attaching a mux to a net_device
This commit adds fwnode_phy_mux_attach() and phy_mux_detach(), so a mux
can be attached to a net_device. A parent, later phylink, can register
attach and detach callbacks. Every PHY behind the mux is attached to the
netdev with its link change callback overridden, and a device link is
added from the netdev's parent to the mux device.
> diff --git a/drivers/net/phy/phy_mux.c b/drivers/net/phy/phy_mux.c
> index e259eb4e271a0..691bca09e0af1 100644
> --- a/drivers/net/phy/phy_mux.c
> +++ b/drivers/net/phy/phy_mux.c
[ ... ]
> @@ -16,12 +18,196 @@ struct phy_mux {
[ ... ]
> +static void phy_mux_phy_link_change(struct phy_device *phydev, bool up)
> +{
> +}
[ ... ]
> + * All the PHYs behind the mux are looked up and attached to @dev, and stay
> + * attached until phy_mux_detach(). The parent only gets to use the one that
> + * is selected.
[ ... ]
> + ret = phy_attach_direct(dev, port->phydev, phy_flags,
> + port->interface);
> + if (ret) {
> + phy_mux_port_unbind_phy(port);
> + goto err_detach;
> + }
> +
> + port->phydev->phy_link_change = phy_mux_phy_link_change;
> + port->attached = true;
> + has_phys = true;
> + }
[Severity: Medium]
phy_attach_direct() does more than set dev->phydev. When the PHY has a
downstream SFP cage, it also does this:
drivers/net/phy/phy_device.c:phy_attach_direct() {
...
if (dev) {
phydev->attached_dev = dev;
dev->phydev = phydev;
if (phydev->sfp_bus_attached)
dev->sfp_bus = phydev->sfp_bus;
...
}
The sysfs link creation is skipped when phydev->mux_port is set, but
this assignment is not. phy_mux_attach() then resets dev->phydev to
NULL and leaves dev->sfp_bus as it is.
Suppose one of the muxed PHYs has its own SFP cage, through an sfp
property handled by phy_sfp_probe() as on 88E1510, 88X3310 or QCA807x.
Attaching the mux then overwrites whatever dev->sfp_bus already held.
That could be the mux SFP cage that phylink_register_mux_sfp() sets up
later in the series, or another muxed PHY's cage.
dev->sfp_bus would then point at the SFP bus of a PHY that may not be
selected. ethtool -m would read the wrong module, and
phy_link_topo_add_phy() would record the wrong parent_sfp_bus for a
copper module plugged into the mux cage.
Deselected PHYs stay attached with attached_dev == dev. So
phy_sfp_attach() and phy_sfp_detach() on any muxed PHY keep rewriting
or clearing dev->sfp_bus, whichever port is selected.
On the way out, neither the err_detach unwind in phy_mux_attach() nor
phy_mux_detach() restores dev->sfp_bus, so the mux cage's entry is
lost. Once phy_detach() has cleared attached_dev, phy_sfp_detach() can
no longer clear dev->sfp_bus either. If the PHY and its SFP socket are
then unbound while the netdev stays registered, dev->sfp_bus is left
dangling for the next ethtool -m.
The Turris Omnia description later in the series has no SFP cage
behind the muxed 88E1514, so it doesn't hit this. Nothing in the
series prevents such a topology, though.
Should phy_attach_direct() and the phy_sfp_attach()/phy_sfp_detach()
upstream ops skip dev->sfp_bus when phydev->mux_port is set? The mux
selection path could then own dev->sfp_bus for the selected port.
Alternatively, should phy_mux_attach() reject muxed PHYs that have a
downstream SFP bus until that is handled?
[Severity: Low]
The commit message says the parent registers callbacks "to be notified
when switching occurs". The phy_mux_attach() kernel-doc says "The parent
only gets to use the one that is selected".
In this patch, struct phy_mux_parent_ops only has attach and detach, and
the mux has no selection state. Every muxed PHY also gets the empty
phy_mux_phy_link_change() stub in place of the phy_link_change() handler
that phy_attach_direct() installed. As a result, link events from all
muxed PHYs are dropped.
Later in the series, "net: phy: phy_mux: Add port selection logic" adds
select/deselect to phy_mux_parent_ops, along with current_port,
phy_mux_select() and phy_mux_start()/stop(). Then "net: phylink: Support
PHYs reached through a phy_mux" points the selected PHY's phy_link_change
at phylink through phylink_bringup_phy(). Nothing calls
fwnode_phy_mux_attach() at this commit, so there is no runtime effect.
Could the commit message and kernel-doc describe only what this patch
provides, or say that port selection arrives in a follow-up patch?
[ ... ]
> +int
> +fwnode_phy_mux_attach(const struct fwnode_handle *fwnode,
> + struct net_device *dev, u32 phy_flags,
> + const struct phy_mux_parent_ops *pops, void *priv)
> +{
> + int ret = -EPROBE_DEFER;
> + struct phy_mux *mux;
> +
> + mutex_lock(&phy_mux_mutex);
> + list_for_each_entry(mux, &phy_muxes, node) {
> + if (dev_fwnode(mux->dev) != fwnode)
> + continue;
> +
> + ret = phy_mux_attach(mux, dev, phy_flags, pops, priv);
> + break;
> + }
> + mutex_unlock(&phy_mux_mutex);
[Severity: Low]
Here the global phy_mux_mutex stays held across phy_attach_direct() for
each muxed PHY, across device_link_add(), and across the parent's
pops->attach() callback.
I couldn't find an in-tree path that reverses the rtnl -> phy_mux_mutex
order:
- phy_mux_unregister() releases phy_mux_mutex before rtnl_lock().
- phy_attach_direct() never reaches sfp_bus_add_upstream() for these
PHYs.
- phylink_mux_attach(), added later in the series, only sets flags and
pointers.
Would it help to note in the struct phy_mux_parent_ops kernel-doc that
@attach runs with phy_mux_mutex held? That would warn a future parent not
to take rtnl or re-enter the mux API from that callback.
[ ... ]
> +void phy_mux_detach(struct phy_mux *mux)
> +{
> + if (!mux->netdev)
> + return;
> +
> + phy_mux_detach_phys(mux);
> +
> + if (mux->devlink) {
> + device_link_del(mux->devlink);
> + mux->devlink = NULL;
> + }
> +
> + mux->pops = NULL;
> + mux->parent_priv = NULL;
> + mux->netdev = NULL;
> +}
[Severity: Medium]
phy_mux_detach() clears mux->pops, mux->parent_priv, mux->netdev and the
per-port attached state without taking or asserting any lock.
phy_mux_attach() writes these fields under phy_mux_mutex. The
check-then-call on them in phy_mux_unregister() below holds only rtnl.
Suppose a parent calls phy_mux_detach() without rtnl while the mux driver
is being unbound. Could that race with phy_mux_unregister() and cause a
NULL mux->pops dereference, or a double phy_detach()/put_device() on the
muxed PHYs?
"net: phy: phy_mux: Add port selection logic" later adds "Caller must
hold rtnl when the mux was started" to the phy_mux_detach() kernel-doc.
The in-tree phylink paths hold rtnl, with one exception:
phylink_destroy()->phylink_detach_mux(). That call is a no-op if
phylink_disconnect_phy() has already run, as phylink_destroy() requires.
The stateless device_link does not order the two unbinds, though.
Would an ASSERT_RTNL() in phy_mux_detach() make the requirement explicit?
[ ... ]
> @@ -160,14 +347,17 @@ EXPORT_SYMBOL_GPL(phy_mux_register);
> /**
> * phy_mux_unregister() - Make the mux unavailable to its parent
> * @mux: The mux, registered
> - *
> - * The mux still has to be freed with phy_mux_free().
> */
[Severity: Low]
This isn't a bug, but the removed sentence "The mux still has to be freed
with phy_mux_free()." still looks accurate. phy_mux_free() is still
required and still exported.
phy_mux_unregister() also now takes rtnl_lock() and calls the parent's
pops->detach() under it. A mux provider that calls it with rtnl held
would deadlock on rtnl_mutex.
Could the kernel-doc keep the phy_mux_free() note and say that the
function must be called without rtnl held?
> void phy_mux_unregister(struct phy_mux *mux)
> {
> mutex_lock(&phy_mux_mutex);
> list_del(&mux->node);
> mutex_unlock(&phy_mux_mutex);
> +
> + rtnl_lock();
> + if (mux->netdev && mux->pops && mux->pops->detach)
> + mux->pops->detach(mux, mux->parent_priv);
> + rtnl_unlock();
> }
[Severity: Medium]
Is the optional pops->detach() the only thing that can undo an attach?
phy_mux_attach() treats the ops as optional:
if (pops && pops->attach)
pops->attach(mux, priv);
fwnode_phy_mux_attach() only returns an int. The parent can therefore
only get the mux pointer that phy_mux_detach() needs through
pops->attach.
If pops or pops->detach is NULL, or the detach callback does not call
phy_mux_detach(), nothing here detaches the PHYs. phy_mux_free() then
calls phy_mux_port_destroy() on every port. For ports that still have
port->attached set, that only unbinds the PHY and never calls
phy_detach():
drivers/net/phy/phy_mux.c:phy_mux_port_destroy() {
...
case PHY_MUX_PORT_PHY:
phy_mux_port_unbind_phy(mux_port);
fwnode_handle_put(mux_port->fwnode);
break;
...
}
Would this leak the references taken by phy_attach_direct(), the
link_topo entry and mux->devlink? It would also leave
phydev->attached_dev pointing at a netdev that may be freed later.
At the end of the series, the only in-tree parent is phylink. It always
passes phylink_mux_ops with all callbacks, and phylink_mux_detach()
calls phy_mux_detach(). Triggering this would take a caller that misuses
the API.
Could phy_mux_attach() reject NULL attach/detach ops with -EINVAL? As an
alternative, phy_mux_unregister() could call phy_mux_detach() itself when
mux->netdev is still set after the callback.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204110622.1106492-1-maxime.chevallier%40bootlin.com
Technical Details
Message-ID:
<179647310752.3146.1046625871089751112@kernel.org>Path:
mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!newsfeed.endofthelinebbs.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377977-linux-kernel-netdev=dewy.ruReferences:
<20261204110622.1106492-5-maxime.chevallier@bootlin.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!newsfeed.endofthelinebbs.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377977-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net-next 04/12] net: phy: phy_mux: Allow attaching a mux to a net_device Date: Sat, 05 Dec 2026 12:18:27 +0000 Organization: Usenet Network Message-ID: <179647310752.3146.1046625871089751112@kernel.org> References: <20261204110622.1106492-5-maxime.chevallier@bootlin.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3023210"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:c/JSd3AWHaBXqREEOoZK1abYYGA= sha256:WkUZbvxXhsZqtsE8HCzfH3o0+BFYacUOcBXoqK9xEUw= sha1:QeyZTniWIuh38qyG4Deyf9+rrsI= sha256:OB6NMDYeegSENPNyGzi6r6V+6uNuPPDhS7BNuXfe9Os= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 59E7E117DED; Sat, 5 Dec 2026 15:19:03 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.54 X-Spam-Status: No, score=-3.54 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.14, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 011pMkpM84vr; Sat, 5 Dec 2026 15:19:00 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-377977-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id CD75B117E15; Sat, 5 Dec 2026 15:18:51 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id 26BCC2DF40; Sat, 5 Dec 2026 12:18:48 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796473116; b=eS43LLIw+OWjSAmE4/gGtjTvf+bJS1RXvog4nQSerka880nZFhqfMq5I9XXbETCRb3+2 Q/KfNfM2byDxTeoErFA9UuFhStjwfFZBMzchHJLLNW2FC2qCICCaTc6x1Hr4xdMGKfJHL BZ3/ES3hvGJYwtxfB3KF0hPfyz5XhAOfHIeSDX49eQWJIAoPpumkipnhncZrWJc4+zRUK 9dBxtehKiJuSCKO8h9+wwtap0XAfEAubGI1ARn5faVtPFtq0/zpss46wOZct38GvKki7U PC3JDt0StbkVJnAPz2zy41o6TwlExzUkPo89XWMvXv83psl26UPC1dxZNfm3UFjDb6A== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796473116; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=aM2YhzBOAV+xGxciMJxQX+h8JylkvfJg3mMIA1fZqLw=; b=cxIx7r6hs/CIANfXeJMpTgdllcAnvcebn7ZdEOreFeG0/8vIOCyUi9HhS6bTeh2U21tQ /o/3ity3AEJaLj6TxijPKWZ0FMOle0IH8Fhefy8lL+E9aH1rYMsk0wyBZJxf4T73G7KJn HK2zPJnhHaWnRb8wMmWboqSzggdWfH9Q7mpIoy65fRg8X0MoT6SSfVtsMGr41eUsPYDUM zE/0tZwDrjTMLxiISbRGuTgbQF1Vi/2RTwTxHozeJEJC207+HFNmrTVGa7+5PObZzKnVB +cjQ1WRnjaZuw2l1TcVff6a10U8Dks4x3GQnvJH6GAnwwDK2A32K4IPx3KBeR3iVy5w== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=OZSDHnT0; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F0900606A696; Sat, 5 Dec 2026 12:18:35 +0000 (UTC) X-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=OZSDHnT0 X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796473110; b=ThP+VU1NbOP7pCsP7bI7y3IU8zCdAJdbfuMSTarlWOmT4/u9x97O45oV/lnlGq95IA1i 8U+oI+HN+7HItXarGdvQMbfq7sBcgmT2IggR9BYqpS5bPMOBS6/6U37niWxkA0tw+CEVN F9H8enUcMsLe60znP1avCh8E7+Fv5cCqbbPwg+ysOm6fcoXdXflgAqJER5Meubd82rWxF MK5/ivyvuyXaoH/Sy+ElE7Anq8NiCafrd1rspNYDgyAtL1EfM8TfXo6Mt2tAxuVfQLMnW njnRR0qTKIL21rcV7mb9eJcNSapu3jCcgBN49w+B3rIdzU8/HLhgMsYjH0ZghXVkdRA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796473110; 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=aM2YhzBOAV+xGxciMJxQX+h8JylkvfJg3mMIA1fZqLw=; b=Dw8DYBvcj26SrjuqCZoh5p8D1v+b8kfwPouzPB+F9KTsyQUVA2lnYkiLjeBTgIkA3jYR kWG4RDTkaLyEUTL4WNIUnWEjYlbwG3G4fgtaK2K542YL0hu0xML/VXMyEJFTrN4HM1Lg8 5ijqudb8Dn17pz85uGcavyyR36ngzu389ldp2nMMhJmNoRt8afg0JUAQ8v/URBT2yYSIW t7qxppXX18iqI49uwFnJ1hKihiiBHWYRRjhVR/5khyHXZGuRq/dZO64hulNrDZ/2A5vPA jTYHFU1Cp0R+5k+GSwm4mpctl0Es36SRsbI8ZpJnw3xZICbbFy1IGCZihd/kdESL1DQ== X-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=OZSDHnT0; arc=none smtp.remote-ip=100.103.45.18 X-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 1C65C606A334; Sat, 5 Dec 2026 12:18:29 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB6521F0092B; Sat, 5 Dec 2026 12:18:27 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796473109; bh=aM2YhzBOAV+xGxciMJxQX+h8JylkvfJg3mMIA1fZqLw=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=OZSDHnT0C2sd9gZI+ZiNU9TUa/4r9xLbZ/2zTo7j1Nw3obMVsks1lnxoxJ+tIkWeP lrIQqebklp0H966z7o/klVtfJwohXPiMceITBsTG2vnOfBySX3PTUXrTs5DGveEIG1 qBf5+WT/Z7d1ZxfW4Erci/xOil//YcecM48NJqwg26IYxrpZalzdKLDd5sEStdOHJp Vzn0jVMkCfl+292ZTPCpcznN0MVxbvHfZMCpG6II6WfElSHeRoU+jjp2Rw0vDNcx80 yEQv5X5Zu6uO5+1x8qXeMkKTPIAIG2MfeSAbD1edUzLouMM+jTb7KuqXx6OcGYK4BW IPCygrh88uOLA== X-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 X-In-Reply-To: <20261204110622.1106492-5-maxime.chevallier@bootlin.com> X-sashiko-severity: Medium X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list