aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/link.c
diff options
context:
space:
mode:
authorYing Xue <ying.xue@windriver.com>2014-02-13 17:29:09 -0500
committerDavid S. Miller <davem@davemloft.net>2014-02-13 17:57:05 -0500
commitc61dd61dec0b79fa22ded8b5caf2e817dc506c24 (patch)
treec81280b1339cb4822d9480ec4617dae2d94c3408 /net/tipc/link.c
parent135daee6d3959a6d7c4f59b448ed6f854d88ce27 (diff)
tipc: remove 'links' list from tipc_bearer struct
In our ongoing effort to simplify the TIPC locking structure, we see a need to remove the linked list for tipc_links in the bearer. This can be explained as follows. Currently, we have three different ways to access a link, via three different lists/tables: 1: Via a node hash table: Used by the time-critical outgoing/incoming data paths. (e.g. link_send_sections_fast() and tipc_recv_msg() ): grab net_lock(read) find node from node hash table grab node_lock select link grab bearer_lock send_msg() release bearer_lock release node lock release net_lock 2: Via a global linked list for nodes: Used by configuration commands (link_cmd_set_value()) grab net_lock(read) find node and link from global node list (using link name) grab node_lock update link release node lock release net_lock (Same locking order as above. No problem.) 3: Via the bearer's linked link list: Used by notifications from interface (e.g. tipc_disable_bearer() ) grab net_lock(write) grab bearer_lock get link ptr from bearer's link list get node from link grab node_lock delete link release node lock release bearer_lock release net_lock (Different order from above, but works because we grab the outer net_lock in write mode first, excluding all other access.) The first major goal in our simplification effort is to get rid of the "big" net_lock, replacing it with rcu-locks when accessing the node list and node hash array. This will come in a later patch series. But to get there we first need to rewrite access methods ##2 and 3, since removal of net_lock would introduce three major problems: a) In access method #2, we access the link before taking the protecting node_lock. This will not work once net_lock is gone, so we will have to change the access order. We will deal with this in a later commit in this series, "tipc: add node lock protection to link found by link_find_link()". b) When the outer protection from net_lock is gone, taking bearer_lock and node_lock in opposite order of method 1) and 2) will become an obvious deadlock hazard. This is fixed in the commit ("tipc: remove bearer_lock from tipc_bearer struct") later in this series. c) Similar to what is described in problem a), access method #3 starts with using a link pointer that is unprotected by node_lock, in order to via that pointer find the correct node struct and lock it. Before we remove net_lock, this access order must be altered. This is what we do with this commit. We can avoid introducing problem problem c) by even here using the global node list to find the node, before accessing its links. When we loop though the node list we use the own bearer identity as search criteria, thus easily finding the links that are associated to the resetting/disabling bearer. It should be noted that although this method is somewhat slower than the current list traversal, it is in no way time critical. This is only about resetting or deleting links, something that must be considered relatively infrequent events. As a bonus, we can get rid of the mutual pointers between links and bearers. After this commit, pointer dependency go in one direction only: from the link to the bearer. This commit pre-empts introduction of problem c) as described above. Signed-off-by: Ying Xue <ying.xue@windriver.com> Reviewed-by: Paul Gortmaker <paul.gortmaker@windriver.com> Signed-off-by: Jon Maloy <jon.maloy@ericsson.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tipc/link.c')
-rw-r--r--net/tipc/link.c67
1 files changed, 24 insertions, 43 deletions
diff --git a/net/tipc/link.c b/net/tipc/link.c
index 2070d032c923..e7e44ab008ec 100644
--- a/net/tipc/link.c
+++ b/net/tipc/link.c
@@ -147,11 +147,6 @@ int tipc_link_is_active(struct tipc_link *l_ptr)
147/** 147/**
148 * link_timeout - handle expiration of link timer 148 * link_timeout - handle expiration of link timer
149 * @l_ptr: pointer to link 149 * @l_ptr: pointer to link
150 *
151 * This routine must not grab "tipc_net_lock" to avoid a potential deadlock conflict
152 * with tipc_link_delete(). (There is no risk that the node will be deleted by
153 * another thread because tipc_link_delete() always cancels the link timer before
154 * tipc_node_delete() is called.)
155 */ 150 */
156static void link_timeout(struct tipc_link *l_ptr) 151static void link_timeout(struct tipc_link *l_ptr)
157{ 152{
@@ -213,8 +208,8 @@ static void link_set_timer(struct tipc_link *l_ptr, u32 time)
213 * Returns pointer to link. 208 * Returns pointer to link.
214 */ 209 */
215struct tipc_link *tipc_link_create(struct tipc_node *n_ptr, 210struct tipc_link *tipc_link_create(struct tipc_node *n_ptr,
216 struct tipc_bearer *b_ptr, 211 struct tipc_bearer *b_ptr,
217 const struct tipc_media_addr *media_addr) 212 const struct tipc_media_addr *media_addr)
218{ 213{
219 struct tipc_link *l_ptr; 214 struct tipc_link *l_ptr;
220 struct tipc_msg *msg; 215 struct tipc_msg *msg;
@@ -279,47 +274,32 @@ struct tipc_link *tipc_link_create(struct tipc_node *n_ptr,
279 274
280 k_init_timer(&l_ptr->timer, (Handler)link_timeout, 275 k_init_timer(&l_ptr->timer, (Handler)link_timeout,
281 (unsigned long)l_ptr); 276 (unsigned long)l_ptr);
282 list_add_tail(&l_ptr->link_list, &b_ptr->links);
283 277
284 link_state_event(l_ptr, STARTING_EVT); 278 link_state_event(l_ptr, STARTING_EVT);
285 279
286 return l_ptr; 280 return l_ptr;
287} 281}
288 282
289/**
290 * tipc_link_delete - delete a link
291 * @l_ptr: pointer to link
292 *
293 * Note: 'tipc_net_lock' is write_locked, bearer is locked.
294 * This routine must not grab the node lock until after link timer cancellation
295 * to avoid a potential deadlock situation.
296 */
297void tipc_link_delete(struct tipc_link *l_ptr)
298{
299 if (!l_ptr) {
300 pr_err("Attempt to delete non-existent link\n");
301 return;
302 }
303
304 k_cancel_timer(&l_ptr->timer);
305 283
306 tipc_node_lock(l_ptr->owner); 284void tipc_link_delete_list(unsigned int bearer_id)
307 tipc_link_reset(l_ptr);
308 tipc_node_detach_link(l_ptr->owner, l_ptr);
309 tipc_link_purge_queues(l_ptr);
310 list_del_init(&l_ptr->link_list);
311 tipc_node_unlock(l_ptr->owner);
312 k_term_timer(&l_ptr->timer);
313 kfree(l_ptr);
314}
315
316void tipc_link_delete_list(struct tipc_bearer *b_ptr)
317{ 285{
318 struct tipc_link *l_ptr; 286 struct tipc_link *l_ptr;
319 struct tipc_link *temp_l_ptr; 287 struct tipc_node *n_ptr;
320 288
321 list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) { 289 list_for_each_entry(n_ptr, &tipc_node_list, list) {
322 tipc_link_delete(l_ptr); 290 spin_lock_bh(&n_ptr->lock);
291 l_ptr = n_ptr->links[bearer_id];
292 if (l_ptr) {
293 tipc_link_reset(l_ptr);
294 tipc_node_detach_link(n_ptr, l_ptr);
295 spin_unlock_bh(&n_ptr->lock);
296
297 /* Nobody else can access this link now: */
298 del_timer_sync(&l_ptr->timer);
299 kfree(l_ptr);
300 continue;
301 }
302 spin_unlock_bh(&n_ptr->lock);
323 } 303 }
324} 304}
325 305
@@ -470,15 +450,16 @@ void tipc_link_reset(struct tipc_link *l_ptr)
470 link_reset_statistics(l_ptr); 450 link_reset_statistics(l_ptr);
471} 451}
472 452
473void tipc_link_reset_list(struct tipc_bearer *b_ptr) 453void tipc_link_reset_list(unsigned int bearer_id)
474{ 454{
475 struct tipc_link *l_ptr; 455 struct tipc_link *l_ptr;
456 struct tipc_node *n_ptr;
476 457
477 list_for_each_entry(l_ptr, &b_ptr->links, link_list) { 458 list_for_each_entry(n_ptr, &tipc_node_list, list) {
478 struct tipc_node *n_ptr = l_ptr->owner;
479
480 spin_lock_bh(&n_ptr->lock); 459 spin_lock_bh(&n_ptr->lock);
481 tipc_link_reset(l_ptr); 460 l_ptr = n_ptr->links[bearer_id];
461 if (l_ptr)
462 tipc_link_reset(l_ptr);
482 spin_unlock_bh(&n_ptr->lock); 463 spin_unlock_bh(&n_ptr->lock);
483 } 464 }
484} 465}