netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] phy: fix possible double lock calling link changed handler
@ 2021-11-23  2:55 Alessandro B Maurici
  2021-11-23  4:18 ` Andrew Lunn
  0 siblings, 1 reply; 11+ messages in thread
From: Alessandro B Maurici @ 2021-11-23  2:55 UTC (permalink / raw)
  To: netdev
  Cc: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
	Alessandro B Maurici

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);
 }
 


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-11-23 22:31 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-23  2:55 [PATCH] phy: fix possible double lock calling link changed handler Alessandro B Maurici
2021-11-23  4:18 ` 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

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).