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=1796081153; b=lY1gx9CbzsPFowJmm2K2WhnA7BmFjkd9clhGY8gxcGM0LB/G3f9AMVy4vwYla12VXdFm ys/BOCK8/BYPznbBP8b4yg3QNjjhF0YZwBkt+trlMXZ5o3OnvlajTwSpu7jF+2MSWLASQ qQHhoqrzVyZXHyO+NedExb9SVml6vJMbDoD85hZFU6tTTEb2JKCKdn7RkQ+CKSZki1sWI qzh6ClkLizxxWXNBFW5eQDdWsKKJbKKebNa31QiQP7lt2j65xlJi3S2Man8KkNxFu91RP yNsarjNrAiodRBQCVon6gUi1V1cC1i8IYR81CxxxIW1EOfN2X5I2TvVIuiXWoiSOaRw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796081153; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=DD/jXuRPU6KNXP9DA5PWuC4hN4hr/g/ccS0Hb6MpSmo=; b=WsgFLh2DY5lzdmaNlFKHEFwrgAk+nRmKF6Grbr4iMfRUqFLqXkuCnqOaZ7xzCRoz1otq wPx+28iaT29B6ojo2u+UKNEs9V9jpJcdJlXUGVBppjuGHfhLZzpRnCSrB8nYtZbhhDQQM HNrUNBXk4ftRGrEvVs16et6cLae9EZo902mDym6RfMCe6eq28FZoVy78iMQvUkmNk5pnm jAHERS8qpBRe92Zs6Z71zCRBpevKFbiUA5AV+3HBOXYS33qwkPJdVDj1z6gFa4KQLHH1D q/BIAYAPjP8kraOyfP84Tdn81QqmMyckX8n7j3lgrdsYIAytcfIg+4u0z9cekw/tF9g== 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=lZFUkszi; 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 47ED5606A320 for ; Mon, 30 Nov 2026 23:25:53 +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=lZFUkszi Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80A431F000C1; Mon, 30 Nov 2026 23:25:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796081152; bh=DD/jXuRPU6KNXP9DA5PWuC4hN4hr/g/ccS0Hb6MpSmo=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=lZFUkszi7E5Kq5B98/4VPd+/iteiBztwIvnGEuPVNp6WIxQhtO59e/Uqha452XDPD nlYK69Jx0WyonyBZnM3ttU20T7YNVXfBvECL4WzldXKRohimjen9EICqbFG9aTKAqg EieUUVPY+5aE+tigpdsSMHKIsptlqtBeLhg5Z3czC2t0o2kG3+ElOWkO8UJNz48Iuc P2HXhd45i8B19QtSkJ1m7Ax4k/r/XvEZVtT7hCm4TthI8oSP+tj0IM4Y8vQQUMkVE7 oUP38oXGmjOXP3LVB01m12sGogVzeMuG2Y15HexVlzEaMgpY4nfuiHV/MDkzHLr3bg +rWItiEbylJRw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH net-next v23 08/15] net: phylink: support PCS provider release 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-9-ansuelsmth@gmail.com> References: <20261129230558.612526-1-ansuelsmth@gmail.com> <20261129230558.612526-9-ansuelsmth@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 23:25:52 +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 4 potential issues to consider: - [Medium] net: phylink: broken capability recalculation in phylink_update_capabilities() - [Medium] net: phylink: stale supported_interfaces on PCS removal in phylink_create() - [Medium] net: phylink: mishandled force_major_config with phylink_disable_state - [Medium] net: phylink: ethtool ksettings_set fails to recover after PCS autoneg failure -- commit 5986209cbd917d337672409773ed100e8165e845 Author: Christian Marangi net: phylink: support PCS provider release This commit adds a blocking notifier chain for fwnode PCS provider removal so phylink instances can detach removed PCS instances, refresh their supported interfaces and link capabilities, and trigger link resolution. > diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c > index 877a0a30ec222..6dde0eae0e73a 100644 > --- a/drivers/net/phy/phylink.c > +++ b/drivers/net/phy/phylink.c [ ... ] > @@ -1504,6 +1530,19 @@ static void phylink_major_config(struct phylink *p= l, bool restart, > } > } > =20 > + /* A replacement PCS may require a different autonegotiation mode */ > + if (!pl->phydev && !phy_interface_empty(pl->sfp_module_interfaces)) { > + unsigned int caps =3D phylink_pcs_inband_caps(pcs, state->interface); > + > + if (!test_bit(state->interface, pl->sfp_interfaces) || > + !phylink_inband_autoneg_valid(caps, state->advertising)) { > + phylink_err(pl, "incompatible SFP configuration for %s\n", > + phy_modes(state->interface)); > + pl->major_config_failed =3D true; > + return; > + } > + } [Severity: Medium] Can an optical SFP link recover via phylink_ethtool_ksettings_set() after this check fails? When a replacement PCS for the current interface requires a different in-band autonegotiation mode, phylink_major_config() sets pl->major_config_failed =3D true and returns before assigning pl->pcs =3D p= cs, leaving pl->pcs NULL while pl->link_config.interface stays unchanged. If userspace then changes autonegotiation on the same interface with ethtool, phylink_ethtool_ksettings_set() sees pl->link_config.interface =3D=3D config.interface and only calls phylink_change_inband_advert(), which is a no-op when pl->pcs is NULL and never attaches the replacement PCS or clears pl->major_config_failed. [ ... ] > @@ -2385,35 +2398,46 @@ static void phylink_update_capabilities(struct ph= ylink *pl, > } > =20 > /* > - * Revalidate SFP modes before generic in-band capabilities, so module > - * EEPROM limits are retained for in-band SFP configurations. > + * Revalidate SFP modes against the current MAC and PCS interfaces > + * before generic in-band capabilities to preserve the module's > + * EEPROM limits. Keep the module's original interface mask so a > + * later PCS addition can make an interface usable again. > */ > - if (pl->sfp_bus && config->interface !=3D PHY_INTERFACE_MODE_NA && > - !phy_interface_empty(pl->sfp_module_interfaces)) { > + if (pl->sfp_bus && !phy_interface_empty(pl->sfp_module_interfaces)) { > __ETHTOOL_DECLARE_LINK_MODE_MASK(active_supported); > struct phylink_link_state sfp_config =3D *config; > __ETHTOOL_DECLARE_LINK_MODE_MASK(supported); > =20 > phy_interface_and(pl->sfp_interfaces, pl->sfp_module_interfaces, > pl->supported_interfaces); > + linkmode_zero(pl->advertising); > + > linkmode_copy(supported, pl->sfp_support); > linkmode_copy(sfp_config.advertising, pl->sfp_support); > if (__phylink_validate_mask(pl, NULL, supported, &sfp_config, > - pl->sfp_interfaces)) > - return; > - > - phylink_sfp_update_capabilities(pl, supported, &sfp_config, > - config->interface); > + pl->sfp_interfaces)) { > + /* No SFP modes remain usable with the current interfaces */ > + linkmode_zero(pl->supported); > + phy_interface_zero(pl->sfp_interfaces); > + goto exit; > + } > =20 > /* > * Keep alternate modes available for interface selection, but > * only advertise modes that the current interface can use. > */ > + linkmode_copy(pl->supported, supported); > + if (!test_bit(config->interface, pl->sfp_interfaces)) > + goto exit; > + > linkmode_copy(active_supported, pl->sfp_support); > - if (__phylink_validate(pl, active_supported, &sfp_config)) > - return; > + if (__phylink_validate(pl, active_supported, &sfp_config)) { > + __clear_bit(config->interface, pl->sfp_interfaces); > + goto exit; > + } > =20 > - linkmode_copy(pl->supported, supported); > + phylink_sfp_update_capabilities(pl, pl->supported, &sfp_config, > + config->interface); > linkmode_copy(pl->advertising, sfp_config.advertising); > goto exit; > } [Severity: Medium] Does phylink_update_capabilities() clear or restrict pl->supported_interfac= es, pl->supported, and pl->advertising when a required PCS is removed? First, MAC drivers populate config->supported_interfaces with all interfaces supported by the MAC and config->pcs_interfaces with the subset requiring a dedicated PCS. phylink_parse_supported_interfaces() copies config->supported_interfaces directly into pl->supported_interfaces without clearing config->pcs_interfaces first, and phylink_validate_mac_and_pcs() still validates against MAC capabilities alone when pcs is NULL: drivers/net/phy/phylink.c:phylink_validate_mac_and_pcs() { ... } else if (test_bit(state->interface, pl->config->pcs_interfaces)) { struct phylink_pcs *tmp; list_for_each_entry(tmp, &pl->pcs_list, list) { if (!phylink_validate_pcs_interface(tmp, state->interface)) { pcs =3D tmp; break; } } } if (pcs) { ... } Because neither function excludes interfaces in config->pcs_interfaces that have no matching PCS in pl->pcs_list, __phylink_validate_mask() and __phylink_validate() continue to succeed after the PCS is removed. Second, in the non-SFP branches of phylink_update_capabilities(), when config->interface is not in pl->supported_interfaces, __phylink_validate() returns -EINVAL immediately without clearing the caller's bitmaps. In the generic fallback branch, phylink_update_capabilities() pre-fills pl->supported and config->advertising with linkmode_fill() and ignores the -EINVAL return from __phylink_validate(), leaving pl->supported, pl->advertising, and pl->link_config.advertising with every linkmode bit set. Similarly, phylink_parse_inband_capabilities(), phylink_parse_fixedlink_capabilities(), and phylink_phy_update_capabilities= () leave unvalidated or stale link modes in pl->supported and pl->advertising when validation fails. > @@ -2494,6 +2518,42 @@ void phylink_update_mac_pause_capabilities(struct = phylink *pl, unsigned long mac > } > EXPORT_SYMBOL_GPL(phylink_update_mac_pause_capabilities); > =20 > +static void phylink_del_pcs(struct phylink *pl, struct phylink_pcs *pcs) > +{ > + ASSERT_RTNL(); > + > + lockdep_assert_held(&pl->state_mutex); > + > + /* > + * Check if we are removing the PCS currently > + * in use by this phylink instance. If this is the case, > + * tear down the link, force phylink resolve to reconfigure the > + * interface mode, disable the current PCS and set the > + * phylink PCS to NULL. > + */ > + if (pl->pcs =3D=3D pcs) { > + if (pl->old_link_state) { > + phylink_link_down(pl); > + pl->old_link_state =3D false; > + } > + if (pl->cfg_link_an_mode =3D=3D MLO_AN_INBAND) > + timer_delete_sync(&pl->link_poll); > + > + if (pl->pcs_state !=3D PCS_STATE_DOWN) > + phylink_pcs_disable(pl->pcs); > + > + if (!pl->phylink_disable_state) > + pl->force_major_config =3D true; > + > + WRITE_ONCE(pl->pcs, NULL); > + } [ ... ] > @@ -2523,12 +2583,243 @@ static void phylink_parse_supported_interfaces(s= truct phylink *pl) > } > } > =20 > +static bool phylink_pcs_changed(struct phylink *pl) > +{ > + lockdep_assert_held(&pl->state_mutex); > + > + /* Defer capability updates until creation finishes */ > + if (pl->pcs_state =3D=3D PCS_STATE_INITIALIZING || > + pl->pcs_state =3D=3D PCS_STATE_INIT_PENDING) { > + pl->pcs_state =3D PCS_STATE_INIT_PENDING; > + return false; > + } > + > + /* Skip forcing a major config if we are disabled */ > + if (!test_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state) && > + (pl->force_major_config || pl->major_config_failed)) { > + pl->force_major_config =3D true; > + pl->link_failed =3D true; > + } > + > + return true; > +} [Severity: Medium] As reported by Jakub Kicinski on v22 [1], how does pl->force_major_config interact with pl->phylink_disable_state and pl->link_failed across PCS removal and phylink_resolve()? In phylink_resolve(), pl->force_major_config triggers phylink_major_config() even when pl->phylink_disable_state is non-zero: drivers/net/phy/phylink.c:phylink_resolve() { ... 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; } ... } If phylink_stop() runs after pcs_provider_notify() releases rtnl_lock() and before pl->resolve executes, phylink_stop() calls timer_delete_sync(&pl->link_poll) and then flushes pl->resolve with PHYLINK_DISABLE_STOPPED set. Because pl->force_major_config is true, phylink_resolve() still calls phylink_major_config() while stopped, which reconfigures hardware and, for a replacement polling PCS in MLO_AN_INBAND mode, calls phylink_pcs_poll_start() and re-arms pl->link_poll after phylink_stop() has deleted it; a subsequent phylink_destroy() then frees pl with an active timer. In addition, phylink_del_pcs() only sets pl->force_major_config when !pl->phylink_disable_state rather than !test_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state), so removing the active PCS while another disable bit (such as PHYLINK_DISABLE_MAC_WOL or PHYLINK_DISABLE_REPLAY) is set leaves pl->pcs NULL without forcing a major config once re-enabled. Finally, when phylink_pcs_changed() or phylink_sfp_link_up() sets both pl->force_major_config =3D true and pl->link_failed =3D true, the first pas= s of phylink_resolve() enters the else if (pl->link_failed) branch (using pl->link_config rather than pl->phy_state or phylink_get_fixed_state()) and consumes pl->force_major_config =3D false before the normal resolve pass ru= ns. > + > +static int phylink_update_pcs(struct phylink *pl, bool rescan) > +{ [ ... ] > + if (rescan) > + ret =3D (added || removed) && phylink_pcs_changed(pl); > + if (!rescan || ret) { > + phylink_parse_supported_interfaces(pl); > + phylink_update_capabilities(pl, &pl->link_config); > + } [Severity: Medium] If a PCS provider is removed while phylink_create() is running, does skipping phylink_parse_supported_interfaces() leave pl->supported_interfaces stale during the rest of initialization? While pl->pcs_state is PCS_STATE_INITIALIZING, phylink_update_pcs() (and phylink_remove_provider_pcs()) detaches the removed PCS from pl->pcs_list immediately, but phylink_pcs_changed() returns false and defers phylink_parse_supported_interfaces() until phylink_pcs_finish_init(). As a result, phylink_parse_mode(), phylink_parse_fixedlink(), and phylink_register_sfp() run with pl->supported_interfaces still containing the removed PCS's interfaces, and phylink_create_sfp_cage_port() permanently initializes pl->sfp_cage_port->interfaces from that stale mask. [1] https://lore.kernel.org/r/20261121232649.1365412-1-kuba@kernel.org --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261129230558.6125= 26-1-ansuelsmth@gmail.com?part=3D8