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 03/15] net: phylink: introduce internal phylink PCS handling
Date: Mon, 30 Nov 2026 23:47:34 +0000 [thread overview]
Message-ID: <179608245404.3146.9305144543922362163@kernel.org> (raw)
In-Reply-To: <20261129230558.612526-4-ansuelsmth@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · 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] In PCS-list mode, phylink chooses a PCS in three places, and
they disagree when no listed PCS supports a mode that needs one.
- [Medium] phylink_destroy() (drivers/net/phy/phylink.c:2375-2376) now
calls phylink_detach_pcss() before cancel_work_sync(&pl->resolve).
- [Low] net: phylink: duplicated PCS lookup logic across three functions
--
net: phylink: introduce internal phylink PCS handling
This adds a PCS list to phylink as an alternative to .mac_select_pcs. The
MAC fills an array through .fill_available_pcs. The modes that need a
dedicated PCS are described by a new pcs_interfaces bitmap. PCS selection
in validation, inband caps and major config walks that list, and the PCS
teardown is shared between phylink_destroy() and the phylink_create()
error path.
> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index 20759fe47eaa7..35e82cccd39a2 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c
[ ... ]
> @@ -536,6 +559,21 @@ static int phylink_validate_mac_and_pcs(struct phylink *pl,
> pcs = pl->mac_ops->mac_select_pcs(pl->config, state->interface);
> if (IS_ERR(pcs))
> return PTR_ERR(pcs);
> + /*
> + * Find a PCS in available PCS list for the requested interface.
> + *
> + * Skip searching if the MAC doesn't require a dedicated PCS for
> + * the requested interface.
> + */
> + } else if (test_bit(state->interface, pl->config->pcs_interfaces)) {
> + struct phylink_pcs *tmp;
> +
> + list_for_each_entry(tmp, &pl->pcs_list, list) {
> + if (!phylink_validate_pcs_interface(tmp, state->interface)) {
> + pcs = tmp;
> + break;
> + }
> + }
> }
>
> if (pcs) {
[Severity: Low]
The same PCS selection is now open-coded three times: here in
phylink_validate_mac_and_pcs(), in phylink_inband_caps() and in
phylink_major_config(). Each copy tests pl->config->pcs_interfaces,
walks pl->pcs_list and takes the first entry that
phylink_validate_pcs_interface() accepts.
The copies already disagree on what a miss means.
phylink_major_config() fails the major config when no PCS on the list
matches. phylink_validate_mac_and_pcs() and phylink_inband_caps() leave
pcs as NULL and carry on as if the mode needed no PCS at all.
Any later change to the selection rule would also have to be repeated
in all three places. Preferring the currently active PCS would be one
example of such a change.
Could this be factored into a single helper, something like
phylink_find_pcs(pl, interface), that also covers the .mac_select_pcs
branch? The callers would then share one place that decides what a
missing PCS for a pcs_interfaces mode means.
[Severity: Medium]
What happens here when a mode is set in pcs_interfaces but no PCS on
pl->pcs_list supports it? pcs stays NULL, the check falls through to the
MAC capabilities only, and phylink_validate_mac_and_pcs() returns success.
phylink_inband_caps() does the same thing and returns 0.
phylink_major_config() treats the same case as fatal:
if (!pcs) {
phylink_err(pl, "couldn't find a PCS for %s\n", ...);
pl->major_config_failed = true;
return;
}
The comment in phylink_parse_supported_interfaces() says it keeps phylink
from accepting a PCS-only mode without a PCS. However, the function starts
by copying config->supported_interfaces unchanged, and after that it only
ORs PCS modes in:
phy_interface_copy(pl->supported_interfaces,
pl->config->supported_interfaces);
phylink_create() rejects an empty config->supported_interfaces before any
PCS is merged. The kernel-doc says supported_interfaces covers modes
"supported by the MAC/PCS". So PCS-required modes end up in
config->supported_interfaces anyway.
Later in the series, Documentation/networking/pcs.rst describes
pcs_interfaces as a subset of supported_interfaces. Also,
airoha_setup_phylink() sets pcs_interfaces equal to supported_interfaces.
That makes the filtering a no-op.
Suppose the PCS list is empty, for example because a fwnode PCS provider
has not probed yet, or it doesn't cover a given mode. Could ethtool then
advertise link modes that can't be configured, and could SFP/PHY
interface selection pick a mode with no PCS?
If that happens, the link would stay down with "couldn't find a PCS" on
every resolve. pl->pcs would still point at the previous PCS, while
phylink_resolve() goes on updating pl->link_config.interface.
The SFP -EAGAIN deferral added later in the series, in
phylink_sfp_module_insert(), tests caps->interfaces against
pl->supported_interfaces. For airoha that test would never fire.
Should pcs_interfaces modes that no listed PCS supports be removed from
pl->supported_interfaces? Or should validation fail in the same way
phylink_major_config() does?
[ ... ]
> @@ -2042,6 +2168,62 @@ EXPORT_SYMBOL_GPL(phylink_update_mac_pause_capabilities);
[ ... ]
> +static void phylink_detach_pcss(struct phylink *pl)
> +{
> + struct phylink_pcs *pcs, *tmp;
> +
> + mutex_lock(&pl->state_mutex);
> +
> + mutex_lock(&phylink_pcs_ownership_mutex);
> + /* Remove every PCS from phylink PCS list */
> + list_for_each_entry_safe(pcs, tmp, &pl->pcs_list, list) {
> + rcu_assign_pointer(pcs->phylink, NULL);
> + list_del(&pcs->list);
> + }
> +
> + if (pl->pcs) {
> + rcu_assign_pointer(pl->pcs->phylink, NULL);
> + WRITE_ONCE(pl->pcs, NULL);
> + }
> + mutex_unlock(&phylink_pcs_ownership_mutex);
> +
> + /*
> + * Unconditionally wait for readers that may have obtained this
> + * phylink through a PCS while phylink_major_config() was clearing
> + * the association.
> + */
> + synchronize_rcu();
> +
> + mutex_unlock(&pl->state_mutex);
> +}
[ ... ]
> @@ -2167,17 +2372,9 @@ void phylink_destroy(struct phylink *pl)
> if (pl->link_gpio)
> gpiod_put(pl->link_gpio);
>
> - if (pl->pcs)
> - rcu_assign_pointer(pl->pcs->phylink, NULL);
> -
> - /*
> - * Unconditionally wait for readers that may have obtained this
> - * phylink through a PCS while phylink_major_config() was clearing
> - * the association.
> - */
> - synchronize_rcu();
> -
> + phylink_detach_pcss(pl);
> cancel_work_sync(&pl->resolve);
> +
> kfree(pl);
> }
[Severity: Medium]
Can the resolve work link a PCS back to pl after phylink_detach_pcss()
has run?
phylink_detach_pcss() clears every pcs->phylink and now also sets pl->pcs
to NULL. It then calls synchronize_rcu() and drops state_mutex. A resolve
work item that was pending, or blocked on state_mutex, runs after that.
phylink_resolve() calls phylink_major_config() whenever
pl->force_major_config is set, even with PHYLINK_DISABLE_STOPPED set. On
the .mac_select_pcs path pl->pcs is now NULL, so pcs_changed is true and
this runs:
if (pcs)
rcu_assign_pointer(pcs->phylink, pl);
cancel_work_sync() then waits for the worker to finish, and kfree(pl)
frees the instance while pcs->phylink still points to it. A later
phylink_pcs_change() on that PCS would rcu_dereference(pcs->phylink) and
read pl->pcs from freed memory.
Both preconditions appear reachable:
- force_major_config can stay set on a stopped port.
phylink_replay_link_end() sets it, but no resolve is queued while STOPPED
is set. sja1105_static_config_reload() runs replay begin/end on every
available port, including ports that are down.
- The work can be queued after phylink_stop() calls flush_work(), because
phylink_run_resolve() checks phylink_disable_state without locking.
Before this patch, pl->pcs stayed set during destroy. Re-selecting the
same PCS gave pcs_changed == false, so the PCS was not linked again.
I couldn't find an in-tree driver where all of these conditions hold at
once, so this may be theoretical for now.
Would it make sense to cancel the resolve work before calling
phylink_detach_pcss()? That would apply here and in the phylink_create()
error path, which uses the same order.
--
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: 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 [this message]
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
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=179608245404.3146.9305144543922362163@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