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 09/15] net: phylink: support late PCS provider attach
Date: Mon, 30 Nov 2026 23:25:53 +0000 [thread overview]
Message-ID: <sashiko-outbox-242233@kernel.org> (raw)
In-Reply-To: <20261129230558.612526-10-ansuelsmth@gmail.com>
Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [High] net: phylink: phylink_create() fails for in-band links with
late PCS
- [High] net: phylink: phylink_parse_supported_interfaces() keeps
unavailable PCS modes
- [Medium] net: phylink: stale sfp_cage_port capabilities after late PCS
attach
- [Medium] net: phylink: phylink_sfp_module_insert() defers when all PCS
attached
- [Medium] net: phylink: stale supported_interfaces during
phylink_create() race
- [Medium] net: phylink: phylink_resolve() passes wrong state to
phylink_major_config()
--
commit 0fe95ceaab889b7312803eee82036e14adbe5fe1
Author: Christian Marangi <ansuelsmth@gmail.com>
net: phylink: support late PCS provider attach
This commit adds FWNODE_PCS_PROVIDER_ADD notifications to attach PCS
providers that register after phylink_create() and retries deferred
optical SFP module insertions when a PCS becomes available.
> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index 6dde0eae0e73a..3471ba8d5ba6f 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c
> @@ -2604,6 +2604,21 @@ static bool phylink_pcs_changed(struct phylink *pl)
> return true;
> }
[Severity: Medium]
When phylink_pcs_changed() sets both pl->force_major_config and
pl->link_failed on a running instance, does phylink_resolve() pass the
wrong link state to phylink_major_config()?
In the first pass of phylink_resolve(), the pl->link_failed branch runs
before the MLO_AN_FIXED and MLO_AN_PHY branches:
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) {
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;
}
}
Because pl->force_major_config is consumed and cleared in that first pass
while link_state is a copy of pl->link_config, phylink_major_config() is
called with pl->link_config instead of pl->phy_state (which holds the
PHY's interface, pause, and rate_matching settings in MLO_AN_PHY mode) or
phylink_get_fixed_state() (in MLO_AN_FIXED mode). If the PHY link is down
or its interface already matches pl->link_config.interface, the
retriggered second pass of phylink_resolve() will not run
phylink_major_config() again.
> +static void phylink_sfp_retry_module(struct phylink *pl)
> +{
> + struct sfp_bus *bus;
> +
> + ASSERT_RTNL();
> +
> + if (!pl->netdev)
> + return;
> +
> + /* The SFP callbacks publish the attached bus under RTNL */
> + bus = pl->netdev->sfp_bus;
> + if (bus && bus == pl->sfp_bus)
> + sfp_upstream_retry_module(bus);
> +}
> +
> static int phylink_update_pcs(struct phylink *pl, bool rescan)
> {
> struct phylink_config *config = pl->config;
> @@ -2613,6 +2628,7 @@ static int phylink_update_pcs(struct phylink *pl, bool rescan)
> unsigned int num_pcs, i;
> bool removed = false;
> bool added = false;
> + bool resolve;
> int ret;
>
> lockdep_assert_held(&pl->pcs_list_mutex);
> @@ -2628,7 +2644,9 @@ static int phylink_update_pcs(struct phylink *pl, bool rescan)
> return ret;
> }
>
> - if (rescan) {
> + /* An add notification can fill the PCS list before the initial update */
> + resolve = rescan || !list_empty(&pl->pcs_list);
> + if (resolve) {
> rtnl_lock();
> mutex_lock(&pl->phydev_mutex);
> phydev = pl->phydev;
> @@ -2672,10 +2690,12 @@ static int phylink_update_pcs(struct phylink *pl, bool rescan)
> }
>
> mutex_unlock(&pl->state_mutex);
> - if (rescan) {
> + if (resolve) {
> if (phydev)
> mutex_unlock(&phydev->lock);
> mutex_unlock(&pl->phydev_mutex);
> + if (rescan && added && ret > 0)
> + phylink_sfp_retry_module(pl);
> rtnl_unlock();
> }
[Severity: High]
Does phylink_create() still fail with -EINVAL on MLO_AN_INBAND links when
the initial pl->link_config.interface requires a PCS provider that attaches
late?
During phylink_create(), phylink_update_pcs(pl, false) runs before the
late PCS provider is registered, so pl->link_config.interface is not yet
in pl->supported_interfaces. phylink_create() then calls
phylink_parse_mode() -> phylink_parse_inband_capabilities() ->
__phylink_validate(), which rejects state->interface with -EINVAL because
it is not set in pl->supported_interfaces, aborting phylink_create()
before phylink_register_sfp() or any late FWNODE_PCS_PROVIDER_ADD event
can run.
Also, in phylink_update_capabilities(), the fallback path fills
pl->supported and config->advertising with all ones before calling
__phylink_validate() and unconditionally copies config->advertising into
pl->advertising, leaving both masks filled with all ones when
__phylink_validate() returns -EINVAL early for a missing PCS interface.
[ ... ]
> @@ -2787,6 +2810,7 @@ static int pcs_provider_notify(struct notifier_block *self,
> static void phylink_pcs_finish_init(struct phylink *pl)
> {
> struct phy_device *phy;
> + bool pending;
>
> /* SFP module callbacks can run once the upstream is registered */
> if (pl->sfp_bus)
> @@ -2797,7 +2821,8 @@ static void phylink_pcs_finish_init(struct phylink *pl)
> mutex_lock(&phy->lock);
> mutex_lock(&pl->state_mutex);
>
> - if (pl->pcs_state == PCS_STATE_INIT_PENDING) {
> + pending = pl->pcs_state == PCS_STATE_INIT_PENDING;
> + if (pending) {
> phylink_parse_supported_interfaces(pl);
> phylink_update_capabilities(pl, &pl->link_config);
> }
[Severity: Medium]
Can pl->supported_interfaces become stale relative to pl->pcs_list if a
PCS notification arrives during phylink_create()?
CPU0 CPU1
phylink_create()
register_fwnode_pcs_notifier()
phylink_update_pcs(pl, false)
mutex_unlock(&pl->pcs_list_mutex)
pcs_provider_notify()
phylink_update_pcs(pl, true)
/* updates pl->pcs_list */
phylink_pcs_changed(pl)
pl->pcs_state =
PCS_STATE_INIT_PENDING;
return false;
/* skips phylink_parse_
* supported_interfaces()
*/
phylink_parse_mode()
phylink_parse_fixedlink()
phylink_register_sfp()
/* uses stale pl->supported_interfaces */
phylink_pcs_finish_init()
Because phylink_pcs_changed() returns false while pl->pcs_state is
PCS_STATE_INITIALIZING or PCS_STATE_INIT_PENDING, phylink_update_pcs() and
phylink_remove_provider_pcs() mutate pl->pcs_list without refreshing
pl->supported_interfaces until phylink_pcs_finish_init() runs at the end
of phylink_create(). phylink_parse_mode(), phylink_parse_fixedlink(), and
phylink_register_sfp() therefore inspect a pl->supported_interfaces bitmap
that does not match pl->pcs_list.
> @@ -2807,8 +2832,11 @@ static void phylink_pcs_finish_init(struct phylink *pl)
> if (phy)
> mutex_unlock(&phy->lock);
> mutex_unlock(&pl->phydev_mutex);
> - if (pl->sfp_bus)
> + if (pl->sfp_bus) {
> + if (pending)
> + phylink_sfp_retry_module(pl);
> rtnl_unlock();
> + }
> }
[Severity: Medium]
When a PCS attaches after phylink_register_sfp() has created
pl->sfp_cage_port (either in phylink_update_pcs() or here in
phylink_pcs_finish_init()), does pl->sfp_cage_port retain stale interfaces
and supported link modes?
phylink_create_sfp_cage_port() initializes pl->sfp_cage_port->interfaces
and pl->sfp_cage_port->supported from pl->supported_interfaces during
phylink_register_sfp(). Neither phylink_update_pcs() nor
phylink_pcs_finish_init() updates pl->sfp_cage_port when
pl->supported_interfaces changes before calling
phylink_sfp_retry_module(). When the retried optical SFP module starts,
phylink_add_sfp_mod_port() intersects caps->interfaces with the stale
pl->sfp_cage_port->interfaces mask, leaving pl->mod_port->supported empty.
> @@ -4789,6 +4817,14 @@ static int phylink_sfp_module_insert(void *upstream,
> ASSERT_RTNL();
>
> caps = sfp_get_module_caps(pl->sfp_bus);
> + /* A late PCS may provide the module's only usable interface */
> + if (!caps->may_have_phy &&
> + !bitmap_intersects(caps->interfaces, pl->supported_interfaces,
> + PHY_INTERFACE_MODE_MAX) &&
> + bitmap_intersects(caps->interfaces, pl->config->pcs_interfaces,
> + PHY_INTERFACE_MODE_MAX))
> + return -EAGAIN;
[Severity: High]
Can this -EAGAIN condition ever trigger when pl->config->pcs_interfaces is
a subset of pl->config->supported_interfaces?
phylink_parse_supported_interfaces() starts by copying all of
pl->config->supported_interfaces into pl->supported_interfaces without
masking out pl->config->pcs_interfaces:
drivers/net/phy/phylink.c:phylink_parse_supported_interfaces() {
phy_interface_copy(pl->supported_interfaces,
pl->config->supported_interfaces);
list_for_each_entry(pcs, &pl->pcs_list, list) {
DECLARE_PHY_INTERFACE_MASK(pcs_interfaces);
phy_interface_copy(pcs_interfaces, pl->config->pcs_interfaces);
if (!phy_interface_empty(pcs->supported_interfaces))
phy_interface_and(pcs_interfaces, pcs_interfaces,
pcs->supported_interfaces);
phy_interface_or(pl->supported_interfaces,
pl->supported_interfaces,
pcs_interfaces);
}
}
Because drivers populate pl->config->supported_interfaces with all MAC
interfaces and mark the PCS-backed subset in pl->config->pcs_interfaces,
every bit in pl->config->pcs_interfaces is already present in
pl->supported_interfaces even when pl->pcs_list is empty. As a result,
!bitmap_intersects(caps->interfaces, pl->supported_interfaces, ...) is
always false whenever caps->interfaces intersects
pl->config->pcs_interfaces, so optical SFP modules are never deferred with
-EAGAIN and unavailable PCS modes remain enabled in
pl->supported_interfaces. Should phylink_parse_supported_interfaces()
initialize pl->supported_interfaces with phy_interface_andnot() to
exclude pl->config->pcs_interfaces before ORing in the interfaces of
attached PCS instances?
[Severity: Medium]
Even with pl->supported_interfaces excluding unattached PCS modes, will
this check return -EAGAIN indefinitely when all possible PCS instances are
already attached?
An attached PCS can support only a subset of pl->config->pcs_interfaces in
pcs->supported_interfaces. If all pl->config->num_possible_pcs PCS
instances are already in pl->pcs_list and an optical SFP module is
inserted whose interface is in pl->config->pcs_interfaces but not
supported by the attached PCS, phylink_sfp_module_insert() will still
return -EAGAIN instead of rejecting the module with -EINVAL, leaving the
SFP state machine stuck in SFP_MOD_WAITDEV.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261129230558.612526-1-ansuelsmth@gmail.com?part=9
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
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 [this message]
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-242233@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