Skip to content

Commit

Permalink
Merge branch 'net-Resolve-races-in-phy-accessors'
Browse files Browse the repository at this point in the history
Russell King says:

====================
Resolve races in phy accessors

This series resolves races with various accesses to PHY registers.
The first five patches are necessary before we add phylink support
to mvneta, the remaining three are merely cleanups for unobserved
races, and hence are less critical.

There are two possible classes of races that can occur: where we
write to a page register that changes the meaning of a group of
other registers, and where we read-modify-write a register.

Resolve these races by performing the accesses under the mdio bus
lock, ensuring that no other user can access the bus while the
series of atomic operations are being performed.

These patches have been posted before, and have been modified
along the lines of previous feedback:

- The third patch was originally reviewed by Florian, but as I've
  added __phy_modify() to it, I've removed that attributation.
- Included generic page-based accessors as suggested last time
  around.
- Since we have the unlocked __phy_modify() in this patch series,
  it is sensible to include the changes for this to marvell.c -
  these accessors have to change anyway to avoid deadlocks on the
  mdio bus lock.

I haven't been able to test the at803x.c changes yet beyond compile
testing - although I do have systems with an ar8035 PHY.  However,
they should be straight forward to review.

This is targetted for net-next because the races have not been
found in existing drivers, but have been observed with phylink
integrated into mvneta - that's not to say that the races do not
exist today, they are just unobserved (probably through lack of
rigorous enough testing.)  The race provoking condition is detailed
in patch 5.
====================

Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
davem330 committed Jan 3, 2018
2 parents be6e36d + fea23fb commit 318ff60
Show file tree
Hide file tree
Showing 7 changed files with 490 additions and 346 deletions.
20 changes: 4 additions & 16 deletions drivers/net/phy/at803x.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,34 +215,22 @@ static int at803x_suspend(struct phy_device *phydev)
int value;
int wol_enabled;

mutex_lock(&phydev->lock);

value = phy_read(phydev, AT803X_INTR_ENABLE);
wol_enabled = value & AT803X_INTR_ENABLE_WOL;

value = phy_read(phydev, MII_BMCR);

if (wol_enabled)
value |= BMCR_ISOLATE;
value = BMCR_ISOLATE;
else
value |= BMCR_PDOWN;
value = BMCR_PDOWN;

phy_write(phydev, MII_BMCR, value);

mutex_unlock(&phydev->lock);
phy_modify(phydev, MII_BMCR, 0, value);

return 0;
}

static int at803x_resume(struct phy_device *phydev)
{
int value;

value = phy_read(phydev, MII_BMCR);
value &= ~(BMCR_PDOWN | BMCR_ISOLATE);
phy_write(phydev, MII_BMCR, value);

return 0;
return phy_modify(phydev, MII_BMCR, ~(BMCR_PDOWN | BMCR_ISOLATE), 0);
}

static int at803x_probe(struct phy_device *phydev)
Expand Down
Loading

0 comments on commit 318ff60

Please sign in to comment.