From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19467606A31F for ; Sun, 6 Dec 2026 14:43:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=cAB9yV0H; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=ffbBTRZu DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=UQ4Gkee5kRIld2x6M4+QTeQ0Zu8X2lUhvWK3uUI5R8k=; b=cAB9yV0H0jnajY 2xR1L6VUdhJIdzNHiQwDYI5Op6fxNcl7avUv6fglgqSe5cmNLF19NxHnAuMB4vLXmMGRcIlIs1zrg MHaBSUc/rtAtL+sKXnXH5r9IjK4anqar/RAmWGOyrLKspnGX1RLtJAr/3w+CsYcjUOL1YuDKVrClN P6pQIJr2ydkE0uYqrShYdAs8o9CNRLIxhp7noTm8dQYEosp8qQjcUKawvxOlaXvX1e7wxQ/Aoo5C3 3ufEnouJQ3xJ8krIHmhIoobVblD9smW/CyERvRcbUg2CEdqFaCIiqAB418LBFLzequVQDBOhO8USg cyyhLY+D0OUWbfpJRlzQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xaDSV-00000003gEg-0EQf; Sun, 06 Dec 2026 14:43:23 +0000 Received: from smtpout-02.galae.net ([185.246.84.56]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xaDSQ-00000003gBP-4BvI for linux-arm-kernel@lists.infradead.org; Sun, 06 Dec 2026 14:43:21 +0000 Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 243731A199A; Sun, 6 Dec 2026 14:43:16 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id D1385604C0; Sun, 6 Dec 2026 14:43:15 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 61F4211EA16D6; Sun, 06 Dec 2026 15:43:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1796568193; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:content-language:in-reply-to:references; bh=UQ4Gkee5kRIld2x6M4+QTeQ0Zu8X2lUhvWK3uUI5R8k=; b=ffbBTRZu3VT6UXWaytxqdtzpzKFmT12U9zskdT9ZTbdYjcVSZCG7HN5qXsULUg9haVqR7E IHwWDLfG7LIcsmSvYU0sf/jNQJV3maTDzV4fIoaoueXMTWzKHZHTEro3AJktg0THPMt153 9qbkZ6r0SDpp9x/rPGmkzIFG001OLuVmJLFJnAsMdrZEcD3V7blJIS29AlRB8hTVEqJH+K T9mRHBjeX9IZIBh0Njb40xOQAig9Cq+MZuzk300lpsGfIVguGY1AuZFJLivJs/iepS2XXk hX7HYZJnVWMp3224QoUhlZKMWkdErlTY2YSkYTkCiyJi142cqs/D1TdMQC5wJg== Message-ID: <8ab494c0-4dce-4e99-a920-1743af517d0b@bootlin.com> Date: Sun, 6 Dec 2026 15:43:05 +0100 X-Archived-By: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net-next 05/12] net: phy: phy_mux: Add port selection logic To: netdev-bot+sashiko@kernel.org 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 References: <20261204110622.1106492-6-maxime.chevallier@bootlin.com> <179647310990.3146.3411864447818810188@kernel.org> Content-Language: en-US From: Maxime Chevallier In-Reply-To: <179647310990.3146.3411864447818810188@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Last-TLS-Session-Version: TLSv1.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261206_064319_244124_4688C485 X-CRM114-Status: GOOD ( 43.72 ) X-Spam-Score: -2.1 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On 12/5/26 13:18, netdev-bot+sashiko@kernel.org wrote: > 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… > [...] > [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. I have never seen a mux on RGMII, even less so on stmmac... The ones I've seen are on RMII or serialized MII. > > [ ... ] > >> +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? For now, this works well with phylink. I don't know if retrying brings anything ? > > [ ... ] > >> @@ -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? Already answered on the previous patch, I'll add RTNL requirement here >