Article View: linux.kernel.netdev
Article #27372Re: [PATCH net-next 05/12] net: phy: phy_mux: Add port selection logic
From: netdev-bot+sashiko
Date: Sat, 05 Dec 2026 12:18
Date: Sat, 05 Dec 2026 12:18
270 lines
18682 bytes
18682 bytes
Thank you for your contribution! Sashiko AI review found 7 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 3 · Low: 4
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] phy_mux_start() (drivers/net/phy/phy_mux.c) sets mux->state =
PHY_MUX_STARTED and then calls phy_mux_select(mux, port), but it…
- [Medium] phy_mux_attach() now runs phy_mux_port_deselect() on every
port right after phy_attach_direct().
- [Medium] net: phy: unlocked phy_mux_detach() races with unregister and
ethtool
- [Low] Concern: phy_mux_unregister() calls pops->detach() and only then
phy_mux_stop(), so a deselect callback could reach a parent that has…
- [Low] The mux's own bookkeeping, phy_mux_port_set_parent_phy(), depends
on which optional parent callbacks exist, and the two directions check…
- [Low] Concern: phy_mux_start() does not check that the mux is attached.
- [Low] Concern: phy_mux_detach() and phy_mux_stop() read mux->state with
no lock under a conditional rtnl contract, so a phy_mux_start() coming…
--
net: phy: phy_mux: Add port selection logic
This patch adds port selection to phy_mux. phy_mux_start() selects the
first port and phy_mux_stop() deselects the current one, and the parent
is told through new select/deselect callbacks. It also adds
phy_mux_port_ops, whose only op for now powers down the PHY of a
deselected port. All ports are deselected when the mux gets attached.
> diff --git a/drivers/net/phy/phy_mux.c b/drivers/net/phy/phy_mux.c
> index 691bca09e0af1..407269980edc1 100644
> --- a/drivers/net/phy/phy_mux.c
> +++ b/drivers/net/phy/phy_mux.c
[ ... ]
> @@ -26,12 +31,97 @@ struct phy_mux {
[ ... ]
> +static void __phy_mux_deselect_port(struct phy_mux *mux,
> + struct phy_mux_port *port)
> +{
> + if (mux->pops && mux->pops->deselect) {
> + mux->pops->deselect(mux, port, mux->parent_priv);
> + phy_mux_port_set_parent_phy(mux, port, false);
> + }
> +
> + phy_mux_port_deselect(port);
> +
> + port->selected = false;
> +}
> +
> +static int __phy_mux_select_port(struct phy_mux *mux,
> + struct phy_mux_port *port)
> +{
> + int ret;
> +
> + if (mux->pops && mux->pops->select) {
> + ret = mux->pops->select(mux, port, mux->parent_priv);
> + phy_mux_port_set_parent_phy(mux, port, !ret);
> + if (ret)
> + return ret;
> + }
[Severity: Low]
Should phy_mux_port_set_parent_phy() depend on which optional parent
callbacks are present?
The select side only sets netdev->phydev when pops->select is set. The
deselect side only clears it when pops->deselect is set. The kernel-doc
for struct phy_mux_parent_ops doesn't say the two have to be implemented
together.
Take a parent that provides .select but not .deselect. After
phy_mux_stop(), netdev->phydev would still point at the deselected PHY,
and phy_link_change would not be restored to phy_mux_phy_link_change.
Meanwhile phy_mux_phy_power_down() suspends that PHY. Generic
netdev->phydev users such as the ethtool PHY ops would then act on a
suspended, deselected PHY until phy_mux_detach_phys() runs.
The reverse case, .deselect without .select, would send the parent a
deselect for a port it was never told was selected.
The only in-tree parent (phylink_mux_ops, later in the series) provides
both callbacks, so nothing hits this today.
Could this bookkeeping run unconditionally, or could the kernel-doc state
that the two callbacks must be paired?
[ ... ]
> @@ -129,6 +219,9 @@ static int phy_mux_attach(struct phy_mux *mux, struct net_device *dev,
> if (has_phys)
> dev->phydev = NULL;
>
> + xa_for_each(&mux->ports, id, port)
> + phy_mux_port_deselect(port);
> +
[Severity: Medium]
This loop calls phy_mux_phy_power_down() -> phy_suspend() on every PHY
right after phy_attach_direct() resumed it with phy_resume(). On genphy
that sets BMCR_PDOWN.
phy_mux_port_ops has no select or resume op, so the mux never powers a
PHY back up itself. Later in the series this only happens in
phylink_mux_select() -> phy_start(), which runs from phylink_start() ->
phy_mux_start() -> state_work.
Also later in the series, phylink_attach_mux() passes PHY_F_RXC_ALWAYS_ON
to fwnode_phy_mux_attach() when pl->config->mac_requires_rxc is set. Does
this power-down cancel out that flag?
phylink_fwnode_phy_connect()
phylink_attach_mux() /* flags |= PHY_F_RXC_ALWAYS_ON */
fwnode_phy_mux_attach()
phy_mux_attach()
phy_attach_direct() /* phy_resume() */
phy_mux_port_deselect()
phy_mux_phy_power_down()
phy_suspend()
Some MACs need the PHY's RX clock between connect and phylink_start(),
for example for a DMA soft reset in ndo_open. Behind a mux, such a MAC
could fail to open.
The only user so far (mvneta on Turris Omnia) doesn't set
mac_requires_rxc. The failure also depends on the PHY stopping RXC while
powered down.
[ ... ]
> +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);
> +}
[Severity: Medium]
What happens here if the parent's ->select() fails?
__phy_mux_select_port() rolls back netdev->phydev and phy_link_change.
phy_mux_select() then returns the error without setting
mux->current_port. phy_mux_start() drops that return value, and it is
declared void in include/linux/phy_mux.h, so the parent can't see the
failure either.
The mux is left in PHY_MUX_STARTED with current_port == NULL. Every PHY is
still powered down from phy_mux_attach(), and nothing retries the
selection.
The rest of the series doesn't change this. phy_mux_start() later only
queues state_work, and phy_mux_state_machine() also ignores the result of
phy_mux_select(mux, phy_mux_choose_port(mux)). The only later re-trigger
is an SFP availability change.
With phylink as the parent, phylink_mux_select() fails if
phylink_bringup_phy() fails. That can happen when port->interface fails
validation, or on an MDIO error from phy_eee_rx_clock_stop(). The
interface would then be up with no PHY and no link until it is taken down
and brought up again.
Should the error be returned to the caller, or should the selection be
retried?
[ ... ]
> @@ -188,13 +281,15 @@ EXPORT_SYMBOL_GPL(fwnode_phy_mux_attach);
> * phy_mux_detach() - Detach the mux from its parent
> * @mux: The mux
> *
> - * The PHYs behind the mux are detached.
> + * The mux is stopped and its PHYs are detached. Caller must hold rtnl when
> + * the mux was started.
> */
> void phy_mux_detach(struct phy_mux *mux)
> {
> if (!mux->netdev)
> return;
>
> + phy_mux_stop(mux);
> phy_mux_detach_phys(mux);
>
> if (mux->devlink) {
[Severity: Medium]
This kernel-doc makes rtnl optional for phy_mux_detach() as long as the
mux is stopped. In that case phy_mux_detach() does all of the following
without holding rtnl or phy_mux_mutex:
- runs phy_mux_detach_phys()
- calls device_link_del(mux->devlink)
- clears mux->pops, mux->parent_priv and mux->netdev
phy_mux_unregister() drops phy_mux_mutex right after list_del(). It
then relies only on rtnl to read mux->netdev and mux->pops and to call
mux->pops->detach(). An unlocked phy_mux_detach() therefore shares no
lock with it.
The two can also run at the same time. The device link added in
phy_mux_attach() is DL_FLAG_STATELESS, so unbinding the mux driver
doesn't unbind the MAC first. mii_mux_auto_remove(), later in the
series, can then run phy_mux_unregister() and phy_mux_free()
concurrently with MAC removal.
Later in the series, phylink_destroy() calls phylink_detach_mux() ->
phy_mux_detach() without rtnl, since phylink_destroy() must not be
called with rtnl held. That path is reachable with a stopped mux, for
example:
mvpp2_open()
phylink_fwnode_phy_connect() /* mux attached, PHY_MUX_STOPPED */
request_irq() fails /* no phylink_disconnect_phy() */
...
mvpp2_port_remove()
phylink_destroy()
phylink_detach_mux()
phy_mux_detach() /* no rtnl */
ucc_geth ends up in the same place when ucc_geth_open() fails in
ucc_geth_init_mac() or request_irq() and ucc_geth_remove() runs
later.
If the mux driver is unbound at that point, both CPUs can be inside
phy_mux_detach(). One of them gets there through mux->pops->detach()
-> phylink_mux_detach(). Possible results are:
- a double phy_detach() and device_link_del()
- a NULL dereference of mux->pops
- a use-after-free of the phylink passed as parent_priv
- a use-after-free of the mux and its ports after phy_mux_free()
ucc_geth registers its netdev with devm_register_netdev(), so it is
still NETREG_REGISTERED when phylink_destroy() runs. Two things follow:
- phy_detach() reaches the rcu_dereference_protected() on dev->hwprov
in phy_detach_internal() without rtnl, and lockdep will complain.
- phy_link_topo_del_phy() kfree()s the phy_device_node while an
ethtool netlink request in ethnl_req_get_phydev() may be looking it
up under rtnl.
The attach side doesn't help either. fwnode_phy_mux_attach() only
takes phy_mux_mutex, and callers such as dsa_user_create() and
ocelot_probe_port() don't hold rtnl. phy_mux_detach() takes neither
lock. So mux->netdev, mux->pops, mux->parent_priv and mux->devlink
have no single lock covering attach, detach and unregister.
Triggering this needs a privileged driver unbind or module unload on
top of an ndo_open() error path, so it isn't easy to hit. Nothing
later in the series changes it, though.
Should phy_mux_detach() always require rtnl, with phylink_destroy()
taking it around phylink_detach_mux()? Or should phy_mux_mutex protect
the mux state across attach, detach and unregister?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204110622.1106492-1-maxime.chevallier%40bootlin.com
Technical Details
Message-ID:
<179647310990.3146.3411864447818810188@kernel.org>Path:
mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mi.newsdeef.eu!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377978-linux-kernel-netdev=dewy.ruReferences:
<20261204110622.1106492-6-maxime.chevallier@bootlin.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mi.newsdeef.eu!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377978-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net-next 05/12] net: phy: phy_mux: Add port selection logic Date: Sat, 05 Dec 2026 12:18:29 +0000 Organization: Usenet Network Message-ID: <179647310990.3146.3411864447818810188@kernel.org> References: <20261204110622.1106492-6-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="3023036"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:7H550XEM6cWv4hl7SwlLqLV3nGA= sha256:8st48knB3k5Tw/w/RsDf40CXwXds5kAYKqWpsK53ILg= sha1:rbLomX9bDKOXX9hMvNXevgiHR5U= sha256:lW06Jba3iWkruwZ7L460BdMzkoxKUMuwKafm73N1C+k= 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 F0EBF117E19; Sat, 5 Dec 2026 15:18:55 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.64 X-Spam-Status: No, score=-3.64 tagged_above=-9999 required=6.31 tests=[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 g8mPMzfKAKae; Sat, 5 Dec 2026 15:18:54 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-377978-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id B817B117E0F; Sat, 5 Dec 2026 15:18:45 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 2958A29833; Sat, 5 Dec 2026 12:18:42 +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=1796473113; b=3QWxpuar3BjruyN7E7QCwvqP7fSv5kFuE8zKafCEWei2Dp6hTfTGYxpDinzJhRTZjLuM ECszYso07x95TlFmyKe4FblerXi8FDOTRLcWN4YaVjer1X3LWmpkSFjYTuvzlPugoIW83 TccD933RwgSR10AeCSCQ3zeTPQ6Az218h6R381rd6i7cRft949mQj43Z77YnNqbzcO4N6 f1dQ1aJO62pgVvXtWDhGxHSynMeQBMv/yb60pjM0vSGABpmzKkPKAns5KBXcYynzxRfeP GfKNFcUd1ieFFqHWjCfRI49htW3SnTxZ/FgwVKRqZ4cTd74Zkg2VIdwpuloZv/Vz41A== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796473113; 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=ItVtU43F501Mf0j96PwHA92lL/6aJdQsK14fReA3/98=; b=lx9z04mL7LWSxiBrdKrl9TJFANqHDggPaYE5bYOuh27tbpzZ1/KZeHisTrWB72x1+9QJ KQt5XuzWbiqdHkVWuq9WTvSe3pg1ZYQch+HXOnkaJL7y6VzpqLs3n9ymzJq8/DXJzs8YP +cJHNw9jCBZJJNNJ4XzO8VQSkQCCMwPy155+tkFVaQL+JLaXFEPogTpzJZiA2f8TLXQIf 0qUFClkaZ4dCm6BIo0cK6iFmMDcQRfXFjfd9gio6+jYFxYc05iegRZFYukI8uWN5kQTcw g9a7jGV1LUpfV8ByF9qohuftQAnhba8GP5g3TBNbQ8bZsKI7YHUoNW7WDnSZqFoNeeg== 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=lHmzn2AM; 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 7457A606A6AF; Sat, 5 Dec 2026 12:18:33 +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=lHmzn2AM 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=1796473112; b=s9wr3IdWiAGBaSIOuxwx6ts9X0mGsn21h7pvHCBTvz1y4ZvrNPiPsJIm17xsph+2SEfA 3gZYEg+r7am+DeK6zQAwvWpPNhf1tXh+FPsTiM4AscWoCW6QjxsI96sq+npbUEmy0X9Gk e+WAdX6aLcm3eYsTy56gX/H48lvXXMABvTSlew0FIoUdTQwizYOqCD3Fz7OTYgCfQdHJJ /UCdAR6hpUuCvyiErp3CHNAxirEINWMzbqEjVQ0RFwYbcgUaJcpu5vg8fpB1LT8F/3T5/ skNVjq1lIvJwVM8rBw3p6TagTUp5HGRr8WAjv1EBVPqR7T/P2mW39HtSHmtOsf0yF4A== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796473112; 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=ItVtU43F501Mf0j96PwHA92lL/6aJdQsK14fReA3/98=; b=t2ufxMm3Xn6N+71kuymrF65lM0Y3XUhE8ZsKYa2M8QceuXIYSKlp1qrjFWnPTZBYd993 FAaOHaBMkKOWpiKx/pwqggfbfb2QKNvttPFVSV4PCslvt8yWQ5WClobCHGmCIEsCvjNgS xQnI25PN0mmIdDr48rckVMSsAMpYbKvgjHkr9bDG0Em9ZECB+sxJ5hfsx8CY46orujfnb EaZgxsxQiDzg+LXcAMymtxyfU0eYVNCN+Csi0KVm3CNLznBVa/CaKrvjZCGRu85oOT+kf TaCWOaMj2wYRDyigqEPYobQWBcHPeqJbInEssVz+1uLAP0gbR8qLwZbGBkGyWlilsLw== 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=lHmzn2AM; 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 937EF606A69E; Sat, 5 Dec 2026 12:18:32 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5AADE1F0092B; Sat, 5 Dec 2026 12:18:30 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796473112; bh=ItVtU43F501Mf0j96PwHA92lL/6aJdQsK14fReA3/98=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=lHmzn2AMR9sBgPhDdawIcITauHFEu1h5yykFY/XrUwvlD2I6vaXM2ZZi1kKjhavzL KP28tyofXTeuAU9ln7cTvT+KCLCURPa0BJF7W2SqZkjNgZGFLlI5oRW90yyoahN4hX mk5Pa4Ve2XDb4NCPzl7jShe7qQA3JFaSqCpp0+k64CSU/UIRlAajeJ8MuZesBWFMyw aaYT3/6W6ZRhIlPChXsFStOqKARXTOAy58cJqfn/XNaCV+WY+ytElC9h0VqXoSP52/ VIanu5HVU79cwXyHfiSzEGbNrguV0hqfLAppvod5Y0Ev1xeIA/w9gGnso98+qvVVa1 VqPp1kc8Tfh+w== 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-6-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 X-Received-Bytes: 18444