wifi: mt76: fix the dev->mutex / iflist_mtx inversion in .config
Subsystems (2)
cover wifi: mt76: fix the dev->mutex / iflist_mtx inversion in .config
mt7921_config() and mt7925_config() hold dev->mutex across ieee80211_iterate_active_interfaces(), which takes local->iflist_mtx. mac80211 goes the other way round: it calls drv_unassign_vif_chanctx() with iflist_mtx held, and mt792x_unassign_vif_chanctx() takes dev->mutex.
Deleting a monitor interface that has a channel assigned hits it. On an MT7922 with lockdep:
ip link set wlp4s0 down
iw phy phy0 interface add mon0 type monitor
ip link set mon0 up
iw dev mon0 set freq 5180
iw dev mon0 del
The splat comes on the last line and nowhere earlier. I reported it in July and had no reply:
https://lore.kernel.org/linux-wireless/[email protected]/
Both ops are reached only from drv_config(), which asserts the wiphy mutex, so ieee80211_iterate_active_interfaces_mtx() applies and never takes iflist_mtx. Reproduced and fixed on an MT7922 and an MT7925: splat before, none after, monitor mode configured and capturing on either arm.
Its kerneldoc says the iterator cannot sleep and these two do, since they send MCU commands. That line is identical to the _atomic variant's directly above it, and no version of the helper has taken RCU, a spinlock or disabled preemption. I can send a doc fix separately if you want one.
The other sites from that report are follow-ups.
Devin Wittmayer (2):
wifi: mt76: mt7921: fix lock inversion between dev->mutex and
iflist_mtx
wifi: mt76: mt7925: fix lock inversion between dev->mutex and
iflist_mtx
drivers/net/wireless/mediatek/mt76/mt7921/main.c | 6 +++--- drivers/net/wireless/mediatek/mt76/mt7925/main.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-)
Signature · 1 line
2.55.0
PATCH 1/2 wifi: mt76: mt7921: fix lock inversion between dev->mutex and iflist_mtx
mt7921_config() holds dev->mutex across ieee80211_iterate_active_interfaces(), which takes local->iflist_mtx. mac80211 uses the opposite order: ieee80211_del_virtual_monitor() holds iflist_mtx while calling drv_unassign_vif_chanctx(), and mt792x_unassign_vif_chanctx() takes dev->mutex.
Deleting a monitor interface that has a channel assigned reaches the second order and lockdep reports the cycle. The driver side of it:
-> #1 (&local->iflist_mtx){+.+.}-{4:4}:
__mutex_lock+0xda/0x1070
ieee80211_iterate_interfaces+0x34/0x70 [mac80211]
mt7921_config+0xb8/0xe0 [mt7921_common]
drv_config+0x63/0x1d0 [mac80211].config is only reached through drv_config(), which asserts the wiphy mutex, so ieee80211_iterate_active_interfaces_mtx() can be used. It walks the same list under the wiphy mutex and never takes iflist_mtx, which drops the driver's dev->mutex -> iflist_mtx edge.
--- drivers/net/wireless/mediatek/mt76/mt7921/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7921/main.c +3 -3
@@ -652,9 +652,9 @@ static int mt7921_config(struct ieee80211_hw *hw, int radio_idx, u32 changed) }if (changed &IEEE80211_CONF_CHANGE_MONITOR ) { -ieee80211_iterate_active_interfaces (hw, -IEEE80211_IFACE_ITER_RESUME_ALL , - mt7921_sniffer_interface_iter, dev); +ieee80211_iterate_active_interfaces_mtx (hw, +IEEE80211_IFACE_ITER_RESUME_ALL , + mt7921_sniffer_interface_iter, dev); } out:
Signature · 1 line
2.55.0
PATCH 2/2 wifi: mt76: mt7925: fix lock inversion between dev->mutex and iflist_mtx
In reply to Devin Wittmayermt7925_config() has the same inversion as mt7921_config(): it holds dev->mutex across ieee80211_iterate_active_interfaces(), which takes local->iflist_mtx, while mac80211 calls drv_unassign_vif_chanctx() with iflist_mtx already held.
.config is only reached through drv_config(), which asserts the wiphy mutex, so use ieee80211_iterate_active_interfaces_mtx() here too.
--- drivers/net/wireless/mediatek/mt76/mt7925/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +3 -3
@@ -816,9 +816,9 @@ static int mt7925_config(struct ieee80211_hw *hw, int radio_idx, u32 changed) }if (changed &IEEE80211_CONF_CHANGE_MONITOR ) { -ieee80211_iterate_active_interfaces (hw, -IEEE80211_IFACE_ITER_RESUME_ALL , - mt7925_sniffer_interface_iter, dev); +ieee80211_iterate_active_interfaces_mtx (hw, +IEEE80211_IFACE_ITER_RESUME_ALL , + mt7925_sniffer_interface_iter, dev); } out:
Signature · 1 line
2.55.0