From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5AADE1F0092B; Sat, 5 Dec 2026 12:18:30 +0000 (UTC) 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== Subject: Re: [PATCH net-next 05/12] net: phy: phy_mux: Add port selection logic 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 Date: Sat, 05 Dec 2026 12:18:29 +0000 Message-ID: <179647310990.3146.3411864447818810188@kernel.org> In-Reply-To: <20261204110622.1106492-6-maxime.chevallier@bootlin.com> References: <20261204110622.1106492-6-maxime.chevallier@bootlin.com> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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