From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.171.202.116 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796567878; b=R3bwc7wOVXiXmOLlHl5qLKrXJ+i8BKe1z3MdW4RudsSSp2VtqEMIBlH8kQHdZVyt3tBk 3OE2tFaB2/FX4AtEEVK0K3oVwzlYj7dU35EZzvp27MdfXfSGlx4q0DQ90uMof3WK2FveC DtnZH75KEiiV2APlbHZZjSD5YaZK5l3fuCNcalzdyD/8X4UqtRXnJO+PSY+eMs8uIKp1m FRzfMgiIMiokagPFI+7ntXd18qbhMMwAoa1U7rCCtvjJJjPe147TybU1AjP0+V/gBZVn4 r4FIXlcBg40ZpETo8yugXLFXJ4RRudqaPayYX2khCDavCK1lpkGNbYCha7ttO/BkzQw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796567878; h=DMARC-Filter:Received:Received:Received:DKIM-Signature:Message-ID: Date:MIME-Version:User-Agent:Subject:To:Cc:References: Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding:X-Last-TLS-Session-Version; bh=F551lJn/1Lbn3k2hlFZDP7L2052tW3AbsPmjeYb8jno=; b=cTSFx5W6XxNhmAZPeTElyZ5/Tmn9cQytIEo2E2k1thpu1OA0gu1b+++F17D8D7lBWG5g V9u7xCV3XxTZ/rNFtN1D0BZ/qsi/nb2ZfdvETemhqw8QeSY5FX/Q8FGRjI+4wJxb8JP5j Pyc13BTS/w8OaqojD/PbIPMy2/akRy3fvXFZvW/dmNdJXjYJ/8zOCRU/PFnNL7RjvUc51 vYFCYHCjGqjC/gfZw/a2S8BN4P4iC/snnzO57+n5T9m/tFREqi39zQafzg4oLmAlGFuAk CVuLxctuNe41H+Th5qXtLQAV3pNm55mcYZJCBOJ7YYgdS6Jfsbo/PBSoV3ub5GHc/sg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=Uj8Suklc; arc=none smtp.remote-ip=185.171.202.116 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (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 331C4606A31F; Sun, 6 Dec 2026 14:37:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 331C4606A31F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=Uj8Suklc Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 66117C026D8; Sun, 6 Dec 2026 14:38:08 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 7CB5C604C0; Sun, 6 Dec 2026 14:37:55 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 2A27011EA16D6; Sun, 06 Dec 2026 15:37:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1796567873; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:content-language:in-reply-to:references; bh=F551lJn/1Lbn3k2hlFZDP7L2052tW3AbsPmjeYb8jno=; b=Uj8Suklc+NTlLBKq9w7gUFBjiHWHZ2wdh/iGnJU2fHPS4LcpVYQJQbhK8ulvve66n32q0r kcAv70yU4dyVPz7xrPYr5VnfSSHyMbQwpCZd/9NrjCCANyh5gTfNawPf0XnHOikycvHkjA iQrVXlj3JRdSlt1kRMlTqlutOcq0lDScvK6zxXyXCp5ONWmpnGhhhl7vIaRUR72acB+kd8 1myS67S6rANf/1AgnYrbElwaUmWB59e84Tk7cIqa4ijOvorX/H2NNs+xoHjfD6srOxvtB3 VftPwVtJqfzBWpwP3Yt7JiXoI1qTBw+O4UKnzKqzS3TS1sfxw6SeP1DJigHtsQ== Message-ID: Date: Sun, 6 Dec 2026 15:37:45 +0100 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net-next 04/12] net: phy: phy_mux: Allow attaching a mux to a net_device 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-5-maxime.chevallier@bootlin.com> <179647310752.3146.1046625871089751112@kernel.org> Content-Language: en-US From: Maxime Chevallier In-Reply-To: <179647310752.3146.1046625871089751112@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Last-TLS-Session-Version: TLSv1.3 On 12/5/26 13:18, netdev-bot+sashiko@kernel.org wrote: > Thank you for your contribution! Sashiko AI review found 6 potential > issue(s) to consider. > > Critical: 0 · High: 0 · Medium: 3 · Low: 3 > > 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] Only the parent's optional pops->detach can undo an attach. > - [Medium] At this commit phy_mux_detach() takes no lock and asserts > none, yet it clears mux->pops, mux->parent_priv and mux->netdev and… > - [Medium] net: phy: phy_mux: phy_mux_attach() clobbers dev->sfp_bus > - [Low] The commit message and kernel-doc describe things this commit > does not contain. > - [Low] The patch deletes the still-accurate kernel-doc line "The mux > still has to be freed with phy_mux_free()" from phy_mux_unregister(). > - [Low] fwnode_phy_mux_attach() holds the global phy_mux_mutex across > phy_attach_direct() for every muxed PHY, across device_link_add(), and… [...] > [Severity: Medium] > phy_attach_direct() does more than set dev->phydev. When the PHY has a > downstream SFP cage, it also does this: > > drivers/net/phy/phy_device.c:phy_attach_direct() { > ... > if (dev) { > phydev->attached_dev = dev; > dev->phydev = phydev; > > if (phydev->sfp_bus_attached) > dev->sfp_bus = phydev->sfp_bus; > ... > } > > The sysfs link creation is skipped when phydev->mux_port is set, but > this assignment is not. phy_mux_attach() then resets dev->phydev to > NULL and leaves dev->sfp_bus as it is. > > Suppose one of the muxed PHYs has its own SFP cage, through an sfp > property handled by phy_sfp_probe() as on 88E1510, 88X3310 or QCA807x. > Attaching the mux then overwrites whatever dev->sfp_bus already held. > That could be the mux SFP cage that phylink_register_mux_sfp() sets up > later in the series, or another muxed PHY's cage. So, /--- SFP MAC --- MUX \--- PHY --- SFP This is creative, we don't handle that no. > [ ... ] > [Severity: Medium] > phy_mux_detach() clears mux->pops, mux->parent_priv, mux->netdev and the > per-port attached state without taking or asserting any lock. > phy_mux_attach() writes these fields under phy_mux_mutex. The > check-then-call on them in phy_mux_unregister() below holds only rtnl. > > Suppose a parent calls phy_mux_detach() without rtnl while the mux driver > is being unbound. Could that race with phy_mux_unregister() and cause a > NULL mux->pops dereference, or a double phy_detach()/put_device() on the > muxed PHYs? I can add an ASSERT_RTNL here ye > [Severity: Medium] > Is the optional pops->detach() the only thing that can undo an attach? > phy_mux_attach() treats the ops as optional: > > if (pops && pops->attach) > pops->attach(mux, priv); > > fwnode_phy_mux_attach() only returns an int. The parent can therefore > only get the mux pointer that phy_mux_detach() needs through > pops->attach. > > If pops or pops->detach is NULL, or the detach callback does not call > phy_mux_detach(), nothing here detaches the PHYs. phy_mux_free() then > calls phy_mux_port_destroy() on every port. For ports that still have > port->attached set, that only unbinds the PHY and never calls > phy_detach(): > > drivers/net/phy/phy_mux.c:phy_mux_port_destroy() { > ... > case PHY_MUX_PORT_PHY: > phy_mux_port_unbind_phy(mux_port); > fwnode_handle_put(mux_port->fwnode); > break; > ... > } > > Would this leak the references taken by phy_attach_direct(), the > link_topo entry and mux->devlink? It would also leave > phydev->attached_dev pointing at a netdev that may be freed later. > > At the end of the series, the only in-tree parent is phylink. It always > passes phylink_mux_ops with all callbacks, and phylink_mux_detach() > calls phy_mux_detach(). Triggering this would take a caller that misuses > the API. > > Could phy_mux_attach() reject NULL attach/detach ops with -EINVAL? As an > alternative, phy_mux_unregister() could call phy_mux_detach() itself when > mux->netdev is still set after the callback. > This is defensive programming :( Maxime