From: Alessandro B Maurici <abmaurici@gmail.com>
To: netdev@vger.kernel.org
Cc: Andrew Lunn <andrew@lunn.ch>,
Heiner Kallweit <hkallweit1@gmail.com>,
Russell King <linux@armlinux.org.uk>,
"David S. Miller" <davem@davemloft.net>,
Alessandro B Maurici <abmaurici@gmail.com>
Subject: [PATCH] phy: fix possible double lock calling link changed handler
Date: Mon, 22 Nov 2021 23:55:48 -0300 [thread overview]
Message-ID: <20211122235548.38b3fc7c@work> (raw)
From: Alessandro B Maurici <abmaurici@gmail.com>
Releases the phy lock before calling phy_link_change to avoid any worker
thread lockup. Some network drivers(eg Microchip's LAN743x), make a call to
phy_ethtool_get_link_ksettings inside the link change handler, and, due to
the commit c10a485c3de5 ("phy: phy_ethtool_ksettings_get: Lock the phy for
consistency"), this will cause a lockup.
As that mutex call is needed for consistency, we need to release the lock,
if previously locked, before calling the handler to prevent issues.
Signed-off-by: Alessandro B Maurici <abmaurici@gmail.com>
---
drivers/net/phy/phy.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index beb2b66da132..0914e339e623 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -58,13 +58,31 @@ static const char *phy_state_to_str(enum phy_state st)
static void phy_link_up(struct phy_device *phydev)
{
+ bool must_relock = false;
+
+ if (mutex_is_locked(&phydev->lock)) {
+ must_relock = true;
+ mutex_unlock(&phydev->lock);
+ }
phydev->phy_link_change(phydev, true);
+ if (must_relock)
+ mutex_lock(&phydev->lock);
+
phy_led_trigger_change_speed(phydev);
}
static void phy_link_down(struct phy_device *phydev)
{
+ bool must_relock = false;
+
+ if (mutex_is_locked(&phydev->lock)) {
+ must_relock = true;
+ mutex_unlock(&phydev->lock);
+ }
phydev->phy_link_change(phydev, false);
+ if (must_relock)
+ mutex_lock(&phydev->lock);
+
phy_led_trigger_change_speed(phydev);
}
next reply other threads:[~2021-11-23 2:55 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-23 2:55 Alessandro B Maurici [this message]
2021-11-23 4:18 ` [PATCH] phy: fix possible double lock calling link changed handler Andrew Lunn
2021-11-23 4:49 ` Alessandro B Maurici
2021-11-23 8:21 ` Heiner Kallweit
2021-11-23 14:11 ` Andrew Lunn
2021-11-23 16:06 ` Alessandro B Maurici
2021-11-23 20:32 ` Heiner Kallweit
2021-11-23 22:31 ` Alessandro B Maurici
2021-11-23 14:09 ` Andrew Lunn
2021-11-23 14:14 ` Russell King (Oracle)
2021-11-23 15:58 ` Alessandro B Maurici
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=20211122235548.38b3fc7c@work \
--to=abmaurici@gmail.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=hkallweit1@gmail.com \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).