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 09/15] net: phylink: support late PCS provider attach
Date: Wed, 18 Nov 2026 12:42:51 +0000 [thread overview]
Message-ID: <sashiko-outbox-220929@kernel.org> (raw)
In-Reply-To: <20261117123956.11981-10-ansuelsmth@gmail.com>
Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [High] net: phylink: pcs_provider_notify() misses PCS reconfig on late
attach
- [High] net: phylink: unreachable SFP revalidation in
phylink_update_capabilities()
- [High] net: phylink: broken supported_interfaces refresh in
pcs_provider_notify()
- [Medium] net: phylink: phylink_resolve() passes wrong state to
phylink_major_config()
- [Medium] net: phylink: missing SFP interface selection in
phylink_update_capabilities()
- [Medium] net: phylink: missing PHY aneg reconfig in
pcs_provider_notify()
- [Low] net: phylink: unlocked mode and fixed-link parse in
phylink_create()
--
commit df5385a2562b3f337c319241b34f5895e1000a4c
Author: Christian Marangi <ansuelsmth@gmail.com>
net: phylink: support late PCS provider attach
This commit adds FWNODE_PCS_PROVIDER_ADD notifier handling and SFP
interface tracking so phylink can attach PCS providers registered after
phylink_create() and revalidate capabilities.
> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index 094a15f3dbcd0..8768d8220a134 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c
[ ... ]
> @@ -2358,11 +2383,24 @@ static void phylink_update_capabilities(struct phylink *pl,
> goto exit;
> }
>
> - /* Revalidate the SFP module modes against every available interface. */
> + /* Revalidate SFP modes against interfaces currently supported by the
> + * MAC and PCS. Keep the module's interface list intact so a later PCS
> + * addition can make an interface usable again.
> + */
> if (pl->sfp_bus && !pl->phydev && config->interface &&
> - !phy_interface_empty(pl->sfp_interfaces)) {
> + !phy_interface_empty(pl->sfp_module_interfaces)) {
[Severity: High]
Is this SFP revalidation block reachable on standard SFP ports configured
with managed = "in-band-status" or default_an_inband?
Just above this hunk, phylink_update_capabilities() checks
pl->cfg_link_an_mode == MLO_AN_INBAND and jumps to exit:
drivers/net/phy/phylink.c:phylink_update_capabilities() {
...
if (pl->cfg_link_an_mode == MLO_AN_INBAND) {
phylink_parse_inband_capabilities(pl, config);
goto exit;
}
...
}
When an SFP module is inserted on an in-band port, pl->cfg_link_an_mode
remains MLO_AN_INBAND. As a result, pcs_provider_notify() runs
phylink_parse_inband_capabilities() instead of this SFP block, leaving
pl->sfp_interfaces stale and overwriting pl->supported and
pl->advertising with generic in-band MII link modes instead of filtering
against pl->sfp_module_interfaces and pl->sfp_support.
> __ETHTOOL_DECLARE_LINK_MODE_MASK(supported);
>
> + phy_interface_and(pl->sfp_interfaces,
> + pl->sfp_module_interfaces,
> + pl->supported_interfaces);
> + if (phy_interface_empty(pl->sfp_interfaces)) {
> + linkmode_zero(pl->supported);
> + linkmode_zero(pl->advertising);
> + linkmode_zero(config->advertising);
> + goto exit;
> + }
> +
> linkmode_copy(supported, pl->sfp_support);
> linkmode_copy(config->advertising, pl->sfp_support);
> if (!__phylink_validate_mask(pl, NULL, supported, config,
[Severity: Medium]
When pl->sfp_interfaces changes here, does phylink_update_capabilities()
also need to re-select config->interface via phylink_choose_sfp_interface()
and restrict config->advertising to that single interface with
__phylink_validate()?
Without re-selecting config->interface and validating against it (as
phylink_sfp_config_optical() does), __phylink_validate_mask() leaves link
modes from all interfaces in pl->sfp_interfaces advertised in
pl->advertising, and if a PCS removal drops the active config->interface
while another interface in pl->sfp_interfaces remains usable,
config->interface stays set to the removed mode.
In addition, if an optical SFP module is inserted before its PCS provider
probes and pl->supported_interfaces has no overlap with
pl->sfp_module_interfaces yet, phylink_sfp_config_optical() returns
-EINVAL before setting pl->link_config.interface (putting the SFP state
machine into SFP_MOD_ERROR with config->interface == PHY_INTERFACE_MODE_NA),
so this config->interface check will skip the SFP module when the PCS
provider later attaches.
> @@ -2494,6 +2532,7 @@ static int pcs_provider_notify(struct notifier_block *self,
> struct phylink_pcs *pcs, *tmp;
> struct phy_device *phydev;
> bool resolve = false;
> + int count, i;
>
> rtnl_lock();
> mutex_lock(&pl->phydev_mutex);
> @@ -2506,16 +2545,44 @@ static int pcs_provider_notify(struct notifier_block *self,
> if (pl->pcs_state == PCS_STATE_DETACHING)
> goto exit;
>
> - /*
> - * Loop all the PCS for phylink instance and check if
> - * this notification is relevant for some of them.
> - */
> - list_for_each_entry_safe(pcs, tmp, &pl->pcs_list, list) {
> - if (!fwnode_pcs_matches_provider(pp, pl->fwnode, pcs))
> - continue;
> + switch (val) {
> + case FWNODE_PCS_PROVIDER_ADD:
> + count = fwnode_phylink_pcs_count(pl->fwnode);
> + for (i = 0; i < count; i++) {
> + pcs = fwnode_pcs_get_from_provider(pp, pl->fwnode, i);
> + if (IS_ERR_OR_NULL(pcs))
> + continue;
> +
> + /* Trigger a resolve only if a PCS is actually added */
> + if (phylink_add_pcs(pl, pcs))
> + resolve = true;
> + }
> +
> + /*
> + * Force an interface reconfig if major config failed.
> + * Configure link_failed to retrigger a resolve a
> + * second time to reevaluate AN mode with the new
> + * PCS if selected.
> + */
> + if (resolve && pl->major_config_failed) {
> + pl->force_major_config = true;
> + pl->link_failed = true;
> + }
[Severity: High]
Can gating pl->force_major_config and pl->link_failed solely on
pl->major_config_failed miss reattaching the PCS after a provider removal
and re-addition?
When an active PCS is removed, phylink_del_pcs() sets pl->pcs = NULL, but
pl->major_config_failed is only set later when the asynchronous
pl->resolve work item runs phylink_major_config(). If
pl->phylink_disable_state is non-zero when FWNODE_PCS_PROVIDER_DEL fires
(for example, PHYLINK_DISABLE_LINK on an SFP cage with no signal),
phylink_del_pcs() does not set pl->force_major_config and
phylink_run_resolve() does not run pl->resolve, so pl->major_config_failed
remains false; when the PCS provider is re-added and optical signal later
returns, phylink_resolve() never runs phylink_major_config() and pl->pcs
stays NULL. Likewise, if FWNODE_PCS_PROVIDER_ADD runs before the queued
pl->resolve work from FWNODE_PCS_PROVIDER_DEL has executed,
pl->major_config_failed is still false, so pl->link_failed is not set and
phylink_resolve() does not retrigger a second pass after attaching
pl->pcs in phylink_major_config().
[Severity: Medium]
When pl->major_config_failed is true in MLO_AN_PHY or MLO_AN_FIXED mode,
does setting both pl->force_major_config = true and pl->link_failed = true
cause phylink_resolve() to run phylink_major_config() with the wrong
link_state?
In phylink_resolve(), the pl->link_failed branch runs before the
MLO_AN_FIXED and MLO_AN_PHY branches and copies link_state from
pl->link_config:
drivers/net/phy/phylink.c:phylink_resolve() {
...
} else if (pl->link_failed) {
link_state = pl->link_config;
link_state.link = false;
retrigger = true;
} else if (pl->act_link_an_mode == MLO_AN_FIXED) {
phylink_get_fixed_state(pl, &link_state);
mac_config = link_state.link;
} else if (pl->act_link_an_mode == MLO_AN_PHY) {
link_state = pl->phy_state;
mac_config = link_state.link;
}
...
if ((mac_config && link_state.interface != pl->link_config.interface) ||
pl->force_major_config) {
...
phylink_major_config(pl, false, &link_state);
pl->link_config.interface = link_state.interface;
pl->force_major_config = false;
}
...
}
In MLO_AN_PHY mode, the PHY's rate_matching, pause, and current interface
live in pl->phy_state, whereas pl->link_config has rate_matching =
RATE_MATCH_NONE. Because the first resolve pass consumes
pl->force_major_config while link_state holds pl->link_config, the
retriggered second pass will not re-run phylink_major_config() if the
interface matches or the PHY link is still down.
> +
> + break;
> + case FWNODE_PCS_PROVIDER_DEL:
> + /*
> + * Loop all the PCS for phylink instance and check if
> + * this notification is relevant for some of them.
> + */
> + list_for_each_entry_safe(pcs, tmp, &pl->pcs_list, list) {
> + if (!fwnode_pcs_matches_provider(pp, pl->fwnode, pcs))
> + continue;
>
> - phylink_del_pcs(pl, pcs);
> - resolve = true;
> + phylink_del_pcs(pl, pcs);
> + resolve = true;
> + }
> + break;
> }
>
> /* Exit early if nothing has changed */
[Severity: High]
right below this hunk, pcs_provider_notify() refreshes
pl->supported_interfaces and revalidates capabilities:
drivers/net/phy/phylink.c:pcs_provider_notify() {
...
/* Refresh supported interfaces */
phy_interface_copy(pl->supported_interfaces,
pl->config->supported_interfaces);
list_for_each_entry(pcs, &pl->pcs_list, list)
phy_interface_or(pl->supported_interfaces,
pl->supported_interfaces,
pcs->supported_interfaces);
/* Recalculate capabilities */
phylink_update_capabilities(pl, &pl->link_config);
...
}
How is pl->supported_interfaces expected to change when a PCS is added or
removed if pl->config->supported_interfaces is copied unconditionally
without stripping unavailable pl->config->pcs_interfaces?
When a MAC driver includes PCS-backed modes in
config->supported_interfaces (which phylink_create() requires to be
non-empty even when all MAC modes need a PCS, as in airoha_setup_phylink()
and Documentation/networking/pcs.rst), pl->supported_interfaces retains
every mode in config->supported_interfaces even when pl->pcs_list is
empty, and phylink_validate_mac_and_pcs() does not fail when no matching
PCS is present in pl->pcs_list. Conversely, if a MAC driver omits
config->pcs_interfaces from config->supported_interfaces until a PCS
attaches, phylink_parse_mode() in phylink_create() and
phylink_bringup_phy() fail validation with -EINVAL whenever the PCS
provider probes late.
[Severity: Medium]
Also in pcs_provider_notify(), when pl->phydev is attached,
phylink_update_capabilities() -> phylink_phy_update_capabilities() updates
phy->advertising in memory, but nothing calls _phy_start_aneg() or
phy_config_aneg(). Won't the PHY hardware keep advertising the stale link
modes after a PCS provider is added or removed?
> @@ -2681,10 +2748,6 @@ struct phylink *phylink_create(struct phylink_config *config,
>
> mutex_lock(&pl->state_mutex);
>
> - /* Link available PCS to phylink */
> - list_for_each_entry(pcs, &pl->pcs_list, list)
> - rcu_assign_pointer(pcs->phylink, pl);
> -
> phy_interface_copy(pl->supported_interfaces,
> pl->config->supported_interfaces);
[Severity: Low]
In phylink_create(), register_fwnode_pcs_notifier() is called before
pl->state_mutex is released and before phylink_parse_mode() and
phylink_parse_fixedlink() run unlocked:
drivers/net/phy/phylink.c:phylink_create() {
...
phylink_update_capabilities(pl, &pl->link_config);
mutex_unlock(&pl->state_mutex);
ret = phylink_parse_mode(pl, fwnode);
if (ret < 0)
goto unregister_pcs_notify;
if (pl->cfg_link_an_mode == MLO_AN_FIXED) {
ret = phylink_parse_fixedlink(pl, fwnode);
...
}
With FWNODE_PCS_PROVIDER_ADD now firing pcs_provider_notify() when a PCS
provider registers on another CPU, can pcs_provider_notify() race with
phylink_parse_mode() and phylink_parse_fixedlink()?
CPU0 CPU1
phylink_create()
register_fwnode_pcs_notifier()
...
phylink_parse_mode()
pl->cfg_link_an_mode = MLO_AN_FIXED;
phylink_parse_fixedlink()
pl->link_config.duplex = DUPLEX_HALF;
fwnode_pcs_add_provider()
pcs_provider_notify()
mutex_lock(&pl->state_mutex);
phylink_update_capabilities()
phylink_parse_fixedlink_capabilities()
/* reads DUPLEX_HALF and
* modifies lp_advertising */
if (full-duplex)
pl->link_config.duplex = DUPLEX_FULL;
__set_bit(..., lp_advertising); <-- data race
Holding pl->state_mutex across phylink_parse_mode() and
phylink_parse_fixedlink(), or registering the notifier after initial
parsing completes, would avoid this race.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117123956.11981-1-ansuelsmth@gmail.com?part=9
next prev parent 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
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 [this message]
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-220929@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.