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, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH net-next v10 03/11] net: phylink: add phylink_release_pcs() to externally release a PCS
Date: Fri, 31 Jul 2026 12:48:15 +0000	[thread overview]
Message-ID: <20260731124815.97F9D1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260730102444.1967900-4-ansuelsmth@gmail.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] phylink_release_pcs() unconditionally calls phylink_link_down(), leading to unbalanced and duplicate mac_link_down() calls if the link is already down.
- [Medium] The polling timer `pl->link_poll` is stopped using non-synchronous `timer_delete()`, allowing it to leak and endlessly poll if racing with the timer callback.
- [Low] Missing WRITE_ONCE() when updating pl->pcs to NULL, causing a data race with concurrent readers.
--

--- Patch [3]: [PATCH net-next v10 03/11] net: phylink: add phylink_release_pcs() to externally release a PCS ---
commit ccb6652ab082daee833a77e32118d4a3d55ac68e
Author: Christian Marangi <ansuelsmth@gmail.com>

net: phylink: add phylink_release_pcs() to externally release a PCS

This commit adds phylink_release_pcs() to externally release a PCS from a
phylink instance. It removes the PCS from the internal list, reparses the
supported interfaces, and triggers a phylink resolve to handle the removal.

> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index a5e2d342a92e1..562e09d1838b0 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c
[ ... ]
> @@ -917,6 +920,63 @@ static void phylink_resolve_an_pause(struct phylink_link_state *state)
>  	}
>  }
>  
> +/**
> + * phylink_release_pcs - Removes a PCS from the phylink PCS available list
> + * @pcs: a pointer to the phylink_pcs struct to be released
> + *
> + * This function release a PCS from the phylink PCS available list if
> + * actually in use. It also refreshes the supported interfaces of the
> + * phylink instance by copying the supported interfaces from the phylink
> + * conf and merging the supported interfaces of the remaining available PCS
> + * in the list and trigger a resolve.
> + */
> +void phylink_release_pcs(struct phylink_pcs *pcs)
> +{
[ ... ]
> +	/*
> +	 * Check if we are removing the PCS currently
> +	 * in use by phylink. If this is the case, tear down
> +	 * the link, force phylink resolve to reconfigure the
> +	 * interface mode, disable the current PCS and set the
> +	 * phylink PCS to NULL.
> +	 */
> +	if (pl->pcs == pcs) {
> +		phylink_link_down(pl);

[Severity: High]
Could this call phylink_link_down() when the link is already down?

If phylink_release_pcs() is called while the link is already administratively
or physically down, we might invoke mac_link_down() a second time. Other
phylink core functions protect against this by checking pl->old_link_state
before tearing down the link:

    if (pl->old_link_state) {
        phylink_link_down(pl);
        pl->old_link_state = false;
    }

Will calling mac_link_down() twice cause unbalanced reference counts or
disable clocks multiple times?

> +		pl->old_link_state = false;
> +		phylink_pcs_poll_stop(pl);

[Severity: Medium]
Does this leave the link_poll timer running if it races with the timer
callback?

Looking at phylink_pcs_poll_stop(), it stops the timer using a
non-synchronous timer_delete():

static void phylink_pcs_poll_stop(struct phylink *pl)
{
    if (pl->cfg_link_an_mode == MLO_AN_INBAND)
        timer_delete(&pl->link_poll);
}

If phylink_release_pcs() runs concurrently with the timer callback on
another CPU, timer_delete() returns immediately. The timer callback
unconditionally re-arms itself with mod_timer(), which would allow the
timer to run indefinitely after the PCS is removed.

Should this use timer_delete_sync() or otherwise ensure the timer is fully
stopped?

> +		phylink_pcs_disable(pl->pcs);
> +
> +		pl->force_major_config = true;
> +		pl->pcs = NULL;

[Severity: Low]
Should this update to pl->pcs use WRITE_ONCE()?

phylink_pcs_change() reads pl->pcs locklessly from asynchronous contexts:
        
    if (!pl || READ_ONCE(pl->pcs) != pcs)

Doing a plain store here could cause a data race with concurrent readers
and trigger KCSAN warnings.

> +	}
> +
> +	mutex_unlock(&pl->state_mutex);
[ ... ]

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

  reply	other threads:[~2026-07-31 12:48 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-30 10:24 [PATCH net-next v10 00/11] net: pcs: Introduce support for fwnode PCS Christian Marangi
2026-07-30 10:24 ` [PATCH net-next v10 01/11] net: phylink: keep and use MAC supported_interfaces in phylink struct Christian Marangi
2026-07-30 10:24 ` [PATCH net-next v10 02/11] net: phylink: introduce internal phylink PCS handling Christian Marangi
2026-07-31 12:48   ` sashiko-bot
2026-07-30 10:24 ` [PATCH net-next v10 03/11] net: phylink: add phylink_release_pcs() to externally release a PCS Christian Marangi
2026-07-31 12:48   ` sashiko-bot [this message]
2026-07-30 10:24 ` [PATCH net-next v10 04/11] net: pcs: implement Firmware node support for PCS driver Christian Marangi
2026-07-31 12:48   ` sashiko-bot
2026-07-30 10:24 ` [PATCH net-next v10 05/11] net: phylink: support late PCS provider attach Christian Marangi
2026-07-31 12:48   ` sashiko-bot
2026-07-30 10:24 ` [PATCH net-next v10 06/11] net: Document PCS subsystem Christian Marangi
2026-07-31 12:48   ` sashiko-bot
2026-07-30 10:24 ` [PATCH net-next v10 07/11] MAINTAINERS: add myself as PCS subsystem maintainer Christian Marangi
2026-07-30 10:24 ` [PATCH net-next v10 08/11] net: phylink: add .pcs_link_down PCS OP Christian Marangi
2026-07-30 10:24 ` [PATCH net-next v10 09/11] dt-bindings: net: pcs: Document support for Airoha Ethernet PCS Christian Marangi
2026-07-30 10:24 ` [PATCH net-next v10 10/11] net: pcs: airoha: add PCS driver for Airoha AN7581 SoC Christian Marangi
2026-07-31 12:48   ` sashiko-bot
2026-07-30 10:24 ` [PATCH net-next v10 11/11] net: airoha: add phylink support Christian Marangi
2026-07-30 11:56   ` Lorenzo Bianconi
2026-07-31 12:48   ` 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=20260731124815.97F9D1F00A3A@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.