All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Christian Marangi" <ansuelsmth@gmail.com>
Cc: devicetree@vger.kernel.org, conor+dt@kernel.org, robh@kernel.org
Subject: Re: [PATCH net-next v7 09/12] net: phylink: add .pcs_link_down PCS OP
Date: Tue, 16 Jun 2026 14:32:20 +0000	[thread overview]
Message-ID: <20260616143220.DF7D81F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260615122950.22281-10-ansuelsmth@gmail.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Data Race and Use-After-Free in `phylink_destroy()` due to incorrect cancellation order
- [Medium] Missing Link Teardown Callback (pcs_link_down) on PCS release
- [Low] Missing Kernel-Doc for `pcs_link_down`
--

commit 33892cef9bd3c637bb8d5d91bf19b186872ff8bf
Author: Christian Marangi <ansuelsmth@gmail.com>

net: phylink: add .pcs_link_down PCS OP

Permit for PCS driver to define specific operation to tear down the link
between the MAC and the PCS. This might be needed for some PCS that reset
counter or require special reset to correctly work if the link needs to be
restored later.

> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index 0734c98498a99..1bedac517d213 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c
[ ... ]
> @@ -1736,6 +1742,9 @@ static void phylink_link_down(struct phylink *pl)
>  
>  	pl->mac_ops->mac_link_down(pl->config, pl->act_link_an_mode,
>  				   pl->cur_interface);
> +
> +	phylink_pcs_link_down(pl->pcs);

[Severity: Medium]
Will this callback be missed if a PCS is released?

In phylink_release_pcs(), pl->pcs is disabled and set to NULL while the link
is logically UP:

	if (pl->pcs == pcs) {
		phylink_pcs_disable(pl->pcs);
		pl->force_major_config = true;
		pl->pcs = NULL;
	}

When this triggers phylink_resolve(), which attempts to bring the link down
using phylink_link_down(), pl->pcs is already NULL. The released PCS never
receives its .pcs_link_down() callback, which might break link lifecycle
symmetry and fail to reset internal counters.

> +
>  	phylink_info(pl, "Link is Down\n");
>  }
>  
> diff --git a/include/linux/phylink.h b/include/linux/phylink.h
> index 15e6b1a39dfe2..eb6c6ca34147f 100644
> --- a/include/linux/phylink.h
> +++ b/include/linux/phylink.h
> @@ -528,6 +528,7 @@ struct phylink_pcs {
>   * @pcs_an_restart: restart 802.3z BaseX autonegotiation.
>   * @pcs_link_up: program the PCS for the resolved link configuration
>   *               (where necessary).
> + * @pcs_link_down: tear down link between MAC and PCS.

[Severity: Low]
Is there a missing kernel-doc entry for the function signature of
pcs_link_down?

The @pcs_link_down callback is added here, but the detailed function signature
appears to be missing from the corresponding "#if 0" block in
include/linux/phylink.h (for kernel-doc purposes only), where other PCS
callbacks like pcs_link_up() are fully documented.

>   * @pcs_disable_eee: optional notification to PCS that EEE has been disabled
>   *		     at the MAC.
>   * @pcs_enable_eee: optional notification to PCS that EEE will be enabled at
[ ... ]


[Severity: High]
Does the incorrect cancellation order in phylink_destroy() cause a data race
and use-after-free?

In phylink_destroy(), pl->pcs_list is modified without holding
pl->state_mutex:

	/* Remove every PCS from phylink PCS list */
	list_for_each_entry_safe(pcs, tmp, &pl->pcs_list, list)
		list_del(&pcs->list);

	cancel_work_sync(&pl->resolve);

If the background work pl->resolve is currently running, the worker thread
executes phylink_major_config() and iterates over pl->pcs_list while holding
pl->state_mutex. Because phylink_destroy() modifies the list concurrently
without synchronization and before canceling the work, the worker thread can
traverse corrupted list pointers, resulting in a use-after-free. Should
cancel_work_sync(&pl->resolve) be called before modifying the list?

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

  reply	other threads:[~2026-06-16 14:32 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-15 12:29 [PATCH net-next v7 00/12] net: pcs: Introduce support for fwnode PCS Christian Marangi
2026-06-15 12:29 ` [PATCH net-next v7 01/12] net: phylink: keep and use MAC supported_interfaces in phylink struct Christian Marangi
2026-06-15 13:33   ` Maxime Chevallier
2026-06-15 14:18     ` Christian Marangi
2026-06-16 14:32   ` sashiko-bot
2026-06-15 12:29 ` [PATCH net-next v7 02/12] net: phylink: introduce internal phylink PCS handling Christian Marangi
2026-06-15 13:31   ` Maxime Chevallier
2026-06-15 14:17     ` Christian Marangi
2026-06-16 14:32   ` sashiko-bot
2026-06-15 12:29 ` [PATCH net-next v7 03/12] net: phylink: add phylink_release_pcs() to externally release a PCS Christian Marangi
2026-06-16 14:32   ` sashiko-bot
2026-06-15 12:29 ` [PATCH net-next v7 04/12] net: pcs: implement Firmware node support for PCS driver Christian Marangi
2026-06-16 14:32   ` sashiko-bot
2026-06-15 12:29 ` [PATCH net-next v7 05/12] net: phylink: support late PCS provider attach Christian Marangi
2026-06-15 14:07   ` Maxime Chevallier
2026-06-15 14:10     ` Christian Marangi
2026-06-15 14:29       ` Maxime Chevallier
2026-06-15 14:35         ` Christian Marangi
2026-06-15 14:44           ` Maxime Chevallier
2026-06-16 14:32   ` sashiko-bot
2026-06-15 12:29 ` [PATCH net-next v7 06/12] net: Document PCS subsystem Christian Marangi
2026-06-16 14:32   ` sashiko-bot
2026-06-15 12:29 ` [PATCH net-next v7 07/12] MAINTAINERS: add myself as PCS subsystem maintainer Christian Marangi
2026-06-15 12:29 ` [PATCH net-next v7 08/12] of: property: fw_devlink: Add support for "pcs-handle" Christian Marangi
2026-06-15 12:29 ` [PATCH net-next v7 09/12] net: phylink: add .pcs_link_down PCS OP Christian Marangi
2026-06-16 14:32   ` sashiko-bot [this message]
2026-06-15 12:29 ` [PATCH net-next v7 10/12] dt-bindings: net: pcs: Document support for Airoha Ethernet PCS Christian Marangi
2026-06-15 12:29 ` [PATCH net-next v7 11/12] net: pcs: airoha: add PCS driver for Airoha AN7581 SoC Christian Marangi
2026-06-15 16:31   ` Benjamin Larsson
2026-06-16 14:32   ` sashiko-bot
2026-06-15 12:29 ` [PATCH net-next v7 12/12] net: airoha: add phylink support Christian Marangi
2026-06-15 16:07   ` Benjamin Larsson
2026-06-16 14:32   ` sashiko-bot

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=20260616143220.DF7D81F00A3D@smtp.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.