From: sashiko-bot@kernel.org
To: "Maxime Chevallier" <maxime.chevallier@bootlin.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH net-next 06/12] net: phy: phy_mux: Support SFP cage ports
Date: Sat, 05 Dec 2026 11:08:50 +0000 [thread overview]
Message-ID: <sashiko-outbox-251447@kernel.org> (raw)
In-Reply-To: <20261204110622.1106492-7-maxime.chevallier@bootlin.com>
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 <maxime.chevallier@bootlin.com>
> 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 <maxime.chevallier@bootlin.com>
[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_power_ops = {
> .deselect = phy_mux_phy_power_down,
> };
>
> +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 = 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 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]
Should phy_mux_port_set_available() return early when
mux->state != 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 = 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);
> }
> 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 == 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;
>
> + 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 = 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.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204110622.1106492-1-maxime.chevallier@bootlin.com?part=6
next prev parent reply other threads:[~2026-12-05 11:08 UTC|newest]
Thread overview: 31+ 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 11:08 ` sashiko-bot
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 11:08 ` sashiko-bot
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 11:08 ` sashiko-bot
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 11:08 ` sashiko-bot
2026-12-05 12:18 ` netdev-bot+sashiko
2026-12-04 11:06 ` [PATCH net-next 06/12] net: phy: phy_mux: Support SFP cage ports Maxime Chevallier
2026-12-05 11:08 ` sashiko-bot [this message]
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 11:08 ` sashiko-bot
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 11:08 ` sashiko-bot
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 11:08 ` sashiko-bot
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 11:08 ` sashiko-bot
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=sashiko-outbox-251447@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=maxime.chevallier@bootlin.com \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.