Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d3cebbdc authored by Johannes Berg's avatar Johannes Berg Committed by John W. Linville
Browse files

mac80211: fix todo lock

The key todo lock can be taken from different locks
that require it to be _bh to avoid lock inversion
due to (soft)irqs.

This should fix the two problems reported by Bob and
Gabor:
http://mid.gmane.org/20090619113049.GB18956@hash.localnet
http://mid.gmane.org/4A3FA376.8020307@openwrt.org



Signed-off-by: default avatarJohannes Berg <johannes@sipsolutions.net>
Cc: Bob Copeland <me@bobcopeland.com>
Cc: Gabor Juhos <juhosg@openwrt.org>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent df2b35b6
Loading
Loading
Loading
Loading
+15 −13
Original line number Original line Diff line number Diff line
@@ -67,6 +67,8 @@ static DECLARE_WORK(todo_work, key_todo);
 *
 *
 * @key: key to add to do item for
 * @key: key to add to do item for
 * @flag: todo flag(s)
 * @flag: todo flag(s)
 *
 * Must be called with IRQs or softirqs disabled.
 */
 */
static void add_todo(struct ieee80211_key *key, u32 flag)
static void add_todo(struct ieee80211_key *key, u32 flag)
{
{
@@ -140,9 +142,9 @@ static void ieee80211_key_enable_hw_accel(struct ieee80211_key *key)
	ret = drv_set_key(key->local, SET_KEY, &sdata->vif, sta, &key->conf);
	ret = drv_set_key(key->local, SET_KEY, &sdata->vif, sta, &key->conf);


	if (!ret) {
	if (!ret) {
		spin_lock(&todo_lock);
		spin_lock_bh(&todo_lock);
		key->flags |= KEY_FLAG_UPLOADED_TO_HARDWARE;
		key->flags |= KEY_FLAG_UPLOADED_TO_HARDWARE;
		spin_unlock(&todo_lock);
		spin_unlock_bh(&todo_lock);
	}
	}


	if (ret && ret != -ENOSPC && ret != -EOPNOTSUPP)
	if (ret && ret != -ENOSPC && ret != -EOPNOTSUPP)
@@ -164,12 +166,12 @@ static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key)
	if (!key || !key->local->ops->set_key)
	if (!key || !key->local->ops->set_key)
		return;
		return;


	spin_lock(&todo_lock);
	spin_lock_bh(&todo_lock);
	if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) {
	if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) {
		spin_unlock(&todo_lock);
		spin_unlock_bh(&todo_lock);
		return;
		return;
	}
	}
	spin_unlock(&todo_lock);
	spin_unlock_bh(&todo_lock);


	sta = get_sta_for_key(key);
	sta = get_sta_for_key(key);
	sdata = key->sdata;
	sdata = key->sdata;
@@ -188,9 +190,9 @@ static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key)
		       wiphy_name(key->local->hw.wiphy),
		       wiphy_name(key->local->hw.wiphy),
		       key->conf.keyidx, sta ? sta->addr : bcast_addr, ret);
		       key->conf.keyidx, sta ? sta->addr : bcast_addr, ret);


	spin_lock(&todo_lock);
	spin_lock_bh(&todo_lock);
	key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE;
	key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE;
	spin_unlock(&todo_lock);
	spin_unlock_bh(&todo_lock);
}
}


static void __ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata,
static void __ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata,
@@ -437,14 +439,14 @@ void ieee80211_key_link(struct ieee80211_key *key,


	__ieee80211_key_replace(sdata, sta, old_key, key);
	__ieee80211_key_replace(sdata, sta, old_key, key);


	spin_unlock_irqrestore(&sdata->local->key_lock, flags);

	/* free old key later */
	/* free old key later */
	add_todo(old_key, KEY_FLAG_TODO_DELETE);
	add_todo(old_key, KEY_FLAG_TODO_DELETE);


	add_todo(key, KEY_FLAG_TODO_ADD_DEBUGFS);
	add_todo(key, KEY_FLAG_TODO_ADD_DEBUGFS);
	if (netif_running(sdata->dev))
	if (netif_running(sdata->dev))
		add_todo(key, KEY_FLAG_TODO_HWACCEL_ADD);
		add_todo(key, KEY_FLAG_TODO_HWACCEL_ADD);

	spin_unlock_irqrestore(&sdata->local->key_lock, flags);
}
}


static void __ieee80211_key_free(struct ieee80211_key *key)
static void __ieee80211_key_free(struct ieee80211_key *key)
@@ -547,7 +549,7 @@ static void __ieee80211_key_todo(void)
	 */
	 */
	synchronize_rcu();
	synchronize_rcu();


	spin_lock(&todo_lock);
	spin_lock_bh(&todo_lock);
	while (!list_empty(&todo_list)) {
	while (!list_empty(&todo_list)) {
		key = list_first_entry(&todo_list, struct ieee80211_key, todo);
		key = list_first_entry(&todo_list, struct ieee80211_key, todo);
		list_del_init(&key->todo);
		list_del_init(&key->todo);
@@ -558,7 +560,7 @@ static void __ieee80211_key_todo(void)
					  KEY_FLAG_TODO_HWACCEL_REMOVE |
					  KEY_FLAG_TODO_HWACCEL_REMOVE |
					  KEY_FLAG_TODO_DELETE);
					  KEY_FLAG_TODO_DELETE);
		key->flags &= ~todoflags;
		key->flags &= ~todoflags;
		spin_unlock(&todo_lock);
		spin_unlock_bh(&todo_lock);


		work_done = false;
		work_done = false;


@@ -591,9 +593,9 @@ static void __ieee80211_key_todo(void)


		WARN_ON(!work_done);
		WARN_ON(!work_done);


		spin_lock(&todo_lock);
		spin_lock_bh(&todo_lock);
	}
	}
	spin_unlock(&todo_lock);
	spin_unlock_bh(&todo_lock);
}
}


void ieee80211_key_todo(void)
void ieee80211_key_todo(void)