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 06/15] net: phylink: add capabilities helpers and track modified advertising
Date: Mon, 30 Nov 2026 23:47:41 +0000 [thread overview]
Message-ID: <179608246142.3146.8194531736512870418@kernel.org> (raw)
In-Reply-To: <20261129230558.612526-7-ansuelsmth@gmail.com>
Thank you for your contribution! Sashiko AI review found 6 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 3 · Low: 2
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: unchecked validation failure in
phylink_update_capabilities()
- [Medium] On SFP links, pl->advertising does not always hold "the full
validated advertisement" that the commit message describes, so modes…
- [Medium] phylink_update_user_disabled_advertising() never clears a
restriction for a mode that is outside the current pl->advertising,…
- [Medium] net: phylink: stale SFP caps after phylink_sfp_module_start()
failure
- [Low] phylink_update_capabilities() falls back to
phylink_parse_inband_capabilities() after an SFP module is removed,…
- [Low] net: phylink: phylink_set_fixed_link() leaves pl->advertising
stale
--
net: phylink: add capabilities helpers and track modified advertising
This commit adds pl->advertising and pl->user_disabled_advertising masks
to struct phylink, along with helpers that recalculate the supported and
advertised link modes when a PCS is added or removed. It also factors the
fixed-link, in-band, PHY and SFP capability calculations into reusable
helpers. The user-disabled mask is applied during SFP interface selection.
> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index 141da617b24bd..877a0a30ec222 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c
[ ... ]
> @@ -2236,6 +2286,157 @@ 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 a restriction on a mode outside the current pl->advertising ever be
cleared here, even when the user explicitly requests that mode?
The result is D = (A & ~R) | (D_old & ~A). A mode that is in D_old and in
R but not in A stays disabled.
On optical SFP links, A only covers the current interface because
phylink_sfp_set_config() sets it. The request built in
phylink_ethtool_ksettings_set() is masked with pl->supported, which covers
every SFP interface.
Take two interfaces X and Y on a may_have_phy module where no PHY was
detected:
1. The link starts on X.
2. The user advertises only a Y mode. D gets the X speed modes and the
interface switches to Y.
3. After a link down/up, phylink_sfp_module_start() calls
phylink_sfp_config_optical(). That skips X, picks Y and sets A = A(Y).
4. The user advertises only an X mode m_X. D & ~A(Y) still contains m_X,
and D also gains all the Y speed modes.
5. After another link down/up, phylink_choose_sfp_interface() finds every
candidate empty after masking:
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;
phylink_sfp_config_optical() then fails with "failed to select SFP
interface". sfp_module_start() fails too, and the SFP state machine moves
to SFP_S_FAIL with the link down.
Later in the series the same stale bits also reach
phylink_update_capabilities() on PCS add/remove. Its exit label sets
link_config.advertising = A & ~D, which drops the modes the user just
asked for.
> +
> +static void phylink_sfp_update_capabilities(struct phylink *pl,
[ ... ]
> +static void phylink_update_capabilities(struct phylink *pl,
> + struct phylink_link_state *config)
> +{
[ ... ]
> + /*
> + * Revalidate SFP modes before generic in-band capabilities, so module
> + * EEPROM limits are retained for in-band SFP configurations.
> + */
> + if (pl->sfp_bus && config->interface != PHY_INTERFACE_MODE_NA &&
> + !phy_interface_empty(pl->sfp_module_interfaces)) {
[Severity: Medium]
Does the deferred optical path need the same cleanup as the error
path added here?
For a module with caps->may_have_phy set, phylink_sfp_module_insert()
caches pl->sfp_module_interfaces, pl->sfp_interfaces and
pl->sfp_support and returns 0. The optical configuration is left to
phylink_sfp_module_start(), which runs once sfp.c has probed for a PHY
and found none.
If phylink_sfp_config_optical() fails there, phylink_sfp_module_start()
only deletes the module port and returns the error. sfp_sm_main() then
moves to SFP_S_FAIL while the module stays SFP_MOD_PRESENT, so
phylink_sfp_module_remove() is not called until the module is pulled.
Nothing clears the cached masks on that path.
>From then on phylink_update_capabilities() sees a non-empty
pl->sfp_module_interfaces and takes the SFP branch whenever
link_config.interface is not PHY_INTERFACE_MODE_NA. pl->supported and
pl->advertising are rebuilt from the failed module's sfp_support. As a
result, ethtool reports, and the next major config uses, modes from a
module that phylink refused to configure.
For may_have_phy modules, the window between insert and
phylink_sfp_module_start() behaves the same way. In this commit the
branch is only reached through phylink_update_mac_pause_capabilities();
later in the series the PCS add/remove paths reach it as well.
Should phylink_sfp_module_start() clear the cached module capabilities
on failure as well, perhaps through a helper shared with the insert
path? And should the SFP branch act on a module that has not been
started yet?
[ ... ]
> + if (pl->cfg_link_an_mode == MLO_AN_INBAND) {
> + phylink_parse_inband_capabilities(pl, config);
> + goto exit;
> + }
[Severity: Low]
Does this branch handle links set up with phylink_set_fixed_link()?
phylink_set_fixed_link() derives link_config.advertising from the
MAC-validated pl->supported with phy_caps_lookup() and sets
cfg_link_an_mode to MLO_AN_FIXED. It does not touch pl->advertising,
which still holds the generic mask computed in phylink_create().
When phylink_update_capabilities() later runs on such a link,
phylink_parse_fixedlink_capabilities() rebuilds everything from
phylink_fill_fixedlink_supported(), which only covers 10baseT to
10000baseT. Take a 25G or 40G link configured this way (txgbe_aml.c
does this). phy_caps_lookup() returns NULL, pl->supported is reduced
to MII, Autoneg and the pause bits, and the advertisement has no speed
modes left. The -EINVAL is ignored, so the link silently loses its
speed modes.
Even for speeds in the BASE-T table, the result can differ from what
phylink_set_fixed_link() picked. That function used every mode at the
speed present in pl->supported.
In this commit only phylink_update_mac_pause_capabilities() reaches
this branch; later in the series the PCS add/remove paths do too.
Should phylink_set_fixed_link() record its result in pl->advertising
and keep the mask it chose? The fixed-link recalculation could then
reuse it rather than the firmware fixed-link table.
[Severity: Low]
After an SFP module is removed, should this branch still run with the
removed module's interface?
phylink_sfp_module_remove() clears pl->sfp_module_interfaces but leaves
pl->link_config.interface at the last SFP interface. On an in-band SFP
port the SFP branch above is skipped and this branch runs instead.
If the last module used PHY_INTERFACE_MODE_100BASEX, the parser reaches
its default case. 100BASEX is in phylink_sfp_interface_preference but not
in the in-band switch list:
default:
phylink_err(pl,
"incorrect link mode %s for in-band status\n",
phy_modes(config->interface));
return -EINVAL;
By then pl->supported has already been reset to just MII, Autoneg, Pause
and Asym_Pause. The error is ignored here, and the exit label rebuilds
link_config.advertising from the removed module's stale pl->advertising.
In this commit the path can only be reached through
phylink_update_mac_pause_capabilities(). Later in the series it runs on
every PCS add/remove event while no module is inserted
(phylink_update_pcs(), phylink_remove_provider_pcs(),
phylink_pcs_finish_init()).
> +
> + /* 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]
phylink_update_capabilities() returns void and drops every validation
result. What state is left behind when nothing validates?
In the generic path, pl->supported is filled and copied into
config->advertising before __phylink_validate() runs. If
config->interface is set but no longer in pl->supported_interfaces,
for example because the PCS providing it went away,
__phylink_validate() returns -EINVAL without masking anything.
pl->supported and pl->advertising stay all-ones, and the exit label
sets link_config.advertising to all-ones minus the user-disabled bits.
phylink_validate_mac_and_pcs() has similar early returns when
mac_select_pcs() or pcs_validate() fail.
The other helpers behave the same way:
- phylink_parse_fixedlink_capabilities() ignores the
__phylink_validate() result after filling pl->supported with the
fixed-link table.
- phylink_parse_inband_capabilities() has already overwritten
pl->supported with the raw interface capabilities when it returns
-EINVAL. The exit label then copies the previous pl->advertising
back into link_config.advertising.
- phylink_phy_update_capabilities() returns early, leaving
pl->supported, pl->advertising and link_config.advertising with the
values from before the PCS change.
The unchecked fill and validate in phylink_create() predates this
patch. However, the helper now also runs on a configured link: through
phylink_update_mac_pause_capabilities() here, and on every PCS
add/remove later in the series. That is exactly when an interface is
likely to lose its PCS.
Relatedly, for an MLO_AN_INBAND link whose PCS attaches late,
phylink_parse_mode() still propagates the in-band validation failure
and phylink_create() fails. Is that intended, given the aim of the
series?
Could phylink_update_capabilities() return an error to its callers?
And on failure, should validation be done into temporaries and only
committed to pl->supported and pl->advertising on success, or should
the masks be cleared?
[ ... ]
> @@ -3567,6 +3741,7 @@ int phylink_ethtool_ksettings_set(struct phylink *pl,
> */
> linkmode_mod_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, config.advertising,
> kset->base.autoneg == AUTONEG_ENABLE);
> + linkmode_copy(requested_advertising, config.advertising);
>
> /* If this link is with an SFP, ensure that changes to advertised modes
> * also cause the associated interface to be selected such that the
> @@ -3614,6 +3789,7 @@ int phylink_ethtool_ksettings_set(struct phylink *pl,
> return -EINVAL;
>
> mutex_lock(&pl->state_mutex);
> + phylink_update_user_disabled_advertising(pl, requested_advertising);
> pl->link_config.speed = config.speed;
> pl->link_config.duplex = config.duplex;
>
[Severity: Medium]
Is pl->advertising still the right reference here when this call also
switches the SFP interface?
phylink_sfp_select_interface() or phylink_sfp_select_interface_speed()
can move the link from, for example, 2500BASE-X to SGMII. Further down,
only link_config is updated:
if (pl->link_config.interface != config.interface) {
...
pl->link_config.interface = config.interface;
linkmode_copy(pl->link_config.advertising, config.advertising);
}
pl->advertising keeps the previous interface's mask A(old), so the new
restrictions are computed as A(old) & ~requested. A mode of the new
interface that the user left out is not in A(old), so it is never added
to pl->user_disabled_advertising.
On the next recalculation those modes come back:
phylink_sfp_module_start()
phylink_sfp_config_optical()
phylink_sfp_set_config()
link_config.advertising = A(new) & ~user_disabled
Later in the series, phylink_update_capabilities() on PCS add/remove has
the same effect.
For example, run "ethtool -s ethX advertise 1000baseT_Full" on a module
that offers 2500BASE-X and SGMII. After a link down/up the port
advertises 10/100/1000baseT again.
A related point concerns the commit message:
The advertising mask holds the full validated advertisement
before applying the phylink user restrictions.
With a PHY attached, phylink_phy_update_capabilities() copies
pl->advertising from phy->advertising. That copy already includes
phylib's ethtool restrictions and any phy_speed_down() reduction. The
user-disabled mask is not used while a PHY is attached, so this part is
mostly a description mismatch. Could the description be adjusted to
match?
[ ... ]
--
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:47 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 [this message]
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
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=179608246142.3146.8194531736512870418@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