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 v23 08/15] net: phylink: support PCS provider release
Date: Mon, 30 Nov 2026 23:25:52 +0000	[thread overview]
Message-ID: <sashiko-outbox-242232@kernel.org> (raw)
In-Reply-To: <20261129230558.612526-9-ansuelsmth@gmail.com>

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 <ansuelsmth@gmail.com>

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 *pl, bool restart,
>  		}
>  	}
>  
> +	/* A replacement PCS may require a different autonegotiation mode */
> +	if (!pl->phydev && !phy_interface_empty(pl->sfp_module_interfaces)) {
> +		unsigned int caps = 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 = 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 = true and returns before assigning pl->pcs = pcs,
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 ==
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 phylink *pl,
>  	}
>  
>  	/*
> -	 * 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 != 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 = *config;
>  		__ETHTOOL_DECLARE_LINK_MODE_MASK(supported);
>  
>  		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;
> +		}
>  
>  		/*
>  		 * 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;
> +		}
>  
> -		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_interfaces,
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 = 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);
>  
> +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 == pcs) {
> +		if (pl->old_link_state) {
> +			phylink_link_down(pl);
> +			pl->old_link_state = false;
> +		}
> +		if (pl->cfg_link_an_mode == MLO_AN_INBAND)
> +			timer_delete_sync(&pl->link_poll);
> +
> +		if (pl->pcs_state != PCS_STATE_DOWN)
> +			phylink_pcs_disable(pl->pcs);
> +
> +		if (!pl->phylink_disable_state)
> +			pl->force_major_config = true;
> +
> +		WRITE_ONCE(pl->pcs, NULL);
> +	}
[ ... ]
> @@ -2523,12 +2583,243 @@ static void phylink_parse_supported_interfaces(struct phylink *pl)
>  	}
>  }
>  
> +static bool phylink_pcs_changed(struct phylink *pl)
> +{
> +	lockdep_assert_held(&pl->state_mutex);
> +
> +	/* Defer capability updates until creation finishes */
> +	if (pl->pcs_state == PCS_STATE_INITIALIZING ||
> +	    pl->pcs_state == PCS_STATE_INIT_PENDING) {
> +		pl->pcs_state = 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 = true;
> +		pl->link_failed = 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 != pl->link_config.interface) ||
	    pl->force_major_config) {
		if (cur_link_state) {
			phylink_link_down(pl);
			cur_link_state = false;
		}
		phylink_major_config(pl, false, &link_state);
		pl->link_config.interface = link_state.interface;
		pl->force_major_config = 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 = true and pl->link_failed = true, the first pass 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 = false before the normal resolve pass runs.

> +
> +static int phylink_update_pcs(struct phylink *pl, bool rescan)
> +{
[ ... ]
> +	if (rescan)
> +		ret = (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

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

  reply	other threads:[~2026-11-30 23:25 UTC|newest]

Thread overview: 26+ 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-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-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-29 23:05 ` [PATCH net-next v23 05/15] net: phylink: make phylink_validate state locked Christian Marangi
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
2026-11-29 23:05 ` [PATCH net-next v23 07/15] net: sfp: support deferred module insertion Christian Marangi
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 [this message]
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-29 23:05 ` [PATCH net-next v23 10/15] net: Document PCS subsystem Christian Marangi
2026-11-30 23:25   ` sashiko-bot
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-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-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-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-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-242232@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