Devicetree
 help / color / mirror / Atom feed
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 05/12] net: phy: phy_mux: Add port selection logic
Date: Sat, 05 Dec 2026 11:08:49 +0000	[thread overview]
Message-ID: <sashiko-outbox-251446@kernel.org> (raw)
In-Reply-To: <20261204110622.1106492-6-maxime.chevallier@bootlin.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] net: phy: phy_mux: selected PHY is not resumed before
  pops->select()
- [Medium] net: phy: unlocked phy_mux_detach() races with unregister and
  ethtool
--

commit dc38119185f1b5ebf431eebfe3a9d57a7ea7cf22
Author: Maxime Chevallier <maxime.chevallier@bootlin.com>

net: phy: phy_mux: Add port selection logic

This patch adds port selection and deselection logic to phy_mux, along with
phy_mux_start(), phy_mux_stop(), and phy_mux_port_ops to power down
deselected PHYs.

> 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

[ ... ]

> +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;
> +	}
> +
> +	port->selected = true;
> +
> +	return 0;
> +}

[Severity: High]
Should port->phydev be resumed before calling mux->pops->select()?

phy_mux_attach() and __phy_mux_deselect_port() suspend every PHY via
phy_mux_phy_power_down() -> phy_suspend(), so mux->pops->select() runs
against a powered-down PHY.  When a parent like phylink runs
phylink_bringup_phy(), EEE clock-stop configuration and
phy_request_interrupt() execute before phy_start() calls __phy_resume().

On PHYs such as Broadcom BCM54xx, non-BMCR register writes are ignored while
BMCR_PDOWN is set and bcm54xx_resume() re-runs bcm54xx_config_init(), leaving
hardware interrupts disabled and EEE settings lost.

If pops->select is NULL or does not call phy_start() or phy_resume(), the
selected PHY also remains suspended while port->selected is true.  Adding a
select callback in phy_mux_port_ops to call phy_resume() before
mux->pops->select() would restore symmetry with phy_mux_port_deselect().

[ ... ]

> @@ -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);

[Severity: Medium]
Can calling phy_mux_detach() without rtnl_lock() race with
phy_mux_unregister() and ethtool?

phy_mux_attach() creates mux->devlink with DL_FLAG_STATELESS, which does not
prevent the mux driver from unbinding while the parent MAC driver is bound.
Because phy_mux_unregister() drops phy_mux_mutex before taking rtnl_lock(), a
caller that runs phy_mux_detach() without rtnl_lock() when the mux is stopped
(such as phylink_destroy() in mvpp2_port_remove() after an ndo_open()
failure) has no lock in common with phy_mux_unregister():

CPU0                              CPU1
phylink_destroy()
  phy_mux_detach(mux)
    if (!mux->netdev) // false
                                  phy_mux_unregister()
                                    rtnl_lock()
                                    mux->pops->detach(...)
                                      phy_mux_detach(mux)
                                        phy_mux_detach_phys(mux)
    phy_mux_detach_phys(mux)
      <-- double phy_detach()
                                    rtnl_unlock()
                                  phy_mux_free(mux)
    mux->netdev = NULL
      <-- use-after-free

In addition, if the netdev is still NETREG_REGISTERED when phy_mux_detach()
runs without rtnl_lock() (such as ucc_geth_remove() with
devm_register_netdev()), phy_detach_internal() triggers a lockdep splat on
dev->hwprov and phy_link_topo_del_phy() frees struct phy_device_node without
RCU while concurrent ethtool queries in ethnl_req_get_phydev() expect
rtnl_lock().

fwnode_phy_mux_attach() also serializes only on phy_mux_mutex and can be
called without rtnl_lock() (for example from dsa_user_phy_setup()), leaving
mux->netdev, mux->pops, and mux->parent_priv without a common lock between
attach and detach.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204110622.1106492-1-maxime.chevallier@bootlin.com?part=5

  reply	other threads:[~2026-12-05 11:08 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 11:08   ` sashiko-bot
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-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-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 [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 11:08   ` sashiko-bot
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-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-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-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

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-251446@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox