[RFC PATCH 04/12] wifi: iwlwifi: mld: cope with different key/sta ordering

Johannes Berg <[email protected]> Sat, 1 Aug 2026 09:58:20 +0200
Newsgroups org.kernel.vger.linux-wireless
Message-ID <20260801095822.a243ae7dba8f.Ib27388f723fdedf6bc327fe5617ddcc49efd36b2@changeid>
From: Johannes Berg <[email protected]>

In a subsequent patch, mac80211 will remove group keys
while the station is removed, not after. The workarounds
in the driver fail with that, adjust them now.

Later, we can let drivers opt in to know the station of
a client-side group key, and remove all of this code.

Signed-off-by: Johannes Berg <[email protected]>
---
 drivers/net/wireless/intel/iwlwifi/mld/key.c      |  4 ++--
 drivers/net/wireless/intel/iwlwifi/mld/mac80211.c | 14 +++++++++++++-
 drivers/net/wireless/intel/iwlwifi/mld/sta.c      |  7 -------
 3 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/mld/key.c b/drivers/net/wireless/intel/iwlwifi/mld/key.c
index bf80b4770b5a..126ce5fa2b0c 100644
--- a/drivers/net/wireless/intel/iwlwifi/mld/key.c
+++ b/drivers/net/wireless/intel/iwlwifi/mld/key.c
@@ -354,8 +354,8 @@ static void iwl_mld_remove_ap_keys_iter(struct ieee80211_hw *hw,
 	if (key->hw_key_idx == STA_KEY_IDX_INVALID)
 		return;
 
-	/* All the pairwise keys should have been removed by now */
-	if (WARN_ON(sta))
+	/* only remove group keys */
+	if (sta)
 		return;
 
 	if (key->link_id >= 0 && key->link_id != data->link_id)
diff --git a/drivers/net/wireless/intel/iwlwifi/mld/mac80211.c b/drivers/net/wireless/intel/iwlwifi/mld/mac80211.c
index 3a4c8fda68d0..13e21fdd1953 100644
--- a/drivers/net/wireless/intel/iwlwifi/mld/mac80211.c
+++ b/drivers/net/wireless/intel/iwlwifi/mld/mac80211.c
@@ -2564,10 +2564,22 @@ static void iwl_mld_sta_pre_rcu_remove(struct ieee80211_hw *hw,
 	 * on further RCU synchronisation after the sta_state()
 	 * callback deleted the station.
 	 */
-	for_each_mld_link_sta(mld_sta, mld_link_sta, link_id)
+
+	for_each_mld_link_sta(mld_sta, mld_link_sta, link_id) {
 		RCU_INIT_POINTER(mld->fw_id_to_link_sta[mld_link_sta->fw_id],
 				 NULL);
 
+		/*
+		 * mac80211 will remove the group keys during the STA
+		 * removal, but then we don't have the AP STA as we've
+		 * already NULLed the pointer below, and thus we cannot
+		 * remove the keys properly from FW since we need the
+		 * station ID. Remove them all here to be able to.
+		 */
+		if (sta == mld_vif->ap_sta)
+			iwl_mld_remove_ap_keys(mld, vif, sta, link_id);
+	}
+
 	if (sta == mld_vif->ap_sta)
 		mld_vif->ap_sta = NULL;
 }
diff --git a/drivers/net/wireless/intel/iwlwifi/mld/sta.c b/drivers/net/wireless/intel/iwlwifi/mld/sta.c
index 7957ac11b0cd..727f005c4a35 100644
--- a/drivers/net/wireless/intel/iwlwifi/mld/sta.c
+++ b/drivers/net/wireless/intel/iwlwifi/mld/sta.c
@@ -915,13 +915,6 @@ void iwl_mld_remove_sta(struct iwl_mld *mld, struct ieee80211_sta *sta)
 		iwl_mld_remove_txq(mld, sta->txq[i]);
 
 	for_each_sta_active_link(vif, sta, link_sta, link_id) {
-		/* Mac8011 will remove the groupwise keys after the sta is
-		 * removed, but FW expects all the keys to be removed before
-		 * the STA is, so remove them all here.
-		 */
-		if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls)
-			iwl_mld_remove_ap_keys(mld, vif, sta, link_id);
-
 		/* Remove the link_sta */
 		iwl_mld_remove_link_sta(mld, link_sta);
 	}
-- 
2.55.0