Devicetree
 help / color / mirror / Atom feed
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 v22 03/15] net: phylink: introduce internal phylink PCS handling
Date: Wed, 18 Nov 2026 12:42:48 +0000	[thread overview]
Message-ID: <sashiko-outbox-220923@kernel.org> (raw)
In-Reply-To: <20261117123956.11981-4-ansuelsmth@gmail.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] net: phylink: missing error return in
  phylink_validate_mac_and_pcs()
- [Medium] net: phylink: broken PCS interface masking in
  phylink_create()
- [Low] net: phylink: duplicated PCS lookup logic across three functions
--

commit 4ee2fa0fe02a77175d57df4608f9c44befd95369
Author: Christian Marangi <ansuelsmth@gmail.com>

net: phylink: introduce internal phylink PCS handling

This commit introduces an internal PCS list in phylink, populated via
.fill_available_pcs in struct phylink_config, as an alternative to
.mac_select_pcs for selecting and validating PCS instances based on
their supported interfaces.

> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index f482dc6088102..e8ba906cfba68 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c
[ ... ]
> @@ -535,6 +554,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;
> +			}
> +		}
>  	}

[Severity: Medium]
Should phylink_validate_mac_and_pcs() return -EINVAL when state->interface
is set in pl->config->pcs_interfaces, but no matching PCS is found in
pl->pcs_list?

When pcs remains NULL, phylink_validate_mac_and_pcs() skips the if (pcs)
block and validates state->interface against MAC capabilities alone via
phylink_validate_mask_caps().  If a MAC lists modes in
config->pcs_interfaces that the attached PCS does not support (for example,
10GBASER and USXGMII when paired with a PCS that only supports up to
2500BASEX), those modes pass validation during phylink_parse_mode(), PHY
attachment, and SFP module selection, only for phylink_major_config() to
fail at runtime with pl->major_config_failed = true when it sees !pcs.

> @@ -968,12 +999,22 @@ static void phylink_pcs_enable_eee(struct phylink_pcs *pcs)
>  static unsigned int phylink_inband_caps(struct phylink *pl,
>  					 phy_interface_t interface)
>  {
> -	struct phylink_pcs *pcs;
> +	struct phylink_pcs *pcs = NULL;
>  
> -	if (!pl->mac_ops->mac_select_pcs)
> -		return 0;
> +	if (pl->mac_ops->mac_select_pcs) {
> +		pcs = pl->mac_ops->mac_select_pcs(pl->config,
> +						  interface);
> +	} else if (test_bit(interface, pl->config->pcs_interfaces)) {
> +		struct phylink_pcs *tmp;
> +
> +		list_for_each_entry(tmp, &pl->pcs_list, list) {
> +			if (!phylink_validate_pcs_interface(tmp, interface)) {
> +				pcs = tmp;
> +				break;
> +			}
> +		}
> +	}
>  
> -	pcs = pl->mac_ops->mac_select_pcs(pl->config, interface);
>  	if (IS_ERR_OR_NULL(pcs))
>  		return 0;
>  
> @@ -1270,10 +1311,36 @@ static void phylink_major_config(struct phylink *pl, bool restart,
>  			pl->major_config_failed = true;
>  			return;
>  		}
> +	/* Find a PCS in available PCS list for the requested interface.
> +	 * This doesn't overwrite the previous .mac_select_pcs as either
> +	 * .mac_select_pcs or PCS list implementation are permitted.
> +	 *
> +	 * 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) {
> +			phylink_err(pl,
> +				    "couldn't find a PCS for %s\n",
> +				    phy_modes(state->interface));
>  
> -		pcs_changed = pl->pcs != pcs;
> +			pl->major_config_failed = true;
> +			return;
> +		}
>  	}

[Severity: Low]
This isn't a bug by itself, but the PCS selection logic checking
pl->mac_ops->mac_select_pcs and walking pl->pcs_list is duplicated across
phylink_validate_mac_and_pcs(), phylink_inband_caps(), and
phylink_major_config().  Factoring this lookup into a helper that returns
a struct phylink_pcs pointer (or an ERR_PTR when a required PCS is not
found) would avoid the triplicated loop and keep missing-PCS handling
consistent across all three callers.

[ ... ]

> @@ -2096,16 +2220,31 @@ struct phylink *phylink_create(struct phylink_config *config,
>  	__set_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state);
>  	timer_setup(&pl->link_poll, phylink_fixed_poll, 0);
>  
> +	/* Fill the PCS list with available PCS from phylink config */
> +	ret = phylink_fill_available_pcs(pl, config);
> +	if (ret < 0)
> +		goto free_pl;
> +
> +	/* Link available PCS to phylink */
> +	list_for_each_entry(pcs, &pl->pcs_list, list)
> +		rcu_assign_pointer(pcs->phylink, pl);
> +
>  	phy_interface_copy(pl->supported_interfaces,
>  			   pl->config->supported_interfaces);
>  
> +	/* Update supported interfaces */
> +	list_for_each_entry(pcs, &pl->pcs_list, list)
> +		phy_interface_or(pl->supported_interfaces,
> +				 pl->supported_interfaces,
> +				 pcs->supported_interfaces);

[Severity: Medium]
As reported by Maxime Chevallier on v7 [1], does ORing
pcs->supported_interfaces into pl->supported_interfaces leave unsupported
interface modes enabled in pl->supported_interfaces?

Because pl->config->supported_interfaces already contains the modes in
pl->config->pcs_interfaces, bitwise-ORing pcs->supported_interfaces never
clears modes in config->pcs_interfaces that no PCS in pl->pcs_list
supports.  Conversely, if a generic PCS sets modes in
pcs->supported_interfaces that the MAC itself does not support,
phy_interface_or() adds them to pl->supported_interfaces, and because
those modes are not in pl->config->pcs_interfaces, phylink treats them as
native MAC modes requiring no PCS.  Callers inspecting
pl->supported_interfaces (such as SFP interface selection and PHY
validation) will then consider unsupported modes valid until
phylink_major_config() fails.

Should pl->supported_interfaces instead start with the non-PCS MAC
interfaces (config->supported_interfaces & ~config->pcs_interfaces) and OR
in (pcs->supported_interfaces & config->pcs_interfaces) for each available
PCS (falling back to config->pcs_interfaces when pcs->supported_interfaces
is empty)?

[1] https://lore.kernel.org/r/3bbacda3-4225-4536-a4b4-3aa31a47a3aa@bootlin.com

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117123956.11981-1-ansuelsmth@gmail.com?part=3

  reply	other threads:[~2026-11-18 12:42 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 12:39 [PATCH net-next v22 00/15] net: pcs: Introduce support for fwnode PCS Christian Marangi
2026-11-17 12:39 ` [PATCH net-next v22 01/15] net: phylink: make PCS phylink instance access RCU protected Christian Marangi
2026-11-18 12:42   ` sashiko-bot
2026-11-17 12:39 ` [PATCH net-next v22 02/15] net: phylink: keep and use MAC supported_interfaces in phylink struct Christian Marangi
2026-11-17 12:39 ` [PATCH net-next v22 03/15] net: phylink: introduce internal phylink PCS handling Christian Marangi
2026-11-18 12:42   ` sashiko-bot [this message]
2026-11-17 12:39 ` [PATCH net-next v22 04/15] net: pcs: implement Firmware node support for PCS driver Christian Marangi
2026-11-18 12:42   ` sashiko-bot
2026-11-17 12:39 ` [PATCH net-next v22 05/15] net: phylink: save phylink instance fwnode on phylink_create Christian Marangi
2026-11-17 12:39 ` [PATCH net-next v22 06/15] net: phylink: make phylink_validate state locked Christian Marangi
2026-11-17 12:39 ` [PATCH net-next v22 07/15] net: phylink: add capabilities helpers and track modified advertising Christian Marangi
2026-11-18 12:42   ` sashiko-bot
2026-11-17 12:39 ` [PATCH net-next v22 08/15] net: phylink: support PCS provider release Christian Marangi
2026-11-18 12:42   ` sashiko-bot
2026-11-17 12:39 ` [PATCH net-next v22 09/15] net: phylink: support late PCS provider attach Christian Marangi
2026-11-18 12:42   ` sashiko-bot
2026-11-17 12:39 ` [PATCH net-next v22 10/15] net: Document PCS subsystem Christian Marangi
2026-11-17 12:39 ` [PATCH net-next v22 11/15] MAINTAINERS: add myself as PCS subsystem maintainer Christian Marangi
2026-11-17 12:39 ` [PATCH net-next v22 12/15] net: phylink: add .pcs_link_down PCS OP Christian Marangi
2026-11-17 12:39 ` [PATCH net-next v22 13/15] dt-bindings: net: pcs: Document support for Airoha Ethernet PCS Christian Marangi
2026-11-18 12:42   ` sashiko-bot
2026-11-17 12:39 ` [PATCH net-next v22 14/15] net: pcs: airoha: add PCS driver for Airoha AN7581 SoC Christian Marangi
2026-11-18 12:42   ` sashiko-bot
2026-11-17 12:39 ` [PATCH net-next v22 15/15] net: airoha: add phylink support Christian Marangi
2026-11-17 12:43 ` [PATCH net-next v22 00/15] net: pcs: Introduce support for fwnode PCS netdev-bot+sinfo
2026-11-17 12:47   ` Christian Marangi

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-220923@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