From: netdev-bot+sashiko@kernel.org
To: ansuelsmth@gmail.com
Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
kuba@kernel.org, pabeni@redhat.com, robh@kernel.org,
krzk+dt@kernel.org, conor+dt@kernel.org, willemb@google.com,
horms@kernel.org, corbet@lwn.net, skhan@linuxfoundation.org,
rdunlap@infradead.org, lorenzo@kernel.org, hkallweit1@gmail.com,
linux@armlinux.org.uk, maxime.chevallier@bootlin.com,
p.zabel@pengutronix.de, nathan@kernel.org,
ndesaulniers@google.com, morbo@google.com,
justinstitt@google.com, rmk+kernel@armlinux.org.uk,
netdev@vger.kernel.org, devicetree@vger.kernel.org,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org, llvm@lists.linux.dev,
zhengping.zhang@airoha.com
Subject: Re: [PATCH net-next v23 09/15] net: phylink: support late PCS provider attach
Date: Mon, 30 Nov 2026 23:47:48 +0000 [thread overview]
Message-ID: <179608246894.3146.869946902212130641@kernel.org> (raw)
In-Reply-To: <20261129230558.612526-10-ansuelsmth@gmail.com>
Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.
Critical: 0 · High: 2 · Medium: 3 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] net: phylink: phylink_parse_supported_interfaces() keeps
unavailable PCS modes
- [High] net: phylink: phylink_create() fails for in-band links with late
PCS
- [Medium] The late-PCS SFP recovery added by this patch only covers
modules with caps->may_have_phy == false.
- [Medium] phylink_sfp_module_insert()
(drivers/net/phy/phylink.c:4820-4826) now returns -EAGAIN for a non-…
- [Medium] net: phylink: stale sfp_cage_port capabilities after late PCS
attach
--
net: phylink: support late PCS provider attach
This adds a FWNODE_PCS_PROVIDER_ADD notification. With it, a phylink
instance can pick up a PCS provider that registers after phylink_create(),
and it then refreshes supported_interfaces and link capabilities. Optical
SFP insertion is deferred with -EAGAIN when the module's only usable
interfaces need a PCS, and the insertion is retried once a PCS is added.
> 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
[ ... ]
> @@ -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 condition ever evaluate to true?
phylink_parse_supported_interfaces() starts from a copy of
pl->config->supported_interfaces. It then ORs in pcs_interfaces modes
for each PCS on pl->pcs_list, and it never removes anything.
Documentation/networking/pcs.rst describes the two masks this way:
config->supported_interfaces lists every mode the MAC supports, and
config->pcs_interfaces is the subset of those that need a PCS.
airoha_setup_phylink() follows that and copies supported_interfaces
into pcs_interfaces.
If pcs_interfaces is a subset of config->supported_interfaces, every
PCS-required mode is always set in pl->supported_interfaces, whether
or not pl->pcs_list is empty. A module interface that intersects
pl->config->pcs_interfaces then also intersects
pl->supported_interfaces, so the -EAGAIN branch can never be taken.
An optical module inserted before its PCS provider probes is
configured immediately instead of being deferred.
Validation does not catch this either. phylink_validate_mac_and_pcs()
searches pl->pcs_list when the interface is in pcs_interfaces. If no
PCS matches, it leaves pcs NULL and validates against the MAC
capabilities alone. phylink_sfp_config_optical() can therefore select
and configure a PCS-required interface with no PCS attached.
The same applies when the attached PCS supports only some of the
modes. For example, the airoha USB PCS tops out at 2500BASE-X, while
the MAC sets 10GBASE-R and USXGMII in both masks.
The comment in phylink_parse_supported_interfaces() suggests the
intent is to advertise PCS-only modes only once a PCS can serve them.
Which contract is intended here? If pcs_interfaces may overlap
config->supported_interfaces, should that overlap be masked out of the
initial copy? And should phylink_validate_mac_and_pcs() fail when no
PCS on pl->pcs_list accepts a pcs_interfaces mode?
[Severity: Medium]
Does late PCS attach also cover modules that have caps->may_have_phy set?
Copper modules (1000BASE-T/SGMII, 10GBASE-T) and quirked fibre modules
skip this deferral and return 0. Their interface setup happens later in
SFP_S_INIT_PHY, after the netdev is up.
Suppose the PCS-only host mode (SGMII, for example) is still missing from
pl->supported_interfaces at that point. One of two things happens. In the
first case, phylink_sfp_connect_phy() takes a snapshot:
phy_interface_and(phy->host_interfaces, phylink_sfp_interfaces,
pl->supported_interfaces);
and phylink_sfp_config_phy() then fails. In the second case, no PHY is
found, so phylink_sfp_module_start() falls through to:
ret = phylink_sfp_config_optical(pl);
if (ret)
goto del_mod_port;
which fails with "unsupported SFP module: no common interface modes".
Either way, sfp_sm_main() moves the socket to SFP_S_FAIL.
When the PCS provider registers later, the path is
phylink_update_pcs()->phylink_sfp_retry_module()->sfp_retry_module(),
and sfp_retry_module() only acts in WAITDEV:
if (sfp->sm_mod_state == SFP_MOD_WAITDEV)
__sfp_sm_event(sfp, SFP_E_UPSTREAM_RETRY);
These modules are already past WAITDEV, so nothing retries them. The link
stays down until ifdown/ifup or a re-plug.
These modules behave the same as before the patch, and the commit message
limits the deferral to optical modules. Is this gap intended, given that
the goal is late PCS provider attach?
[Severity: Medium]
What happens to the module if a suitable PCS never shows up?
This check only uses the static config->pcs_interfaces mask. It does not
check that a provider exists, or that any PCS supports the module's
interface. On -EAGAIN, sfp_sm_module() leaves the module in
SFP_MOD_WAITDEV:
err = sfp_module_insert(sfp->sfp_bus, &sfp->id,
sfp->quirk);
if (err == -EAGAIN)
break;
WAITDEV is entered with sfp_sm_mod_next(sfp, SFP_MOD_WAITDEV, 0), so no
timer is armed. A retry can come from only two places. One is
phylink_update_pcs():
if (rescan && added && ret > 0)
phylink_sfp_retry_module(pl);
The other is phylink_pcs_finish_init() when an update is pending. Both
need a PCS to be added to this phylink instance.
A suitable PCS may never arrive. The PCS driver may not be built, may fail
to probe, or may be missing from DT. A PCS may also attach without
supporting the module's interface, and then every retry returns -EAGAIN
again.
In those cases the module stays in WAITDEV indefinitely, TX_DISABLE stays
asserted and high-power mode is never enabled. Nothing is logged.
Before this patch the same module failed in phylink_sfp_config_optical()
with "unsupported SFP module: no common interface modes" and moved to
SFP_MOD_ERROR.
This branch can only trigger when the MAC leaves PCS-required modes out of
config->supported_interfaces. A MAC such as airoha copies
supported_interfaces into pcs_interfaces, so it cannot reach it.
Could a message be logged when insertion is deferred here? Alternatively,
could the old error path be kept for the case where no PCS can provide the
interface?
[ ... ]
> @@ -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: Medium]
Is the SFP cage port refreshed when a late PCS extends
pl->supported_interfaces?
phylink_register_sfp() runs inside phylink_create() and calls
phylink_create_sfp_cage_port(). That function sets the cage port's
masks once, from the supported_interfaces that exist at that point:
phy_interface_and(port->interfaces, pl->supported_interfaces,
phylink_sfp_interfaces);
phy_port_update_supported(port);
This runs before phylink_pcs_finish_init() and before any
FWNODE_PCS_PROVIDER_ADD notification can be handled.
When the PCS appears later, phylink_update_pcs() and
phylink_pcs_finish_init() rebuild pl->supported_interfaces with
phylink_parse_supported_interfaces() and then call
phylink_sfp_retry_module(). The interfaces and supported masks of
pl->sfp_cage_port are never recomputed, so they keep the pre-PCS
values.
The module deferred by the new -EAGAIN check is, by construction, one
whose caps->interfaces do not intersect the old
pl->supported_interfaces. They therefore do not intersect the cage
port's interfaces either. When the retried module reaches
phylink_sfp_module_start(), phylink_add_sfp_mod_port() does:
phy_interface_and(interfaces, pl->sfp_cage_port->interfaces,
caps->interfaces);
phy_caps_linkmode_filter_ifaces(port->supported, caps->link_modes,
interfaces);
The result is an empty interfaces mask, and pl->mod_port->supported
ends up with no link modes. The cage port also never gains the
PCS-backed interfaces and link modes. The phy_port topology that
userspace sees then does not match the link that is actually running.
Should the cage port masks be recomputed wherever
phylink_parse_supported_interfaces() runs after the SFP bus has been
registered? Or should phylink_add_sfp_mod_port() derive its mask from
the current pl->supported_interfaces instead?
[ ... ]
> @@ -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: High]
What happens on an in-band link whose initial interface needs a PCS
that has not registered yet?
Consider a MAC that leaves the PCS-required mode out of
config->supported_interfaces, which is the case late attach is meant
for. phylink_create() calls phylink_update_pcs(pl, false) while
pl->pcs_list is still empty. As a result, pl->supported_interfaces
does not contain pl->link_config.interface.
phylink_create() then calls phylink_parse_mode(). For MLO_AN_INBAND
(managed = "in-band-status" or config->default_an_inband, the usual
setup for SFP cages), this reaches phylink_parse_inband_capabilities().
There, __phylink_validate() returns early:
if (!test_bit(state->interface, interfaces))
return -EINVAL;
phylink_parse_mode() propagates the error, and phylink_create() jumps
to unregister_pcs_notify. This happens before phylink_register_sfp(),
before phylink_pcs_finish_init(), and before any
FWNODE_PCS_PROVIDER_ADD can be handled. The INIT_PENDING handling
added here therefore never gets to run. If the provider probes after
the MAC, or concurrently with phylink_create(), the MAC probe simply
fails.
The same early return also affects the generic branch of
phylink_update_capabilities() during the initial phylink_update_pcs().
That branch fills pl->supported with linkmode_fill() and copies it
into config->advertising. __phylink_validate() then bails out before
masking anything, and pl->advertising is saved as all ones.
Should phylink_parse_mode() tolerate an interface that is in
config->pcs_interfaces but not yet backed by a PCS, and defer the
in-band capability parsing until a PCS attaches? Or is late PCS attach
not meant to support in-band links? If so, could the commit message
say that?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261129230558.612526-1-ansuelsmth%40gmail.com
next prev parent reply other threads:[~2026-11-30 23:48 UTC|newest]
Thread overview: 30+ 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: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: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: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: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:47 ` netdev-bot+sashiko [this message]
2026-11-29 23:05 ` [PATCH net-next v23 10/15] net: Document PCS subsystem Christian Marangi
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: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: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: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=179608246894.3146.869946902212130641@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=ansuelsmth@gmail.com \
--cc=conor+dt@kernel.org \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=edumazet@kernel.org \
--cc=hkallweit1@gmail.com \
--cc=horms@kernel.org \
--cc=justinstitt@google.com \
--cc=krzk+dt@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux@armlinux.org.uk \
--cc=llvm@lists.linux.dev \
--cc=lorenzo@kernel.org \
--cc=maxime.chevallier@bootlin.com \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=netdev@vger.kernel.org \
--cc=p.zabel@pengutronix.de \
--cc=pabeni@redhat.com \
--cc=rdunlap@infradead.org \
--cc=rmk+kernel@armlinux.org.uk \
--cc=robh@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=willemb@google.com \
--cc=zhengping.zhang@airoha.com \
/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