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=1796082464; b=UoLDqyn4tLf6R6bkLQcMBn9p8FmRgtrb+Urxykbuj77m6pcx9rsQDV8uo9fTUTTIKc2C hKKqTVaResrjNJveKrvdVJ/Pg6EoDG5OzlCjci0jGBV0iC+Rl8X1Ovv41+yvpN/xxNruK ESbl9j+COrw+94gdJEer2yWLBCFzFDSdZRUqXmxETYbuh/CgccIfipDwT6qgqUsFOESxL p1iOlDikhK1qoMr/BrEQZ5MHuU2ajbAtFNZAUz9odTy4X0INC33zagQbwifY5+9xFmEBz neKIwBQ8+dPBdzWhO/nKSuAngng0IMgm8itpjuDG3owBCI2IYq5TksvGku95rr/CyVw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796082464; 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=InGS80hQWRyzR1BTRoH19ejktTsHyzHHK891ypATtig=; b=ZYhqQFBTGiHmc3VRY01mzvOfDZHTH0Ad+8E22pdIk8q6MqEST4Uou8QQzPqvMmW9DvOZ 9Nw+eL2UCX0p4Ob1YonzbplE1kbDUlzs74yhbGfn74xtG3DV/Zv7Ll7p946R6VPw0i2Ox mNXalckh7umcjolC0UXvehY0kbSSAasz76FM7Hc/Sjac510Hx7psJJqUewl6G6HdwRtfT Ia2N1obdRkMQhSpArB3smKjVp5hqDlprX5ArgcWVn85ftezD+6oiNW1425dIvadk/XMIf FEwvmpdhWClNmpxt0BytveCnlRKfto+SMKgr6QjEWSuOUaNiL9ZnyTTBJhuRUBOwdIg== 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=c3z6Qryp; 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 2A551606A31A; Mon, 30 Nov 2026 23:47:43 +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=c3z6Qryp Received: by smtp.kernel.org (Postfix) with ESMTPSA id DF5151F0092C; Mon, 30 Nov 2026 23:47:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796082463; bh=InGS80hQWRyzR1BTRoH19ejktTsHyzHHK891ypATtig=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=c3z6QryptDjDiedOZ6iiN1KDu8+F2wJ2YjEUT/boEh0pFOFcZlRntaIA69e9A89dh 51yQrRxFRCiqnwlSa6dqyGP3mOjGxpBJrzrx9sevFqimqich1TudwbwyF1pZLWblLY tXTxHmFY1TVNNy33uu46pSNNKy90or+Lin0gO4MsCaUTAmHQ7ymwJyWm3cM+MkwvzG WYaR4b8oEwb6N0mOl/dPd65fqSIG/gMqy8AjHMmghHXdcNZmvbxYHv1KVflK7BRPl4 DRbZwpn7KzAN8M70+ZZKp0XJPLEXbcfbmkp7k60hyz3WHHyGYOvFutmx8yNzexgwid owiSgCcQZOSHw== Subject: Re: [PATCH net-next v23 06/15] net: phylink: add capabilities helpers and track modified advertising 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:41 +0000 Message-ID: <179608246142.3146.8194531736512870418@kernel.org> In-Reply-To: <20261129230558.612526-7-ansuelsmth@gmail.com> References: <20261129230558.612526-7-ansuelsmth@gmail.com> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@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 6 potential issue(s) to consider. Critical: 0 · High: 1 · Medium: 3 · Low: 2 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: unchecked validation failure in phylink_update_capabilities() - [Medium] On SFP links, pl->advertising does not always hold "the full validated advertisement" that the commit message describes, so modes… - [Medium] phylink_update_user_disabled_advertising() never clears a restriction for a mode that is outside the current pl->advertising,… - [Medium] net: phylink: stale SFP caps after phylink_sfp_module_start() failure - [Low] phylink_update_capabilities() falls back to phylink_parse_inband_capabilities() after an SFP module is removed,… - [Low] net: phylink: phylink_set_fixed_link() leaves pl->advertising stale -- net: phylink: add capabilities helpers and track modified advertising This commit adds pl->advertising and pl->user_disabled_advertising masks to struct phylink, along with helpers that recalculate the supported and advertised link modes when a PCS is added or removed. It also factors the fixed-link, in-band, PHY and SFP capability calculations into reusable helpers. The user-disabled mask is applied during SFP interface selection. > diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c > index 141da617b24bd..877a0a30ec222 100644 > --- a/drivers/net/phy/phylink.c > +++ b/drivers/net/phy/phylink.c [ ... ] > @@ -2236,6 +2286,157 @@ static void phylink_update_pause_state(struct phylink *pl, int pause_state) > } > } > > +static void phylink_update_user_disabled_advertising(struct phylink *pl, > + const unsigned long *advertising) > +{ > + __ETHTOOL_DECLARE_LINK_MODE_MASK(disabled); > + > + /* Preserve restrictions for modes absent from the current full mask */ > + linkmode_andnot(disabled, pl->user_disabled_advertising, > + pl->advertising); > + > + /* Update restrictions for modes in the current full advertisement */ > + linkmode_andnot(pl->user_disabled_advertising, pl->advertising, > + advertising); > + > + /* Combine the updated restrictions with those preserved above */ > + linkmode_or(pl->user_disabled_advertising, > + pl->user_disabled_advertising, disabled); > +} [Severity: Medium] Can a restriction on a mode outside the current pl->advertising ever be cleared here, even when the user explicitly requests that mode? The result is D = (A & ~R) | (D_old & ~A). A mode that is in D_old and in R but not in A stays disabled. On optical SFP links, A only covers the current interface because phylink_sfp_set_config() sets it. The request built in phylink_ethtool_ksettings_set() is masked with pl->supported, which covers every SFP interface. Take two interfaces X and Y on a may_have_phy module where no PHY was detected: 1. The link starts on X. 2. The user advertises only a Y mode. D gets the X speed modes and the interface switches to Y. 3. After a link down/up, phylink_sfp_module_start() calls phylink_sfp_config_optical(). That skips X, picks Y and sets A = A(Y). 4. The user advertises only an X mode m_X. D & ~A(Y) still contains m_X, and D also gains all the Y speed modes. 5. After another link down/up, phylink_choose_sfp_interface() finds every candidate empty after masking: linkmode_andnot(tmp_state.advertising, tmp_state.advertising, pl->user_disabled_advertising); if (!phylink_is_empty_linkmode(tmp_state.advertising)) return interface; ... return PHY_INTERFACE_MODE_NA; phylink_sfp_config_optical() then fails with "failed to select SFP interface". sfp_module_start() fails too, and the SFP state machine moves to SFP_S_FAIL with the link down. Later in the series the same stale bits also reach phylink_update_capabilities() on PCS add/remove. Its exit label sets link_config.advertising = A & ~D, which drops the modes the user just asked for. > + > +static void phylink_sfp_update_capabilities(struct phylink *pl, [ ... ] > +static void phylink_update_capabilities(struct phylink *pl, > + struct phylink_link_state *config) > +{ [ ... ] > + /* > + * Revalidate SFP modes before generic in-band capabilities, so module > + * EEPROM limits are retained for in-band SFP configurations. > + */ > + if (pl->sfp_bus && config->interface != PHY_INTERFACE_MODE_NA && > + !phy_interface_empty(pl->sfp_module_interfaces)) { [Severity: Medium] Does the deferred optical path need the same cleanup as the error path added here? For a module with caps->may_have_phy set, phylink_sfp_module_insert() caches pl->sfp_module_interfaces, pl->sfp_interfaces and pl->sfp_support and returns 0. The optical configuration is left to phylink_sfp_module_start(), which runs once sfp.c has probed for a PHY and found none. If phylink_sfp_config_optical() fails there, phylink_sfp_module_start() only deletes the module port and returns the error. sfp_sm_main() then moves to SFP_S_FAIL while the module stays SFP_MOD_PRESENT, so phylink_sfp_module_remove() is not called until the module is pulled. Nothing clears the cached masks on that path. >>From then on phylink_update_capabilities() sees a non-empty pl->sfp_module_interfaces and takes the SFP branch whenever link_config.interface is not PHY_INTERFACE_MODE_NA. pl->supported and pl->advertising are rebuilt from the failed module's sfp_support. As a result, ethtool reports, and the next major config uses, modes from a module that phylink refused to configure. For may_have_phy modules, the window between insert and phylink_sfp_module_start() behaves the same way. In this commit the branch is only reached through phylink_update_mac_pause_capabilities(); later in the series the PCS add/remove paths reach it as well. Should phylink_sfp_module_start() clear the cached module capabilities on failure as well, perhaps through a helper shared with the insert path? And should the SFP branch act on a module that has not been started yet? [ ... ] > + if (pl->cfg_link_an_mode == MLO_AN_INBAND) { > + phylink_parse_inband_capabilities(pl, config); > + goto exit; > + } [Severity: Low] Does this branch handle links set up with phylink_set_fixed_link()? phylink_set_fixed_link() derives link_config.advertising from the MAC-validated pl->supported with phy_caps_lookup() and sets cfg_link_an_mode to MLO_AN_FIXED. It does not touch pl->advertising, which still holds the generic mask computed in phylink_create(). When phylink_update_capabilities() later runs on such a link, phylink_parse_fixedlink_capabilities() rebuilds everything from phylink_fill_fixedlink_supported(), which only covers 10baseT to 10000baseT. Take a 25G or 40G link configured this way (txgbe_aml.c does this). phy_caps_lookup() returns NULL, pl->supported is reduced to MII, Autoneg and the pause bits, and the advertisement has no speed modes left. The -EINVAL is ignored, so the link silently loses its speed modes. Even for speeds in the BASE-T table, the result can differ from what phylink_set_fixed_link() picked. That function used every mode at the speed present in pl->supported. In this commit only phylink_update_mac_pause_capabilities() reaches this branch; later in the series the PCS add/remove paths do too. Should phylink_set_fixed_link() record its result in pl->advertising and keep the mask it chose? The fixed-link recalculation could then reuse it rather than the firmware fixed-link table. [Severity: Low] After an SFP module is removed, should this branch still run with the removed module's interface? phylink_sfp_module_remove() clears pl->sfp_module_interfaces but leaves pl->link_config.interface at the last SFP interface. On an in-band SFP port the SFP branch above is skipped and this branch runs instead. If the last module used PHY_INTERFACE_MODE_100BASEX, the parser reaches its default case. 100BASEX is in phylink_sfp_interface_preference but not in the in-band switch list: default: phylink_err(pl, "incorrect link mode %s for in-band status\n", phy_modes(config->interface)); return -EINVAL; By then pl->supported has already been reset to just MII, Autoneg, Pause and Asym_Pause. The error is ignored here, and the exit label rebuilds link_config.advertising from the removed module's stale pl->advertising. In this commit the path can only be reached through phylink_update_mac_pause_capabilities(). Later in the series it runs on every PCS add/remove event while no module is inserted (phylink_update_pcs(), phylink_remove_provider_pcs(), phylink_pcs_finish_init()). > + > + /* No media is attached yet. Recalculate the generic capabilities */ > + linkmode_fill(pl->supported); > + linkmode_copy(config->advertising, pl->supported); > + __phylink_validate(pl, pl->supported, config); > + > + /* Save the newly calculated full advertisement */ > + linkmode_copy(pl->advertising, config->advertising); > + > +exit: > + /* Keep user-disabled modes out of the active advertisement */ > + linkmode_andnot(config->advertising, > + pl->advertising, pl->user_disabled_advertising); > +} [Severity: High] phylink_update_capabilities() returns void and drops every validation result. What state is left behind when nothing validates? In the generic path, pl->supported is filled and copied into config->advertising before __phylink_validate() runs. If config->interface is set but no longer in pl->supported_interfaces, for example because the PCS providing it went away, __phylink_validate() returns -EINVAL without masking anything. pl->supported and pl->advertising stay all-ones, and the exit label sets link_config.advertising to all-ones minus the user-disabled bits. phylink_validate_mac_and_pcs() has similar early returns when mac_select_pcs() or pcs_validate() fail. The other helpers behave the same way: - phylink_parse_fixedlink_capabilities() ignores the __phylink_validate() result after filling pl->supported with the fixed-link table. - phylink_parse_inband_capabilities() has already overwritten pl->supported with the raw interface capabilities when it returns -EINVAL. The exit label then copies the previous pl->advertising back into link_config.advertising. - phylink_phy_update_capabilities() returns early, leaving pl->supported, pl->advertising and link_config.advertising with the values from before the PCS change. The unchecked fill and validate in phylink_create() predates this patch. However, the helper now also runs on a configured link: through phylink_update_mac_pause_capabilities() here, and on every PCS add/remove later in the series. That is exactly when an interface is likely to lose its PCS. Relatedly, for an MLO_AN_INBAND link whose PCS attaches late, phylink_parse_mode() still propagates the in-band validation failure and phylink_create() fails. Is that intended, given the aim of the series? Could phylink_update_capabilities() return an error to its callers? And on failure, should validation be done into temporaries and only committed to pl->supported and pl->advertising on success, or should the masks be cleared? [ ... ] > @@ -3567,6 +3741,7 @@ int phylink_ethtool_ksettings_set(struct phylink *pl, > */ > linkmode_mod_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, config.advertising, > kset->base.autoneg == AUTONEG_ENABLE); > + linkmode_copy(requested_advertising, config.advertising); > > /* If this link is with an SFP, ensure that changes to advertised modes > * also cause the associated interface to be selected such that the > @@ -3614,6 +3789,7 @@ int phylink_ethtool_ksettings_set(struct phylink *pl, > return -EINVAL; > > mutex_lock(&pl->state_mutex); > + phylink_update_user_disabled_advertising(pl, requested_advertising); > pl->link_config.speed = config.speed; > pl->link_config.duplex = config.duplex; > [Severity: Medium] Is pl->advertising still the right reference here when this call also switches the SFP interface? phylink_sfp_select_interface() or phylink_sfp_select_interface_speed() can move the link from, for example, 2500BASE-X to SGMII. Further down, only link_config is updated: if (pl->link_config.interface != config.interface) { ... pl->link_config.interface = config.interface; linkmode_copy(pl->link_config.advertising, config.advertising); } pl->advertising keeps the previous interface's mask A(old), so the new restrictions are computed as A(old) & ~requested. A mode of the new interface that the user left out is not in A(old), so it is never added to pl->user_disabled_advertising. On the next recalculation those modes come back: phylink_sfp_module_start() phylink_sfp_config_optical() phylink_sfp_set_config() link_config.advertising = A(new) & ~user_disabled Later in the series, phylink_update_capabilities() on PCS add/remove has the same effect. For example, run "ethtool -s ethX advertise 1000baseT_Full" on a module that offers 2500BASE-X and SGMII. After a link down/up the port advertises 10/100/1000baseT again. A related point concerns the commit message: The advertising mask holds the full validated advertisement before applying the phylink user restrictions. With a PHY attached, phylink_phy_update_capabilities() copies pl->advertising from phy->advertising. That copy already includes phylib's ethtool restrictions and any phy_speed_down() reduction. The user-disabled mask is not used while a PHY is attached, so this part is mostly a description mismatch. Could the description be adjusted to match? [ ... ] -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261129230558.612526-1-ansuelsmth%40gmail.com