wifi: ath11k: stop the RX paths before tearing down the peer TIDs
PATCH 1/1 wifi: ath11k: stop the RX paths before tearing down the peer TIDs
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.
---
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(-)
drivers/net/wireless/ath/ath11k/dp.c +7 -1
@@ -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); }
drivers/net/wireless/ath/ath11k/dp.h +2 -0
@@ -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;
drivers/net/wireless/ath/ath11k/dp_rx.c +37 -13
79 lines not on this page · raw message
drivers/net/wireless/ath/ath11k/mac.c +1 -0
@@ -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);
Signature · 1 line
2.34.1