Skip to contentSkip to conversation

wifi: mt76: mt7996: Fix some locking issues for MLO

PATCH In review Lorenzo Bianconi 2 participants 6 messages Nov 14, 2025

Subsystems (2)
lore
Share & tools
lore

Lorenzo Bianconi

author maintainer
#0 lore raw

cover wifi: mt76: mt7996: Fix some locking issues for MLO

---
Lorenzo Bianconi (4):
wifi: mt76: mt7996: grab mt76 mutex in mt7996_mac_sta_event()
wifi: mt76: mt7996: Move mt7996_update_beacons inside mt76 mutex critical section
wifi: mt76: Move mt76_abort_scan out of mt76_reset_device()
wifi: mt76: mt7996: skip deflink accounting for offchannel links

 drivers/net/wireless/mediatek/mt76/mac80211.c    |  2 --
 drivers/net/wireless/mediatek/mt76/mt7915/mac.c  |  2 ++
 drivers/net/wireless/mediatek/mt76/mt7996/mac.c  |  5 +++--
 drivers/net/wireless/mediatek/mt76/mt7996/main.c | 21 ++++++++++++++-------
 4 files changed, 19 insertions(+), 11 deletions(-)

---
base-commit: c99ebb6132595b4b288a413981197eb076547c5a
change-id: 20251114-mt76-fix-missing-mtx-db664ffcce1a

Best regards,

Signature · 1 line
Lorenzo Bianconi <[email protected]>
author maintainer
#1 lore raw

PATCH 1/4 wifi: mt76: mt7996: grab mt76 mutex in mt7996_mac_sta_event()

Grab mt76 mutex in mt7996_mac_sta_event routine in order to rely on mt76_dereference() utility macro.

Fixes ecd72f9695e7e ("wifi: mt76: mt7996: Support MLO in mt7996_mac_sta_event()")
---
 drivers/net/wireless/mediatek/mt76/mt7996/main.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/main.c +10 -5
index 581314368c5ba566f6050bee86696c4654619176..ad8698cf16242489b92e23befab4d040abbdcac2 100644
@@ -1160,12 +1160,15 @@ mt7996_mac_sta_event(struct mt7996_dev *dev, struct ieee80211_vif *vif,
 	unsigned long links = sta->valid_links;
 	struct ieee80211_link_sta *link_sta;
 	unsigned int link_id;
+	int err = 0;
+
+	mutex_lock(&dev->mt76.mutex);
 
 	for_each_sta_active_link(vif, sta, link_sta, link_id) {
 		struct ieee80211_bss_conf *link_conf;
 		struct mt7996_sta_link *msta_link;
 		struct mt7996_vif_link *link;
-		int i, err;
+		int i;
 
 		link_conf = link_conf_dereference_protected(vif, link_id);
 		if (!link_conf)
@@ -1185,12 +1188,12 @@ mt7996_mac_sta_event(struct mt7996_dev *dev, struct ieee80211_vif *vif,
 						 link, msta_link,
 						 CONN_STATE_CONNECT, true);
 			if (err)
-				return err;
+				goto unlock;
 
 			err = mt7996_mcu_add_rate_ctrl(dev, msta_link->sta, vif,
 						       link_id, false);
 			if (err)
-				return err;
+				goto unlock;
 
 			msta_link->wcid.tx_info |= MT_WCID_TX_INFO_SET;
 			break;
@@ -1199,7 +1202,7 @@ mt7996_mac_sta_event(struct mt7996_dev *dev, struct ieee80211_vif *vif,
 						 link, msta_link,
 						 CONN_STATE_PORT_SECURE, false);
 			if (err)
-				return err;
+				goto unlock;
 			break;
 		case MT76_STA_EVENT_DISASSOC:
 			for (i = 0; i < ARRAY_SIZE(msta_link->twt.flow); i++)
@@ -1219,8 +1222,10 @@ mt7996_mac_sta_event(struct mt7996_dev *dev, struct ieee80211_vif *vif,
 			break;
 		}
 	}
+unlock:
+	mutex_unlock(&dev->mt76.mutex);
 
-	return 0;
+	return err;
 }
 
 static void
Signature · 1 line
2.51.1
author maintainer
#2 lore raw

PATCH 2/4 wifi: mt76: mt7996: Move mt7996_update_beacons inside mt76 mutex critical section

In reply to Lorenzo Bianconi

Move mt7996_update_beacons routine inside mt76 mutex critical section in mt7996_mac_reset_work() in order to run mt7996_vif_conf_link() in mt7996_mcu_add_beacon routine.

Fixes f30906c55a400 ("wifi: mt76: mt7996: disable beacons when going offchannel")
---
 drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +1 -2
index 9501def3e0e3e20132fdbcfe0b1f489694afdc5f..1fac3815c523c05643705b9b6b7263a7fdf2e3a4 100644
@@ -2599,11 +2599,10 @@ void mt7996_mac_reset_work(struct work_struct *work)
 	local_bh_enable();
 
 	ieee80211_wake_queues(hw);
+	mt7996_update_beacons(dev);
 
 	mutex_unlock(&dev->mt76.mutex);
 
-	mt7996_update_beacons(dev);
-
 	mt7996_for_each_phy(dev, phy)
 		ieee80211_queue_delayed_work(hw, &phy->mt76->mac_work,
 					     MT7996_WATCHDOG_TIME);
Signature · 1 line
2.51.1
author maintainer
#3 lore raw

PATCH 3/4 wifi: mt76: Move mt76_abort_scan out of mt76_reset_device()

In reply to Lorenzo Bianconi

Move mt76_abort_scan routine out of mt76_reset_device() in order to avoid a possible deadlock since mt76_reset_device routine is running with mt76 mutex help and mt76_abort_scan_complete() can grab mt76 mutex in some cases.

Fixes b36d55610215a ("wifi: mt76: abort scan/roc on hw restart")
---
 drivers/net/wireless/mediatek/mt76/mac80211.c   | 2 --
 drivers/net/wireless/mediatek/mt76/mt7915/mac.c | 2 ++
 drivers/net/wireless/mediatek/mt76/mt7996/mac.c | 2 ++
 3 files changed, 4 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mac80211.c +0 -2
index 5ceaf78c9ea064bf898c347c611a7ccdf9cb9ebc..5e75861bf6f990dc5745b81224faf705395e894d 100644
@@ -847,8 +847,6 @@ void mt76_reset_device(struct mt76_dev *dev)
 	}
 	rcu_read_unlock();
 
-	mt76_abort_scan(dev);
-
 	INIT_LIST_HEAD(&dev->wcid_list);
 	INIT_LIST_HEAD(&dev->sta_poll_list);
 	dev->vif_mask = 0;
drivers/net/wireless/mediatek/mt76/mt7915/mac.c +2 -0
index 1c0d310146d63bc39357d604b549c83e37c8da35..5caf818e8283438ee3c79124384636cbdd641780 100644
@@ -1451,6 +1451,8 @@ mt7915_mac_full_reset(struct mt7915_dev *dev)
 	if (ext_phy)
 		cancel_delayed_work_sync(&ext_phy->mac_work);
 
+	mt76_abort_scan(&dev->mt76);
+
 	mutex_lock(&dev->mt76.mutex);
 	for (i = 0; i < 10; i++) {
 		if (!mt7915_mac_restart(dev))
drivers/net/wireless/mediatek/mt76/mt7996/mac.c +2 -0
index 1fac3815c523c05643705b9b6b7263a7fdf2e3a4..6fd732a924ab3a4bdc9224b8fd3cc53438e1db60 100644
@@ -2420,6 +2420,8 @@ mt7996_mac_full_reset(struct mt7996_dev *dev)
 	mt7996_for_each_phy(dev, phy)
 		cancel_delayed_work_sync(&phy->mt76->mac_work);
 
+	mt76_abort_scan(&dev->mt76);
+
 	mutex_lock(&dev->mt76.mutex);
 	for (i = 0; i < 10; i++) {
 		if (!mt7996_mac_restart(dev))
Signature · 1 line
2.51.1
author maintainer
#4 lore raw

PATCH 4/4 wifi: mt76: mt7996: skip deflink accounting for offchannel links

In reply to Lorenzo Bianconi

Do not take into account offchannel links for deflink accounting.

Fixes a3316d2fc669f ("wifi: mt76: mt7996: set vif default link_id adding/removing vif links")
---
 drivers/net/wireless/mediatek/mt76/mt7996/main.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/main.c +4 -2
index ad8698cf16242489b92e23befab4d040abbdcac2..d3cd2fed31cd55f1a949ae3f2e3ed5f488514b1d 100644
@@ -376,7 +376,8 @@ int mt7996_vif_link_add(struct mt76_phy *mphy, struct ieee80211_vif *vif,
 
 	ieee80211_iter_keys(mphy->hw, vif, mt7996_key_iter, &it);
 
-	if (mvif->mt76.deflink_id == IEEE80211_LINK_UNSPECIFIED)
+	if (!mlink->wcid->offchannel &&
+	    mvif->mt76.deflink_id == IEEE80211_LINK_UNSPECIFIED)
 		mvif->mt76.deflink_id = link_conf->link_id;
 
 	return 0;
@@ -407,7 +408,8 @@ void mt7996_vif_link_remove(struct mt76_phy *mphy, struct ieee80211_vif *vif,
 
 	rcu_assign_pointer(dev->mt76.wcid[idx], NULL);
 
-	if (mvif->mt76.deflink_id == link_conf->link_id) {
+	if (!mlink->wcid->offchannel &&
+	    mvif->mt76.deflink_id == link_conf->link_id) {
 		struct ieee80211_bss_conf *iter;
 		unsigned int link_id;
 
Signature · 1 line
2.51.1
Tested-by on the v1 series
#5 lore raw
In reply to Lorenzo Bianconi

Hello Lorenzo,

These 4 patches appear to fix some of the problems, but the mac802.11/key.c lockdep splat remains. I sent you email with the details.

The kernel crash due to NPE that I was previously hacking around appears gone now, or at least harder to reproduce.

You are welcome to add:

Thanks,
Ben

Quoted 18 lines · Lorenzo Bianconi

---
Lorenzo Bianconi (4):
wifi: mt76: mt7996: grab mt76 mutex in mt7996_mac_sta_event()
wifi: mt76: mt7996: Move mt7996_update_beacons inside mt76 mutex critical section
wifi: mt76: Move mt76_abort_scan out of mt76_reset_device()
wifi: mt76: mt7996: skip deflink accounting for offchannel links

  drivers/net/wireless/mediatek/mt76/mac80211.c    |  2 --
  drivers/net/wireless/mediatek/mt76/mt7915/mac.c  |  2 ++
  drivers/net/wireless/mediatek/mt76/mt7996/mac.c  |  5 +++--
  drivers/net/wireless/mediatek/mt76/mt7996/main.c | 21 ++++++++++++++-------
  4 files changed, 19 insertions(+), 11 deletions(-)

---
base-commit: c99ebb6132595b4b288a413981197eb076547c5a
change-id: 20251114-mt76-fix-missing-mtx-db664ffcce1a

Best regards,

Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com