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=1796081152; b=aB2158tREokr1ugnkTWOEq8BRy9k/YIyzUgMY+fVxoVRdoDd4MsmJga3ucouXU3+4gE8 XMG+AatUpMosuRyZ+qpRGgg04hEsqzrk8vA06HgCecWieMt3S49zpW8zBPLNYj/4q7WfI kkEkQm6uNvJfCy1nWVKJCilTeqYrQe+FDY/ygODOo39v/MOem3WGF6C/Ucw5wOKUvXCzV JK7GL9hzELHsstu6HDPeW3q9Ze/YQhi3xrKxkORp/kDcNvfkvyUc1jR9GKypm8g2BiDN/ sdeRcL24aoaDgow/lTYux9+rB+3KQ2cJ37dxZzp0Sjz7uXx24A6ujagY+OPCwaFv6Ig== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796081152; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=OT45vD4mfX9u7Bhke02E8sDMMZmmu/naa5S78mTgKdU=; b=3Phbun5N+S9tBqk0i38jaWl6oT2P/9UTFHPWODPHx4JpPrRMPq8kW7SwawwVKSKcpuJu pGreq/9+HntCpFMZXJ0t2bnYWKfsrBizsZtPIL5Z7gHlCNLNpQllrCa+XfUM5R24ETA0G jc8Loblf17Sy+yMX7XqgROWrvGo773nCiE0DzqRUNzU+xSVjQoFTL50DncaaEmj4sE89i pFg8RJqzYUnvJRKMXveCVx5k6FDGf+ae1mdeW/4BhNvQaSJRTtJKE+zT8bQe8m7w7UJm4 Pv067mo9JC15RcFg5Jbto056Tooy184dOm4+nDdnik9SfmTiE7DLOwm8AaU99bHZKjg== 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=dGEJ2nHg; 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 35E12606A320 for ; Mon, 30 Nov 2026 23:25:52 +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=dGEJ2nHg Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B5471F000C1; Mon, 30 Nov 2026 23:25:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796081151; bh=OT45vD4mfX9u7Bhke02E8sDMMZmmu/naa5S78mTgKdU=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=dGEJ2nHgLgS04Q8wDxHE13EUZC+vVIAHhy7phCp8cMdNK228YcoTadF20iuq1XJHv Is/bJM2bd/9Zfgt5Str605VAKaY/yBtNJKbSeVGqrR/odMXMfmQSp4BR01lSaZvoCq GWpUjkMnpUnZ4Z0lLza5aEROmBhh9ERv/rsB4cRYrJ++lCmQtRIig9bVTuyT4Oqfcu XNkIiYEHWycxmZDXH4JvTrFmiR5U7WkqyR1clYCpORctrAqHonHY+MFtmQMYFzYNzx /sIs6qFBrcC5+NxxlPBj06oa5aMYw00WdHmWyhNIoVlUby8EZql+n5kwRlp+ZSWxX6 CuUKAH7K7xgXg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH net-next v23 06/15] net: phylink: add capabilities helpers and track modified advertising 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-7-ansuelsmth@gmail.com> References: <20261129230558.612526-1-ansuelsmth@gmail.com> <20261129230558.612526-7-ansuelsmth@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 23:25:51 +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 5 potential issues to consider: - [High] net: phylink: unchecked validation failure in phylink_update_capabilities() - [Medium] net: phylink: broken pause update in phylink_update_mac_pause_capabilities() - [Medium] net: phylink: broken multi-interface SFP tracking in pl->advertising - [Medium] net: phylink: stale SFP caps after phylink_sfp_module_start() failure - [Low] net: phylink: phylink_set_fixed_link() leaves pl->advertising stale -- commit 06bd90a17fedb9411d5656094806f695412ef9b6 Author: Christian Marangi net: phylink: add capabilities helpers and track modified advertising This commit adds helpers to recalculate phylink capabilities across fixed-link, in-band, PHY, and SFP modes, and introduces masks in struct phylink to track the full validated advertisement and user-disabled advertising modes. > 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 phy= link *pl, int pause_state) > } > } > =20 > +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); > +} [ ... ] > +static int phylink_phy_update_capabilities(struct phylink *pl, struct ph= y_device *phy, > + phy_interface_t interface) > +{ > + __ETHTOOL_DECLARE_LINK_MODE_MASK(supported); > + struct phylink_link_state config; > + int ret; > + > + lockdep_assert_held(&pl->phydev_mutex); > + lockdep_assert_held(&phy->lock); > + lockdep_assert_held(&pl->state_mutex); > + > + memset(&config, 0, sizeof(config)); > + linkmode_copy(supported, phy->supported); > + /* Use the advertisement phylib is currently applying */ > + linkmode_copy(config.advertising, phy->advertising); > + config.interface =3D interface; > + > + ret =3D __phylink_validate_phy(pl, phy, supported, &config); > + if (ret) { > + phylink_warn(pl, "validation of %s with support %*pb and advertisement= %*pb failed: %pe\n", > + phy_modes(config.interface), > + __ETHTOOL_LINK_MODE_MASK_NBITS, phy->supported, > + __ETHTOOL_LINK_MODE_MASK_NBITS, config.advertising, > + ERR_PTR(ret)); > + return ret; > + } > + > + linkmode_copy(pl->supported, supported); > + linkmode_copy(pl->link_config.advertising, config.advertising); > + linkmode_copy(pl->advertising, pl->link_config.advertising); > + > + return 0; > +} > + > +static void phylink_update_capabilities(struct phylink *pl, > + struct phylink_link_state *config) > +{ > + if (pl->phydev) { > + lockdep_assert_held(&pl->phydev_mutex); > + lockdep_assert_held(&pl->phydev->lock); > + } > + lockdep_assert_held(&pl->state_mutex); > + > + if (pl->phydev) { > + phylink_phy_update_capabilities(pl, pl->phydev, > + pl->phy_state.interface); > + return; > + } > + > + if (pl->cfg_link_an_mode =3D=3D MLO_AN_FIXED) { > + phylink_parse_fixedlink_capabilities(pl, config); > + goto exit; > + } [Severity: Low] Does phylink_set_fixed_link() also need to update pl->advertising, and can phylink_parse_fixedlink_capabilities() handle fixed links faster than 10G? phylink_set_fixed_link() sets pl->cfg_link_an_mode =3D MLO_AN_FIXED and updates pl->link_config.advertising against the full MAC-validated pl->supported mask (which includes 25G/40G modes for drivers such as txgbe), but leaves pl->advertising untouched. If phylink_update_capabilities() runs later, phylink_parse_fixedlink_capabilities() resets pl->supported via phylink_fill_fixedlink_supported(), which only populates 10baseT through 10000baseT and causes phy_caps_lookup() to fail and strip all speed modes on 25G/40G fixed links. > + > + /* > + * 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 !=3D PHY_INTERFACE_MODE_NA && > + !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); > + > + phy_interface_and(pl->sfp_interfaces, pl->sfp_module_interfaces, > + pl->supported_interfaces); > + 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); > + > + /* > + * Keep alternate modes available for interface selection, but > + * only advertise modes that the current interface can use. > + */ > + linkmode_copy(active_supported, pl->sfp_support); > + if (__phylink_validate(pl, active_supported, &sfp_config)) > + return; > + > + linkmode_copy(pl->supported, supported); > + linkmode_copy(pl->advertising, sfp_config.advertising); > + goto exit; > + } > + > + if (pl->cfg_link_an_mode =3D=3D MLO_AN_INBAND) { > + phylink_parse_inband_capabilities(pl, config); > + goto exit; > + } > + > + /* 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] What happens to pl->supported, pl->advertising, and config->advertising when validation fails because a PCS has not attached yet or has just been removed? When state->interface is not in pl->supported_interfaces, __phylink_validate() returns -EINVAL immediately without clearing or masking supported or state->advertising. In the generic fallback path above, linkmode_fill(pl->supported) and linkmode_copy(config->advertising, pl->supported) run in-place before __phylink_validate(), so an ignored validation failure leaves pl->supported, pl->advertising, and config->advertising with every linkmode bit set to 1. The mode-specific helpers have similar issues when the required PCS is absent: - phylink_parse_inband_capabilities() populates pl->supported and config->advertising in-place before __phylink_validate(); on failure, phylink_parse_mode() aborts phylink_create() with -EINVAL (preventing late PCS attach on MLO_AN_INBAND links), while phylink_update_capabilities() ignores the error and leaves pl->supported unvalidated and pl->advertising stale. - phylink_parse_fixedlink_capabilities() populates pl->supported and config->advertising in-place and ignores __phylink_validate() errors. - phylink_phy_update_capabilities() and the SFP path return early on validation failure without clearing stale capabilities in pl->supported, pl->advertising, or pl->link_config.advertising. > @@ -2262,20 +2464,16 @@ void phylink_update_mac_pause_capabilities(struct= phylink *pl, unsigned long mac > if (old_pause =3D=3D mac_pause) > return; > =20 > + mutex_lock(&pl->phydev_mutex); > + phydev =3D pl->phydev; > + if (phydev) > + mutex_lock(&phydev->lock); > mutex_lock(&pl->state_mutex); > =20 > pl->config->mac_capabilities &=3D ~(MAC_SYM_PAUSE | MAC_ASYM_PAUSE); > pl->config->mac_capabilities |=3D mac_pause; > =20 > - phylink_set(pl->supported, Pause); > - phylink_set(pl->supported, Asym_Pause); > - > - if (pl->phydev) > - linkmode_and(pl->supported, pl->supported, pl->phydev->supported); > - else if (pl->sfp_bus) > - linkmode_and(pl->supported, pl->supported, pl->sfp_support); > - > - __phylink_validate(pl, pl->supported, config); > + phylink_update_capabilities(pl, config); > =20 > pause_state =3D config->pause; > =20 > @@ -2287,8 +2485,12 @@ void phylink_update_mac_pause_capabilities(struct = phylink *pl, unsigned long mac > } > =20 > mutex_unlock(&pl->state_mutex); > + if (phydev) > + mutex_unlock(&phydev->lock); > + mutex_unlock(&pl->phydev_mutex); > =20 > - phylink_update_pause_state(pl, pause_state); > + /* Let phylib detect the change against the current PHY advertisement */ > + phylink_update_pause_state(pl, pause_state, false); > } [Severity: Medium] Can phylink_update_mac_pause_capabilities() ever re-enable pause advertisement after it has been disabled (for instance, when a driver like r8169 disables MAC pause for a large MTU and then restores it when the MTU is lowered)? Initially, or after phylink_update_mac_pause_capabilities(pl, 0) clears MLO_PAUSE_RX and MLO_PAUSE_TX, config->pause has neither MLO_PAUSE_RX nor MLO_PAUSE_TX set. When MAC pause capabilities are re-enabled: - On non-PHY links, phylink_update_capabilities() restores Pause and Asym_Pause in config->advertising, but phylink_update_pause_state(pl, pause_state, false) then runs linkmode_set_pause(config->advertising, false, false) because MLO_PAUSE_TX and MLO_PAUSE_RX are 0 in pause_state, immediately clearing both bits again. - On PHY links, phylink_phy_update_capabilities() seeds config.advertising from phy->advertising (where Pause and Asym_Pause were cleared when MAC pause was disabled), and phylink_update_pause_state() calls phy_set_asym_pause(pl->phydev, false, false), leaving pause advertisement disabled on the PHY. [ ... ] > @@ -3614,6 +3789,7 @@ int phylink_ethtool_ksettings_set(struct phylink *p= l, > return -EINVAL; > =20 > mutex_lock(&pl->state_mutex); > + phylink_update_user_disabled_advertising(pl, requested_advertising); > pl->link_config.speed =3D config.speed; > pl->link_config.duplex =3D config.duplex; > =20 [Severity: Medium] Does tracking user-disabled modes against a single interface's pl->advertising work on multi-interface optical SFPs (e.g. 1000BASE-X/2500BASE-X)? In phylink_sfp_config_optical() and phylink_update_capabilities(), pl->advertising is populated after per-interface validation for the active config.interface, so modes belonging to alternate interfaces in pl->sfp_interfaces are stripped from pl->advertising. When an ethtool advertisement change in phylink_ethtool_ksettings_set() switches config.interface, pl->link_config.interface and pl->link_config.advertising are updated, but pl->advertising is never updated for the new interface. Even if pl->advertising is updated for the new interface, phylink_update_user_disabled_advertising() preserves every bit in pl->user_disabled_advertising that is absent from pl->advertising without clearing bits that the user just enabled in advertising. Once an SFP switches from 2500BASE-X to 1000BASE-X because the user disabled 2500baseX_Full, 2500baseX_Full is no longer in pl->advertising, so a later ethtool request to re-enable 2500baseX_Full cannot clear it from pl->user_disabled_advertising. [ ... ] > @@ -4297,10 +4482,12 @@ static int phylink_sfp_module_insert(void *upstre= am, > { > const struct sfp_module_caps *caps; > struct phylink *pl =3D upstream; > + int ret; > =20 > ASSERT_RTNL(); > =20 > caps =3D sfp_get_module_caps(pl->sfp_bus); > + phy_interface_copy(pl->sfp_module_interfaces, caps->interfaces); > phy_interface_copy(pl->sfp_interfaces, caps->interfaces); > linkmode_copy(pl->sfp_support, caps->link_modes); > pl->sfp_may_have_phy =3D caps->may_have_phy; > @@ -4310,14 +4497,29 @@ static int phylink_sfp_module_insert(void *upstre= am, > if (pl->sfp_may_have_phy) > return 0; > =20 > - return phylink_sfp_config_optical(pl); > + ret =3D phylink_sfp_config_optical(pl); > + if (ret) { > + /* Only accepted modules get a removal callback */ > + mutex_lock(&pl->state_mutex); > + phy_interface_zero(pl->sfp_interfaces); > + phy_interface_zero(pl->sfp_module_interfaces); > + linkmode_zero(pl->sfp_support); > + mutex_unlock(&pl->state_mutex); > + } > + > + return ret; > } [Severity: Medium] When pl->sfp_may_have_phy is true, phylink_sfp_module_insert() caches pl->sfp_module_interfaces and pl->sfp_support and defers phylink_sfp_config_optical() to phylink_sfp_module_start(). If no PHY is found and phylink_sfp_config_optical() fails in phylink_sfp_module_start(), can those cached masks remain populated without a removal callback? drivers/net/phy/phylink.c:phylink_sfp_module_start() { ... ret =3D phylink_sfp_config_optical(pl); if (ret) goto del_mod_port; return 0; del_mod_port: phylink_del_sfp_mod_port(pl); return ret; } When sfp_module_start() fails, the SFP state machine enters SFP_S_FAIL without calling phylink_sfp_module_remove(), so any subsequent phylink_update_capabilities() call sees a non-empty pl->sfp_module_interfaces and applies the failed module's capabilities. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261129230558.6125= 26-1-ansuelsmth@gmail.com?part=3D6