From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5676A606A6B4 for ; Mon, 30 Nov 2026 23:47:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=YI7uzd7a; 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 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version: Content-Transfer-Encoding:Content-Type:References:In-Reply-To:Message-ID:Date :Cc:To:From:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=rMgGKCL4q3dYBOheD2SpcsKzyODRVp6Y11V14UdrXAs=; b=YI7uzd7aQR684X1pWG6Bvn6oFd Qd0eGapoiaharqJyY18KpttNoo8mUYqFql6kD95tAUT7EDpxJyQVv/1XsIEI93ACY+IQT1w2CVZK2 BHNhOeqIwpN1jN+wXD2qXjjc+YHu62tjB6vJFSUp0/1j0Sstyqen3wZA6Tlos6nGCvr0uALwQGtPn nQJPeimiK3me6INHRKcBQ3ZzXya38g5JDHz7uAeZ2KuKk1B4TkPlb+6aV2/2gyLGus68PuiNjywyc /ZQimsYmHyUhFu+vnL1OkCQ7daJzi3mAjrYZ4hd3nnDRZ9O43gxE/H2R+d3/G/70gx2Pji7JsTB41 BmQdRfzg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYB65-00000006429-0ECJ; Mon, 30 Nov 2026 23:47:49 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYB5t-000000063xl-2P0s; Mon, 30 Nov 2026 23:47:37 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id B38B960E76; Mon, 30 Nov 2026 23:47:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 86C9E1F0089C; Mon, 30 Nov 2026 23:47:34 +0000 (UTC) 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== Subject: Re: [PATCH net-next v23 03/15] net: phylink: introduce internal phylink PCS handling 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 Date: Mon, 30 Nov 2026 23:47:34 +0000 Message-ID: <179608245404.3146.9305144543922362163@kernel.org> In-Reply-To: <20261129230558.612526-4-ansuelsmth@gmail.com> References: <20261129230558.612526-4-ansuelsmth@gmail.com> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Archived-By: MIME-Version: 1.0 X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" X-Spam-Status: No, score=-10.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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