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 v20 06/15] net: phylink: make phylink_validate state locked
Date: Sun, 15 Nov 2026 10:45:15 +0000 [thread overview]
Message-ID: <sashiko-outbox-215397@kernel.org> (raw)
In-Reply-To: <20261114104426.235620-7-ansuelsmth@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] net: phylink: lock order inversion between state_mutex and
phy->lock in phylink_validate_mask()
--
commit 15371468f04d0bb04d8068bf4c41584df2589e40
Author: Christian Marangi <ansuelsmth@gmail.com>
net: phylink: make phylink_validate state locked
This commit acquires pl->state_mutex in phylink_validate() and
phylink_validate_mask(), adds unlocked __phylink_validate() and
__phylink_validate_mask() helpers, and asserts that pl->state_mutex is held
in the inner validation functions.
> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index 8a0e87a9062f8..d1bd7109c5668 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c
[ ... ]
> @@ -667,14 +674,30 @@ static int phylink_validate_mask(struct phylink *pl, struct phy_device *phy,
> return phylink_is_empty_linkmode(supported) ? -EINVAL : 0;
> }
>
> -static int phylink_validate(struct phylink *pl, unsigned long *supported,
> - struct phylink_link_state *state)
> +static int phylink_validate_mask(struct phylink *pl, struct phy_device *phy,
> + unsigned long *supported,
> + struct phylink_link_state *state,
> + const unsigned long *interfaces)
> +{
> + int ret;
> +
> + mutex_lock(&pl->state_mutex);
> + ret = __phylink_validate_mask(pl, phy, supported, state, interfaces);
> + mutex_unlock(&pl->state_mutex);
> +
> + return ret;
> +}
[Severity: High]
Does taking pl->state_mutex in phylink_validate_mask() invert the lock order
against phy->lock?
When phylink_bringup_phy() -> phylink_validate_phy() validates a PHY with
non-empty phy->possible_interfaces, __phylink_validate_mask() ->
phylink_validate_one() calls phy_get_rate_matching() under pl->state_mutex,
which takes phy->lock if the PHY driver implements .get_rate_matching:
drivers/net/phy/phy.c:phy_get_rate_matching() {
...
if (phydev->drv->get_rate_matching) {
mutex_lock(&phydev->lock);
ret = phydev->drv->get_rate_matching(phydev, iface);
mutex_unlock(&phydev->lock);
}
...
}
Elsewhere in phylink (including later in phylink_bringup_phy(),
phylink_resolve(), and phylink_phy_change()), phy->lock is acquired before
pl->state_mutex, creating an ABBA deadlock and lockdep splat:
CPU0 CPU1
---- ----
lock(&pl->state_mutex)
lock(&phy->lock)
lock(&phy->lock)
lock(&pl->state_mutex)
*** DEADLOCK ***
CPU0: phylink_bringup_phy() -> phylink_validate_phy() ->
phylink_validate_mask() -> __phylink_validate_mask() ->
phylink_validate_one() -> phy_get_rate_matching()
CPU1: phy_state_machine() -> phylink_phy_change()
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261114104426.235620-1-ansuelsmth@gmail.com?part=6
next prev parent reply other threads:[~2026-11-15 10:45 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-14 10:43 [PATCH net-next v20 00/15] net: pcs: Introduce support for fwnode PCS Christian Marangi
2026-11-14 10:43 ` [PATCH net-next v20 01/15] net: phylink: keep and use MAC supported_interfaces in phylink struct Christian Marangi
2026-11-15 10:45 ` sashiko-bot
2026-11-14 10:43 ` [PATCH net-next v20 02/15] net: phylink: make PCS phylink instance access RCU protected Christian Marangi
2026-11-15 10:45 ` sashiko-bot
2026-11-14 10:43 ` [PATCH net-next v20 03/15] net: phylink: introduce internal phylink PCS handling Christian Marangi
2026-11-15 10:45 ` sashiko-bot
2026-11-14 10:43 ` [PATCH net-next v20 04/15] net: pcs: implement Firmware node support for PCS driver Christian Marangi
2026-11-15 10:45 ` sashiko-bot
2026-11-14 10:43 ` [PATCH net-next v20 05/15] net: phylink: save phylink instance fwnode on phylink_create Christian Marangi
2026-11-14 10:43 ` [PATCH net-next v20 06/15] net: phylink: make phylink_validate state locked Christian Marangi
2026-11-15 10:45 ` sashiko-bot [this message]
2026-11-14 10:43 ` [PATCH net-next v20 07/15] net: phylink: add capabilities helper and track modified advertising Christian Marangi
2026-11-15 10:45 ` sashiko-bot
2026-11-14 10:43 ` [PATCH net-next v20 08/15] net: phylink: support PCS provider release Christian Marangi
2026-11-15 10:45 ` sashiko-bot
2026-11-14 10:43 ` [PATCH net-next v20 09/15] net: phylink: support late PCS provider attach Christian Marangi
2026-11-15 10:45 ` sashiko-bot
2026-11-14 10:43 ` [PATCH net-next v20 10/15] net: Document PCS subsystem Christian Marangi
2026-11-14 10:43 ` [PATCH net-next v20 11/15] MAINTAINERS: add myself as PCS subsystem maintainer Christian Marangi
2026-11-14 10:43 ` [PATCH net-next v20 12/15] net: phylink: add .pcs_link_down PCS OP Christian Marangi
2026-11-14 10:43 ` [PATCH net-next v20 13/15] dt-bindings: net: pcs: Document support for Airoha Ethernet PCS Christian Marangi
2026-11-15 10:45 ` sashiko-bot
2026-11-14 10:43 ` [PATCH net-next v20 14/15] net: pcs: airoha: add PCS driver for Airoha AN7581 SoC Christian Marangi
2026-11-15 10:45 ` sashiko-bot
2026-11-14 10:43 ` [PATCH net-next v20 15/15] net: airoha: add phylink support Christian Marangi
2026-11-15 10:45 ` sashiko-bot
2026-11-14 13:27 ` [PATCH net-next v20 00/15] net: pcs: Introduce support for fwnode PCS Frank Wunderlich
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-215397@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