Skip to content

Commit af296bd

Browse files
Michal Kaziorjmberg-intel
authored andcommitted
mac80211: move csa counters from sdata to beacon/presp
Having csa counters part of beacon and probe_resp structures makes it easier to get rid of possible races between setting a beacon and updating counters on SMP systems by guaranteeing counters are always consistent against given beacon struct. While at it relax WARN_ON into WARN_ON_ONCE to prevent spamming logs and racing. Signed-off-by: Michal Kazior <michal.kazior@tieto.com> [remove pointless array check] Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent b493283 commit af296bd

5 files changed

Lines changed: 115 additions & 75 deletions

File tree

‎net/mac80211/cfg.c‎

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,8 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
554554
}
555555

556556
static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
557-
const u8 *resp, size_t resp_len)
557+
const u8 *resp, size_t resp_len,
558+
const struct ieee80211_csa_settings *csa)
558559
{
559560
struct probe_resp *new, *old;
560561

@@ -570,6 +571,11 @@ static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
570571
new->len = resp_len;
571572
memcpy(new->data, resp, resp_len);
572573

574+
if (csa)
575+
memcpy(new->csa_counter_offsets, csa->counter_offsets_presp,
576+
csa->n_counter_offsets_presp *
577+
sizeof(new->csa_counter_offsets[0]));
578+
573579
rcu_assign_pointer(sdata->u.ap.probe_resp, new);
574580
if (old)
575581
kfree_rcu(old, rcu_head);
@@ -578,7 +584,8 @@ static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
578584
}
579585

580586
static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
581-
struct cfg80211_beacon_data *params)
587+
struct cfg80211_beacon_data *params,
588+
const struct ieee80211_csa_settings *csa)
582589
{
583590
struct beacon_data *new, *old;
584591
int new_head_len, new_tail_len;
@@ -622,6 +629,13 @@ static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
622629
new->head_len = new_head_len;
623630
new->tail_len = new_tail_len;
624631

632+
if (csa) {
633+
new->csa_current_counter = csa->count;
634+
memcpy(new->csa_counter_offsets, csa->counter_offsets_beacon,
635+
csa->n_counter_offsets_beacon *
636+
sizeof(new->csa_counter_offsets[0]));
637+
}
638+
625639
/* copy in head */
626640
if (params->head)
627641
memcpy(new->head, params->head, new_head_len);
@@ -636,7 +650,7 @@ static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
636650
memcpy(new->tail, old->tail, new_tail_len);
637651

638652
err = ieee80211_set_probe_resp(sdata, params->probe_resp,
639-
params->probe_resp_len);
653+
params->probe_resp_len, csa);
640654
if (err < 0)
641655
return err;
642656
if (err == 0)
@@ -721,7 +735,7 @@ static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
721735
sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
722736
IEEE80211_P2P_OPPPS_ENABLE_BIT;
723737

724-
err = ieee80211_assign_beacon(sdata, &params->beacon);
738+
err = ieee80211_assign_beacon(sdata, &params->beacon, NULL);
725739
if (err < 0) {
726740
ieee80211_vif_release_channel(sdata);
727741
return err;
@@ -769,7 +783,7 @@ static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
769783
if (!old)
770784
return -ENOENT;
771785

772-
err = ieee80211_assign_beacon(sdata, params);
786+
err = ieee80211_assign_beacon(sdata, params, NULL);
773787
if (err < 0)
774788
return err;
775789
ieee80211_bss_info_change_notify(sdata, err);
@@ -2752,7 +2766,8 @@ static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata,
27522766

27532767
switch (sdata->vif.type) {
27542768
case NL80211_IFTYPE_AP:
2755-
err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon);
2769+
err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon,
2770+
NULL);
27562771
kfree(sdata->u.ap.next_beacon);
27572772
sdata->u.ap.next_beacon = NULL;
27582773

@@ -2855,6 +2870,7 @@ static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
28552870
struct cfg80211_csa_settings *params,
28562871
u32 *changed)
28572872
{
2873+
struct ieee80211_csa_settings csa = {};
28582874
int err;
28592875

28602876
switch (sdata->vif.type) {
@@ -2889,20 +2905,13 @@ static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
28892905
IEEE80211_MAX_CSA_COUNTERS_NUM))
28902906
return -EINVAL;
28912907

2892-
/* make sure we don't have garbage in other counters */
2893-
memset(sdata->csa_counter_offset_beacon, 0,
2894-
sizeof(sdata->csa_counter_offset_beacon));
2895-
memset(sdata->csa_counter_offset_presp, 0,
2896-
sizeof(sdata->csa_counter_offset_presp));
2897-
2898-
memcpy(sdata->csa_counter_offset_beacon,
2899-
params->counter_offsets_beacon,
2900-
params->n_counter_offsets_beacon * sizeof(u16));
2901-
memcpy(sdata->csa_counter_offset_presp,
2902-
params->counter_offsets_presp,
2903-
params->n_counter_offsets_presp * sizeof(u16));
2908+
csa.counter_offsets_beacon = params->counter_offsets_beacon;
2909+
csa.counter_offsets_presp = params->counter_offsets_presp;
2910+
csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
2911+
csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
2912+
csa.count = params->count;
29042913

2905-
err = ieee80211_assign_beacon(sdata, &params->beacon_csa);
2914+
err = ieee80211_assign_beacon(sdata, &params->beacon_csa, &csa);
29062915
if (err < 0) {
29072916
kfree(sdata->u.ap.next_beacon);
29082917
return err;
@@ -3046,7 +3055,6 @@ __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
30463055
sdata->csa_radar_required = params->radar_required;
30473056
sdata->csa_chandef = params->chandef;
30483057
sdata->csa_block_tx = params->block_tx;
3049-
sdata->csa_current_counter = params->count;
30503058
sdata->vif.csa_active = true;
30513059

30523060
if (sdata->csa_block_tx)
@@ -3194,10 +3202,23 @@ static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
31943202
sdata->vif.type == NL80211_IFTYPE_ADHOC) &&
31953203
params->n_csa_offsets) {
31963204
int i;
3197-
u8 c = sdata->csa_current_counter;
3205+
struct beacon_data *beacon = NULL;
31983206

3199-
for (i = 0; i < params->n_csa_offsets; i++)
3200-
data[params->csa_offsets[i]] = c;
3207+
rcu_read_lock();
3208+
3209+
if (sdata->vif.type == NL80211_IFTYPE_AP)
3210+
beacon = rcu_dereference(sdata->u.ap.beacon);
3211+
else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
3212+
beacon = rcu_dereference(sdata->u.ibss.presp);
3213+
else if (ieee80211_vif_is_mesh(&sdata->vif))
3214+
beacon = rcu_dereference(sdata->u.mesh.beacon);
3215+
3216+
if (beacon)
3217+
for (i = 0; i < params->n_csa_offsets; i++)
3218+
data[params->csa_offsets[i]] =
3219+
beacon->csa_current_counter;
3220+
3221+
rcu_read_unlock();
32013222
}
32023223

32033224
IEEE80211_SKB_CB(skb)->flags = flags;

‎net/mac80211/ibss.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ ieee80211_ibss_build_presp(struct ieee80211_sub_if_data *sdata,
143143
*pos++ = csa_settings->block_tx ? 1 : 0;
144144
*pos++ = ieee80211_frequency_to_channel(
145145
csa_settings->chandef.chan->center_freq);
146-
sdata->csa_counter_offset_beacon[0] = (pos - presp->head);
146+
presp->csa_counter_offsets[0] = (pos - presp->head);
147147
*pos++ = csa_settings->count;
148148
}
149149

‎net/mac80211/ieee80211_i.h‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,16 +229,29 @@ struct ieee80211_rx_data {
229229
u16 tkip_iv16;
230230
};
231231

232+
struct ieee80211_csa_settings {
233+
const u16 *counter_offsets_beacon;
234+
const u16 *counter_offsets_presp;
235+
236+
int n_counter_offsets_beacon;
237+
int n_counter_offsets_presp;
238+
239+
u8 count;
240+
};
241+
232242
struct beacon_data {
233243
u8 *head, *tail;
234244
int head_len, tail_len;
235245
struct ieee80211_meshconf_ie *meshconf;
246+
u16 csa_counter_offsets[IEEE80211_MAX_CSA_COUNTERS_NUM];
247+
u8 csa_current_counter;
236248
struct rcu_head rcu_head;
237249
};
238250

239251
struct probe_resp {
240252
struct rcu_head rcu_head;
241253
int len;
254+
u16 csa_counter_offsets[IEEE80211_MAX_CSA_COUNTERS_NUM];
242255
u8 data[0];
243256
};
244257

@@ -754,8 +767,6 @@ struct ieee80211_sub_if_data {
754767
struct mac80211_qos_map __rcu *qos_map;
755768

756769
struct work_struct csa_finalize_work;
757-
u16 csa_counter_offset_beacon[IEEE80211_MAX_CSA_COUNTERS_NUM];
758-
u16 csa_counter_offset_presp[IEEE80211_MAX_CSA_COUNTERS_NUM];
759770
bool csa_radar_required;
760771
bool csa_block_tx; /* write-protected by sdata_lock and local->mtx */
761772
struct cfg80211_chan_def csa_chandef;
@@ -767,7 +778,6 @@ struct ieee80211_sub_if_data {
767778
struct ieee80211_chanctx *reserved_chanctx;
768779
struct cfg80211_chan_def reserved_chandef;
769780
bool reserved_radar_required;
770-
u8 csa_current_counter;
771781

772782
/* used to reconfigure hardware SM PS */
773783
struct work_struct recalc_smps;

‎net/mac80211/mesh.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ ieee80211_mesh_build_beacon(struct ieee80211_if_mesh *ifmsh)
679679
*pos++ = 0x0;
680680
*pos++ = ieee80211_frequency_to_channel(
681681
csa->settings.chandef.chan->center_freq);
682-
sdata->csa_counter_offset_beacon[0] = hdr_len + 6;
682+
bcn->csa_counter_offsets[0] = hdr_len + 6;
683683
*pos++ = csa->settings.count;
684684
*pos++ = WLAN_EID_CHAN_SWITCH_PARAM;
685685
*pos++ = 6;

0 commit comments

Comments
 (0)