Commit 56fe63b
net: phylink: add lock for serializing concurrent pl->phydev writes with resolver
[ Upstream commit 0ba5b2f ]
Currently phylink_resolve() protects itself against concurrent
phylink_bringup_phy() or phylink_disconnect_phy() calls which modify
pl->phydev by relying on pl->state_mutex.
The problem is that in phylink_resolve(), pl->state_mutex is in a lock
inversion state with pl->phydev->lock. So pl->phydev->lock needs to be
acquired prior to pl->state_mutex. But that requires dereferencing
pl->phydev in the first place, and without pl->state_mutex, that is
racy.
Hence the reason for the extra lock. Currently it is redundant, but it
will serve a functional purpose once mutex_lock(&phy->lock) will be
moved outside of the mutex_lock(&pl->state_mutex) section.
Another alternative considered would have been to let phylink_resolve()
acquire the rtnl_mutex, which is also held when phylink_bringup_phy()
and phylink_disconnect_phy() are called. But since phylink_disconnect_phy()
runs under rtnl_lock(), it would deadlock with phylink_resolve() when
calling flush_work(&pl->resolve). Additionally, it would have been
undesirable because it would have unnecessarily blocked many other call
paths as well in the entire kernel, so the smaller-scoped lock was
preferred.
Link: https://lore.kernel.org/netdev/aLb6puGVzR29GpPx@shell.armlinux.org.uk/
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Link: https://patch.msgid.link/20250904125238.193990-1-vladimir.oltean@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Stable-dep-of: e2a10da ("net: phy: transfer phy_config_inband() locking responsibility to phylink")
Signed-off-by: Sasha Levin <sashal@kernel.org>1 parent eb148d8 commit 56fe63b
1 file changed
Lines changed: 16 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
| 71 | + | |
70 | 72 | | |
71 | 73 | | |
72 | 74 | | |
| |||
1568 | 1570 | | |
1569 | 1571 | | |
1570 | 1572 | | |
| 1573 | + | |
1571 | 1574 | | |
1572 | 1575 | | |
| 1576 | + | |
| 1577 | + | |
1573 | 1578 | | |
1574 | 1579 | | |
1575 | 1580 | | |
| |||
1603 | 1608 | | |
1604 | 1609 | | |
1605 | 1610 | | |
1606 | | - | |
| 1611 | + | |
1607 | 1612 | | |
1608 | 1613 | | |
1609 | 1614 | | |
1610 | | - | |
| 1615 | + | |
1611 | 1616 | | |
1612 | 1617 | | |
1613 | 1618 | | |
| |||
1671 | 1676 | | |
1672 | 1677 | | |
1673 | 1678 | | |
| 1679 | + | |
1674 | 1680 | | |
1675 | 1681 | | |
1676 | 1682 | | |
| |||
1806 | 1812 | | |
1807 | 1813 | | |
1808 | 1814 | | |
| 1815 | + | |
1809 | 1816 | | |
1810 | 1817 | | |
1811 | 1818 | | |
| |||
2066 | 2073 | | |
2067 | 2074 | | |
2068 | 2075 | | |
| 2076 | + | |
2069 | 2077 | | |
2070 | 2078 | | |
2071 | 2079 | | |
| |||
2111 | 2119 | | |
2112 | 2120 | | |
2113 | 2121 | | |
| 2122 | + | |
2114 | 2123 | | |
2115 | 2124 | | |
2116 | 2125 | | |
| |||
2289 | 2298 | | |
2290 | 2299 | | |
2291 | 2300 | | |
| 2301 | + | |
2292 | 2302 | | |
2293 | 2303 | | |
2294 | 2304 | | |
| |||
2298 | 2308 | | |
2299 | 2309 | | |
2300 | 2310 | | |
2301 | | - | |
| 2311 | + | |
| 2312 | + | |
2302 | 2313 | | |
| 2314 | + | |
| 2315 | + | |
2303 | 2316 | | |
2304 | 2317 | | |
2305 | 2318 | | |
| |||
0 commit comments