Thank you for your contribution! Sashiko AI review found 7 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 6 · Low: 1
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).
- [Medium] The new SFP check in phylink_major_config()
(drivers/net/phy/phylink.c, starting at line 1533) runs for every…
- [Medium] The new fwnode_pcs_del_provider() kernel-doc in
include/linux/pcs/pcs-provider.h says unconditionally that "Phylink…
- [Medium] If a PCS provider is removed while phylink_create() is
running, the supported_interfaces/capability rebuild is deferred.
- [Medium] net: phylink: ethtool ksettings_set fails to recover after PCS
autoneg failure
- [Medium] net: phylink: mishandled force_major_config with
phylink_disable_state
- [Medium] net: phylink: broken capability recalculation in
phylink_update_capabilities()
- [Low] In the phylink_create() error path, the comment "previous PCS
notifier might have queued a resolve, cancel it" is followed by…
--
net: phylink: support PCS provider release
This adds a blocking notifier chain so that phylink instances using the
PCS list are notified when a fwnode PCS provider is removed. Each such
instance then detaches that provider's PCS synchronously. The PCS list is
refreshed via fill_available_pcs() and supported interfaces and
capabilities are rebuilt. If the active PCS goes away, the link is torn
down and reconfigured. SFP capability handling and major config are also
updated to cope with interfaces becoming unavailable.
> 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;
> + }
> + }
> +
> pcs_changed = pl->pcs != pcs;
[Severity: Medium]
Can the link recover from this early return when the user fixes the
autoneg setting with ethtool?
Take an optical SFP whose active PCS is removed. phylink_del_pcs()
clears pl->pcs and sets force_major_config. On the next resolve,
phylink_major_config() picks a replacement PCS for the same interface
from pl->pcs_list. Suppose the replacement only supports the other
in-band mode (LINK_INBAND_DISABLE vs LINK_INBAND_ENABLE). This check
then sets major_config_failed and returns before pl->pcs is assigned,
so pl->pcs stays NULL.
The obvious recovery is to change autoneg with ethtool to match the
replacement PCS. phylink_ethtool_ksettings_set() validates the new
advertisement against pl->pcs_list and accepts it. The interface is
unchanged, so it takes this branch instead of running a major config:
} else if (!linkmode_equal(pl->link_config.advertising,
config.advertising)) {
linkmode_copy(pl->link_config.advertising, config.advertising);
phylink_change_inband_advert(pl);
}
phylink_change_inband_advert() works on pl->pcs, which is still NULL,
so phylink_pcs_config() does nothing. The replacement PCS is never
attached, configured or enabled, and major_config_failed is never
cleared. phylink_resolve() keeps the link down while
major_config_failed is set.
Nothing else retries the major config while the interface stays the
same. The link stays down until the interface changes or the module
is reinserted.
Should phylink_ethtool_ksettings_set() force a major config when
major_config_failed is set, or when pl->pcs is NULL for an interface in
pcs_interfaces?
[Severity: Medium]
Does this check also fire after a copper module that may have a PHY has
been inserted, but before its PHY has attached?
The check runs for every phylink instance with an SFP bus. That includes
existing .mac_select_pcs drivers, not only PCS list users.
phylink_sfp_module_insert() copies caps->interfaces into both masks. It
then returns early for may-have-PHY modules without updating
link_config.interface:
phy_interface_copy(pl->sfp_module_interfaces, caps->interfaces);
phy_interface_copy(pl->sfp_interfaces, caps->interfaces);
...
if (pl->sfp_may_have_phy)
return 0;
The SFP state machine reports insertion from SFP_MOD_WAITDEV once
sm_dev_state >= SFP_DEV_DOWN. The module PHY is only probed later, once
the SFP device is up. phylink_start() calls phylink_mac_initial_config()
before sfp_upstream_start(). So the initial major config runs in this
window, and link_config.interface is still the DT phy-mode.
For example, take phy-mode = "10gbase-r" on an SFP+ cage with a
1000BASE-T module whose caps only contain SGMII. 10gbase-r is not in
sfp_interfaces, so this logs "incompatible SFP configuration" and returns
with major_config_failed set. Before this patch the configuration was
applied.
The link would normally recover once the module PHY attaches. However,
the early return also skips this step:
if (pl->pcs_state == PCS_STATE_STARTING || pcs_changed)
phylink_pcs_enable(pl->pcs);
Could the PCS end up never being re-enabled? Consider a module swapped
while the interface is down:
- phylink_stop() disables the PCS.
- The next phylink_start() hits this check and returns early.
- The later PHY attach selects the same pl->pcs, so pcs_changed is false.
The commit message only describes this check as part of the
replacement-PCS flow. Should it be limited to that case? The code looks
unchanged later in the series.
[ ... ]
> @@ -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;
> + }
[Severity: Medium]
Can deferring the rebuild here leave an optical SFP stuck on an interface
that has no PCS?
Suppose a provider is removed during phylink_create(). The call chain
pcs_provider_notify() -> phylink_update_pcs(pl, true) -> phylink_del_pcs()
has already taken the PCS off pl->pcs_list. But
phylink_parse_supported_interfaces() is skipped, so
pl->supported_interfaces still includes the removed PCS's modes.
phylink_create() then calls phylink_register_sfp(). A module waiting in
SFP_MOD_WAITDEV is inserted synchronously:
phylink_register_sfp()
sfp_bus_add_upstream()
... SFP_E_DEV_ATTACH
phylink_sfp_module_insert()
phylink_sfp_config_optical()
phylink_sfp_config_optical() computes sfp_interfaces from the stale
supported_interfaces.
When no listed PCS supports an interface, phylink_validate_mac_and_pcs()
leaves pcs NULL and still passes on MAC caps alone. So
phylink_choose_sfp_interface() can pick the interface whose PCS was just
removed. phylink_sfp_set_config() then stores it in
pl->link_config.interface.
phylink_pcs_finish_init() later rebuilds supported_interfaces and calls
phylink_update_capabilities(). That function zeroes pl->advertising and
then reaches:
linkmode_copy(pl->supported, supported);
if (!test_bit(config->interface, pl->sfp_interfaces))
goto exit;
No alternate interface from sfp_interfaces is selected.
A later commit in the series ("net: phylink: support late PCS provider
attach") adds a phylink_sfp_retry_module() call to
phylink_pcs_finish_init(). That doesn't seem to help.
SFP_E_UPSTREAM_RETRY is only handled in SFP_MOD_WAITDEV, and a module
that was inserted successfully has already left that state.
On phylink_start(), phylink_major_config() then logs "couldn't find a
PCS" and sets major_config_failed. phylink_resolve() keeps the link down,
even if another interface of the module has a usable PCS.
Wouldn't the same thing happen at runtime when the provider of an optical
SFP's active PCS is removed? link_config.interface stays on the
now-unusable interface, so every forced major config fails.
[ ... ]
> @@ -2672,13 +2980,18 @@ struct phylink *phylink_create(struct phylink_config *config,
> if (ret < 0)
> goto release_link_gpio;
>
> + if (pl->fwnode_pcs_nb.notifier_call)
> + phylink_pcs_finish_init(pl);
> +
> return pl;
>
> release_link_gpio:
> if (pl->link_gpio)
> gpiod_put(pl->link_gpio);
> -unlink_pcs_list:
> +unregister_pcs_notify:
> phylink_detach_pcss(pl);
> + /* previous PCS notifier might have queued a resolve, cancel it */
> + cancel_work_sync(&pl->resolve);
[Severity: Low]
This isn't a bug, but is this comment accurate?
PHYLINK_DISABLE_STOPPED is set before the notifier is registered and is
only cleared by phylink_start(). phylink_run_resolve() does nothing while
phylink_disable_state is non-zero:
if (!pl->phylink_disable_state)
queue_work(system_power_efficient_wq, &pl->resolve);
While pcs_state is INITIALIZING or INIT_PENDING, phylink_pcs_changed()
returns false. So neither phylink_update_pcs() nor
phylink_remove_provider_pcs() asks for a resolve on these error paths.
In-flight notifiers are already excluded by the
unregister_fwnode_pcs_notifier() call in phylink_detach_pcss(). That call
takes the chain rwsem for write.
The cancel_work_sync() looks like dead code here. This is still the same
at the end of the series.
[ ... ]
> diff --git a/include/linux/pcs/pcs-provider.h b/include/linux/pcs/pcs-provider.h
> index 6b03a635f73c0..2505c280946f0 100644
> --- a/include/linux/pcs/pcs-provider.h
> +++ b/include/linux/pcs/pcs-provider.h
> @@ -43,6 +43,12 @@ fwnode_pcs_add_provider(struct fwnode_handle *fwnode,
> /**
> * fwnode_pcs_del_provider - Removes a PCS provider
> * @pp: PCS provider returned by fwnode_pcs_add_provider()
> + *
> + * Phylink detaches the provider's PCS instances synchronously and may call
> + * their operations during detach. Keep the PCS instances and the resources
> + * needed to access their hardware available until this function returns.
> + *
> + * Call without holding RTNL.
> */
> void fwnode_pcs_del_provider(struct fwnode_pcs_provider *pp);
[Severity: Medium]
Does this guarantee hold for every phylink consumer?
phylink_create() only registers the notifier for PCS list users:
if (has_pcs_interfaces) {
...
register_fwnode_pcs_notifier(&pl->fwnode_pcs_nb);
It also rejects .mac_select_pcs combined with pcs_interfaces.
fwnode_pcs_get() is exported in include/linux/pcs/pcs.h, and its
documentation doesn't restrict how it is used. A MAC driver that gets a
PCS with fwnode_pcs_get() and returns it from .mac_select_pcs() would
never be notified.
phylink_major_config() stores that PCS in pl->pcs and sets pcs->phylink.
This comment allows the provider to free the PCS once
fwnode_pcs_del_provider() returns. Would phylink then keep using the
freed PCS?
There is no in-tree user of that combination today. airoha_eth uses
fwnode_phylink_pcs_parse() with fill_available_pcs.
Should the documentation say that the synchronous detach only applies to
fill_available_pcs users? This looks unchanged later in the series.
[ ... ]
> @@ -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);
> + }
> +
> + mutex_lock(&phylink_pcs_ownership_mutex);
> + rcu_assign_pointer(pcs->phylink, NULL);
> + list_del(&pcs->list);
> + mutex_unlock(&phylink_pcs_ownership_mutex);
> +}
> +
> static void phylink_parse_supported_interfaces(struct phylink *pl)
> {
> struct phylink_pcs *pcs;
[Severity: Medium]
Does the capability rebuild after a PCS removal actually drop the
removed PCS's interfaces?
phylink_parse_supported_interfaces() starts from a copy of
pl->config->supported_interfaces and only ORs in PCS modes. Some MAC
drivers that use the PCS list appear to list the PCS modes in
config->supported_interfaces as well. airoha_setup_phylink() does, and
so does the example in Documentation/networking/pcs.rst. In that case
the pcs_interfaces modes stay in pl->supported_interfaces after their
PCS leaves pl->pcs_list.
phylink_validate_mac_and_pcs() doesn't catch it either. For an
interface in pcs_interfaces with no matching PCS in pl->pcs_list, pcs
stays NULL and validation passes on MAC capabilities alone. Unlike
phylink_major_config(), it doesn't return -EINVAL here.
So __phylink_validate_mask() and __phylink_validate() in this SFP
branch still succeed after the PCS is gone. The new handling for
unusable interfaces is never reached. This would also stop the
late-PCS -EAGAIN check, which a later patch in the series adds to
phylink_sfp_module_insert(), from firing.
A MAC driver might instead leave the PCS modes out of
config->supported_interfaces. Then the interface does drop out of
pl->supported_interfaces. __phylink_validate() returns -EINVAL from
its test_bit() check without touching the masks, and only the SFP
branch handles that:
- In the generic fallback, linkmode_fill() has just filled
pl->supported and config->advertising. The return value is ignored,
so pl->supported, pl->advertising and link_config.advertising keep
every link mode bit set.
- phylink_parse_inband_capabilities() has already filled pl->supported
with unvalidated modes when it returns -EINVAL. pl->advertising
keeps the modes from the removed PCS.
- phylink_parse_fixedlink_capabilities() ignores the failure after
phylink_fill_fixedlink_supported().
- phylink_phy_update_capabilities() returns early and keeps the old
supported and advertising masks.
These masks are what phylink_ethtool_ksettings_get() reports. They are
also used to validate phylink_ethtool_ksettings_set() and to compute
user_disabled_advertising.
Should phylink_parse_supported_interfaces() remove pcs_interfaces from
the MAC mask before adding back the modes a listed PCS supports? And
should the remaining branches clear the masks when validation fails?
[Severity: Medium]
Is it safe to leave force_major_config pending once RTNL is dropped?
Before this patch, force_major_config was only set by
phylink_replay_link_end(). That runs under RTNL, right after clearing
PHYLINK_DISABLE_REPLAY, and flushes the resolve work before returning.
Here phylink_update_pcs() and phylink_remove_provider_pcs() set it and
drop RTNL. Only after that does pcs_provider_notify() call
phylink_run_resolve().
phylink_resolve() acts on the flag without looking at
phylink_disable_state:
if ((mac_config &&
link_state.interface != pl->link_config.interface) ||
pl->force_major_config) {
...
phylink_major_config(pl, false, &link_state);
Suppose phylink_stop() runs in that window, or before the queued work
executes:
- It stops the SFP upstream and the PHY.
- It calls timer_delete_sync(&pl->link_poll).
- phylink_run_resolve_and_disable() sets PHYLINK_DISABLE_STOPPED and
flushes the work.
That resolve still sees force_major_config. phylink_major_config()
then reconfigures the MAC and PCS on a stopped interface. With
MLO_AN_INBAND and a polling replacement PCS, phylink_pcs_poll_start()
re-arms pl->link_poll after phylink_stop() deleted it.
phylink_destroy() doesn't delete the timer, so pl can be freed while
the timer is pending. phylink_fixed_poll() would then run on freed
memory.
phylink_del_pcs() has the opposite problem. It only sets
force_major_config when phylink_disable_state is zero, while
phylink_pcs_changed() only tests PHYLINK_DISABLE_STOPPED. Suppose the
active PCS is removed while PHYLINK_DISABLE_MAC_WOL is set, or while
PHYLINK_DISABLE_LINK is set together with another bit. pl->pcs
becomes NULL without forcing a reconfiguration:
- phylink_sfp_link_up() only handles DISABLE_LINK as the only bit set.
- phylink_pcs_changed() only sets the flag again if force_major_config
or major_config_failed was already set.
Once the bit clears, a resolve with an unchanged interface never runs
a major config. The replacement PCS is never selected.
Finally, phylink_pcs_changed() and phylink_sfp_link_up() set both
force_major_config and link_failed. The next resolve pass takes the
link_failed branch. The forced major config therefore runs with a
link_state based on pl->link_config, not on pl->phy_state or
phylink_get_fixed_state(). force_major_config is cleared on that pass,
so the retrigger pass no longer sees it. Is that intended?
Would it work to set the flag whenever PHYLINK_DISABLE_STOPPED is
clear, and have phylink_resolve() only honour it once
phylink_disable_state is zero and link_failed is clear?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/2026…%40gmail.com