Commit ad0e2b5a authored by Johannes Berg's avatar Johannes Berg Committed by John W. Linville

mac80211: simplify key locking

Since I recently made station management able
to sleep, I can now rework key management as
well; since it will no longer need a spinlock
and can also use a mutex instead, a bunch of
code to allow drivers' set_key to sleep while
key management is protected by a spinlock can
now be removed.
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent efe4c457
......@@ -120,6 +120,9 @@ static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
struct ieee80211_key *key;
int err;
if (!netif_running(dev))
return -ENETDOWN;
sdata = IEEE80211_DEV_TO_SUB_IF(dev);
switch (params->cipher) {
......@@ -145,7 +148,7 @@ static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
if (!key)
return -ENOMEM;
rcu_read_lock();
mutex_lock(&sdata->local->sta_mtx);
if (mac_addr) {
sta = sta_info_get_bss(sdata, mac_addr);
......@@ -160,7 +163,7 @@ static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
err = 0;
out_unlock:
rcu_read_unlock();
mutex_unlock(&sdata->local->sta_mtx);
return err;
}
......@@ -174,7 +177,7 @@ static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
sdata = IEEE80211_DEV_TO_SUB_IF(dev);
rcu_read_lock();
mutex_lock(&sdata->local->sta_mtx);
if (mac_addr) {
ret = -ENOENT;
......@@ -202,7 +205,7 @@ static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
ret = 0;
out_unlock:
rcu_read_unlock();
mutex_unlock(&sdata->local->sta_mtx);
return ret;
}
......@@ -305,15 +308,10 @@ static int ieee80211_config_default_key(struct wiphy *wiphy,
struct net_device *dev,
u8 key_idx)
{
struct ieee80211_sub_if_data *sdata;
rcu_read_lock();
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
sdata = IEEE80211_DEV_TO_SUB_IF(dev);
ieee80211_set_default_key(sdata, key_idx);
rcu_read_unlock();
return 0;
}
......
......@@ -746,10 +746,10 @@ struct ieee80211_local {
struct mutex iflist_mtx;
/*
* Key lock, protects sdata's key_list and sta_info's
* Key mutex, protects sdata's key_list and sta_info's
* key pointers (write access, they're RCU.)
*/
spinlock_t key_lock;
struct mutex key_mtx;
/* Scanning and BSS list */
......
......@@ -268,7 +268,6 @@ static int ieee80211_open(struct net_device *dev)
changed |= ieee80211_reset_erp_info(sdata);
ieee80211_bss_info_change_notify(sdata, changed);
ieee80211_enable_keys(sdata);
if (sdata->vif.type == NL80211_IFTYPE_STATION)
netif_carrier_off(dev);
......@@ -522,8 +521,8 @@ static int ieee80211_stop(struct net_device *dev)
BSS_CHANGED_BEACON_ENABLED);
}
/* disable all keys for as long as this netdev is down */
ieee80211_disable_keys(sdata);
/* free all remaining keys, there shouldn't be any */
ieee80211_free_keys(sdata);
drv_remove_interface(local, &sdata->vif);
}
......
This diff is collapsed.
......@@ -38,25 +38,9 @@ struct sta_info;
*
* @KEY_FLAG_UPLOADED_TO_HARDWARE: Indicates that this key is present
* in the hardware for TX crypto hardware acceleration.
* @KEY_FLAG_TODO_DELETE: Key is marked for deletion and will, after an
* RCU grace period, no longer be reachable other than from the
* todo list.
* @KEY_FLAG_TODO_HWACCEL_ADD: Key needs to be added to hardware acceleration.
* @KEY_FLAG_TODO_HWACCEL_REMOVE: Key needs to be removed from hardware
* acceleration.
* @KEY_FLAG_TODO_DEFKEY: Key is default key and debugfs needs to be updated.
* @KEY_FLAG_TODO_ADD_DEBUGFS: Key needs to be added to debugfs.
* @KEY_FLAG_TODO_DEFMGMTKEY: Key is default management key and debugfs needs
* to be updated.
*/
enum ieee80211_internal_key_flags {
KEY_FLAG_UPLOADED_TO_HARDWARE = BIT(0),
KEY_FLAG_TODO_DELETE = BIT(1),
KEY_FLAG_TODO_HWACCEL_ADD = BIT(2),
KEY_FLAG_TODO_HWACCEL_REMOVE = BIT(3),
KEY_FLAG_TODO_DEFKEY = BIT(4),
KEY_FLAG_TODO_ADD_DEBUGFS = BIT(5),
KEY_FLAG_TODO_DEFMGMTKEY = BIT(6),
};
enum ieee80211_internal_tkip_state {
......@@ -79,10 +63,8 @@ struct ieee80211_key {
/* for sdata list */
struct list_head list;
/* for todo list */
struct list_head todo;
/* protected by todo lock! */
/* protected by key mutex */
unsigned int flags;
union {
......@@ -155,6 +137,4 @@ void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata);
void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata);
void ieee80211_disable_keys(struct ieee80211_sub_if_data *sdata);
void ieee80211_key_todo(void);
#endif /* IEEE80211_KEY_H */
......@@ -448,7 +448,7 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
mutex_init(&local->iflist_mtx);
mutex_init(&local->scan_mtx);
spin_lock_init(&local->key_lock);
mutex_init(&local->key_mtx);
spin_lock_init(&local->filter_lock);
spin_lock_init(&local->queue_stop_reason_lock);
......
......@@ -648,14 +648,6 @@ static int __must_check __sta_info_destroy(struct sta_info *sta)
if (sta->key) {
ieee80211_key_free(sta->key);
/*
* We have only unlinked the key, and actually destroying it
* may mean it is removed from hardware which requires that
* the key->sta pointer is still valid, so flush the key todo
* list here.
*/
ieee80211_key_todo();
WARN_ON(sta->key);
}
......
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