1. Jan 04, 2018
    • David S. Miller's avatar
      Merge branch 'net-Resolve-races-in-phy-accessors' · 318ff60e
      David S. Miller authored
      
      
      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: default avatarDavid S. Miller <davem@davemloft.net>
      318ff60e
    • Russell King's avatar
      net: phy: convert read-modify-write to phy_modify() · fea23fb5
      Russell King authored
      
      
      Convert read-modify-write sequences in at803x, Marvell and core phylib
      to use phy_modify() to ensure safety.
      
      Signed-off-by: default avatarRussell King <rmk+kernel@armlinux.org.uk>
      Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      fea23fb5
    • Russell King's avatar
      net: phy: add phy_modify() accessor · 2b74e5be
      Russell King authored
      
      
      Add phy_modify() convenience accessor to complement the mdiobus
      counterpart.
      
      Signed-off-by: default avatarRussell King <rmk+kernel@armlinux.org.uk>
      Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      2b74e5be
    • Russell King's avatar
      net: phy: marvell: fix paged access races · 424ca4c5
      Russell King authored
      
      
      For paged accesses to be truely safe, we need to hold the bus lock to
      prevent anyone else gaining access to the registers while we modify
      them.
      
      The phydev->lock mutex does not do this: userspace via the MII ioctl
      can still sneak in and read or write any register while we are on a
      different page, and the suspend/resume methods can be called by a
      thread different to the thread polling the phy status.
      
      Races have been observed with mvneta on SolidRun Clearfog with phylink,
      particularly between the phylib worker reading the PHYs status, and
      the thread resuming mvneta, calling phy_start() which then calls
      through to m88e1121_config_aneg_rgmii_delays(), which tries to
      read-modify-write the MSCR register:
      
      	CPU0			CPU1
      	marvell_read_status_page()
      	marvell_set_page(phydev, MII_MARVELL_FIBER_PAGE)
      	...
      				m88e1121_config_aneg_rgmii_delays()
      				set_page(MII_MARVELL_MSCR_PAGE)
      				phy_read(phydev, MII_88E1121_PHY_MSCR_REG)
      	marvell_set_page(phydev, MII_MARVELL_COPPER_PAGE);
      	...
      				phy_write(phydev, MII_88E1121_PHY_MSCR_REG)
      
      The result of this is we end up writing the copper page register 21,
      which causes the copper PHY to be disabled, and the link partner sees
      the link immediately go down.
      
      Solve this by taking the bus lock instead of the PHY lock, thereby
      preventing other accesses to the PHY while we are accessing other PHY
      pages.
      
      Signed-off-by: default avatarRussell King <rmk+kernel@armlinux.org.uk>
      Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      424ca4c5
    • Russell King's avatar
      net: phy: add paged phy register accessors · 78ffc4ac
      Russell King authored
      
      
      Add a set of paged phy register accessors which are inherently safe in
      their design against other accesses interfering with the paged access.
      
      Signed-off-by: default avatarRussell King <rmk+kernel@armlinux.org.uk>
      Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      78ffc4ac
    • Russell King's avatar
      net: phy: add unlocked accessors · 788f9933
      Russell King authored
      
      
      Add unlocked versions of the bus accessors, which allows access to the
      bus with all the tracing. These accessors validate that the bus mutex
      is held, which is a basic requirement for all mii bus accesses.
      
      Also added is a read-modify-write unlocked accessor with the same
      locking requirements.
      
      Signed-off-by: default avatarRussell King <rmk+kernel@armlinux.org.uk>
      Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      788f9933
    • Russell King's avatar
      net: phy: use unlocked accessors for indirect MMD accesses · 1b2dea2e
      Russell King authored
      
      
      Use unlocked accessors for indirect MMD accesses to clause 22 PHYs.
      This permits tracing of these accesses.
      
      Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
      Signed-off-by: default avatarRussell King <rmk+kernel@armlinux.org.uk>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      1b2dea2e
    • Russell King's avatar
      net: mdiobus: add unlocked accessors · 34dc08e4
      Russell King authored
      
      
      Add unlocked versions of the bus accessors, which allows access to the
      bus with all the tracing. These accessors validate that the bus mutex
      is held, which is a basic requirement for all mii bus accesses.
      
      Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
      Signed-off-by: default avatarRussell King <rmk+kernel@armlinux.org.uk>
      Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
      34dc08e4
  2. Jan 03, 2018