Commit 4afaff17 authored by Emmanuel Grumbach's avatar Emmanuel Grumbach Committed by Johannes Berg
Browse files

mac80211: avoid races related to suspend flow

When we go to suspend, there is complex set of states that
avoids races. The quiescing variable is set whlie
__ieee80211_suspend is running. Then suspended is set.
The code makes sure there is no window without any of these

The problem is that workers can still be enqueued while we
are quiescing. This leads to situations where the driver is
already suspending and other flows like disassociation are
handled by a worker.

To fix this, we need to check quiescing and suspended flags
in the worker itself and not only before enqueueing it.
I also add here extensive documentation to ease the
understanding of these complex issues.
Signed-off-by: default avatarEmmanuel Grumbach <>
Signed-off-by: default avatarJohannes Berg <>
parent 14f2ae83
...@@ -1886,6 +1886,36 @@ void __ieee80211_flush_queues(struct ieee80211_local *local, ...@@ -1886,6 +1886,36 @@ void __ieee80211_flush_queues(struct ieee80211_local *local,
struct ieee80211_sub_if_data *sdata, struct ieee80211_sub_if_data *sdata,
unsigned int queues, bool drop); unsigned int queues, bool drop);
static inline bool ieee80211_can_run_worker(struct ieee80211_local *local)
* If quiescing is set, we are racing with __ieee80211_suspend.
* __ieee80211_suspend flushes the workers after setting quiescing,
* and we check quiescing / suspended before enqueing new workers.
* We should abort the worker to avoid the races below.
if (local->quiescing)
return false;
* We might already be suspended if the following scenario occurs:
* __ieee80211_suspend Control path
* if (local->quiescing)
* return;
* local->quiescing = true;
* flush_workqueue();
* queue_work(...);
* local->suspended = true;
* local->quiescing = false;
* worker starts running...
if (local->suspended)
return false;
return true;
void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata, void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
u16 transaction, u16 auth_alg, u16 status, u16 transaction, u16 auth_alg, u16 status,
const u8 *extra, size_t extra_len, const u8 *bssid, const u8 *extra, size_t extra_len, const u8 *bssid,
...@@ -1170,12 +1170,7 @@ static void ieee80211_iface_work(struct work_struct *work) ...@@ -1170,12 +1170,7 @@ static void ieee80211_iface_work(struct work_struct *work)
if (local->scanning) if (local->scanning)
return; return;
/* if (!ieee80211_can_run_worker(local))
* ieee80211_queue_work() should have picked up most cases,
* here we'll pick the rest.
if (WARN(local->suspended,
"interface work scheduled while going to suspend\n"))
return; return;
/* first process frames */ /* first process frames */
...@@ -744,16 +744,19 @@ EXPORT_SYMBOL_GPL(wdev_to_ieee80211_vif); ...@@ -744,16 +744,19 @@ EXPORT_SYMBOL_GPL(wdev_to_ieee80211_vif);
/* /*
* Nothing should have been stuffed into the workqueue during * Nothing should have been stuffed into the workqueue during
* the suspend->resume cycle. If this WARN is seen then there * the suspend->resume cycle. Since we can't check each caller
* is a bug with either the driver suspend or something in * of this function if we are already quiescing / suspended,
* mac80211 stuffing into the workqueue which we haven't yet * check here and don't WARN since this can actually happen when
* cleared during mac80211's suspend cycle. * the rx path (for example) is racing against __ieee80211_suspend
* and suspending / quiescing was set after the rx path checked
* them.
*/ */
static bool ieee80211_can_queue_work(struct ieee80211_local *local) static bool ieee80211_can_queue_work(struct ieee80211_local *local)
{ {
if (WARN(local->suspended && !local->resuming, if (local->quiescing || (local->suspended && !local->resuming)) {
"queueing ieee80211 work while going to suspend\n")) pr_warn("queueing ieee80211 work while going to suspend\n");
return false; return false;
return true; return true;
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment