aboutsummaryrefslogtreecommitdiffstats
path: root/net/mac80211/sta_info.c
diff options
context:
space:
mode:
authorJohannes Berg <johannes@sipsolutions.net>2008-02-25 10:27:47 -0500
committerJohn W. Linville <linville@tuxdriver.com>2008-03-06 15:30:47 -0500
commit73651ee6396c499ccb59ebc84c9274db01ed026d (patch)
tree1d59027cbdaec732f3e1378770cbf7b42b48cd70 /net/mac80211/sta_info.c
parentd0709a65181beb787ef3f58cfe45536a2bb254c8 (diff)
mac80211: split sta_info_add
sta_info_add() has two functions: allocating a station info structure and inserting it into the hash table/list. Splitting these two functions allows allocating with GFP_KERNEL in many places instead of GFP_ATOMIC which is now required by the RCU protection. Additionally, in many places RCU protection is now no longer needed at all because between sta_info_alloc() and sta_info_insert() the caller owns the structure. This fixes a few race conditions with setting initial flags and similar, but not all (see comments in ieee80211_sta.c and cfg.c). More documentation on the existing races will be in a follow-up patch. Signed-off-by: Johannes Berg <johannes@sipsolutions.net> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'net/mac80211/sta_info.c')
-rw-r--r--net/mac80211/sta_info.c72
1 files changed, 50 insertions, 22 deletions
diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c
index ee5b66abc0f1..a230a9597398 100644
--- a/net/mac80211/sta_info.c
+++ b/net/mac80211/sta_info.c
@@ -31,12 +31,13 @@
31 * for faster lookup and a list for iteration. They are managed using 31 * for faster lookup and a list for iteration. They are managed using
32 * RCU, i.e. access to the list and hash table is protected by RCU. 32 * RCU, i.e. access to the list and hash table is protected by RCU.
33 * 33 *
34 * STA info structures are always "alive" when they are added with 34 * Upon allocating a STA info structure with @sta_info_alloc() or
35 * @sta_info_add() [this may be changed in the future to allow allocating 35 * mesh_plink_alloc(), the caller owns that structure. It must then either
36 * outside of a critical section!], they are then added to the hash 36 * destroy it using @sta_info_destroy() (which is pretty useless) or insert
37 * table and list. Therefore, @sta_info_add() must also be RCU protected, 37 * it into the hash table using @sta_info_insert() which demotes the reference
38 * also, the caller of @sta_info_add() cannot assume that it owns the 38 * from ownership to a regular RCU-protected reference; if the function
39 * structure. 39 * is called without protection by an RCU critical section the reference
40 * is instantly invalidated.
40 * 41 *
41 * Because there are debugfs entries for each station, and adding those 42 * Because there are debugfs entries for each station, and adding those
42 * must be able to sleep, it is also possible to "pin" a station entry, 43 * must be able to sleep, it is also possible to "pin" a station entry,
@@ -131,6 +132,10 @@ void sta_info_destroy(struct sta_info *sta)
131 struct ieee80211_local *local = sta->local; 132 struct ieee80211_local *local = sta->local;
132 struct sk_buff *skb; 133 struct sk_buff *skb;
133 int i; 134 int i;
135 DECLARE_MAC_BUF(mbuf);
136
137 if (!sta)
138 return;
134 139
135 ASSERT_RTNL(); 140 ASSERT_RTNL();
136 might_sleep(); 141 might_sleep();
@@ -171,6 +176,11 @@ void sta_info_destroy(struct sta_info *sta)
171 rate_control_free_sta(sta->rate_ctrl, sta->rate_ctrl_priv); 176 rate_control_free_sta(sta->rate_ctrl, sta->rate_ctrl_priv);
172 rate_control_put(sta->rate_ctrl); 177 rate_control_put(sta->rate_ctrl);
173 178
179#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
180 printk(KERN_DEBUG "%s: Destroyed STA %s\n",
181 wiphy_name(local->hw.wiphy), print_mac(mbuf, sta->addr));
182#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
183
174 kfree(sta); 184 kfree(sta);
175} 185}
176 186
@@ -183,18 +193,17 @@ static void sta_info_hash_add(struct ieee80211_local *local,
183 rcu_assign_pointer(local->sta_hash[STA_HASH(sta->addr)], sta); 193 rcu_assign_pointer(local->sta_hash[STA_HASH(sta->addr)], sta);
184} 194}
185 195
186struct sta_info *sta_info_add(struct ieee80211_sub_if_data *sdata, 196struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
187 u8 *addr) 197 u8 *addr, gfp_t gfp)
188{ 198{
189 struct ieee80211_local *local = sdata->local; 199 struct ieee80211_local *local = sdata->local;
190 struct sta_info *sta; 200 struct sta_info *sta;
191 int i; 201 int i;
192 DECLARE_MAC_BUF(mac); 202 DECLARE_MAC_BUF(mbuf);
193 unsigned long flags;
194 203
195 sta = kzalloc(sizeof(*sta), GFP_ATOMIC); 204 sta = kzalloc(sizeof(*sta), gfp);
196 if (!sta) 205 if (!sta)
197 return ERR_PTR(-ENOMEM); 206 return NULL;
198 207
199 memcpy(sta->addr, addr, ETH_ALEN); 208 memcpy(sta->addr, addr, ETH_ALEN);
200 sta->local = local; 209 sta->local = local;
@@ -202,11 +211,11 @@ struct sta_info *sta_info_add(struct ieee80211_sub_if_data *sdata,
202 211
203 sta->rate_ctrl = rate_control_get(local->rate_ctrl); 212 sta->rate_ctrl = rate_control_get(local->rate_ctrl);
204 sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl, 213 sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl,
205 GFP_ATOMIC); 214 gfp);
206 if (!sta->rate_ctrl_priv) { 215 if (!sta->rate_ctrl_priv) {
207 rate_control_put(sta->rate_ctrl); 216 rate_control_put(sta->rate_ctrl);
208 kfree(sta); 217 kfree(sta);
209 return ERR_PTR(-ENOMEM); 218 return NULL;
210 } 219 }
211 220
212 spin_lock_init(&sta->ampdu_mlme.ampdu_rx); 221 spin_lock_init(&sta->ampdu_mlme.ampdu_rx);
@@ -233,11 +242,27 @@ struct sta_info *sta_info_add(struct ieee80211_sub_if_data *sdata,
233 } 242 }
234 skb_queue_head_init(&sta->ps_tx_buf); 243 skb_queue_head_init(&sta->ps_tx_buf);
235 skb_queue_head_init(&sta->tx_filtered); 244 skb_queue_head_init(&sta->tx_filtered);
245
246#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
247 printk(KERN_DEBUG "%s: Allocated STA %s\n",
248 wiphy_name(local->hw.wiphy), print_mac(mbuf, sta->addr));
249#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
250
251 return sta;
252}
253
254int sta_info_insert(struct sta_info *sta)
255{
256 struct ieee80211_local *local = sta->local;
257 struct ieee80211_sub_if_data *sdata = sta->sdata;
258 unsigned long flags;
259 DECLARE_MAC_BUF(mac);
260
236 spin_lock_irqsave(&local->sta_lock, flags); 261 spin_lock_irqsave(&local->sta_lock, flags);
237 /* check if STA exists already */ 262 /* check if STA exists already */
238 if (__sta_info_find(local, addr)) { 263 if (__sta_info_find(local, sta->addr)) {
239 spin_unlock_irqrestore(&local->sta_lock, flags); 264 spin_unlock_irqrestore(&local->sta_lock, flags);
240 return ERR_PTR(-EEXIST); 265 return -EEXIST;
241 } 266 }
242 list_add(&sta->list, &local->sta_list); 267 list_add(&sta->list, &local->sta_list);
243 local->num_sta++; 268 local->num_sta++;
@@ -249,16 +274,16 @@ struct sta_info *sta_info_add(struct ieee80211_sub_if_data *sdata,
249 sdata = sdata->u.vlan.ap; 274 sdata = sdata->u.vlan.ap;
250 275
251 local->ops->sta_notify(local_to_hw(local), &sdata->vif, 276 local->ops->sta_notify(local_to_hw(local), &sdata->vif,
252 STA_NOTIFY_ADD, addr); 277 STA_NOTIFY_ADD, sta->addr);
253 } 278 }
254 279
255 spin_unlock_irqrestore(&local->sta_lock, flags);
256
257#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 280#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
258 printk(KERN_DEBUG "%s: Added STA %s\n", 281 printk(KERN_DEBUG "%s: Inserted STA %s\n",
259 wiphy_name(local->hw.wiphy), print_mac(mac, addr)); 282 wiphy_name(local->hw.wiphy), print_mac(mac, sta->addr));
260#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ 283#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
261 284
285 spin_unlock_irqrestore(&local->sta_lock, flags);
286
262#ifdef CONFIG_MAC80211_DEBUGFS 287#ifdef CONFIG_MAC80211_DEBUGFS
263 /* debugfs entry adding might sleep, so schedule process 288 /* debugfs entry adding might sleep, so schedule process
264 * context task for adding entry for STAs that do not yet 289 * context task for adding entry for STAs that do not yet
@@ -266,7 +291,10 @@ struct sta_info *sta_info_add(struct ieee80211_sub_if_data *sdata,
266 queue_work(local->hw.workqueue, &local->sta_debugfs_add); 291 queue_work(local->hw.workqueue, &local->sta_debugfs_add);
267#endif 292#endif
268 293
269 return sta; 294 if (ieee80211_vif_is_mesh(&sdata->vif))
295 mesh_accept_plinks_update(sdata);
296
297 return 0;
270} 298}
271 299
272static inline void __bss_tim_set(struct ieee80211_if_ap *bss, u16 aid) 300static inline void __bss_tim_set(struct ieee80211_if_ap *bss, u16 aid)