@@ -48,10 +48,10 @@ static struct mesh_table __rcu *mpp_paths; /* Store paths for MPP&MAP */
4848int mesh_paths_generation ;
4949
5050/* This lock will have the grow table function as writer and add / delete nodes
51- * as readers. When reading the table (i.e. doing lookups) we are well protected
52- * by RCU. We need to take this lock when modying the number of buckets
53- * on one of the path tables but we don't need to if adding or removing mpaths
54- * from hash buckets.
51+ * as readers. RCU provides sufficient protection only when reading the table
52+ * (i.e. doing lookups). Adding or adding or removing nodes requires we take
53+ * the read lock or we risk operating on an old table. The write lock is only
54+ * needed when modifying the number of buckets a table .
5555 */
5656static DEFINE_RWLOCK (pathtbl_resize_lock );
5757
@@ -335,25 +335,14 @@ static void mesh_path_move_to_queue(struct mesh_path *gate_mpath,
335335}
336336
337337
338- /**
339- * mesh_path_lookup - look up a path in the mesh path table
340- * @dst: hardware address (ETH_ALEN length) of destination
341- * @sdata: local subif
342- *
343- * Returns: pointer to the mesh path structure, or NULL if not found
344- *
345- * Locking: must be called within a read rcu section.
346- */
347- struct mesh_path * mesh_path_lookup (u8 * dst , struct ieee80211_sub_if_data * sdata )
338+ static struct mesh_path * path_lookup (struct mesh_table * tbl , u8 * dst ,
339+ struct ieee80211_sub_if_data * sdata )
348340{
349341 struct mesh_path * mpath ;
350342 struct hlist_node * n ;
351343 struct hlist_head * bucket ;
352- struct mesh_table * tbl ;
353344 struct mpath_node * node ;
354345
355- tbl = rcu_dereference (mesh_paths );
356-
357346 bucket = & tbl -> hash_buckets [mesh_table_hash (dst , sdata , tbl )];
358347 hlist_for_each_entry_rcu (node , n , bucket , list ) {
359348 mpath = node -> mpath ;
@@ -370,30 +359,23 @@ struct mesh_path *mesh_path_lookup(u8 *dst, struct ieee80211_sub_if_data *sdata)
370359 return NULL ;
371360}
372361
373- struct mesh_path * mpp_path_lookup (u8 * dst , struct ieee80211_sub_if_data * sdata )
362+ /**
363+ * mesh_path_lookup - look up a path in the mesh path table
364+ * @dst: hardware address (ETH_ALEN length) of destination
365+ * @sdata: local subif
366+ *
367+ * Returns: pointer to the mesh path structure, or NULL if not found
368+ *
369+ * Locking: must be called within a read rcu section.
370+ */
371+ struct mesh_path * mesh_path_lookup (u8 * dst , struct ieee80211_sub_if_data * sdata )
374372{
375- struct mesh_path * mpath ;
376- struct hlist_node * n ;
377- struct hlist_head * bucket ;
378- struct mesh_table * tbl ;
379- struct mpath_node * node ;
380-
381- tbl = rcu_dereference (mpp_paths );
373+ return path_lookup (rcu_dereference (mesh_paths ), dst , sdata );
374+ }
382375
383- bucket = & tbl -> hash_buckets [mesh_table_hash (dst , sdata , tbl )];
384- hlist_for_each_entry_rcu (node , n , bucket , list ) {
385- mpath = node -> mpath ;
386- if (mpath -> sdata == sdata &&
387- memcmp (dst , mpath -> dst , ETH_ALEN ) == 0 ) {
388- if (MPATH_EXPIRED (mpath )) {
389- spin_lock_bh (& mpath -> state_lock );
390- mpath -> flags &= ~MESH_PATH_ACTIVE ;
391- spin_unlock_bh (& mpath -> state_lock );
392- }
393- return mpath ;
394- }
395- }
396- return NULL ;
376+ struct mesh_path * mpp_path_lookup (u8 * dst , struct ieee80211_sub_if_data * sdata )
377+ {
378+ return path_lookup (rcu_dereference (mpp_paths ), dst , sdata );
397379}
398380
399381
@@ -836,7 +818,8 @@ void mesh_path_flush_by_nexthop(struct sta_info *sta)
836818 int i ;
837819
838820 rcu_read_lock ();
839- tbl = rcu_dereference (mesh_paths );
821+ read_lock_bh (& pathtbl_resize_lock );
822+ tbl = resize_dereference_mesh_paths ();
840823 for_each_mesh_entry (tbl , p , node , i ) {
841824 mpath = node -> mpath ;
842825 if (rcu_dereference (mpath -> next_hop ) == sta ) {
@@ -845,6 +828,7 @@ void mesh_path_flush_by_nexthop(struct sta_info *sta)
845828 spin_unlock_bh (& tbl -> hashwlock [i ]);
846829 }
847830 }
831+ read_unlock_bh (& pathtbl_resize_lock );
848832 rcu_read_unlock ();
849833}
850834
@@ -880,10 +864,12 @@ void mesh_path_flush_by_iface(struct ieee80211_sub_if_data *sdata)
880864 struct mesh_table * tbl ;
881865
882866 rcu_read_lock ();
883- tbl = rcu_dereference (mesh_paths );
867+ read_lock_bh (& pathtbl_resize_lock );
868+ tbl = resize_dereference_mesh_paths ();
884869 table_flush_by_iface (tbl , sdata );
885- tbl = rcu_dereference ( mpp_paths );
870+ tbl = resize_dereference_mpp_paths ( );
886871 table_flush_by_iface (tbl , sdata );
872+ read_unlock_bh (& pathtbl_resize_lock );
887873 rcu_read_unlock ();
888874}
889875
0 commit comments