Linux wireless drivers development
 help / color / mirror / Atom feed
From: Felix Fietkau <nbd@nbd.name>
To: linux-wireless@vger.kernel.org
Subject: [PATCH mt76-next 05/17] wifi: mt76: mt792x: look up the TX links under RCU
Date: Sat, 21 Nov 2026 13:09:14 +0100	[thread overview]
Message-ID: <20261121120926.3603979-5-nbd@nbd.name> (raw)
In-Reply-To: <20261121120926.3603979-1-nbd@nbd.name>

mt792x_sta_to_link() and mt792x_vif_to_link() dereference the link
pointers with rcu_dereference_protected() and the mt76 mutex as its
condition. mt792x_tx() and mt7925_mac_write_txwi() call them on the TX
path, which holds an RCU read section but not the mutex. With
CONFIG_PROVE_RCU, the first frame sent on an MLO connection thus gives
a "suspicious rcu_dereference_protected() usage" warning.

Look the links up with rcu_dereference() on the TX path, matching
mt7996_sta_link(). Hold the read section of mt792x_tx() from the lookup
until the frame is queued, like mt7996_tx().

Fixes: ebb1406813c6 ("wifi: mt76: mt7925: add link handling to txwi")
Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
 .../net/wireless/mediatek/mt76/mt7925/mac.c   |  4 +-
 drivers/net/wireless/mediatek/mt76/mt792x.h   | 46 ++++++++++++++-----
 .../net/wireless/mediatek/mt76/mt792x_core.c  | 12 +++--
 3 files changed, 44 insertions(+), 18 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7925/mac.c b/drivers/net/wireless/mediatek/mt76/mt7925/mac.c
index ca54d71db4c7..a99a2c497458 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7925/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7925/mac.c
@@ -804,8 +804,8 @@ mt7925_mac_write_txwi(struct mt76_dev *dev, __le32 *txwi,
 					 BSS_CHANGED_FILS_DISCOVERY));
 	struct mt792x_bss_conf *mconf;
 
-	mconf = vif ? mt792x_vif_to_link((struct mt792x_vif *)vif->drv_priv,
-					 wcid->link_id) : NULL;
+	mconf = vif ? mt792x_vif_to_link_rcu((struct mt792x_vif *)vif->drv_priv,
+					     wcid->link_id) : NULL;
 	mvif = mconf ? (struct mt76_vif_link *)&mconf->mt76 : NULL;
 
 	if (mvif) {
diff --git a/drivers/net/wireless/mediatek/mt76/mt792x.h b/drivers/net/wireless/mediatek/mt76/mt792x.h
index b142be13ab78..3604f02a5376 100644
--- a/drivers/net/wireless/mediatek/mt76/mt792x.h
+++ b/drivers/net/wireless/mediatek/mt76/mt792x.h
@@ -434,16 +434,23 @@ struct mt792x_dev {
 	} cached_cal;
 };
 
-static inline struct mt792x_bss_conf *
-mt792x_vif_to_link(struct mt792x_vif *mvif, u8 link_id)
+static inline bool
+mt792x_vif_is_mld_link(struct mt792x_vif *mvif, u8 link_id)
 {
 	struct ieee80211_vif *vif;
-	struct mt792x_bss_conf *bss_conf;
 
 	vif = container_of((void *)mvif, struct ieee80211_vif, drv_priv);
 
-	if (!ieee80211_vif_is_mld(vif) ||
-	    link_id >= IEEE80211_LINK_UNSPECIFIED)
+	return ieee80211_vif_is_mld(vif) &&
+	       link_id < IEEE80211_LINK_UNSPECIFIED;
+}
+
+static inline struct mt792x_bss_conf *
+mt792x_vif_to_link(struct mt792x_vif *mvif, u8 link_id)
+{
+	struct mt792x_bss_conf *bss_conf;
+
+	if (!mt792x_vif_is_mld_link(mvif, link_id))
 		return &mvif->bss_conf;
 
 	bss_conf = rcu_dereference_protected(mvif->link_conf[link_id],
@@ -452,21 +459,38 @@ mt792x_vif_to_link(struct mt792x_vif *mvif, u8 link_id)
 	return bss_conf ? bss_conf : &mvif->bss_conf;
 }
 
+static inline struct mt792x_bss_conf *
+mt792x_vif_to_link_rcu(struct mt792x_vif *mvif, u8 link_id)
+{
+	struct mt792x_bss_conf *bss_conf;
+
+	if (!mt792x_vif_is_mld_link(mvif, link_id))
+		return &mvif->bss_conf;
+
+	bss_conf = rcu_dereference(mvif->link_conf[link_id]);
+
+	return bss_conf ? bss_conf : &mvif->bss_conf;
+}
+
 static inline struct mt792x_link_sta *
 mt792x_sta_to_link(struct mt792x_sta *msta, u8 link_id)
 {
-	struct ieee80211_vif *vif;
-
-	vif = container_of((void *)msta->vif, struct ieee80211_vif, drv_priv);
-
-	if (!ieee80211_vif_is_mld(vif) ||
-	    link_id >= IEEE80211_LINK_UNSPECIFIED)
+	if (!mt792x_vif_is_mld_link(msta->vif, link_id))
 		return &msta->deflink;
 
 	return rcu_dereference_protected(msta->link[link_id],
 		lockdep_is_held(&msta->vif->phy->dev->mt76.mutex));
 }
 
+static inline struct mt792x_link_sta *
+mt792x_sta_to_link_rcu(struct mt792x_sta *msta, u8 link_id)
+{
+	if (!mt792x_vif_is_mld_link(msta->vif, link_id))
+		return &msta->deflink;
+
+	return rcu_dereference(msta->link[link_id]);
+}
+
 static inline struct mt792x_bss_conf *
 mt792x_link_conf_to_mconf(struct ieee80211_bss_conf *link_conf)
 {
diff --git a/drivers/net/wireless/mediatek/mt76/mt792x_core.c b/drivers/net/wireless/mediatek/mt76/mt792x_core.c
index 8dbc5e84cd48..5babfc00dee1 100644
--- a/drivers/net/wireless/mediatek/mt76/mt792x_core.c
+++ b/drivers/net/wireless/mediatek/mt76/mt792x_core.c
@@ -189,6 +189,8 @@ void mt792x_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control,
 		}
 	}
 
+	rcu_read_lock();
+
 	if (control->sta) {
 		struct mt792x_link_sta *mlink;
 		struct mt792x_sta *sta;
@@ -197,10 +199,10 @@ void mt792x_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control,
 		sta = (struct mt792x_sta *)control->sta->drv_priv;
 		if (link_id >= IEEE80211_LINK_UNSPECIFIED)
 			link_id = sta->deflink_id;
-		mlink = mt792x_sta_to_link(sta, link_id);
+		mlink = mt792x_sta_to_link_rcu(sta, link_id);
 		if (!mlink) {
 			ieee80211_free_txskb(hw, skb);
-			return;
+			goto unlock;
 		}
 		wcid = &mlink->wcid;
 	}
@@ -229,7 +231,6 @@ void mt792x_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control,
 		struct ieee80211_bss_conf *conf;
 
 		link_id = wcid->link_id;
-		rcu_read_lock();
 		conf = rcu_dereference(vif->link_conf[link_id]);
 		memcpy(hdr->addr2, conf->addr, ETH_ALEN);
 
@@ -238,13 +239,12 @@ void mt792x_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control,
 
 		if (vif->type == NL80211_IFTYPE_STATION)
 			memcpy(hdr->addr3, conf->bssid, ETH_ALEN);
-		rcu_read_unlock();
 	}
 
 	if (mt76_connac_pm_ref(mphy, &dev->pm)) {
 		mt76_tx(mphy, control->sta, wcid, skb);
 		mt76_connac_pm_unref(mphy, &dev->pm);
-		return;
+		goto unlock;
 	}
 
 	qid = skb_get_queue_mapping(skb);
@@ -254,6 +254,8 @@ void mt792x_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control,
 	}
 
 	mt76_connac_pm_queue_skb(hw, &dev->pm, wcid, skb);
+unlock:
+	rcu_read_unlock();
 }
 EXPORT_SYMBOL_GPL(mt792x_tx);
 
-- 
2.47.3


  parent reply	other threads:[~2026-11-21 12:09 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-21 12:09 [PATCH mt76-next 01/17] wifi: mt76: mt7996: name a new secondary link to the firmware first Felix Fietkau
2026-11-21 12:09 ` [PATCH mt76-next 02/17] wifi: mt76: add a helper to point the TXQs of a station at a wcid Felix Fietkau
2026-11-21 12:09 ` [PATCH mt76-next 03/17] wifi: mt76: mt7925: move the default link to a remaining link Felix Fietkau
2026-11-21 12:09 ` [PATCH mt76-next 04/17] wifi: mt76: mt7925: keep the deflink wcid index until station removal Felix Fietkau
2026-11-21 12:09 ` Felix Fietkau [this message]
2026-11-21 12:09 ` [PATCH mt76-next 06/17] wifi: mt76: mt7925: read the links under RCU in the IPv6 notifier Felix Fietkau
2026-11-21 12:09 ` [PATCH mt76-next 07/17] wifi: mt76: mt7925: abort a ROC on the BSS that requested it Felix Fietkau
2026-11-21 12:09 ` [PATCH mt76-next 08/17] wifi: mt76: mt7925: take the link conf of a removed link from old[] Felix Fietkau
2026-11-21 12:09 ` [PATCH mt76-next 09/17] wifi: mt76: mt7925: send the MLO ROC only for a station vif Felix Fietkau
2026-11-21 12:09 ` [PATCH mt76-next 10/17] wifi: mt76: mt7996: send the Beacon rate table again after a full reset Felix Fietkau
2026-11-21 12:09 ` [PATCH mt76-next 11/17] wifi: mt76: mt7996: restore the operating channel after an L1 SER Felix Fietkau
2026-11-21 12:09 ` [PATCH mt76-next 12/17] wifi: mt76: reset the DFS state of a phy at a full reset Felix Fietkau
2026-11-21 12:09 ` [PATCH mt76-next 13/17] wifi: mt76: mt7996: abort a background CAC " Felix Fietkau
2026-11-21 12:09 ` [PATCH mt76-next 14/17] wifi: mt76: mt7915: " Felix Fietkau
2026-11-21 12:09 ` [PATCH mt76-next 15/17] wifi: mt76: mt7996: clear the airtime counts with the WTBL counters Felix Fietkau
2026-11-21 12:09 ` [PATCH mt76-next 16/17] wifi: mt76: mt7996: drop the host WTBL write of a fixed GI Felix Fietkau
2026-11-21 12:09 ` [PATCH mt76-next 17/17] wifi: mt76: mt7925: don't reset the USB device on probe Felix Fietkau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261121120926.3603979-5-nbd@nbd.name \
    --to=nbd@nbd.name \
    --cc=linux-wireless@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox