Commit 0ba5b2f
net: phylink: add lock for serializing concurrent pl->phydev writes with resolver
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/[email protected]/
Signed-off-by: Vladimir Oltean <[email protected]>
Reviewed-by: Russell King (Oracle) <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>1 parent 03e79de commit 0ba5b2f
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 | | |
| |||
1591 | 1593 | | |
1592 | 1594 | | |
1593 | 1595 | | |
| 1596 | + | |
1594 | 1597 | | |
1595 | 1598 | | |
| 1599 | + | |
| 1600 | + | |
1596 | 1601 | | |
1597 | 1602 | | |
1598 | 1603 | | |
| |||
1626 | 1631 | | |
1627 | 1632 | | |
1628 | 1633 | | |
1629 | | - | |
| 1634 | + | |
1630 | 1635 | | |
1631 | 1636 | | |
1632 | 1637 | | |
1633 | | - | |
| 1638 | + | |
1634 | 1639 | | |
1635 | 1640 | | |
1636 | 1641 | | |
| |||
1694 | 1699 | | |
1695 | 1700 | | |
1696 | 1701 | | |
| 1702 | + | |
1697 | 1703 | | |
1698 | 1704 | | |
1699 | 1705 | | |
| |||
1829 | 1835 | | |
1830 | 1836 | | |
1831 | 1837 | | |
| 1838 | + | |
1832 | 1839 | | |
1833 | 1840 | | |
1834 | 1841 | | |
| |||
2089 | 2096 | | |
2090 | 2097 | | |
2091 | 2098 | | |
| 2099 | + | |
2092 | 2100 | | |
2093 | 2101 | | |
2094 | 2102 | | |
| |||
2134 | 2142 | | |
2135 | 2143 | | |
2136 | 2144 | | |
| 2145 | + | |
2137 | 2146 | | |
2138 | 2147 | | |
2139 | 2148 | | |
| |||
2312 | 2321 | | |
2313 | 2322 | | |
2314 | 2323 | | |
| 2324 | + | |
2315 | 2325 | | |
2316 | 2326 | | |
2317 | 2327 | | |
| |||
2321 | 2331 | | |
2322 | 2332 | | |
2323 | 2333 | | |
2324 | | - | |
| 2334 | + | |
| 2335 | + | |
2325 | 2336 | | |
| 2337 | + | |
| 2338 | + | |
2326 | 2339 | | |
2327 | 2340 | | |
2328 | 2341 | | |
| |||
0 commit comments