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=1796081154; b=OtYkg5KJn5+bb7j4T/djyxUaaMR/JhQ4S6VQiXdemuuGIassAU5wtXXnhjVQvoZAUhc8 O4wciY3Gv2Vtw13lqCoHyWtcXvT9rvyy8BwsC75QPfTb/3I40ZSw23kiMX/5mfQaXBSen YxC6zGo18gcoS1NjAS0Ql4zgWwWp13ORNH1wZJEbN+KtgaC96jxYjVlh163t6M/mZ3SsI tyKCzP/g+dh2iWiALxxhExRNVyopiE8jJv3PHKqQ7h5wVubehhVM7IO5r/xWjGDRRg2kf X8O9OAKcaCiYNKnHusbGu+jvz0ONd3cxDCXk2uZht5XGm97EEh1RAv84nzY+eGo1LTg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796081154; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=JV8V7VO8NATQMCzP42hu/0CjfHquY2diOudQrxCVYPk=; b=j3Mx6dH7C3f1BtzLtx0LBifpw+TCdRvX+54Qks+6NPgTknxblU6k4cgjx55ZmEsMQONT lVbb88SYyn2BsCL0z0IJvELCuGbbwCNIoKcdn2pRA1317iPVRrDvqYMCDZgQRFMHdYh+M 6hqdkN329O6NDD3+6zsQFhV+/g0ZwXq3rZqi/txplcB3YeckBPXuPr+KJja6QPSjVzZmN cLZH8pdCyX9fVaQ8N86Hcib96fjqfR2zAqC983ZNf757rDCd0FkKRPf2l0c41Ta+fkLXl 4tToCfB0wrkjj2nZFMXOYNFf5UxGMcvkWqr/IqKnHElch8WaMpdHMLsQD9K4a/+lahg== 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=eQ0mMOGj; 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 CBCBD606A320 for ; Mon, 30 Nov 2026 23:25:54 +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=eQ0mMOGj Received: by smtp.kernel.org (Postfix) with ESMTPSA id C0B121F000C1; Mon, 30 Nov 2026 23:25:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796081154; bh=JV8V7VO8NATQMCzP42hu/0CjfHquY2diOudQrxCVYPk=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=eQ0mMOGjPItaGtkw+xpdSr5mg1PzN7orAH4Ll1XFU+4eD95nEVkD3pb5F0z5pTCww xRbfZupg7yQc5dLT+u62l9Pb8XQgLwSHID1KR2l9+O2TDguKF3X81cUtx8g5ug2AkE IsqbVqaOIUguqi2ySgCFesrergKxvPzzsV7D7ES1cgSZcKWkngXvZyAWvNLM4v5ipg s76QG8p6oO3l3A62awRmYnV0DexhcX/vj47KdSq3Lofm2nJFJEUhHmjOMkSq9lqVY0 +3owlWfmtaQdT1zMPHhfkmHgC2NyVx+rLXhLFeFQMi7BpszV2R2+3oo0N1fYxBYi/7 iRaVcJUML4d8A== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH net-next v23 09/15] net: phylink: support late PCS provider attach Reply-To: sashiko-reviews@lists.linux.dev To: "Christian Marangi" , devicetree@vger.kernel.org Cc: robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261129230558.612526-10-ansuelsmth@gmail.com> References: <20261129230558.612526-1-ansuelsmth@gmail.com> <20261129230558.612526-10-ansuelsmth@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 23:25:53 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 6 potential issues to consider: - [High] net: phylink: phylink_create() fails for in-band links with late PCS - [High] net: phylink: phylink_parse_supported_interfaces() keeps unavailable PCS modes - [Medium] net: phylink: stale sfp_cage_port capabilities after late PCS attach - [Medium] net: phylink: phylink_sfp_module_insert() defers when all PCS attached - [Medium] net: phylink: stale supported_interfaces during phylink_create() race - [Medium] net: phylink: phylink_resolve() passes wrong state to phylink_major_config() -- commit 0fe95ceaab889b7312803eee82036e14adbe5fe1 Author: Christian Marangi net: phylink: support late PCS provider attach This commit adds FWNODE_PCS_PROVIDER_ADD notifications to attach PCS providers that register after phylink_create() and retries deferred optical SFP module insertions when a PCS becomes available. > 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 > @@ -2604,6 +2604,21 @@ static bool phylink_pcs_changed(struct phylink *pl) > return true; > } [Severity: Medium] When phylink_pcs_changed() sets both pl->force_major_config and pl->link_failed on a running instance, does phylink_resolve() pass the wrong link state to phylink_major_config()? In the first pass of phylink_resolve(), the pl->link_failed branch runs before the MLO_AN_FIXED and MLO_AN_PHY branches: drivers/net/phy/phylink.c:phylink_resolve() { ... } else if (pl->link_failed) { link_state =3D pl->link_config; link_state.link =3D false; retrigger =3D true; } else if (pl->act_link_an_mode =3D=3D MLO_AN_FIXED) { phylink_get_fixed_state(pl, &link_state); mac_config =3D link_state.link; } else if (pl->act_link_an_mode =3D=3D MLO_AN_PHY) { link_state =3D pl->phy_state; mac_config =3D link_state.link; } ... if ((mac_config && link_state.interface !=3D pl->link_config.interface) || pl->force_major_config) { if (cur_link_state) { phylink_link_down(pl); cur_link_state =3D false; } phylink_major_config(pl, false, &link_state); pl->link_config.interface =3D link_state.interface; pl->force_major_config =3D false; } } Because pl->force_major_config is consumed and cleared in that first pass while link_state is a copy of pl->link_config, phylink_major_config() is called with pl->link_config instead of pl->phy_state (which holds the PHY's interface, pause, and rate_matching settings in MLO_AN_PHY mode) or phylink_get_fixed_state() (in MLO_AN_FIXED mode). If the PHY link is down or its interface already matches pl->link_config.interface, the retriggered second pass of phylink_resolve() will not run phylink_major_config() again. > +static void phylink_sfp_retry_module(struct phylink *pl) > +{ > + struct sfp_bus *bus; > + > + ASSERT_RTNL(); > + > + if (!pl->netdev) > + return; > + > + /* The SFP callbacks publish the attached bus under RTNL */ > + bus =3D pl->netdev->sfp_bus; > + if (bus && bus =3D=3D pl->sfp_bus) > + sfp_upstream_retry_module(bus); > +} > + > static int phylink_update_pcs(struct phylink *pl, bool rescan) > { > struct phylink_config *config =3D pl->config; > @@ -2613,6 +2628,7 @@ static int phylink_update_pcs(struct phylink *pl, b= ool rescan) > unsigned int num_pcs, i; > bool removed =3D false; > bool added =3D false; > + bool resolve; > int ret; > =20 > lockdep_assert_held(&pl->pcs_list_mutex); > @@ -2628,7 +2644,9 @@ static int phylink_update_pcs(struct phylink *pl, b= ool rescan) > return ret; > } > =20 > - if (rescan) { > + /* An add notification can fill the PCS list before the initial update = */ > + resolve =3D rescan || !list_empty(&pl->pcs_list); > + if (resolve) { > rtnl_lock(); > mutex_lock(&pl->phydev_mutex); > phydev =3D pl->phydev; > @@ -2672,10 +2690,12 @@ static int phylink_update_pcs(struct phylink *pl,= bool rescan) > } > =20 > 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: High] Does phylink_create() still fail with -EINVAL on MLO_AN_INBAND links when the initial pl->link_config.interface requires a PCS provider that attaches late? During phylink_create(), phylink_update_pcs(pl, false) runs before the late PCS provider is registered, so pl->link_config.interface is not yet in pl->supported_interfaces. phylink_create() then calls phylink_parse_mode() -> phylink_parse_inband_capabilities() -> __phylink_validate(), which rejects state->interface with -EINVAL because it is not set in pl->supported_interfaces, aborting phylink_create() before phylink_register_sfp() or any late FWNODE_PCS_PROVIDER_ADD event can run. Also, in phylink_update_capabilities(), the fallback path fills pl->supported and config->advertising with all ones before calling __phylink_validate() and unconditionally copies config->advertising into pl->advertising, leaving both masks filled with all ones when __phylink_validate() returns -EINVAL early for a missing PCS interface. [ ... ] > @@ -2787,6 +2810,7 @@ static int pcs_provider_notify(struct notifier_bloc= k *self, > static void phylink_pcs_finish_init(struct phylink *pl) > { > struct phy_device *phy; > + bool pending; > =20 > /* SFP module callbacks can run once the upstream is registered */ > if (pl->sfp_bus) > @@ -2797,7 +2821,8 @@ static void phylink_pcs_finish_init(struct phylink = *pl) > mutex_lock(&phy->lock); > mutex_lock(&pl->state_mutex); > =20 > - if (pl->pcs_state =3D=3D PCS_STATE_INIT_PENDING) { > + pending =3D pl->pcs_state =3D=3D PCS_STATE_INIT_PENDING; > + if (pending) { > phylink_parse_supported_interfaces(pl); > phylink_update_capabilities(pl, &pl->link_config); > } [Severity: Medium] Can pl->supported_interfaces become stale relative to pl->pcs_list if a PCS notification arrives during phylink_create()? CPU0 CPU1 phylink_create() register_fwnode_pcs_notifier() phylink_update_pcs(pl, false) mutex_unlock(&pl->pcs_list_mutex) pcs_provider_notify() phylink_update_pcs(pl, true) /* updates pl->pcs_list */ phylink_pcs_changed(pl) pl->pcs_state =3D PCS_STATE_INIT_PENDING; return false; /* skips phylink_parse_ * supported_interfaces() */ phylink_parse_mode() phylink_parse_fixedlink() phylink_register_sfp() /* uses stale pl->supported_interfaces */ phylink_pcs_finish_init() Because phylink_pcs_changed() returns false while pl->pcs_state is PCS_STATE_INITIALIZING or PCS_STATE_INIT_PENDING, phylink_update_pcs() and phylink_remove_provider_pcs() mutate pl->pcs_list without refreshing pl->supported_interfaces until phylink_pcs_finish_init() runs at the end of phylink_create(). phylink_parse_mode(), phylink_parse_fixedlink(), and phylink_register_sfp() therefore inspect a pl->supported_interfaces bitmap that does not match pl->pcs_list. > @@ -2807,8 +2832,11 @@ static void phylink_pcs_finish_init(struct phylink= *pl) > if (phy) > mutex_unlock(&phy->lock); > mutex_unlock(&pl->phydev_mutex); > - if (pl->sfp_bus) > + if (pl->sfp_bus) { > + if (pending) > + phylink_sfp_retry_module(pl); > rtnl_unlock(); > + } > } [Severity: Medium] When a PCS attaches after phylink_register_sfp() has created pl->sfp_cage_port (either in phylink_update_pcs() or here in phylink_pcs_finish_init()), does pl->sfp_cage_port retain stale interfaces and supported link modes? phylink_create_sfp_cage_port() initializes pl->sfp_cage_port->interfaces and pl->sfp_cage_port->supported from pl->supported_interfaces during phylink_register_sfp(). Neither phylink_update_pcs() nor phylink_pcs_finish_init() updates pl->sfp_cage_port when pl->supported_interfaces changes before calling phylink_sfp_retry_module(). When the retried optical SFP module starts, phylink_add_sfp_mod_port() intersects caps->interfaces with the stale pl->sfp_cage_port->interfaces mask, leaving pl->mod_port->supported empty. > @@ -4789,6 +4817,14 @@ static int phylink_sfp_module_insert(void *upstrea= m, > ASSERT_RTNL(); > =20 > caps =3D 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 -EAGAIN condition ever trigger when pl->config->pcs_interfaces is a subset of pl->config->supported_interfaces? phylink_parse_supported_interfaces() starts by copying all of pl->config->supported_interfaces into pl->supported_interfaces without masking out pl->config->pcs_interfaces: drivers/net/phy/phylink.c:phylink_parse_supported_interfaces() { phy_interface_copy(pl->supported_interfaces, pl->config->supported_interfaces); list_for_each_entry(pcs, &pl->pcs_list, list) { DECLARE_PHY_INTERFACE_MASK(pcs_interfaces); phy_interface_copy(pcs_interfaces, pl->config->pcs_interfaces); if (!phy_interface_empty(pcs->supported_interfaces)) phy_interface_and(pcs_interfaces, pcs_interfaces, pcs->supported_interfaces); phy_interface_or(pl->supported_interfaces, pl->supported_interfaces, pcs_interfaces); } } Because drivers populate pl->config->supported_interfaces with all MAC interfaces and mark the PCS-backed subset in pl->config->pcs_interfaces, every bit in pl->config->pcs_interfaces is already present in pl->supported_interfaces even when pl->pcs_list is empty. As a result, !bitmap_intersects(caps->interfaces, pl->supported_interfaces, ...) is always false whenever caps->interfaces intersects pl->config->pcs_interfaces, so optical SFP modules are never deferred with -EAGAIN and unavailable PCS modes remain enabled in pl->supported_interfaces. Should phylink_parse_supported_interfaces() initialize pl->supported_interfaces with phy_interface_andnot() to exclude pl->config->pcs_interfaces before ORing in the interfaces of attached PCS instances? [Severity: Medium] Even with pl->supported_interfaces excluding unattached PCS modes, will this check return -EAGAIN indefinitely when all possible PCS instances are already attached? An attached PCS can support only a subset of pl->config->pcs_interfaces in pcs->supported_interfaces. If all pl->config->num_possible_pcs PCS instances are already in pl->pcs_list and an optical SFP module is inserted whose interface is in pl->config->pcs_interfaces but not supported by the attached PCS, phylink_sfp_module_insert() will still return -EAGAIN instead of rejecting the module with -EINVAL, leaving the SFP state machine stuck in SFP_MOD_WAITDEV. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261129230558.6125= 26-1-ansuelsmth@gmail.com?part=3D9