Skip to content

Commit 8d61ffa

Browse files
committed
cfg80211/mac80211: use cfg80211 wdev mutex in mac80211
Using separate locks in cfg80211 and mac80211 has always caused issues, for example having to unlock in places in mac80211 to call cfg80211, which even needed a framework to make cfg80211 calls after some functions returned etc. Additionally, I suspect some issues people have reported with the cfg80211 state getting confused could be due to such issues, when cfg80211 is asking mac80211 to change state but mac80211 is in the process of telling cfg80211 that the state changed (in another way.) Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent 5fe231e commit 8d61ffa

14 files changed

Lines changed: 220 additions & 355 deletions

File tree

‎Documentation/DocBook/80211.tmpl‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,7 @@
132132
!Finclude/net/cfg80211.h cfg80211_send_rx_assoc
133133
!Finclude/net/cfg80211.h cfg80211_send_assoc_timeout
134134
!Finclude/net/cfg80211.h cfg80211_send_deauth
135-
!Finclude/net/cfg80211.h __cfg80211_send_deauth
136135
!Finclude/net/cfg80211.h cfg80211_send_disassoc
137-
!Finclude/net/cfg80211.h __cfg80211_send_disassoc
138136
!Finclude/net/cfg80211.h cfg80211_ibss_joined
139137
!Finclude/net/cfg80211.h cfg80211_connect_result
140138
!Finclude/net/cfg80211.h cfg80211_roamed

‎include/net/cfg80211.h‎

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,7 +1867,9 @@ struct cfg80211_update_ft_ies_params {
18671867
* @get_mpath: get a mesh path for the given parameters
18681868
* @dump_mpath: dump mesh path callback -- resume dump at index @idx
18691869
* @join_mesh: join the mesh network with the specified parameters
1870+
* (invoked with the wireless_dev mutex held)
18701871
* @leave_mesh: leave the current mesh network
1872+
* (invoked with the wireless_dev mutex held)
18711873
*
18721874
* @get_mesh_config: Get the current mesh configuration
18731875
*
@@ -1894,20 +1896,28 @@ struct cfg80211_update_ft_ies_params {
18941896
* the scan/scan_done bracket too.
18951897
*
18961898
* @auth: Request to authenticate with the specified peer
1899+
* (invoked with the wireless_dev mutex held)
18971900
* @assoc: Request to (re)associate with the specified peer
1901+
* (invoked with the wireless_dev mutex held)
18981902
* @deauth: Request to deauthenticate from the specified peer
1903+
* (invoked with the wireless_dev mutex held)
18991904
* @disassoc: Request to disassociate from the specified peer
1905+
* (invoked with the wireless_dev mutex held)
19001906
*
19011907
* @connect: Connect to the ESS with the specified parameters. When connected,
19021908
* call cfg80211_connect_result() with status code %WLAN_STATUS_SUCCESS.
19031909
* If the connection fails for some reason, call cfg80211_connect_result()
19041910
* with the status from the AP.
1911+
* (invoked with the wireless_dev mutex held)
19051912
* @disconnect: Disconnect from the BSS/ESS.
1913+
* (invoked with the wireless_dev mutex held)
19061914
*
19071915
* @join_ibss: Join the specified IBSS (or create if necessary). Once done, call
19081916
* cfg80211_ibss_joined(), also call that function when changing BSSID due
19091917
* to a merge.
1918+
* (invoked with the wireless_dev mutex held)
19101919
* @leave_ibss: Leave the IBSS.
1920+
* (invoked with the wireless_dev mutex held)
19111921
*
19121922
* @set_mcast_rate: Set the specified multicast rate (only if vif is in ADHOC or
19131923
* MESH mode)
@@ -2851,7 +2861,8 @@ struct cfg80211_cached_keys;
28512861
* by cfg80211 on change_interface
28522862
* @mgmt_registrations: list of registrations for management frames
28532863
* @mgmt_registrations_lock: lock for the list
2854-
* @mtx: mutex used to lock data in this struct
2864+
* @mtx: mutex used to lock data in this struct, may be used by drivers
2865+
* and some API functions require it held
28552866
* @cleanup_work: work struct used for cleanup that can't be done directly
28562867
* @beacon_interval: beacon interval used on this device for transmitting
28572868
* beacons, 0 when not valid
@@ -3424,7 +3435,8 @@ void cfg80211_unlink_bss(struct wiphy *wiphy, struct cfg80211_bss *bss);
34243435
* This function is called whenever an authentication has been processed in
34253436
* station mode. The driver is required to call either this function or
34263437
* cfg80211_send_auth_timeout() to indicate the result of cfg80211_ops::auth()
3427-
* call. This function may sleep.
3438+
* call. This function may sleep. The caller must hold the corresponding wdev's
3439+
* mutex.
34283440
*/
34293441
void cfg80211_send_rx_auth(struct net_device *dev, const u8 *buf, size_t len);
34303442

@@ -3433,7 +3445,8 @@ void cfg80211_send_rx_auth(struct net_device *dev, const u8 *buf, size_t len);
34333445
* @dev: network device
34343446
* @addr: The MAC address of the device with which the authentication timed out
34353447
*
3436-
* This function may sleep.
3448+
* This function may sleep. The caller must hold the corresponding wdev's
3449+
* mutex.
34373450
*/
34383451
void cfg80211_send_auth_timeout(struct net_device *dev, const u8 *addr);
34393452

@@ -3448,7 +3461,8 @@ void cfg80211_send_auth_timeout(struct net_device *dev, const u8 *addr);
34483461
* This function is called whenever a (re)association response has been
34493462
* processed in station mode. The driver is required to call either this
34503463
* function or cfg80211_send_assoc_timeout() to indicate the result of
3451-
* cfg80211_ops::assoc() call. This function may sleep.
3464+
* cfg80211_ops::assoc() call. This function may sleep. The caller must hold
3465+
* the corresponding wdev's mutex.
34523466
*/
34533467
void cfg80211_send_rx_assoc(struct net_device *dev, struct cfg80211_bss *bss,
34543468
const u8 *buf, size_t len);
@@ -3458,7 +3472,7 @@ void cfg80211_send_rx_assoc(struct net_device *dev, struct cfg80211_bss *bss,
34583472
* @dev: network device
34593473
* @addr: The MAC address of the device with which the association timed out
34603474
*
3461-
* This function may sleep.
3475+
* This function may sleep. The caller must hold the corresponding wdev's mutex.
34623476
*/
34633477
void cfg80211_send_assoc_timeout(struct net_device *dev, const u8 *addr);
34643478

@@ -3470,20 +3484,11 @@ void cfg80211_send_assoc_timeout(struct net_device *dev, const u8 *addr);
34703484
*
34713485
* This function is called whenever deauthentication has been processed in
34723486
* station mode. This includes both received deauthentication frames and
3473-
* locally generated ones. This function may sleep.
3487+
* locally generated ones. This function may sleep. The caller must hold the
3488+
* corresponding wdev's mutex.
34743489
*/
34753490
void cfg80211_send_deauth(struct net_device *dev, const u8 *buf, size_t len);
34763491

3477-
/**
3478-
* __cfg80211_send_deauth - notification of processed deauthentication
3479-
* @dev: network device
3480-
* @buf: deauthentication frame (header + body)
3481-
* @len: length of the frame data
3482-
*
3483-
* Like cfg80211_send_deauth(), but doesn't take the wdev lock.
3484-
*/
3485-
void __cfg80211_send_deauth(struct net_device *dev, const u8 *buf, size_t len);
3486-
34873492
/**
34883493
* cfg80211_send_disassoc - notification of processed disassociation
34893494
* @dev: network device
@@ -3492,21 +3497,11 @@ void __cfg80211_send_deauth(struct net_device *dev, const u8 *buf, size_t len);
34923497
*
34933498
* This function is called whenever disassociation has been processed in
34943499
* station mode. This includes both received disassociation frames and locally
3495-
* generated ones. This function may sleep.
3500+
* generated ones. This function may sleep. The caller must hold the
3501+
* corresponding wdev's mutex.
34963502
*/
34973503
void cfg80211_send_disassoc(struct net_device *dev, const u8 *buf, size_t len);
34983504

3499-
/**
3500-
* __cfg80211_send_disassoc - notification of processed disassociation
3501-
* @dev: network device
3502-
* @buf: disassociation response frame (header + body)
3503-
* @len: length of the frame data
3504-
*
3505-
* Like cfg80211_send_disassoc(), but doesn't take the wdev lock.
3506-
*/
3507-
void __cfg80211_send_disassoc(struct net_device *dev, const u8 *buf,
3508-
size_t len);
3509-
35103505
/**
35113506
* cfg80211_send_unprot_deauth - notification of unprotected deauthentication
35123507
* @dev: network device

‎net/mac80211/cfg.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2318,7 +2318,7 @@ int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
23182318
enum ieee80211_smps_mode old_req;
23192319
int err;
23202320

2321-
lockdep_assert_held(&sdata->u.mgd.mtx);
2321+
lockdep_assert_held(&sdata->wdev.mtx);
23222322

23232323
old_req = sdata->u.mgd.req_smps;
23242324
sdata->u.mgd.req_smps = smps_mode;
@@ -2375,9 +2375,7 @@ static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
23752375
local->dynamic_ps_forced_timeout = timeout;
23762376

23772377
/* no change, but if automatic follow powersave */
2378-
mutex_lock(&sdata->u.mgd.mtx);
23792378
__ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
2380-
mutex_unlock(&sdata->u.mgd.mtx);
23812379

23822380
if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
23832381
ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);

‎net/mac80211/debugfs_netdev.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ static int ieee80211_set_smps(struct ieee80211_sub_if_data *sdata,
228228
if (sdata->vif.type != NL80211_IFTYPE_STATION)
229229
return -EOPNOTSUPP;
230230

231-
mutex_lock(&sdata->u.mgd.mtx);
231+
sdata_lock(sdata);
232232
err = __ieee80211_request_smps(sdata, smps_mode);
233-
mutex_unlock(&sdata->u.mgd.mtx);
233+
sdata_unlock(sdata);
234234

235235
return err;
236236
}
@@ -313,16 +313,16 @@ static ssize_t ieee80211_if_parse_tkip_mic_test(
313313
case NL80211_IFTYPE_STATION:
314314
fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
315315
/* BSSID SA DA */
316-
mutex_lock(&sdata->u.mgd.mtx);
316+
sdata_lock(sdata);
317317
if (!sdata->u.mgd.associated) {
318-
mutex_unlock(&sdata->u.mgd.mtx);
318+
sdata_unlock(sdata);
319319
dev_kfree_skb(skb);
320320
return -ENOTCONN;
321321
}
322322
memcpy(hdr->addr1, sdata->u.mgd.associated->bssid, ETH_ALEN);
323323
memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
324324
memcpy(hdr->addr3, addr, ETH_ALEN);
325-
mutex_unlock(&sdata->u.mgd.mtx);
325+
sdata_unlock(sdata);
326326
break;
327327
default:
328328
dev_kfree_skb(skb);

‎net/mac80211/ht.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,9 @@ void ieee80211_request_smps_work(struct work_struct *work)
429429
container_of(work, struct ieee80211_sub_if_data,
430430
u.mgd.request_smps_work);
431431

432-
mutex_lock(&sdata->u.mgd.mtx);
432+
sdata_lock(sdata);
433433
__ieee80211_request_smps(sdata, sdata->u.mgd.driver_smps_mode);
434-
mutex_unlock(&sdata->u.mgd.mtx);
434+
sdata_unlock(sdata);
435435
}
436436

437437
void ieee80211_request_smps(struct ieee80211_vif *vif,

‎net/mac80211/ibss.c‎

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
5454
struct beacon_data *presp;
5555
int frame_len;
5656

57-
lockdep_assert_held(&ifibss->mtx);
57+
sdata_assert_lock(sdata);
5858

5959
/* Reset own TSF to allow time synchronization work. */
6060
drv_reset_tsf(local, sdata);
@@ -74,7 +74,7 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
7474
}
7575

7676
presp = rcu_dereference_protected(ifibss->presp,
77-
lockdep_is_held(&ifibss->mtx));
77+
lockdep_is_held(&sdata->wdev.mtx));
7878
rcu_assign_pointer(ifibss->presp, NULL);
7979
if (presp)
8080
kfree_rcu(presp, rcu_head);
@@ -263,7 +263,7 @@ static void ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
263263
const struct cfg80211_bss_ies *ies;
264264
u64 tsf;
265265

266-
lockdep_assert_held(&sdata->u.ibss.mtx);
266+
sdata_assert_lock(sdata);
267267

268268
if (beacon_int < 10)
269269
beacon_int = 10;
@@ -410,7 +410,7 @@ static void ieee80211_rx_mgmt_auth_ibss(struct ieee80211_sub_if_data *sdata,
410410
struct sta_info *sta;
411411
u8 deauth_frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
412412

413-
lockdep_assert_held(&sdata->u.ibss.mtx);
413+
sdata_assert_lock(sdata);
414414

415415
if (len < 24 + 6)
416416
return;
@@ -677,7 +677,7 @@ static int ieee80211_sta_active_ibss(struct ieee80211_sub_if_data *sdata)
677677
int active = 0;
678678
struct sta_info *sta;
679679

680-
lockdep_assert_held(&sdata->u.ibss.mtx);
680+
sdata_assert_lock(sdata);
681681

682682
rcu_read_lock();
683683

@@ -703,7 +703,7 @@ static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata)
703703
{
704704
struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
705705

706-
lockdep_assert_held(&ifibss->mtx);
706+
sdata_assert_lock(sdata);
707707

708708
mod_timer(&ifibss->timer,
709709
round_jiffies(jiffies + IEEE80211_IBSS_MERGE_INTERVAL));
@@ -734,7 +734,7 @@ static void ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata)
734734
u16 capability;
735735
int i;
736736

737-
lockdep_assert_held(&ifibss->mtx);
737+
sdata_assert_lock(sdata);
738738

739739
if (ifibss->fixed_bssid) {
740740
memcpy(bssid, ifibss->bssid, ETH_ALEN);
@@ -777,7 +777,7 @@ static void ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata)
777777
int active_ibss;
778778
u16 capability;
779779

780-
lockdep_assert_held(&ifibss->mtx);
780+
sdata_assert_lock(sdata);
781781

782782
active_ibss = ieee80211_sta_active_ibss(sdata);
783783
ibss_dbg(sdata, "sta_find_ibss (active_ibss=%d)\n", active_ibss);
@@ -847,10 +847,10 @@ static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
847847
struct beacon_data *presp;
848848
u8 *pos, *end;
849849

850-
lockdep_assert_held(&ifibss->mtx);
850+
sdata_assert_lock(sdata);
851851

852852
presp = rcu_dereference_protected(ifibss->presp,
853-
lockdep_is_held(&ifibss->mtx));
853+
lockdep_is_held(&sdata->wdev.mtx));
854854

855855
if (ifibss->state != IEEE80211_IBSS_MLME_JOINED ||
856856
len < 24 + 2 || !presp)
@@ -934,7 +934,7 @@ void ieee80211_ibss_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
934934
mgmt = (struct ieee80211_mgmt *) skb->data;
935935
fc = le16_to_cpu(mgmt->frame_control);
936936

937-
mutex_lock(&sdata->u.ibss.mtx);
937+
sdata_lock(sdata);
938938

939939
if (!sdata->u.ibss.ssid_len)
940940
goto mgmt_out; /* not ready to merge yet */
@@ -957,15 +957,15 @@ void ieee80211_ibss_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
957957
}
958958

959959
mgmt_out:
960-
mutex_unlock(&sdata->u.ibss.mtx);
960+
sdata_unlock(sdata);
961961
}
962962

963963
void ieee80211_ibss_work(struct ieee80211_sub_if_data *sdata)
964964
{
965965
struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
966966
struct sta_info *sta;
967967

968-
mutex_lock(&ifibss->mtx);
968+
sdata_lock(sdata);
969969

970970
/*
971971
* Work could be scheduled after scan or similar
@@ -1001,7 +1001,7 @@ void ieee80211_ibss_work(struct ieee80211_sub_if_data *sdata)
10011001
}
10021002

10031003
out:
1004-
mutex_unlock(&ifibss->mtx);
1004+
sdata_unlock(sdata);
10051005
}
10061006

10071007
static void ieee80211_ibss_timer(unsigned long data)
@@ -1018,7 +1018,6 @@ void ieee80211_ibss_setup_sdata(struct ieee80211_sub_if_data *sdata)
10181018

10191019
setup_timer(&ifibss->timer, ieee80211_ibss_timer,
10201020
(unsigned long) sdata);
1021-
mutex_init(&ifibss->mtx);
10221021
INIT_LIST_HEAD(&ifibss->incomplete_stations);
10231022
spin_lock_init(&ifibss->incomplete_lock);
10241023
}
@@ -1045,8 +1044,6 @@ int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
10451044
{
10461045
u32 changed = 0;
10471046

1048-
mutex_lock(&sdata->u.ibss.mtx);
1049-
10501047
if (params->bssid) {
10511048
memcpy(sdata->u.ibss.bssid, params->bssid, ETH_ALEN);
10521049
sdata->u.ibss.fixed_bssid = true;
@@ -1079,8 +1076,6 @@ int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
10791076
memcpy(sdata->u.ibss.ssid, params->ssid, params->ssid_len);
10801077
sdata->u.ibss.ssid_len = params->ssid_len;
10811078

1082-
mutex_unlock(&sdata->u.ibss.mtx);
1083-
10841079
/*
10851080
* 802.11n-2009 9.13.3.1: In an IBSS, the HT Protection field is
10861081
* reserved, but an HT STA shall protect HT transmissions as though
@@ -1116,8 +1111,6 @@ int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata)
11161111
struct sta_info *sta;
11171112
struct beacon_data *presp;
11181113

1119-
mutex_lock(&sdata->u.ibss.mtx);
1120-
11211114
active_ibss = ieee80211_sta_active_ibss(sdata);
11221115

11231116
if (!active_ibss && !is_zero_ether_addr(ifibss->bssid)) {
@@ -1161,7 +1154,7 @@ int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata)
11611154
/* remove beacon */
11621155
kfree(sdata->u.ibss.ie);
11631156
presp = rcu_dereference_protected(ifibss->presp,
1164-
lockdep_is_held(&sdata->u.ibss.mtx));
1157+
lockdep_is_held(&sdata->wdev.mtx));
11651158
RCU_INIT_POINTER(sdata->u.ibss.presp, NULL);
11661159
sdata->vif.bss_conf.ibss_joined = false;
11671160
sdata->vif.bss_conf.ibss_creator = false;
@@ -1177,7 +1170,5 @@ int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata)
11771170

11781171
del_timer_sync(&sdata->u.ibss.timer);
11791172

1180-
mutex_unlock(&sdata->u.ibss.mtx);
1181-
11821173
return 0;
11831174
}

0 commit comments

Comments
 (0)