1 From: Johannes Berg <johannes@sipsolutions.net>
2 Subject: mac80211: fix todo lock
4 The key todo lock can be taken from different locks
5 that require it to be _bh to avoid lock inversion
8 This should fix the two problems reported by Bob and
10 http://mid.gmane.org/20090619113049.GB18956@hash.localnet
11 http://mid.gmane.org/4A3FA376.8020307@openwrt.org
13 Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
14 Cc: Bob Copeland <me@bobcopeland.com>
15 Cc: Gabor Juhos <juhosg@openwrt.org>
17 net/mac80211/key.c | 28 +++++++++++++++-------------
18 1 file changed, 15 insertions(+), 13 deletions(-)
20 --- a/net/mac80211/key.c
21 +++ b/net/mac80211/key.c
22 @@ -70,6 +70,8 @@ static DECLARE_WORK(todo_work, key_todo)
24 * @key: key to add to do item for
27 + * Must be called with IRQs or softirqs disabled.
29 static void add_todo(struct ieee80211_key *key, u32 flag)
31 @@ -143,9 +145,9 @@ static void ieee80211_key_enable_hw_acce
32 ret = drv_set_key(key->local, SET_KEY, &sdata->vif, sta, &key->conf);
35 - spin_lock(&todo_lock);
36 + spin_lock_bh(&todo_lock);
37 key->flags |= KEY_FLAG_UPLOADED_TO_HARDWARE;
38 - spin_unlock(&todo_lock);
39 + spin_unlock_bh(&todo_lock);
42 if (ret && ret != -ENOSPC && ret != -EOPNOTSUPP)
43 @@ -167,12 +169,12 @@ static void ieee80211_key_disable_hw_acc
44 if (!key || !key->local->ops->set_key)
47 - spin_lock(&todo_lock);
48 + spin_lock_bh(&todo_lock);
49 if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) {
50 - spin_unlock(&todo_lock);
51 + spin_unlock_bh(&todo_lock);
54 - spin_unlock(&todo_lock);
55 + spin_unlock_bh(&todo_lock);
57 sta = get_sta_for_key(key);
59 @@ -191,9 +193,9 @@ static void ieee80211_key_disable_hw_acc
60 wiphy_name(key->local->hw.wiphy),
61 key->conf.keyidx, sta ? sta->addr : bcast_addr, ret);
63 - spin_lock(&todo_lock);
64 + spin_lock_bh(&todo_lock);
65 key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE;
66 - spin_unlock(&todo_lock);
67 + spin_unlock_bh(&todo_lock);
70 static void __ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata,
71 @@ -440,14 +442,14 @@ void ieee80211_key_link(struct ieee80211
73 __ieee80211_key_replace(sdata, sta, old_key, key);
75 - spin_unlock_irqrestore(&sdata->local->key_lock, flags);
77 /* free old key later */
78 add_todo(old_key, KEY_FLAG_TODO_DELETE);
80 add_todo(key, KEY_FLAG_TODO_ADD_DEBUGFS);
81 if (netif_running(sdata->dev))
82 add_todo(key, KEY_FLAG_TODO_HWACCEL_ADD);
84 + spin_unlock_irqrestore(&sdata->local->key_lock, flags);
87 static void __ieee80211_key_free(struct ieee80211_key *key)
88 @@ -550,7 +552,7 @@ static void __ieee80211_key_todo(void)
92 - spin_lock(&todo_lock);
93 + spin_lock_bh(&todo_lock);
94 while (!list_empty(&todo_list)) {
95 key = list_first_entry(&todo_list, struct ieee80211_key, todo);
96 list_del_init(&key->todo);
97 @@ -561,7 +563,7 @@ static void __ieee80211_key_todo(void)
98 KEY_FLAG_TODO_HWACCEL_REMOVE |
99 KEY_FLAG_TODO_DELETE);
100 key->flags &= ~todoflags;
101 - spin_unlock(&todo_lock);
102 + spin_unlock_bh(&todo_lock);
106 @@ -594,9 +596,9 @@ static void __ieee80211_key_todo(void)
110 - spin_lock(&todo_lock);
111 + spin_lock_bh(&todo_lock);
113 - spin_unlock(&todo_lock);
114 + spin_unlock_bh(&todo_lock);
117 void ieee80211_key_todo(void)