mac80211: fix mesh deadlock
PATCH 1/2 mac80211: fix mesh deadlock
The patch "cfg80211/mac80211: use cfg80211 wdev mutex in mac80211" introduced several deadlocks by converting the ifmsh->mtx to wdev->mtx. Solve these by:
1. drop the cancel_work_sync() in ieee80211_stop_mesh(). Instead make the mesh work conditional on whether the mesh is running or not.
2. lock the mesh work with sdata_lock() to protect beacon updates and prevent races with wdev->mesh_id_len or cfg80211.
--- net/mac80211/mesh.c | 29 +++++++++++++++++------------ net/mac80211/mesh_plink.c | 7 +------ 2 files changed, 18 insertions(+), 18 deletions(-)
net/mac80211/mesh.c +17 -12
@@ -579,9 +579,7 @@ static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata)mesh_path_expire (sdata); changed =mesh_accept_plinks_update (sdata); -sdata_lock (sdata);ieee80211_mbss_info_change_notify (sdata, changed); -sdata_unlock (sdata); mod_timer(&ifmsh->housekeeping_timer, round_jiffies(jiffies +
@@ -788,12 +786,10 @@ void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata) sdata->vif.bss_conf.enable_beacon = false;clear_bit (SDATA_STATE_OFFCHANNEL_BEACON_STOPPED , &sdata->state);ieee80211_bss_info_change_notify (sdata,BSS_CHANGED_BEACON_ENABLED ); -sdata_lock (sdata); bcn =rcu_dereference_protected (ifmsh->beacon,lockdep_is_held (&sdata->wdev.mtx));rcu_assign_pointer (ifmsh->beacon,NULL );kfree_rcu (bcn, rcu_head); -sdata_unlock (sdata);/* flush STAs and mpaths on this iface */ sta_info_flush (sdata);
@@ -806,14 +802,6 @@ void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata)del_timer_sync (&sdata->u.mesh.housekeeping_timer);del_timer_sync (&sdata->u.mesh.mesh_path_root_timer);del_timer_sync (&sdata->u.mesh.mesh_path_timer); -/* -* If the timer fired while we waited for it, it will have -* requeued the work. Now the work will be running again -* but will not rearm the timer again because it checks -* whether the interface is running, which, at this point, -* it no longer is. -*/ -cancel_work_sync (&sdata->work); local->fif_other_bss--;atomic_dec (&local->iff_allmultis);
@@ -954,6 +942,12 @@ void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,struct ieee80211_mgmt *mgmt;u16 stype; +sdata_lock (sdata); + +/* mesh already went down */ +if (!sdata->wdev.mesh_id_len) + goto out; + rx_status =IEEE80211_SKB_RXCB (skb); mgmt = (struct ieee80211_mgmt *) skb->data; stype =le16_to_cpu (mgmt->frame_control) &IEEE80211_FCTL_STYPE ;
@@ -971,12 +965,20 @@ void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,ieee80211_mesh_rx_mgmt_action (sdata, mgmt, skb->len, rx_status);break ; } +out: +sdata_unlock (sdata); }void ieee80211_mesh_work (struct ieee80211_sub_if_data *sdata) {struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; +sdata_lock (sdata); + +/* mesh already went down */ +if (!sdata->wdev.mesh_id_len) + goto out; +if (ifmsh->preq_queue_len &&time_after (jiffies, ifmsh->last_preq +msecs_to_jiffies (ifmsh->mshcfg.dot11MeshHWMPpreqMinInterval)))
@@ -996,6 +998,9 @@ void ieee80211_mesh_work(struct ieee80211_sub_if_data *sdata)if (test_and_clear_bit (MESH_WORK_DRIFT_ADJUST , &ifmsh->wrkq_flags))mesh_sync_adjust_tbtt (sdata); + +out: +sdata_unlock (sdata); }void ieee80211_mesh_notify_scan_completed (struct ieee80211_local *local)
net/mac80211/mesh_plink.c +1 -6
@@ -517,9 +517,7 @@ void mesh_neighbour_update(struct ieee80211_sub_if_data *sdata,ieee80211_mps_frame_release (sta, elems); out:rcu_read_unlock (); -sdata_lock (sdata);ieee80211_mbss_info_change_notify (sdata, changed); -sdata_unlock (sdata); }static void mesh_plink_timer (unsigned long data)
@@ -1070,9 +1068,6 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata,rcu_read_unlock (); -if (changed) { -sdata_lock (sdata); +if (changed)ieee80211_mbss_info_change_notify (sdata, changed); -sdata_unlock (sdata); - } }
Signature · 1 line
1.7.10.4
PATCH 2/2 mac80211: update mesh beacon on workqueue
Fixes yet another deadlock on calling sta_info_flush() with the sdata_lock() held. Should make it easier to reason about locking in the future, since the sdata_lock() is now held on all mesh work.
--- net/mac80211/ieee80211_i.h | 1 + net/mac80211/mesh.c | 43 +++++++++++++++++++++++++++++++------------ net/mac80211/mesh.h | 2 ++ 3 files changed, 34 insertions(+), 12 deletions(-)
net/mac80211/ieee80211_i.h +1 -0
@@ -542,6 +542,7 @@ struct ieee80211_if_mesh {struct timer_list mesh_path_root_timer;unsigned long wrkq_flags; +unsigned long mbss_changed;u8 mesh_id[IEEE80211_MAX_MESH_ID_LEN ];size_t mesh_id_len;
net/mac80211/mesh.c +31 -12
68 lines not on this page · raw message
net/mac80211/mesh.h +2 -0
@@ -57,6 +57,7 @@ enum mesh_path_flags {* grow * @MESH_WORK_ROOT: the mesh root station needs to send a frame * @MESH_WORK_DRIFT_ADJUST: time to compensate for clock drift relative to other +* @MESH_WORK_MBSS_CHANGED: rebuild beacon and notify driver of BSS changes * mesh nodes */ enum mesh_deferred_task_flags {
@@ -65,6 +66,7 @@ enum mesh_deferred_task_flags {MESH_WORK_GROW_MPP_TABLE ,MESH_WORK_ROOT ,MESH_WORK_DRIFT_ADJUST , + MESH_WORK_MBSS_CHANGED, };/**
Signature · 1 line
1.7.10.4
Re: [PATCH 2/2] mac80211: update mesh beacon on workqueue
Quoted 7 lines · Thomas Pedersen
Fixes yet another deadlock on calling
sta_info_flush()with thesdata_lock()held. Should make it easier to reason about locking in the future, since thesdata_lock()is now held on all mesh work.Signed-off-by Thomas Pedersen <[email protected]>---
[...]
net/mac80211/mesh.c out: · line 980
Quoted 11 lines
net/mac80211/mesh.c +11
-0+static void mesh_bss_info_changed (struct ieee80211_sub_if_data *sdata) +{ +struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; +#define TEST_CHANGED_BIT (bit) \ + test_and_clear_bit(bit, &ifmsh->mbss_changed) + +u32 changed =TEST_CHANGED_BIT (BSS_CHANGED_BEACON ) | +TEST_CHANGED_BIT (BSS_CHANGED_HT ) | +TEST_CHANGED_BIT (BSS_CHANGED_BASIC_RATES ) | +TEST_CHANGED_BIT (BSS_CHANGED_BEACON_INT ); +#undef TEST_CHANGED_BIT
Uhhh we should read all the bits here. Will fix and resubmit as v2.
--
Thomas
Johannes Berg
maintainerRe: [PATCH 2/2] mac80211: update mesh beacon on workqueue
Quoted 5 lines · Thomas Pedersen
Quoted 5 lines
net/mac80211/mesh.c +5
-0+static void mesh_bss_info_changed (struct ieee80211_sub_if_data *sdata) +{ +struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; +#define TEST_CHANGED_BIT (bit) \ + test_and_clear_bit(bit, &ifmsh->mbss_changed)
Quoted 8 lines
net/mac80211/mesh.c out: · line 980
Quoted 6 lines
net/mac80211/mesh.c +6
-0+ +u32 changed =TEST_CHANGED_BIT (BSS_CHANGED_BEACON ) | +TEST_CHANGED_BIT (BSS_CHANGED_HT ) | +TEST_CHANGED_BIT (BSS_CHANGED_BASIC_RATES ) | +TEST_CHANGED_BIT (BSS_CHANGED_BEACON_INT ); +#undef TEST_CHANGED_BITUhhh we should read all the bits here. Will fix and resubmit as v2.
Now that you're quoting it I'd also say that the macro isn't really best, does removing it really make the code so much worse?
johannes
Re: [PATCH 2/2] mac80211: update mesh beacon on workqueue
Quoted 16 lines · Johannes Berg
Quoted 5 lines · Thomas Pedersen
Quoted 5 lines
net/mac80211/mesh.c +5
-0+static void mesh_bss_info_changed (struct ieee80211_sub_if_data *sdata) +{ +struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; +#define TEST_CHANGED_BIT (bit) \ + test_and_clear_bit(bit, &ifmsh->mbss_changed)Quoted 8 lines
net/mac80211/mesh.c out: · line 980
Quoted 6 lines
net/mac80211/mesh.c +6
-0+ +u32 changed =TEST_CHANGED_BIT (BSS_CHANGED_BEACON ) | +TEST_CHANGED_BIT (BSS_CHANGED_HT ) | +TEST_CHANGED_BIT (BSS_CHANGED_BASIC_RATES ) | +TEST_CHANGED_BIT (BSS_CHANGED_BEACON_INT ); +#undef TEST_CHANGED_BITUhhh we should read all the bits here. Will fix and resubmit as v2.
Quoted 2 lines
Now that you're quoting it I'd also say that the macro isn't really best, does removing it really make the code so much worse?
No, it won't be there in v2. Thanks.
--
Thomas