๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24842

Re: [PATCH net-next v23 03/15] net: phylink: introduce internal phylink PCS handling

#24842
From: netdev-bot+sashiko
Date: Mon, 30 Nov 2026 23:47
229 lines
16885 bytes
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
Technical Details
Message-ID: <179608245404.3146.9305144543922362163@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374529-linux-kernel-netdev=dewy.ru
References: <20261129230558.612526-4-ansuelsmth@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374529-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v23 03/15] net: phylink: introduce internal
 phylink PCS handling
Date: Mon, 30 Nov 2026 23:47:34 +0000
Organization: Usenet Network
Message-ID: <179608245404.3146.9305144543922362163@kernel.org>
References: <20261129230558.612526-4-ansuelsmth@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1568340"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:qXRnZcDePTsg79C2kaJrDG/Q6Ng= sha256:pKrLDCoMEBSSZN3X/u7IsGR7u3Mm1jHvdGolrf7mpLA=
	sha1:vSrvlAUzsE24diuFy5KIr4cH56M= sha256:sTBPKwOndS7cj79k2K0XGdrakDWBS9RUKYojwzjaeoE=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 36067126019; Tue,  1 Dec 2026 02:47:55 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id oHNWNG-BLoBm;
	Tue,  1 Dec 2026 02:47:51 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-374529-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id 2CEAF126015; Tue,  1 Dec 2026 02:47:42 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id 4E3B5241A7; Mon, 30 Nov 2026 23:47:39 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796082457;
	b=GqkMtqSUc42T8Da45OE8D+ZL2WQCDH5Lh02cBWYbm3NeF2S9nJxtd0tIFDPQ+gXVPsl/
	 kzGiCe0DKkMBgXeLos8KgvTnehgaFAQrfOYEDkqA9mQNOGp02qRiMDWPgqR/8Ap1NVDXu
	 1tB/u0Qc/4sPp3KeQHdO9hfZWCdgd5mR4sI73+F7OWGFXZxNpw0vc5tBM6lPsQtA46Of3
	 XwSIjJ154Y6aQXG13DRmzu7/JUkdGt7wFWYcOcwBx5KRMMIAehMaSUtq/uI6rgh/QM6/k
	 AwPPXePzNBH0tRFjIC2YR3fXDMWZqTu5GDJcvLdLRyI/zARysbBcN3pazz5srAkw+NQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796082457;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=rMgGKCL4q3dYBOheD2SpcsKzyODRVp6Y11V14UdrXAs=;
	b=D9NbBlU+T2nU7CT0IvGNWDGTZeivIX5oWeym3IGou00ZExqJ0xV/RTMBuhkvWJ0Qtlpq
	 mRm4I5UUyqBaWOMv4MABafuQa+vwy8xMKjPgn7iWArdrZWGXosT4/SHI5KoExRu/5OfQ4
	 qFvQCUH7HpSDa8TCZ3REGfqtdVfQe3EB/jbeNVq36I0LHpwa/wg9SUn4rDs7D5qLtAiiD
	 7WEhwGzFEYVEsBgLn2ERtErCiHv8jyU7spvBZkAI4vMrB5LklfG9azCY1HNg8FU45df+u
	 D4/x7aqMsKqEfQBLZTBu0JgXDN5VxJY3zgR/ehmBw5CxzRel0t5SYeMrnsd2DMjHJnw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=h+IGre+V;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 813E9606A33F;
	Mon, 30 Nov 2026 23:47:37 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=h+IGre+V
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796082456;
	b=gfaolhC4iyFYZ8uFT8hdlzrAEMJv0VhzsK3oUqHFgfQyqD73w/q4ElHUcWU7p1VfrjxL
	 3qcN9Yua6dnp7+anHnUfQz1tAJxx7IKPMYFenuVwArqwQT7Q7sJ6+n44bWvdwdedVJryD
	 zcBwcgy113In02uiz8S5OasH3OZR7jwfQ2vE0zqrEIsXxmcmZjPREtIsYGL/axJb327E3
	 k7KgecxrIU5SjTzJ9ePa6stJ/XN852hvzX/QDKe9GsTvrlgrnwEjLhF2OfSyEM5DNxAPU
	 IqbfOF0xkgtQmdX3m8R0ggbVh7DOT3HoULFIV33XK/CCgeqQhVC8jj3fKHWLdTjDylA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796082456;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=rMgGKCL4q3dYBOheD2SpcsKzyODRVp6Y11V14UdrXAs=;
	b=xFxkwg4x7Xa/GQPsRtA+k5i3VSdKGpVxW05aOYN2oxDfjxWEVtmC9jaXZk4VFV4ah94R
	 +D7f+d6HiOowjksQmPo+sKCHuDWMdhMKRn9a9sOKLADYlPtsS4UIsDaKUVEZtfcxyJcnr
	 UBH5VKk6AQh6Q6GrEKoLmK75p9I0AlPF8cDIL2y0iBI281iM2Le/nJqavnOS1TB7jkyBB
	 YPqMaxbbEAJmM/n+OeGGi2RpUcOiCsmVYQbCbUvrGsjAhqOR6BSX1ScJHsVZj7G7l4g7m
	 Og++Jyla50rWSQz0ycz9zfsK/bEqOwCS5CbDxfg4PF8aAyDbCbo+D0FxpoT0O6u6vFA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=h+IGre+V;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1F74606A686;
	Mon, 30 Nov 2026 23:47:36 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 86C9E1F0089C;
	Mon, 30 Nov 2026 23:47:34 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796082456;
	bh=rMgGKCL4q3dYBOheD2SpcsKzyODRVp6Y11V14UdrXAs=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=h+IGre+VdN22GZsef/SNoCa92QOl42dnO1ARPRt+APLRtWUU8wr0qAz0VsrOZh7n/
	 D9nsRoadXubTK9dTAw+wq75Hhc6mgbovwFjxu99lGoWryyMEo2w52lQujp2CvPv78x
	 hCuRSvtfCQ2+o81bMUysW8vfyHu8Abt4rQIjTX/kz8gfbyCsqqFEykGGcFlu4e3FTV
	 +v11WOyqq35hGSA+gLlXu3kiRkQNI7XT1H/R60zzSy+h3JlmDkHPvMFWRifVISvWhL
	 UI50A0uD0eHD6A03f7xjeUIOGo3Nc/OCxs/1ogylSB4lCXLIHA5rGR1dfE2EF0hzb4
	 FbhqBeTPKYQZQ==
X-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
X-In-Reply-To: <20261129230558.612526-4-ansuelsmth@gmail.com>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list