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=1796082471; b=Lo2g4REglR5yzo7xJgrAjZifO9rudCmV+NXoT6VUlhunl7mSd8pap3K5LgSjDY24UqWN 0BCi4cMHdexYe1vtsWMOz55YcssGqB7TuBSHuyn4ZJITBGPfBP7wi8I7izSC/AAhgOU7V YzVFTIXexSsm4wqRxpsgCzzEOzXMsgTym2FJ/MXap+aZU4Mf4cjCIqnvZccGLVGz74cFi xBgBCZcDWwG6W94knKBAu6FMr9lKVJ/yTg5qn/WkPh3MV1BjlMZ3kqevEF78bdaIFvHZp 4gOj/Vod6F25aKOumxgmWhW82oVGvscWIq80h7LxXTwslf5iSZimn8xZNu+2467nm5w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796082471; 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=8isanyi8GUDpGWv/+53wK4c8mXSTJRB6YEiizcbrlcU=; b=Y6VVrKqqEjJBrYl94ZciMMZPIAPhZrE9JK3WhrH6i1sypYyL1FHj696aHcmzpmR1ZNzC DAIiKJhEWPN4eLH8+UgyiP5B5Rbot3KTB6qQIXREWEMBqHVHvBhuSlfFgfCC+exnt2esg SBfE7XajLeI037Z/E4pg6fJDrfnnkWyuh07iOR0TBF2pdjDVL7cpe2H+bx5QTw/e5tjAx SReuqGaSqhBR1/jCRBTf5nxcfYrlYTbddcYDt6M9C9nA7M1FIN9UBP7NxEFm/3OQ1TwAc fVIf9GcDE4+iZ9RdqEOhO78hZmh1nVk6xIRSbfj2OjblStQwqR0Jx/wIZoaQMIXa6SA== 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=ATtiFFhH; 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 51EDF606A33D; Mon, 30 Nov 2026 23:47:51 +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=ATtiFFhH Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64EEB1F000C1; Mon, 30 Nov 2026 23:47:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796082471; bh=8isanyi8GUDpGWv/+53wK4c8mXSTJRB6YEiizcbrlcU=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=ATtiFFhHVC+A6AxgsTJ9FxL3Eoa82dUcbDXtL0AJgIxK2FHrGv8cAWuBmhbjl7qeS Svthwob3BRHA0kkSwRMC4Y0GoRuECnZ9q1M8VE09WZWHOTAOVLLhI7SDA0neeGlo+V 0No3BnPv8PldKHQjvjTguSB9f1b+oBMOPSwarEwaot9pVQKNadbPJ2XbszmkvSBN1J MgakOKp+CvahVpn/VOlgOT+1rlm3JH4wscXU1lBNquDD+bcKbuuBwu6M4nt2QdGOEy Nqc1fBdI+wGNcRWR5m3hQWjtcSAzY9i5c19y/J4caF1agq63HiVkV67tjOR7Vww2SE KOAt6jTaxz7Sg== Subject: Re: [PATCH net-next v23 09/15] net: phylink: support late PCS provider attach From: netdev-bot+sashiko@kernel.org To: ansuelsmth@gmail.com Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, willemb@google.com, horms@kernel.org, corbet@lwn.net, skhan@linuxfoundation.org, rdunlap@infradead.org, lorenzo@kernel.org, hkallweit1@gmail.com, linux@armlinux.org.uk, maxime.chevallier@bootlin.com, p.zabel@pengutronix.de, nathan@kernel.org, ndesaulniers@google.com, morbo@google.com, justinstitt@google.com, rmk+kernel@armlinux.org.uk, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, llvm@lists.linux.dev, zhengping.zhang@airoha.com Date: Mon, 30 Nov 2026 23:47:48 +0000 Message-ID: <179608246894.3146.869946902212130641@kernel.org> In-Reply-To: <20261129230558.612526-10-ansuelsmth@gmail.com> References: <20261129230558.612526-10-ansuelsmth@gmail.com> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: devicetree@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 5 potential issue(s) to consider. Critical: 0 · High: 2 · Medium: 3 · Low: 0 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_parse_supported_interfaces() keeps unavailable PCS modes - [High] net: phylink: phylink_create() fails for in-band links with late PCS - [Medium] The late-PCS SFP recovery added by this patch only covers modules with caps->may_have_phy == false. - [Medium] phylink_sfp_module_insert() (drivers/net/phy/phylink.c:4820-4826) now returns -EAGAIN for a non-… - [Medium] net: phylink: stale sfp_cage_port capabilities after late PCS attach -- net: phylink: support late PCS provider attach This adds a FWNODE_PCS_PROVIDER_ADD notification. With it, a phylink instance can pick up a PCS provider that registers after phylink_create(), and it then refreshes supported_interfaces and link capabilities. Optical SFP insertion is deferred with -EAGAIN when the module's only usable interfaces need a PCS, and the insertion is retried once a PCS is added. > diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c > index 6dde0eae0e73a..3471ba8d5ba6f 100644 > --- a/drivers/net/phy/phylink.c > +++ b/drivers/net/phy/phylink.c [ ... ] > @@ -4789,6 +4817,14 @@ static int phylink_sfp_module_insert(void *upstream, > ASSERT_RTNL(); > > caps = sfp_get_module_caps(pl->sfp_bus); > + /* A late PCS may provide the module's only usable interface */ > + if (!caps->may_have_phy && > + !bitmap_intersects(caps->interfaces, pl->supported_interfaces, > + PHY_INTERFACE_MODE_MAX) && > + bitmap_intersects(caps->interfaces, pl->config->pcs_interfaces, > + PHY_INTERFACE_MODE_MAX)) > + return -EAGAIN; [Severity: High] Can this condition ever evaluate to true? phylink_parse_supported_interfaces() starts from a copy of pl->config->supported_interfaces. It then ORs in pcs_interfaces modes for each PCS on pl->pcs_list, and it never removes anything. Documentation/networking/pcs.rst describes the two masks this way: config->supported_interfaces lists every mode the MAC supports, and config->pcs_interfaces is the subset of those that need a PCS. airoha_setup_phylink() follows that and copies supported_interfaces into pcs_interfaces. If pcs_interfaces is a subset of config->supported_interfaces, every PCS-required mode is always set in pl->supported_interfaces, whether or not pl->pcs_list is empty. A module interface that intersects pl->config->pcs_interfaces then also intersects pl->supported_interfaces, so the -EAGAIN branch can never be taken. An optical module inserted before its PCS provider probes is configured immediately instead of being deferred. Validation does not catch this either. phylink_validate_mac_and_pcs() searches pl->pcs_list when the interface is in pcs_interfaces. If no PCS matches, it leaves pcs NULL and validates against the MAC capabilities alone. phylink_sfp_config_optical() can therefore select and configure a PCS-required interface with no PCS attached. The same applies when the attached PCS supports only some of the modes. For example, the airoha USB PCS tops out at 2500BASE-X, while the MAC sets 10GBASE-R and USXGMII in both masks. The comment in phylink_parse_supported_interfaces() suggests the intent is to advertise PCS-only modes only once a PCS can serve them. Which contract is intended here? If pcs_interfaces may overlap config->supported_interfaces, should that overlap be masked out of the initial copy? And should phylink_validate_mac_and_pcs() fail when no PCS on pl->pcs_list accepts a pcs_interfaces mode? [Severity: Medium] Does late PCS attach also cover modules that have caps->may_have_phy set? Copper modules (1000BASE-T/SGMII, 10GBASE-T) and quirked fibre modules skip this deferral and return 0. Their interface setup happens later in SFP_S_INIT_PHY, after the netdev is up. Suppose the PCS-only host mode (SGMII, for example) is still missing from pl->supported_interfaces at that point. One of two things happens. In the first case, phylink_sfp_connect_phy() takes a snapshot: phy_interface_and(phy->host_interfaces, phylink_sfp_interfaces, pl->supported_interfaces); and phylink_sfp_config_phy() then fails. In the second case, no PHY is found, so phylink_sfp_module_start() falls through to: ret = phylink_sfp_config_optical(pl); if (ret) goto del_mod_port; which fails with "unsupported SFP module: no common interface modes". Either way, sfp_sm_main() moves the socket to SFP_S_FAIL. When the PCS provider registers later, the path is phylink_update_pcs()->phylink_sfp_retry_module()->sfp_retry_module(), and sfp_retry_module() only acts in WAITDEV: if (sfp->sm_mod_state == SFP_MOD_WAITDEV) __sfp_sm_event(sfp, SFP_E_UPSTREAM_RETRY); These modules are already past WAITDEV, so nothing retries them. The link stays down until ifdown/ifup or a re-plug. These modules behave the same as before the patch, and the commit message limits the deferral to optical modules. Is this gap intended, given that the goal is late PCS provider attach? [Severity: Medium] What happens to the module if a suitable PCS never shows up? This check only uses the static config->pcs_interfaces mask. It does not check that a provider exists, or that any PCS supports the module's interface. On -EAGAIN, sfp_sm_module() leaves the module in SFP_MOD_WAITDEV: err = sfp_module_insert(sfp->sfp_bus, &sfp->id, sfp->quirk); if (err == -EAGAIN) break; WAITDEV is entered with sfp_sm_mod_next(sfp, SFP_MOD_WAITDEV, 0), so no timer is armed. A retry can come from only two places. One is phylink_update_pcs(): if (rescan && added && ret > 0) phylink_sfp_retry_module(pl); The other is phylink_pcs_finish_init() when an update is pending. Both need a PCS to be added to this phylink instance. A suitable PCS may never arrive. The PCS driver may not be built, may fail to probe, or may be missing from DT. A PCS may also attach without supporting the module's interface, and then every retry returns -EAGAIN again. In those cases the module stays in WAITDEV indefinitely, TX_DISABLE stays asserted and high-power mode is never enabled. Nothing is logged. Before this patch the same module failed in phylink_sfp_config_optical() with "unsupported SFP module: no common interface modes" and moved to SFP_MOD_ERROR. This branch can only trigger when the MAC leaves PCS-required modes out of config->supported_interfaces. A MAC such as airoha copies supported_interfaces into pcs_interfaces, so it cannot reach it. Could a message be logged when insertion is deferred here? Alternatively, could the old error path be kept for the case where no PCS can provide the interface? [ ... ] > @@ -2672,10 +2690,12 @@ static int phylink_update_pcs(struct phylink *pl, bool rescan) > } > > mutex_unlock(&pl->state_mutex); > - if (rescan) { > + if (resolve) { > if (phydev) > mutex_unlock(&phydev->lock); > mutex_unlock(&pl->phydev_mutex); > + if (rescan && added && ret > 0) > + phylink_sfp_retry_module(pl); > rtnl_unlock(); > } > [Severity: Medium] Is the SFP cage port refreshed when a late PCS extends pl->supported_interfaces? phylink_register_sfp() runs inside phylink_create() and calls phylink_create_sfp_cage_port(). That function sets the cage port's masks once, from the supported_interfaces that exist at that point: phy_interface_and(port->interfaces, pl->supported_interfaces, phylink_sfp_interfaces); phy_port_update_supported(port); This runs before phylink_pcs_finish_init() and before any FWNODE_PCS_PROVIDER_ADD notification can be handled. When the PCS appears later, phylink_update_pcs() and phylink_pcs_finish_init() rebuild pl->supported_interfaces with phylink_parse_supported_interfaces() and then call phylink_sfp_retry_module(). The interfaces and supported masks of pl->sfp_cage_port are never recomputed, so they keep the pre-PCS values. The module deferred by the new -EAGAIN check is, by construction, one whose caps->interfaces do not intersect the old pl->supported_interfaces. They therefore do not intersect the cage port's interfaces either. When the retried module reaches phylink_sfp_module_start(), phylink_add_sfp_mod_port() does: phy_interface_and(interfaces, pl->sfp_cage_port->interfaces, caps->interfaces); phy_caps_linkmode_filter_ifaces(port->supported, caps->link_modes, interfaces); The result is an empty interfaces mask, and pl->mod_port->supported ends up with no link modes. The cage port also never gains the PCS-backed interfaces and link modes. The phy_port topology that userspace sees then does not match the link that is actually running. Should the cage port masks be recomputed wherever phylink_parse_supported_interfaces() runs after the SFP bus has been registered? Or should phylink_add_sfp_mod_port() derive its mask from the current pl->supported_interfaces instead? [ ... ] > @@ -2797,7 +2821,8 @@ static void phylink_pcs_finish_init(struct phylink *pl) > mutex_lock(&phy->lock); > mutex_lock(&pl->state_mutex); > > - if (pl->pcs_state == PCS_STATE_INIT_PENDING) { > + pending = pl->pcs_state == PCS_STATE_INIT_PENDING; > + if (pending) { > phylink_parse_supported_interfaces(pl); > phylink_update_capabilities(pl, &pl->link_config); > } [Severity: High] What happens on an in-band link whose initial interface needs a PCS that has not registered yet? Consider a MAC that leaves the PCS-required mode out of config->supported_interfaces, which is the case late attach is meant for. phylink_create() calls phylink_update_pcs(pl, false) while pl->pcs_list is still empty. As a result, pl->supported_interfaces does not contain pl->link_config.interface. phylink_create() then calls phylink_parse_mode(). For MLO_AN_INBAND (managed = "in-band-status" or config->default_an_inband, the usual setup for SFP cages), this reaches phylink_parse_inband_capabilities(). There, __phylink_validate() returns early: if (!test_bit(state->interface, interfaces)) return -EINVAL; phylink_parse_mode() propagates the error, and phylink_create() jumps to unregister_pcs_notify. This happens before phylink_register_sfp(), before phylink_pcs_finish_init(), and before any FWNODE_PCS_PROVIDER_ADD can be handled. The INIT_PENDING handling added here therefore never gets to run. If the provider probes after the MAC, or concurrently with phylink_create(), the MAC probe simply fails. The same early return also affects the generic branch of phylink_update_capabilities() during the initial phylink_update_pcs(). That branch fills pl->supported with linkmode_fill() and copies it into config->advertising. __phylink_validate() then bails out before masking anything, and pl->advertising is saved as all ones. Should phylink_parse_mode() tolerate an interface that is in config->pcs_interfaces but not yet backed by a PCS, and defer the in-band capability parsing until a PCS attaches? Or is late PCS attach not meant to support in-band links? If so, could the commit message say that? -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261129230558.612526-1-ansuelsmth%40gmail.com