Netdev List
 help / color / mirror / Atom feed
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 09/12] net: phylink: Support PHYs reached through a phy_mux
Date: Sat, 05 Dec 2026 12:18:34 +0000	[thread overview]
Message-ID: <179647311481.3146.4575966133992501685@kernel.org> (raw)
In-Reply-To: <20261204110622.1106492-10-maxime.chevallier@bootlin.com>

Thank you for your contribution! Sashiko AI review found 8 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 5 · Low: 2

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).

- [High] net: phylink: phylink_mux_select() configures suspended PHY
- [Medium] With a mux, phylink has no PHY every time the interface is
  down, not only before the first selection as the commit message says.
- [Medium] The patch changes what
  phylink_fwnode_phy_connect()/phylink_of_phy_connect() guarantee on…
- [Medium] On MACs that set mac_requires_rxc (stmmac sets it
  unconditionally), the PHYs behind a mux are left in BMCR power-down…
- [Medium] With a mux, phylink_suspend() with PHY-handled WoL breaks the
  wake path.
- [Medium] net: phylink: missing rtnl_lock() in phylink_destroy() mux
  detach
- [Low] The kernel-doc for phylink_of_phy_connect() still says "Actions
  specified in phylink_connect_phy() will be performed": attach the PHY,…
- [Low] phylink_mux_select() writes `pl->link_config.interface =
  port->interface;` with only rtnl held, after phylink_bringup_phy() has…

--

net: phylink: Support PHYs reached through a phy_mux

This makes phylink act as the parent of a phy_mux. When the MAC node has
a mii-mux-handle property, phylink_fwnode_phy_connect() attaches to the
mux instead of connecting a PHY. phylink starts and stops the mux along
with the interface, and the select/deselect parent ops bring up or stop
the selected port's PHY and reconfigure the MAC.

> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index 03e255f5ceb17..702614adcb945 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c

[ ... ]

> @@ -2494,6 +2510,34 @@ int phylink_of_phy_connect(struct phylink *pl, struct device_node *dn,
>  }
>  EXPORT_SYMBOL_GPL(phylink_of_phy_connect);
>  
> +static const struct phy_mux_parent_ops phylink_mux_ops;
> +
> +static int phylink_attach_mux(struct phylink *pl,
> +			      const struct fwnode_handle *fwnode, u32 flags)
> +{
> +	struct fwnode_handle *mux_fwnode;
> +	int ret;
> +
> +	if (pl->mux || !IS_ENABLED(CONFIG_PHY_MUX))
> +		return 0;
> +
> +	if (pl->config->type != PHYLINK_NETDEV)
> +		return 0;
> +
> +	mux_fwnode = fwnode_find_reference(fwnode, "mii-mux-handle", 0);
> +	if (IS_ERR(mux_fwnode))
> +		return 0;
> +
> +	if (pl->config->mac_requires_rxc)
> +		flags |= PHY_F_RXC_ALWAYS_ON;
> +
> +	ret = fwnode_phy_mux_attach(mux_fwnode, pl->netdev, flags,
> +				    &phylink_mux_ops, pl);

[Severity: Medium]
On MACs that set mac_requires_rxc, can the PHYs behind the mux still be
powered down when the MAC runs its DMA reset?

phy_mux_attach() resumes each PHY through phy_attach_direct(), but then
deselects every port:

drivers/net/phy/phy_mux.c:phy_mux_attach() {
    ...
	xa_for_each(&mux->ports, id, port)
		phy_mux_port_deselect(port);
    ...
}

For PHY ports this ends up in phy_mux_phy_power_down() -> phy_suspend().
phylink_fwnode_phy_connect() then returns with pl->phydev == NULL.

phylink_prepare_resume() is the helper that guarantees RXC for these
MACs, and it only looks at pl->phydev:

	if (pl->config->mac_requires_rxc && phydev && phydev->suspended)
		phy_resume(phydev);

stmmac sets mac_requires_rxc unconditionally. __stmmac_open() calls
phylink_prepare_resume() and then stmmac_hw_setup(), both before
phylink_start(), so no PHY gets resumed. On resume, phylink_suspend() ->
phylink_stop() -> phy_mux_stop() has already cleared pl->phydev, so the
same thing seems to happen there.

If the PHY stops RXC in power-down, wouldn't the DMA reset fail, so that
open or resume fails with "Hw setup failed"?

stmmac takes this path when its node has both phy-handle and
mii-mux-handle. No in-tree DT pairs stmmac with a mux today.

> +	fwnode_handle_put(mux_fwnode);
> +
> +	return ret == -EPROBE_DEFER ? -ENODEV : ret;
> +}
> +
>  /**
>   * phylink_fwnode_phy_connect() - connect the PHY specified in the fwnode.
>   * @pl: a pointer to a &struct phylink returned from phylink_create()
> @@ -2501,7 +2545,7 @@ EXPORT_SYMBOL_GPL(phylink_of_phy_connect);
>   * @flags: PHY-specific flags to communicate to the PHY device driver
>   *
>   * Connect the phy specified @fwnode to the phylink instance specified
> - * by @pl.
> + * by @pl, or attach to the PHY multiplexer it refers to.

[Severity: Low]
This isn't a bug, but phylink_of_phy_connect() forwards to this function,
and its kernel-doc still says:

 * Connect the phy specified in the device node @dn to the phylink instance
 * specified by @pl. Actions specified in phylink_connect_phy() will be
 * performed.

With mii-mux-handle, none of those actions (attaching the PHY,
restricting its advertisement, starting it, enabling interrupts, updating
the supported/advertising masks) happen until phylink_mux_select() runs
after phylink_start().

Should that comment be updated as well? It is still unchanged at the end
of the series.

>   *
>   * Returns 0 on success or a negative errno.
>   */
> @@ -2516,6 +2560,13 @@ int phylink_fwnode_phy_connect(struct phylink *pl,
>  	if (!phylink_expects_phy(pl))
>  		return 0;
>  
> +	ret = phylink_attach_mux(pl, fwnode, flags);
> +	if (ret)
> +		return ret;
> +
> +	if (pl->mux)
> +		return 0;

[Severity: Medium]
This changes what a successful phylink_fwnode_phy_connect() or
phylink_of_phy_connect() guarantees. Are the existing callers ready for
pl->phydev to be NULL here?

mvneta_mdio_probe() queries WoL right after connecting:

drivers/net/ethernet/marvell/mvneta.c:mvneta_mdio_probe() {
    ...
	int err = phylink_of_phy_connect(pp->phylink, pp->dn, 0);
    ...
	phylink_ethtool_get_wol(pp->phylink, &wol);
	device_set_wakeup_capable(&pp->dev->dev, !!wol.supported);
    ...
}

The Turris Omnia WAN port is an mvneta, and the DTS change in this series
gives it mii-mux-handle. There, wol.supported would be 0 and the netdev
would be marked not wakeup-capable, even though the 88E1514 behind the
mux supports WoL.

stmmac_init_phy() also calls phylink_ethtool_get_eee()/set_eee() right
after connecting, to program the PHY's tx_lpi_timer. With a mux that
would silently do nothing.

Also, stmmac_init_phy() only calls phylink_fwnode_phy_connect() when
fwnode_get_phy_node() finds a phy-handle:

	if (!phy_fwnode || IS_ERR(phy_fwnode)) {
		int addr = priv->plat->phy_addr;

So a MAC node that only has mii-mux-handle, like the mii-mux-auto.yaml
example, never reaches phylink_attach_mux(). It fails with "no phy found"
when phy_addr < 0.

Should these callers be adapted along with this change?

> +
>  	phy_fwnode = fwnode_get_phy_node(fwnode);
>  	if (IS_ERR(phy_fwnode)) {
>  		/* PHY mode requires a PHY to be specified. */

[ ... ]

> @@ -2727,6 +2787,8 @@ void phylink_stop(struct phylink *pl)
>  {
>  	ASSERT_RTNL();
>  
> +	if (pl->mux)
> +		phy_mux_stop(pl->mux);

[Severity: Medium]
The commit message says phylink has no PHY "between the time it attaches
to the mux and the first selection". Doesn't every phylink_stop() also
drop the PHY?

phylink_stop()
  phy_mux_stop()
    phy_mux_select(mux, NULL)
      __phy_mux_deselect_port()
        phylink_mux_deselect()
          phylink_clear_phydev()

After that, phy_mux_port_set_parent_phy(..., false) sets netdev->phydev
to NULL.

While the interface is down, phylink_ethtool_ksettings_set() with
cfg_link_an_mode == MLO_AN_PHY and no PHY falls through to the branch
commented "All that is left are in-band links". It stores speed, duplex
and advertising in pl->link_config and returns 0.

On the next open, phylink_mux_select() -> phylink_bringup_phy()
overwrites pl->link_config.advertising with phy->advertising. The PHY
itself was never reprogrammed.

So would an ethtool -s, or a systemd .link file applied while the device
is down, be accepted and then silently lost?

In the same state, phylink_ethtool_set_wol() and phylink_ethtool_set_eee()
return -EOPNOTSUPP, and phylink_ethtool_get_wol() reports no support.
ksettings_get reports the leftover pl->supported/advertising of whichever
PHY was selected last.

>  	if (pl->sfp_bus)
>  		sfp_upstream_stop(pl->sfp_bus);
>  	if (pl->phydev)

[ ... ]

> +static int phylink_mux_select(struct phy_mux *mux, struct phy_mux_port *port,
> +			      void *priv)
> +{
> +	struct phylink *pl = priv;
> +	struct phy_device *phy;
> +	int ret;
> +
> +	if (port->type != PHY_MUX_PORT_PHY)
> +		return -EOPNOTSUPP;
> +
> +	if (pl->phydev)
> +		return -EBUSY;
> +
> +	phy = port->phydev;
> +
> +	ret = phylink_bringup_phy(pl, phy, port->interface);
> +	if (ret) {
> +		phy->phylink = NULL;
> +		return ret;
> +	}
> +
> +	pl->link_config.interface = port->interface;

[Severity: High]
Is the PHY still suspended when phylink_mux_select() runs?

phy_mux_attach() deselects every port right after phy_attach_direct().
For PHY ports that ends in phy_mux_phy_power_down() -> phy_suspend(),
and every later deselection suspends the port again. Nothing in
phy_mux.c resumes the PHY before it calls pops->select().

phylink_mux_select() then calls phylink_bringup_phy() and
phylink_mac_initial_config() on that suspended PHY. Only the final
phy_start() goes through __phy_resume(). Before that point:

 - phylink_bringup_phy() does MDIO accesses through phy_support_eee(),
   phy_eee_tx_clock_stop_capable() and phy_eee_rx_clock_stop()

 - phy_request_interrupt() -> phy_enable_interrupts() calls
   config_intr()

 - phylink_major_config() calls phy_config_inband()

Without a mux this ordering doesn't occur, because phy_attach_direct()
resumes the PHY before phylink_bringup_phy() is called.

Several in-tree drivers don't tolerate register accesses in that
state:

 - bcm54xx_resume() notes that writes to registers other than BMCR
   are ignored until PDOWN is cleared, and resume can soft-reset and
   re-run config_init

 - kszphy_resume() says leaving power-down generates an internal
   global reset

 - rtl821x_suspend() gates priv->clk while suspended

On those PHYs, the interrupt enable written by config_intr(), or the
inband and EEE clock-stop settings, could be ignored or wiped by the
resume in phy_start(). phylib would then believe interrupts are
enabled and stop polling while the hardware still has them masked.
The link would never come up. If config_intr() fails outright, the
PHY is silently downgraded to PHY_POLL.

Should the PHY be resumed before phylink_bringup_phy(), either here
(and suspended again if select fails) or by phy_mux before it calls
pops->select()?

[Severity: Low]
Can this store race with phylink_resolve()?

phylink_mux_select() runs from the mux state work after phylink_start()
has cleared PHYLINK_DISABLE_STOPPED. phylink_bringup_phy() has already
published pl->phydev at this point. This line writes
pl->link_config.interface with only rtnl held.

phylink_resolve() can be queued at the same time by phylink_pcs_change(),
phylink_mac_change() or phylink_phy_change(). It reads and writes the
same field under state_mutex:

drivers/net/phy/phylink.c:phylink_resolve() {
    ...
	if ((mac_config && link_state.interface != pl->link_config.interface) ||
	    pl->force_major_config) {
		...
		pl->link_config.interface = link_state.interface;
    ...
}

Could resolve compare against a stale interface and run an extra major
config while select is changing it?

Later in the series, this same unlocked block also gets
clear_bit(PHYLINK_DISABLE_LINK) and a pl->req_link_an_mode store.

> +	phylink_mac_initial_config(pl, false);
> +	phy_start(phy);
> +
> +	return 0;
> +}
> +
> +static void phylink_mux_deselect(struct phy_mux *mux,
> +				 struct phy_mux_port *port, void *priv)
> +{
> +	struct phylink *pl = priv;
> +	struct phy_device *phy;
> +
> +	if (pl->phydev != port->phydev)
> +		return;
> +
> +	phy = port->phydev;
> +
> +	if (phy_is_started(phy) || phy->state == PHY_ERROR)
> +		phy_stop(phy);
> +
> +	phylink_clear_phydev(pl);
> +
> +	if (phy_interrupt_is_valid(phy))
> +		phy_free_interrupt(phy);

[Severity: Medium]
phylink_destroy() is called without rtnl held. Both of its neighbours
here, sfp_bus_del_upstream() and phylink_destroy_sfp_cage_port(),
take rtnl_lock() themselves. phylink_detach_mux() takes no lock at
all, but the paths it can race with rely on rtnl:

 - phy_mux_unregister() takes rtnl_lock() before it checks
   mux->netdev and calls pops->detach(). That ends in
   phylink_mux_detach(), which clears pl->mux.

 - phy_mux_state_machine() runs phy_mux_select() under rtnl.
   phy_mux_stop() only does cancel_work(), not cancel_work_sync(), so
   rtnl is the only thing keeping the work from running alongside
   detach.

If pl->mux is still set when phylink_destroy() runs, could
phylink_destroy() and phy_mux_unregister() both detach the same mux,
so that phy_detach() and device_link_del() run twice? Could a state
work item that is already running still dereference pl after the
kfree(pl) at the end of phylink_destroy()?

If the mux was started, the chain phy_mux_detach() -> phy_mux_stop()
-> phylink_mux_deselect() -> phylink_clear_phydev() also hits
ASSERT_RTNL().

Most drivers call phylink_disconnect_phy() under rtnl before
phylink_destroy(). So this needs a teardown or error path where the
mux is still attached at destroy time.

Should phylink_destroy() take rtnl_lock() around phylink_detach_mux(),
and should phylink_detach_mux() get an ASSERT_RTNL()?

[Severity: Medium]
With a mux, does PHY-based Wake-on-LAN still work across suspend?

When the PHY handles WoL, phylink_suspend() calls phylink_stop(). That
now goes through phy_mux_stop() -> phylink_mux_deselect(), which reaches
this phy_free_interrupt().

phy_free_interrupt() calls config_intr(PHY_INTERRUPT_DISABLED) and then
frees the IRQ. Some PHYs signal WoL through their interrupt enable
register: at803x writes 0 to AT803X_INTR_ENABLE, and Marvell clears the
IMASK register that holds WOL_EIE. On those PHYs this disables the wake
source.

phy_suspend() in the port deselect returns -EBUSY because WoL is enabled.
The PHY therefore stays powered but can no longer raise a wake.

Without a mux, phylink_stop() only calls phy_stop(), which leaves the
interrupt configuration and the IRQ in place.

phylink_suspend() then does:

	} else {
		phylink_stop(pl);
	}

	if (phylink_phy_pm_speed_ctrl(pl))
		phylink_speed_down(pl, false);

phylink_phy_pm_speed_ctrl() needs pl->phydev, and deselect has already
cleared it. When wol_phy_speed_ctrl is set, wouldn't phylink_speed_down()
be skipped, leaving the PHY at full link speed during WoL suspend?

> +
> +	phy->phylink = NULL;
> +}

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204110622.1106492-1-maxime.chevallier%40bootlin.com

  reply	other threads:[~2026-12-05 12:18 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
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 [this message]
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=179647311481.3146.4575966133992501685@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