Skip to contentSkip to conversation

wifi: mac80211: drain PS delivery work during station teardown

PATCH New Zhao Li 1 participant 1 message Sep 16

Subsystems (2)
lore
Share & tools
lore

Zhao Li

author
#0 lore raw

PATCH 1/1 wifi: mac80211: drain PS delivery work during station teardown

Removing an AP or mesh station can notify the driver and wake TXQs after the station has already been removed from the driver, and can update num_sta_ps and the power-save queues after station cleanup has purged them.

sta_deliver_ps_frames() tests sta->dead only before it starts delivery. A worker that passes that test can be delayed while teardown sets sta->dead and removes the station from the driver; when it resumes it still runs the full delivery.

The existing cancel_work_sync() sits near the end of __cleanup_single_sta(), after the final driver state transition and after PS accounting and queue purging, so it drains the worker only once the state it has to protect has already changed. Before commit d34ba2168a3c ("mac80211: don't delay station destruction") cleanup was deferred through the same ordered workqueue as the delivery work, which kept the two ordered.

Cancel the work after setting sta->dead and before moving the driver state, and move the existing cancellation to the start of __cleanup_single_sta(). The first drain closes the driver-lifetime window; driver callbacks during the remaining state transitions can still queue drv_deliver_wk through ieee80211_sta_block_awake(), so retain the second drain at the start of __cleanup_single_sta(). That drain also covers insertion failures, which reach cleanup without setting sta->dead.

Fixes d34ba2168a3c ("mac80211: don't delay station destruction")
Assisted-by LLM sparse smatch coccinelle kasan

---
Validation:
- GCC W=1, Sparse C=2, Smatch, and five targeted Coccinelle rules produced no diagnostics.
- A controlled in-driver AP teardown filled ps_tx_buf and tx_filtered through ieee80211_xmit() and ieee80211_tx_status_ni(). Before the fix, cleanup purged both queues while the worker was held; the worker then ran after NOTEXIST and left num_sta_ps at -1. With the fix, the worker delivered both queues before NOTEXIST and num_sta_ps ended at 0.
- No KASAN or list-corruption report occurred. Each arm has the same three disclosed harness warnings. No physical-device test was run.

 net/mac80211/sta_info.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
net/mac80211/sta_info.c +4 -2
index fdf00cbf49d8..e81cd155197b 100644
@@ -137,6 +137,8 @@ static void __cleanup_single_sta(struct sta_info *sta)
 	struct ieee80211_local *local = sdata->local;
 	struct ps_data *ps;
 
+	cancel_work_sync(&sta->drv_deliver_wk);
+
 	if (test_sta_flag(sta, WLAN_STA_PS_STA) ||
 	    test_sta_flag(sta, WLAN_STA_PS_DRIVER) ||
 	    test_sta_flag(sta, WLAN_STA_PS_DELIVER)) {
@@ -166,8 +168,6 @@ static void __cleanup_single_sta(struct sta_info *sta)
 	if (ieee80211_vif_is_mesh(&sdata->vif))
 		mesh_sta_cleanup(sta);
 
-	cancel_work_sync(&sta->drv_deliver_wk);
-
 	/*
 	 * Destroy aggregation state here. It would be nice to wait for the
 	 * driver to finish aggregation stop and then clean up, but for now
@@ -1582,6 +1582,8 @@ static void __sta_info_destroy_part2(struct sta_info *sta, bool recalc)
 
 	sta->dead = true;
 
+	cancel_work_sync(&sta->drv_deliver_wk);
+
 	local->num_sta--;
 	local->sta_generation++;
 

base-commit: 50d3d79dc0743b616afb00d01a626c76758721f7

Signature · 1 line
2.55.0