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
Subject: Re: [PATCH net-next 05/12] net: phy: phy_mux: Add port selection logic
Date: Sat, 05 Dec 2026 12:18:29 +0000 [thread overview]
Message-ID: <179647310990.3146.3411864447818810188@kernel.org> (raw)
In-Reply-To: <20261204110622.1106492-6-maxime.chevallier@bootlin.com>
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
next prev parent reply other threads:[~2026-12-05 12:19 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 11:06 [PATCH net-next 00/12] net: phy: Introduce MII multiplexers Maxime Chevallier
2026-12-04 11:06 ` [PATCH net-next 01/12] dt-bindings: net: Add Ethernet " Maxime Chevallier
2026-12-05 12:18 ` netdev-bot+sashiko
2026-12-04 11:06 ` [PATCH net-next 02/12] net: phy: Introduce phy_mux, a MII multiplexer representation Maxime Chevallier
2026-12-04 11:06 ` [PATCH net-next 03/12] net: phy: Don't create the sysfs links for PHYs behind a mux Maxime Chevallier
2026-12-05 12:18 ` netdev-bot+sashiko
2026-12-04 11:06 ` [PATCH net-next 04/12] net: phy: phy_mux: Allow attaching a mux to a net_device Maxime Chevallier
2026-12-05 12:18 ` netdev-bot+sashiko
2026-12-04 11:06 ` [PATCH net-next 05/12] net: phy: phy_mux: Add port selection logic Maxime Chevallier
2026-12-05 12:18 ` netdev-bot+sashiko [this message]
2026-12-04 11:06 ` [PATCH net-next 06/12] net: phy: phy_mux: Support SFP cage ports Maxime Chevallier
2026-12-05 12:18 ` netdev-bot+sashiko
2026-12-04 11:06 ` [PATCH net-next 07/12] net: phylink: Factor out phylink_clear_phydev() Maxime Chevallier
2026-12-04 11:06 ` [PATCH net-next 08/12] net: phy: phy_mux: Add phy_mux_set_mac_managed_pm() Maxime Chevallier
2026-12-04 11:06 ` [PATCH net-next 09/12] net: phylink: Support PHYs reached through a phy_mux Maxime Chevallier
2026-12-05 12:18 ` netdev-bot+sashiko
2026-12-04 11:06 ` [PATCH net-next 10/12] net: phylink: Support an SFP cage behind " Maxime Chevallier
2026-12-05 12:18 ` netdev-bot+sashiko
2026-12-04 11:06 ` [PATCH net-next 11/12] net: phy: mux: Add the mii-mux-auto driver Maxime Chevallier
2026-12-05 12:18 ` netdev-bot+sashiko
2026-12-04 11:06 ` [PATCH net-next 12/12] ARM: dts: turris-omnia: Describe the WAN port multiplexer Maxime Chevallier
2026-12-05 12:18 ` netdev-bot+sashiko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179647310990.3146.3411864447818810188@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=christophe.leroy@csgroup.eu \
--cc=conor+dt@kernel.org \
--cc=daniel@makrotopia.org \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=dimitri.fedrau@liebherr.com \
--cc=edumazet@kernel.org \
--cc=f.fainelli@gmail.com \
--cc=f@lex.la \
--cc=frank.wunderlich@linux.dev \
--cc=gregory.clement@bootlin.com \
--cc=herve.codina@bootlin.com \
--cc=hkallweit1@gmail.com \
--cc=horms@kernel.org \
--cc=kabel@kernel.org \
--cc=kory.maincent@bootlin.com \
--cc=krzk+dt@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=marcin.s.wojtas@gmail.com \
--cc=maxime.chevallier@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=nicveronese@gmail.com \
--cc=o.rempel@pengutronix.de \
--cc=p.ameruoso@live.it \
--cc=pabeni@redhat.com \
--cc=robh@kernel.org \
--cc=sebastian.hesselbarth@gmail.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=vladimir.oltean@nxp.com \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox