Skip to content

Commit 1f4ac5a

Browse files
committed
mac80211: explicitly copy channels to VLANs where needed
Currently the code assigns channel contexts to VLANs (for use by the TX/RX code) when the AP master gets its channel context assigned. This works fine, but in the upcoming radar detection work the VLANs don't require a channel context (during radar detection) and assigning one to them anyway causes issues with locking and also inconsistencies -- a VLAN interface that is added before radar detection would get the channel context, while one added during it wouldn't. Fix these issues moving the channel context copying to a new explicit operation that will not be used in the radar detection code. Acked-by: Simon Wunderlich <siwu@hrz.tu-chemnitz.de> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent 757af6f commit 1f4ac5a

File tree

3 files changed

+38
-18
lines changed

3 files changed

+38
-18
lines changed

net/mac80211/cfg.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,7 @@ static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
933933
IEEE80211_CHANCTX_SHARED);
934934
if (err)
935935
return err;
936+
ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
936937

937938
/*
938939
* Apply control port protocol, this allows us to
@@ -1047,6 +1048,7 @@ static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
10471048
local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
10481049
skb_queue_purge(&sdata->u.ap.ps.bc_buf);
10491050

1051+
ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
10501052
ieee80211_vif_release_channel(sdata);
10511053

10521054
return 0;

net/mac80211/chan.c

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,6 @@ static void __ieee80211_vif_release_channel(struct ieee80211_sub_if_data *sdata)
198198

199199
ctx = container_of(conf, struct ieee80211_chanctx, conf);
200200

201-
if (sdata->vif.type == NL80211_IFTYPE_AP) {
202-
struct ieee80211_sub_if_data *vlan;
203-
204-
/* for the VLAN list */
205-
ASSERT_RTNL();
206-
list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
207-
rcu_assign_pointer(vlan->vif.chanctx_conf, NULL);
208-
}
209-
210201
ieee80211_unassign_vif_chanctx(sdata, ctx);
211202
if (ctx->refcount == 0)
212203
ieee80211_free_chanctx(local, ctx);
@@ -326,15 +317,6 @@ int ieee80211_vif_use_channel(struct ieee80211_sub_if_data *sdata,
326317
goto out;
327318
}
328319

329-
if (sdata->vif.type == NL80211_IFTYPE_AP) {
330-
struct ieee80211_sub_if_data *vlan;
331-
332-
/* for the VLAN list */
333-
ASSERT_RTNL();
334-
list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
335-
rcu_assign_pointer(vlan->vif.chanctx_conf, &ctx->conf);
336-
}
337-
338320
ieee80211_recalc_smps_chanctx(local, ctx);
339321
out:
340322
mutex_unlock(&local->chanctx_mtx);
@@ -369,6 +351,40 @@ void ieee80211_vif_vlan_copy_chanctx(struct ieee80211_sub_if_data *sdata)
369351
mutex_unlock(&local->chanctx_mtx);
370352
}
371353

354+
void ieee80211_vif_copy_chanctx_to_vlans(struct ieee80211_sub_if_data *sdata,
355+
bool clear)
356+
{
357+
struct ieee80211_local *local = sdata->local;
358+
struct ieee80211_sub_if_data *vlan;
359+
struct ieee80211_chanctx_conf *conf;
360+
361+
ASSERT_RTNL();
362+
363+
if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_AP))
364+
return;
365+
366+
mutex_lock(&local->chanctx_mtx);
367+
368+
/*
369+
* Check that conf exists, even when clearing this function
370+
* must be called with the AP's channel context still there
371+
* as it would otherwise cause VLANs to have an invalid
372+
* channel context pointer for a while, possibly pointing
373+
* to a channel context that has already been freed.
374+
*/
375+
conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
376+
lockdep_is_held(&local->chanctx_mtx));
377+
WARN_ON(!conf);
378+
379+
if (clear)
380+
conf = NULL;
381+
382+
list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
383+
rcu_assign_pointer(vlan->vif.chanctx_conf, conf);
384+
385+
mutex_unlock(&local->chanctx_mtx);
386+
}
387+
372388
void ieee80211_iter_chan_contexts_atomic(
373389
struct ieee80211_hw *hw,
374390
void (*iter)(struct ieee80211_hw *hw,

net/mac80211/ieee80211_i.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,6 +1605,8 @@ ieee80211_vif_use_channel(struct ieee80211_sub_if_data *sdata,
16051605
enum ieee80211_chanctx_mode mode);
16061606
void ieee80211_vif_release_channel(struct ieee80211_sub_if_data *sdata);
16071607
void ieee80211_vif_vlan_copy_chanctx(struct ieee80211_sub_if_data *sdata);
1608+
void ieee80211_vif_copy_chanctx_to_vlans(struct ieee80211_sub_if_data *sdata,
1609+
bool clear);
16081610

16091611
void ieee80211_recalc_smps_chanctx(struct ieee80211_local *local,
16101612
struct ieee80211_chanctx *chanctx);

0 commit comments

Comments
 (0)