[PATCH] wifi: ath11k: stop the RX paths before tearing down the peer TIDs

Yaohan Li shunsheng1218 at gmail.com
Tue Nov 17 23:24:33 PST 2026


ath11k_dp_peer_cleanup() clears peer->dp_setup_done only after
ath11k_peer_rx_tid_cleanup() has returned, but that cleanup gives up
base_lock around every timer_delete_sync() call.  A fragment that
arrives during one of those windows still sees dp_setup_done set, so it
passes the check ath11k_dp_rx_frag_h_mpdu() makes under base_lock and
goes on to use the rx_tid whose REO entry has just been deleted and
whose fragment queue has just been purged.

Clear the flag first, while base_lock is still held, so an RX path that
runs during the cleanup takes the -ENOENT branch instead of touching
TID state that is being torn down.

ath11k_mac_peer_cleanup_all() walks every peer under base_lock and calls
the same cleanup before freeing the peer; clear the flag there as well
for the same reason.

The RX path has the mirror image of the problem: it drops base_lock
around its own timer_delete_sync() after it has already queued msdu into
rx_tid->rx_frags, and the teardown can purge that queue and free the
peer in that window, so neither the rx_tid pointer nor the ownership of
msdu can be proven afterwards.  The fragment timer callback takes
base_lock itself, so the lock does not have to be dropped at all:
delete the timer with timer_delete() while it is held, which keeps the
whole check-and-reassemble sequence atomic and leaves msdu owned here.

Deleting the timer is not enough on its own, because timer_delete() does
not wait for a callback that has already started and is blocked on
base_lock.  That callback would later run
ath11k_dp_rx_frags_cleanup() against whatever sequence is queued by
then.  Track the armed timeout per TID, clear it whenever the fragments
are cleaned, and let the callback clean up only once the deadline it was
armed for has passed, so a stale callback cannot drop the fragments of a
newer sequence.

The per-TID timeout state is initialised together with the fragment
queue, so the first callback after a peer is set up again cannot act on
values left behind by its previous incarnation.

Fixes: a06bfb3c9f69 ("wifi: ath11k: Ignore frags from uninitialized peer in dp.")
Signed-off-by: Yaohan Li <shunsheng1218 at gmail.com>
---
Prepared against v7.4-rc1-1969-g666539eecdf4.

AI assistance: the analysis, the change and its review notes were
prepared with Claude (Anthropic) as a coding assistant.  The author
reviewed the reasoning and takes responsibility for the content.

Testing: compile tested only (arm64, gcc 11.4).  No ath11k hardware was
available, so the race was not run.
 drivers/net/wireless/ath/ath11k/dp.c    |  8 +++-
 drivers/net/wireless/ath/ath11k/dp.h    |  2 +
 drivers/net/wireless/ath/ath11k/dp_rx.c | 50 ++++++++++++++++++-------
 drivers/net/wireless/ath/ath11k/mac.c   |  1 +
 4 files changed, 47 insertions(+), 14 deletions(-)

diff --git a/drivers/net/wireless/ath/ath11k/dp.c b/drivers/net/wireless/ath/ath11k/dp.c
index be65d73b904b..c1ec35262bd1 100644
--- a/drivers/net/wireless/ath/ath11k/dp.c
+++ b/drivers/net/wireless/ath/ath11k/dp.c
@@ -35,8 +35,14 @@ void ath11k_dp_peer_cleanup(struct ath11k *ar, int vdev_id, const u8 *addr)
 		return;
 	}
 
-	ath11k_peer_rx_tid_cleanup(ar, peer);
+	/*
+	 * Stop the RX paths before tearing the TIDs down.  The TID cleanup
+	 * drops base_lock around timer_delete_sync(), and a fragment that
+	 * arrives in that window would otherwise still see dp_setup_done set
+	 * and go on to use an rx_tid that is being cleaned up.
+	 */
 	peer->dp_setup_done = false;
+	ath11k_peer_rx_tid_cleanup(ar, peer);
 	spin_unlock_bh(&ab->base_lock);
 }
 
diff --git a/drivers/net/wireless/ath/ath11k/dp.h b/drivers/net/wireless/ath/ath11k/dp.h
index 84f66839f0c6..d343f8e6df23 100644
--- a/drivers/net/wireless/ath/ath11k/dp.h
+++ b/drivers/net/wireless/ath/ath11k/dp.h
@@ -35,6 +35,8 @@ struct dp_rx_tid {
 
 	/* Timer info related to fragments */
 	struct timer_list frag_timer;
+	bool frag_timeout_armed;
+	unsigned long frag_deadline;
 	struct ath11k_base *ab;
 	u32 *vaddr_unaligned;
 	dma_addr_t paddr_unaligned;
diff --git a/drivers/net/wireless/ath/ath11k/dp_rx.c b/drivers/net/wireless/ath/ath11k/dp_rx.c
index 6d95f7b343a5..37fc116c4996 100644
--- a/drivers/net/wireless/ath/ath11k/dp_rx.c
+++ b/drivers/net/wireless/ath/ath11k/dp_rx.c
@@ -886,6 +886,13 @@ static void ath11k_dp_rx_frags_cleanup(struct dp_rx_tid *rx_tid, bool rel_link_d
 
 	lockdep_assert_held(&ab->base_lock);
 
+	/*
+	 * Whoever cleans the fragments also cancels the sequence that was
+	 * waiting for the timeout, so a callback that already started for it
+	 * has to stay out.
+	 */
+	rx_tid->frag_timeout_armed = false;
+
 	if (rx_tid->dst_ring_desc) {
 		if (rel_link_desc)
 			ath11k_dp_rx_link_desc_return(ab, (u32 *)rx_tid->dst_ring_desc,
@@ -3204,12 +3211,24 @@ static void ath11k_dp_rx_frag_timer(struct timer_list *timer)
 						      frag_timer);
 
 	spin_lock_bh(&rx_tid->ab->base_lock);
+
+	/*
+	 * This callback can have been started for an older fragment sequence
+	 * and only get the lock after a newer one has queued its fragments
+	 * and armed its own timeout.  Only clean up once the timeout of the
+	 * sequence that is currently queued has expired.
+	 */
+	if (!rx_tid->frag_timeout_armed ||
+	    time_before(jiffies, rx_tid->frag_deadline))
+		goto out_unlock;
+
 	if (rx_tid->last_frag_no &&
-	    rx_tid->rx_frag_bitmap == GENMASK(rx_tid->last_frag_no, 0)) {
-		spin_unlock_bh(&rx_tid->ab->base_lock);
-		return;
-	}
+	    rx_tid->rx_frag_bitmap == GENMASK(rx_tid->last_frag_no, 0))
+		goto out_unlock;
+
 	ath11k_dp_rx_frags_cleanup(rx_tid, true);
+
+out_unlock:
 	spin_unlock_bh(&rx_tid->ab->base_lock);
 }
 
@@ -3238,6 +3257,8 @@ int ath11k_peer_rx_frag_setup(struct ath11k *ar, const u8 *peer_mac, int vdev_id
 		rx_tid = &peer->rx_tid[i];
 		rx_tid->ab = ab;
 		timer_setup(&rx_tid->frag_timer, ath11k_dp_rx_frag_timer, 0);
+		rx_tid->frag_timeout_armed = false;
+		rx_tid->frag_deadline = 0;
 		skb_queue_head_init(&rx_tid->rx_frags);
 	}
 
@@ -3698,18 +3719,21 @@ static int ath11k_dp_rx_frag_h_mpdu(struct ath11k *ar,
 
 	if (!rx_tid->last_frag_no ||
 	    rx_tid->rx_frag_bitmap != GENMASK(rx_tid->last_frag_no, 0)) {
-		mod_timer(&rx_tid->frag_timer, jiffies +
-					       ATH11K_DP_RX_FRAGMENT_TIMEOUT_MS);
+		rx_tid->frag_timeout_armed = true;
+		rx_tid->frag_deadline = jiffies +
+					ATH11K_DP_RX_FRAGMENT_TIMEOUT_MS;
+		mod_timer(&rx_tid->frag_timer, rx_tid->frag_deadline);
 		goto out_unlock;
 	}
 
-	spin_unlock_bh(&ab->base_lock);
-	timer_delete_sync(&rx_tid->frag_timer);
-	spin_lock_bh(&ab->base_lock);
-
-	peer = ath11k_peer_find_by_id(ab, peer_id);
-	if (!peer)
-		goto err_frags_cleanup;
+	/*
+	 * The timer callback takes base_lock itself, so it cannot run while
+	 * the lock is held and deleting the timer here is enough.  Waiting
+	 * for it with timer_delete_sync() would require dropping the lock,
+	 * which lets the peer teardown free rx_tid while this path still
+	 * uses it.
+	 */
+	timer_delete(&rx_tid->frag_timer);
 
 	if (!ath11k_dp_rx_h_defrag_validate_incr_pn(ar, rx_tid))
 		goto err_frags_cleanup;
diff --git a/drivers/net/wireless/ath/ath11k/mac.c b/drivers/net/wireless/ath/ath11k/mac.c
index 1a237adaa37d..4bdc9afbc3c1 100644
--- a/drivers/net/wireless/ath/ath11k/mac.c
+++ b/drivers/net/wireless/ath/ath11k/mac.c
@@ -899,6 +899,7 @@ void ath11k_mac_peer_cleanup_all(struct ath11k *ar)
 	mutex_lock(&ab->tbl_mtx_lock);
 	spin_lock_bh(&ab->base_lock);
 	list_for_each_entry_safe(peer, tmp, &ab->peers, list) {
+		peer->dp_setup_done = false;
 		ath11k_peer_rx_tid_cleanup(ar, peer);
 		ath11k_peer_rhash_delete(ab, peer);
 		ath11k_mac_station_cleanup(peer->sta);
-- 
2.34.1




More information about the ath11k mailing list