From: sashiko-bot@kernel.org
To: "Christian Marangi" <ansuelsmth@gmail.com>, devicetree@vger.kernel.org
Cc: robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH net-next v23 06/15] net: phylink: add capabilities helpers and track modified advertising
Date: Mon, 30 Nov 2026 23:25:51 +0000 [thread overview]
Message-ID: <sashiko-outbox-242230@kernel.org> (raw)
In-Reply-To: <20261129230558.612526-7-ansuelsmth@gmail.com>
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 <ansuelsmth@gmail.com>
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 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);
> +}
[ ... ]
> +static int phylink_phy_update_capabilities(struct phylink *pl, struct phy_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 = interface;
> +
> + ret = __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 == 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 = 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 != PHY_INTERFACE_MODE_NA &&
> + !phy_interface_empty(pl->sfp_module_interfaces)) {
> + __ETHTOOL_DECLARE_LINK_MODE_MASK(active_supported);
> + struct phylink_link_state sfp_config = *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 == 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 == mac_pause)
> return;
>
> + mutex_lock(&pl->phydev_mutex);
> + phydev = pl->phydev;
> + if (phydev)
> + mutex_lock(&phydev->lock);
> mutex_lock(&pl->state_mutex);
>
> pl->config->mac_capabilities &= ~(MAC_SYM_PAUSE | MAC_ASYM_PAUSE);
> pl->config->mac_capabilities |= mac_pause;
>
> - 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);
>
> pause_state = config->pause;
>
> @@ -2287,8 +2485,12 @@ void phylink_update_mac_pause_capabilities(struct phylink *pl, unsigned long mac
> }
>
> mutex_unlock(&pl->state_mutex);
> + if (phydev)
> + mutex_unlock(&phydev->lock);
> + mutex_unlock(&pl->phydev_mutex);
>
> - 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 *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]
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 *upstream,
> {
> const struct sfp_module_caps *caps;
> struct phylink *pl = upstream;
> + int ret;
>
> ASSERT_RTNL();
>
> caps = 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 = caps->may_have_phy;
> @@ -4310,14 +4497,29 @@ static int phylink_sfp_module_insert(void *upstream,
> if (pl->sfp_may_have_phy)
> return 0;
>
> - return phylink_sfp_config_optical(pl);
> + ret = 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 = 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.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261129230558.612526-1-ansuelsmth@gmail.com?part=6
next prev parent reply other threads:[~2026-11-30 23:25 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 23:05 [PATCH net-next v23 00/15] net: pcs: Introduce support for fwnode PCS Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 01/15] net: phylink: make PCS phylink instance access RCU protected Christian Marangi
2026-11-30 23:47 ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 02/15] net: phylink: keep and use MAC supported_interfaces in phylink struct Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 03/15] net: phylink: introduce internal phylink PCS handling Christian Marangi
2026-11-30 23:25 ` sashiko-bot
2026-11-30 23:47 ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 04/15] net: pcs: implement Firmware node support for PCS driver Christian Marangi
2026-11-30 23:25 ` sashiko-bot
2026-11-30 23:47 ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 05/15] net: phylink: make phylink_validate state locked Christian Marangi
2026-11-30 23:47 ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 06/15] net: phylink: add capabilities helpers and track modified advertising Christian Marangi
2026-11-30 23:25 ` sashiko-bot [this message]
2026-11-30 23:47 ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 07/15] net: sfp: support deferred module insertion Christian Marangi
2026-11-30 23:47 ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 08/15] net: phylink: support PCS provider release Christian Marangi
2026-11-30 23:25 ` sashiko-bot
2026-11-30 23:47 ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 09/15] net: phylink: support late PCS provider attach Christian Marangi
2026-11-30 23:25 ` sashiko-bot
2026-11-30 23:47 ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 10/15] net: Document PCS subsystem Christian Marangi
2026-11-30 23:25 ` sashiko-bot
2026-11-30 23:47 ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 11/15] MAINTAINERS: add myself as PCS subsystem maintainer Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 12/15] net: phylink: add .pcs_link_down PCS OP Christian Marangi
2026-11-30 23:47 ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 13/15] dt-bindings: net: pcs: Document support for Airoha Ethernet PCS Christian Marangi
2026-11-30 23:25 ` sashiko-bot
2026-11-30 23:47 ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 14/15] net: pcs: airoha: add PCS driver for Airoha AN7581 SoC Christian Marangi
2026-11-30 23:25 ` sashiko-bot
2026-11-30 23:47 ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 15/15] net: airoha: add phylink support Christian Marangi
2026-11-30 23:25 ` sashiko-bot
2026-11-30 23:48 ` netdev-bot+sashiko
2026-11-29 23:09 ` [PATCH net-next v23 00/15] net: pcs: Introduce support for fwnode PCS netdev-bot+sinfo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-242230@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=ansuelsmth@gmail.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.