Devicetree
 help / color / mirror / Atom feed
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 v22 07/15] net: phylink: add capabilities helpers and track modified advertising
Date: Wed, 18 Nov 2026 12:42:49 +0000	[thread overview]
Message-ID: <sashiko-outbox-220927@kernel.org> (raw)
In-Reply-To: <20261117123956.11981-8-ansuelsmth@gmail.com>

Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [High] net: phylink: in-band check bypasses SFP in
  phylink_update_capabilities()
- [High] net: phylink: broken pause update in
  phylink_update_mac_pause_capabilities()
- [High] net: phylink: unchecked validation failure in
  phylink_update_capabilities()
- [Medium] net: phylink: stale Autoneg bit saved in
  phylink_ethtool_ksettings_set()
- [Medium] net: phylink: untracked advertising in
  phylink_update_pause_state()
- [Medium] net: phylink: broken multi-interface SFP tracking in
  pl->advertising
- [Medium] net: phylink: phylink_choose_sfp_interface() fails on
  disabled modes
--

commit 8b66b984e920c4acb0054fea1ab1a279ce12371a
Author: Christian Marangi <ansuelsmth@gmail.com>

net: phylink: add capabilities helpers and track modified advertising

This commit adds helpers to recalculate phylink capabilities and tracks
full and user-disabled advertising masks across fixed-link, in-band, PHY,
and SFP modes in preparation for dynamic PCS attach and release.

> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index 88280866c19a2..921c227a5b3c0 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c
[ ... ]
> @@ -2087,6 +2198,8 @@ static void phylink_update_pause_state(struct phylink *pl, int pause_state)
>  	 */
>  	linkmode_set_pause(config->advertising, tx_pause,
>  			   rx_pause);
> +	if (pl->phydev)
> +		linkmode_set_pause(pl->phy_advertising, tx_pause, rx_pause);
>  
>  	manual_changed = (config->pause ^ pause_state) & MLO_PAUSE_AN ||
>  			 (!(pause_state & MLO_PAUSE_AN) &&

[Severity: Medium]
When pl->phydev is NULL, does phylink_update_pause_state() leave
pl->user_disabled_advertising and pl->advertising unupdated?

On in-band or optical SFP links, pause changes made via ethtool -A only
update config->advertising here. Any later call to
phylink_update_capabilities() or phylink_sfp_set_config() recalculates
config->advertising from pl->advertising and
pl->user_disabled_advertising, overwriting the user's pause settings.
Similarly, phylink_set_fixed_link() updates pl->link_config.advertising
without updating pl->advertising.

> @@ -2120,6 +2233,142 @@ 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 modes outside pl->advertising ever be re-enabled once added to
pl->user_disabled_advertising?

In phylink_sfp_config_optical(), phylink_validate() narrows
config.advertising to the single selected interface before
phylink_sfp_set_config() copies it into pl->advertising, and
phylink_ethtool_ksettings_set() never updates pl->advertising when
switching SFP interfaces. Because disabled here is not masked with
~advertising, any mode not in the current interface's pl->advertising
remains permanently stuck in pl->user_disabled_advertising even when
explicitly requested in advertising, and switching SFP interfaces via
ethtool marks the previous interface's modes as disabled.

[ ... ]

> +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;
> +	}
> +
> +	if (pl->cfg_link_an_mode == MLO_AN_INBAND) {
> +		phylink_parse_inband_capabilities(pl, config);
> +		goto exit;
> +	}
> +
> +	/* Revalidate the SFP module modes against every available interface. */
> +	if (pl->sfp_bus && !pl->phydev && config->interface &&
> +	    !phy_interface_empty(pl->sfp_interfaces)) {
> +		__ETHTOOL_DECLARE_LINK_MODE_MASK(supported);
> +
> +		linkmode_copy(supported, pl->sfp_support);
> +		linkmode_copy(config->advertising, pl->sfp_support);
> +		if (!__phylink_validate_mask(pl, NULL, supported, config,
> +					     pl->sfp_interfaces)) {
> +			phylink_sfp_update_capabilities(pl, supported, config,
> +							config->interface);
> +			linkmode_copy(pl->supported, supported);
> +			linkmode_copy(pl->advertising, config->advertising);
> +		}
> +
> +		goto exit;
> +	}

[Severity: High]
Does checking pl->cfg_link_an_mode == MLO_AN_INBAND before pl->sfp_bus
bypass SFP capability recalculation on in-band SFP ports?

Direct MAC-to-SFP links specify managed = "in-band-status" in DT (or set
config->default_an_inband = true), so pl->cfg_link_an_mode is
MLO_AN_INBAND. Calling phylink_update_capabilities() (for example from
phylink_update_mac_pause_capabilities()) runs
phylink_parse_inband_capabilities() and jumps to exit, overwriting the SFP
module's pl->supported and advertising masks with generic MII capabilities
(and failing with -EINVAL on 100BASE-X SFP modules). In addition, when the
SFP block is reached, it validates config->advertising across all
pl->sfp_interfaces via __phylink_validate_mask() without restricting
config->advertising to the active config->interface as
phylink_sfp_config_optical() does.

> +
> +	/* 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 __phylink_validate() fails because config->interface is not in
pl->supported_interfaces?

Before a late-attached PCS is registered in phylink_create() (or after a
PCS is removed), __phylink_validate() returns -EINVAL immediately on the
!test_bit(state->interface, interfaces) check without modifying
pl->supported or config->advertising. Because the return value is ignored
here after linkmode_fill(pl->supported), all three masks remain filled
with all ones. Similarly, on validation failure,
phylink_phy_update_capabilities() returns early leaving stale capabilities
from a removed PCS in pl->supported and phy->advertising,
phylink_parse_inband_capabilities() leaves pl->supported unvalidated and
causes phylink_parse_mode() to fail phylink_create() when an in-band link
uses a late-attached PCS, and phylink_parse_fixedlink_capabilities()
ignores the __phylink_validate() failure.

> @@ -2146,20 +2396,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;
>  
> @@ -2171,6 +2417,9 @@ 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);
>  }

[Severity: High]
When a PHY is attached, does calling phylink_update_capabilities() followed
by phylink_update_pause_state() break PHY pause renegotiation and
permanently clear pause in pl->phy_advertising?

First, phylink_phy_update_capabilities() already updates phy->advertising
with the new pause bits, so when phylink_update_pause_state() subsequently
calls phy_set_asym_pause(), phy->advertising matches oldadv and
phy_start_aneg() is skipped. Second, phylink_update_pause_state() writes
the stripped pause_state (or the initial MLO_PAUSE_AN where MLO_PAUSE_RX
and MLO_PAUSE_TX are both 0) into pl->phy_advertising via
linkmode_set_pause(), permanently losing the PHY's pause advertisement
when MAC pause capabilities are later re-enabled.

[ ... ]

> @@ -3434,7 +3603,15 @@ int phylink_ethtool_ksettings_set(struct phylink *pl,
>  		 *   the presence of a PHY, this should not be changed as that
>  		 *   should be determined from the media side advertisement.
>  		 */
> -		return phy_ethtool_ksettings_set(pl->phydev, &phy_kset);
> +		ret = phy_ethtool_ksettings_set(pl->phydev, &phy_kset);
> +		if (!ret) {
> +			mutex_lock(&pl->state_mutex);
> +			linkmode_copy(pl->phy_advertising,
> +				      phy_kset.link_modes.advertising);
> +			mutex_unlock(&pl->state_mutex);
> +		}
> +
> +		return ret;
>  	}

[Severity: Medium]
Does copying phy_kset.link_modes.advertising into pl->phy_advertising save
a stale ETHTOOL_LINK_MODE_Autoneg_BIT and a MAC-restricted mask?

phy_ethtool_ksettings_set() takes a const struct ethtool_link_ksettings *
and updates ETHTOOL_LINK_MODE_Autoneg_BIT in phydev->advertising from
cmd->base.autoneg without modifying phy_kset.link_modes.advertising, which
was also already masked by pl->supported above. When
phylink_phy_update_capabilities() later copies pl->phy_advertising back to
phy->advertising, it overwrites the PHY's Autoneg bit and loses modes that
were only temporarily unsupported by the MAC/PCS.

[ ... ]

> @@ -4022,19 +4201,34 @@ static void phylink_sfp_detach(void *upstream, struct sfp_bus *bus)
>  }
>  
>  static phy_interface_t phylink_choose_sfp_interface(struct phylink *pl,
> -						    const unsigned long *intf)
> +						    const unsigned long *intf,
> +						    const unsigned long *supported,
> +						    const struct phylink_link_state *state)
>  {
> +	__ETHTOOL_DECLARE_LINK_MODE_MASK(tmp_supported);
> +	struct phylink_link_state tmp_state;
>  	phy_interface_t interface;
>  	size_t i;
>  
> -	interface = PHY_INTERFACE_MODE_NA;
> -	for (i = 0; i < ARRAY_SIZE(phylink_sfp_interface_preference); i++)
> -		if (test_bit(phylink_sfp_interface_preference[i], intf)) {
> -			interface = phylink_sfp_interface_preference[i];
> -			break;
> -		}
> +	for (i = 0; i < ARRAY_SIZE(phylink_sfp_interface_preference); i++) {
> +		interface = phylink_sfp_interface_preference[i];
> +		if (!test_bit(interface, intf))
> +			continue;
>  
> -	return interface;
> +		tmp_state = *state;
> +		tmp_state.interface = interface;
> +		linkmode_copy(tmp_supported, supported);
> +		if (phylink_validate(pl, tmp_supported, &tmp_state))
> +			continue;
> +
> +		/* Skip this preferred interface if user-disabled in advertising */
> +		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;
>  }

[Severity: Medium]
What happens if all link modes supported by a newly inserted optical SFP
module are currently disabled in pl->user_disabled_advertising?

phylink_choose_sfp_interface() skips every interface and returns
PHY_INTERFACE_MODE_NA without a fallback, causing
phylink_sfp_config_optical() to fail module insertion with -EINVAL before
phylink_sfp_set_config() updates pl->supported. The SFP state machine
enters SFP_MOD_ERROR and the user cannot re-enable the module's modes via
ethtool.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117123956.11981-1-ansuelsmth@gmail.com?part=7

  reply	other threads:[~2026-11-18 12:42 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 12:39 [PATCH net-next v22 00/15] net: pcs: Introduce support for fwnode PCS Christian Marangi
2026-11-17 12:39 ` [PATCH net-next v22 01/15] net: phylink: make PCS phylink instance access RCU protected Christian Marangi
2026-11-18 12:42   ` sashiko-bot
2026-11-17 12:39 ` [PATCH net-next v22 02/15] net: phylink: keep and use MAC supported_interfaces in phylink struct Christian Marangi
2026-11-17 12:39 ` [PATCH net-next v22 03/15] net: phylink: introduce internal phylink PCS handling Christian Marangi
2026-11-18 12:42   ` sashiko-bot
2026-11-17 12:39 ` [PATCH net-next v22 04/15] net: pcs: implement Firmware node support for PCS driver Christian Marangi
2026-11-18 12:42   ` sashiko-bot
2026-11-17 12:39 ` [PATCH net-next v22 05/15] net: phylink: save phylink instance fwnode on phylink_create Christian Marangi
2026-11-17 12:39 ` [PATCH net-next v22 06/15] net: phylink: make phylink_validate state locked Christian Marangi
2026-11-17 12:39 ` [PATCH net-next v22 07/15] net: phylink: add capabilities helpers and track modified advertising Christian Marangi
2026-11-18 12:42   ` sashiko-bot [this message]
2026-11-17 12:39 ` [PATCH net-next v22 08/15] net: phylink: support PCS provider release Christian Marangi
2026-11-18 12:42   ` sashiko-bot
2026-11-17 12:39 ` [PATCH net-next v22 09/15] net: phylink: support late PCS provider attach Christian Marangi
2026-11-18 12:42   ` sashiko-bot
2026-11-17 12:39 ` [PATCH net-next v22 10/15] net: Document PCS subsystem Christian Marangi
2026-11-17 12:39 ` [PATCH net-next v22 11/15] MAINTAINERS: add myself as PCS subsystem maintainer Christian Marangi
2026-11-17 12:39 ` [PATCH net-next v22 12/15] net: phylink: add .pcs_link_down PCS OP Christian Marangi
2026-11-17 12:39 ` [PATCH net-next v22 13/15] dt-bindings: net: pcs: Document support for Airoha Ethernet PCS Christian Marangi
2026-11-18 12:42   ` sashiko-bot
2026-11-17 12:39 ` [PATCH net-next v22 14/15] net: pcs: airoha: add PCS driver for Airoha AN7581 SoC Christian Marangi
2026-11-18 12:42   ` sashiko-bot
2026-11-17 12:39 ` [PATCH net-next v22 15/15] net: airoha: add phylink support Christian Marangi
2026-11-17 12:43 ` [PATCH net-next v22 00/15] net: pcs: Introduce support for fwnode PCS netdev-bot+sinfo
2026-11-17 12:47   ` Christian Marangi

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-220927@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox