Skip to contentSkip to conversation

net: phy: mscc: fix deadlock in vsc85xx_default_config

PATCH Superseded Quentin Schulz 2 participants 3 messages Nov 22, 2018 – Nov 23, 2018

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: phy: mscc: fix deadlock in vsc85xx_default_config

The vsc85xx_default_config function called in the vsc85xx_config_init function which is used by VSC8530, VSC8531, VSC8540 and VSC8541 PHYs mistakenly calls phy_read and phy_write in-between phy_select_page and phy_restore_page.

phy_select_page and phy_restore_page actually take and release the MDIO bus lock so __phy_write and __phy_read (which assume that you already have the MDIO bus lock unlike phy_write and phy_read) should be used for any call in between the two said functions.

Let's fix this deadlock.

Fixes 6a0bfbbe20b0 ("net: phy: mscc: migrate to phy_select/restore_page functions")
---
 drivers/net/phy/mscc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/phy/mscc.c +2 -2
index 62269e578718..6856fe4d1a60 100644
@@ -814,10 +814,10 @@ static int vsc85xx_default_config(struct phy_device *phydev)
 	if (rc < 0)
 		goto out_unlock;
 
-	reg_val = phy_read(phydev, MSCC_PHY_RGMII_CNTL);
+	reg_val = __phy_read(phydev, MSCC_PHY_RGMII_CNTL);
 	reg_val &= ~(RGMII_RX_CLK_DELAY_MASK);
 	reg_val |= (RGMII_RX_CLK_DELAY_1_1_NS << RGMII_RX_CLK_DELAY_POS);
-	phy_write(phydev, MSCC_PHY_RGMII_CNTL, reg_val);
+	__phy_write(phydev, MSCC_PHY_RGMII_CNTL, reg_val);
 
 out_unlock:
 	rc = phy_restore_page(phydev, rc, rc > 0 ? 0 : rc);
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 24 lines · Quentin Schulz

The vsc85xx_default_config function called in the vsc85xx_config_init function which is used by VSC8530, VSC8531, VSC8540 and VSC8541 PHYs mistakenly calls phy_read and phy_write in-between phy_select_page and phy_restore_page.

phy_select_page and phy_restore_page actually take and release the MDIO bus lock so __phy_write and __phy_read (which assume that you already have the MDIO bus lock unlike phy_write and phy_read) should be used for any call in between the two said functions.

Let's fix this deadlock.

Fixes 6a0bfbbe20b0 ("net: phy: mscc: migrate to phy_select/restore_page functions")
---
 drivers/net/phy/mscc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/phy/mscc.c +0 -0
index 62269e578718..6856fe4d1a60 100644

drivers/net/phy/mscc.c static int vsc85xx_default_config(struct phy_device *phydev) · line 820

Quoted 9 lines
drivers/net/phy/mscc.c +2 -2
@@ -814,10 +814,10 @@ static int vsc85xx_default_config(struct phy_device *phydev)
 	if (rc < 0)
 		goto out_unlock;
 
-	reg_val = phy_read(phydev, MSCC_PHY_RGMII_CNTL);
+	reg_val = __phy_read(phydev, MSCC_PHY_RGMII_CNTL);
 	reg_val &= ~(RGMII_RX_CLK_DELAY_MASK);
 	reg_val |= (RGMII_RX_CLK_DELAY_1_1_NS << RGMII_RX_CLK_DELAY_POS);
-	phy_write(phydev, MSCC_PHY_RGMII_CNTL, reg_val);
+	__phy_write(phydev, MSCC_PHY_RGMII_CNTL, reg_val);

Hi Quentin

You appear to be only accessing a single register, read/modify/write. I think you can use phy_modify_paged(), which will take care of all the locking for you.

Andrew

#2 lore raw

Hi Andrew,

Quoted 37 lines · Andrew Lunn
Quoted 24 lines · Quentin Schulz

The vsc85xx_default_config function called in the vsc85xx_config_init function which is used by VSC8530, VSC8531, VSC8540 and VSC8541 PHYs mistakenly calls phy_read and phy_write in-between phy_select_page and phy_restore_page.

phy_select_page and phy_restore_page actually take and release the MDIO bus lock so __phy_write and __phy_read (which assume that you already have the MDIO bus lock unlike phy_write and phy_read) should be used for any call in between the two said functions.

Let's fix this deadlock.

Fixes 6a0bfbbe20b0 ("net: phy: mscc: migrate to phy_select/restore_page functions")
---
 drivers/net/phy/mscc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/phy/mscc.c +0 -0
index 62269e578718..6856fe4d1a60 100644

drivers/net/phy/mscc.c static int vsc85xx_default_config(struct phy_device *phydev) · line 820

Quoted 9 lines
drivers/net/phy/mscc.c +2 -2
@@ -814,10 +814,10 @@ static int vsc85xx_default_config(struct phy_device *phydev)
 	if (rc < 0)
 		goto out_unlock;
 
-	reg_val = phy_read(phydev, MSCC_PHY_RGMII_CNTL);
+	reg_val = __phy_read(phydev, MSCC_PHY_RGMII_CNTL);
 	reg_val &= ~(RGMII_RX_CLK_DELAY_MASK);
 	reg_val |= (RGMII_RX_CLK_DELAY_1_1_NS << RGMII_RX_CLK_DELAY_POS);
-	phy_write(phydev, MSCC_PHY_RGMII_CNTL, reg_val);
+	__phy_write(phydev, MSCC_PHY_RGMII_CNTL, reg_val);

Hi Quentin

Quoted 4 lines

You appear to be only accessing a single register, read/modify/write. I think you can use phy_modify_paged(), which will take care of all the locking for you.

Grmbl... Of course :)

Thanks,
Quentin