diff options
| author | Ying Xue <ying.xue@windriver.com> | 2014-12-02 02:00:30 -0500 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2014-12-08 20:39:57 -0500 |
| commit | 97ede29e80eead50d8bd533cf163401b88c027be (patch) | |
| tree | c85f9f4af8b3e830847be0de35048bbd92218147 /net | |
| parent | 834caafa3e61f63805738376fa9c02dc0c1eb224 (diff) | |
tipc: convert name table read-write lock to RCU
Convert tipc name table read-write lock to RCU. After this change,
a new spin lock is used to protect name table on write side while
RCU is applied on read side.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
Tested-by: Erik Hugne <erik.hugne@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
| -rw-r--r-- | net/tipc/name_distr.c | 28 | ||||
| -rw-r--r-- | net/tipc/name_table.c | 87 | ||||
| -rw-r--r-- | net/tipc/name_table.h | 4 |
3 files changed, 60 insertions, 59 deletions
diff --git a/net/tipc/name_distr.c b/net/tipc/name_distr.c index ed00929f16c8..ba6083dca95b 100644 --- a/net/tipc/name_distr.c +++ b/net/tipc/name_distr.c | |||
| @@ -113,8 +113,8 @@ struct sk_buff *tipc_named_publish(struct publication *publ) | |||
| 113 | struct sk_buff *buf; | 113 | struct sk_buff *buf; |
| 114 | struct distr_item *item; | 114 | struct distr_item *item; |
| 115 | 115 | ||
| 116 | list_add_tail(&publ->local_list, | 116 | list_add_tail_rcu(&publ->local_list, |
| 117 | &tipc_nametbl->publ_list[publ->scope]); | 117 | &tipc_nametbl->publ_list[publ->scope]); |
| 118 | 118 | ||
| 119 | if (publ->scope == TIPC_NODE_SCOPE) | 119 | if (publ->scope == TIPC_NODE_SCOPE) |
| 120 | return NULL; | 120 | return NULL; |
| @@ -208,12 +208,12 @@ void tipc_named_node_up(u32 dnode) | |||
| 208 | 208 | ||
| 209 | __skb_queue_head_init(&head); | 209 | __skb_queue_head_init(&head); |
| 210 | 210 | ||
| 211 | read_lock_bh(&tipc_nametbl_lock); | 211 | rcu_read_lock(); |
| 212 | named_distribute(&head, dnode, | 212 | named_distribute(&head, dnode, |
| 213 | &tipc_nametbl->publ_list[TIPC_CLUSTER_SCOPE]); | 213 | &tipc_nametbl->publ_list[TIPC_CLUSTER_SCOPE]); |
| 214 | named_distribute(&head, dnode, | 214 | named_distribute(&head, dnode, |
| 215 | &tipc_nametbl->publ_list[TIPC_ZONE_SCOPE]); | 215 | &tipc_nametbl->publ_list[TIPC_ZONE_SCOPE]); |
| 216 | read_unlock_bh(&tipc_nametbl_lock); | 216 | rcu_read_unlock(); |
| 217 | 217 | ||
| 218 | tipc_link_xmit(&head, dnode, dnode); | 218 | tipc_link_xmit(&head, dnode, dnode); |
| 219 | } | 219 | } |
| @@ -260,12 +260,12 @@ static void tipc_publ_purge(struct publication *publ, u32 addr) | |||
| 260 | { | 260 | { |
| 261 | struct publication *p; | 261 | struct publication *p; |
| 262 | 262 | ||
| 263 | write_lock_bh(&tipc_nametbl_lock); | 263 | spin_lock_bh(&tipc_nametbl_lock); |
| 264 | p = tipc_nametbl_remove_publ(publ->type, publ->lower, | 264 | p = tipc_nametbl_remove_publ(publ->type, publ->lower, |
| 265 | publ->node, publ->ref, publ->key); | 265 | publ->node, publ->ref, publ->key); |
| 266 | if (p) | 266 | if (p) |
| 267 | tipc_publ_unsubscribe(p, addr); | 267 | tipc_publ_unsubscribe(p, addr); |
| 268 | write_unlock_bh(&tipc_nametbl_lock); | 268 | spin_unlock_bh(&tipc_nametbl_lock); |
| 269 | 269 | ||
| 270 | if (p != publ) { | 270 | if (p != publ) { |
| 271 | pr_err("Unable to remove publication from failed node\n" | 271 | pr_err("Unable to remove publication from failed node\n" |
| @@ -274,7 +274,7 @@ static void tipc_publ_purge(struct publication *publ, u32 addr) | |||
| 274 | publ->key); | 274 | publ->key); |
| 275 | } | 275 | } |
| 276 | 276 | ||
| 277 | kfree(p); | 277 | kfree_rcu(p, rcu); |
| 278 | } | 278 | } |
| 279 | 279 | ||
| 280 | void tipc_publ_notify(struct list_head *nsub_list, u32 addr) | 280 | void tipc_publ_notify(struct list_head *nsub_list, u32 addr) |
| @@ -311,7 +311,7 @@ static bool tipc_update_nametbl(struct distr_item *i, u32 node, u32 dtype) | |||
| 311 | ntohl(i->key)); | 311 | ntohl(i->key)); |
| 312 | if (publ) { | 312 | if (publ) { |
| 313 | tipc_publ_unsubscribe(publ, node); | 313 | tipc_publ_unsubscribe(publ, node); |
| 314 | kfree(publ); | 314 | kfree_rcu(publ, rcu); |
| 315 | return true; | 315 | return true; |
| 316 | } | 316 | } |
| 317 | } else { | 317 | } else { |
| @@ -376,14 +376,14 @@ void tipc_named_rcv(struct sk_buff *buf) | |||
| 376 | u32 count = msg_data_sz(msg) / ITEM_SIZE; | 376 | u32 count = msg_data_sz(msg) / ITEM_SIZE; |
| 377 | u32 node = msg_orignode(msg); | 377 | u32 node = msg_orignode(msg); |
| 378 | 378 | ||
| 379 | write_lock_bh(&tipc_nametbl_lock); | 379 | spin_lock_bh(&tipc_nametbl_lock); |
| 380 | while (count--) { | 380 | while (count--) { |
| 381 | if (!tipc_update_nametbl(item, node, msg_type(msg))) | 381 | if (!tipc_update_nametbl(item, node, msg_type(msg))) |
| 382 | tipc_named_add_backlog(item, msg_type(msg), node); | 382 | tipc_named_add_backlog(item, msg_type(msg), node); |
| 383 | item++; | 383 | item++; |
| 384 | } | 384 | } |
| 385 | tipc_named_process_backlog(); | 385 | tipc_named_process_backlog(); |
| 386 | write_unlock_bh(&tipc_nametbl_lock); | 386 | spin_unlock_bh(&tipc_nametbl_lock); |
| 387 | kfree_skb(buf); | 387 | kfree_skb(buf); |
| 388 | } | 388 | } |
| 389 | 389 | ||
| @@ -399,12 +399,12 @@ void tipc_named_reinit(void) | |||
| 399 | struct publication *publ; | 399 | struct publication *publ; |
| 400 | int scope; | 400 | int scope; |
| 401 | 401 | ||
| 402 | write_lock_bh(&tipc_nametbl_lock); | 402 | spin_lock_bh(&tipc_nametbl_lock); |
| 403 | 403 | ||
| 404 | for (scope = TIPC_ZONE_SCOPE; scope <= TIPC_NODE_SCOPE; scope++) | 404 | for (scope = TIPC_ZONE_SCOPE; scope <= TIPC_NODE_SCOPE; scope++) |
| 405 | list_for_each_entry(publ, &tipc_nametbl->publ_list[scope], | 405 | list_for_each_entry_rcu(publ, &tipc_nametbl->publ_list[scope], |
| 406 | local_list) | 406 | local_list) |
| 407 | publ->node = tipc_own_addr; | 407 | publ->node = tipc_own_addr; |
| 408 | 408 | ||
| 409 | write_unlock_bh(&tipc_nametbl_lock); | 409 | spin_unlock_bh(&tipc_nametbl_lock); |
| 410 | } | 410 | } |
diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c index 3c2e0c300fe2..aafa684c4db9 100644 --- a/net/tipc/name_table.c +++ b/net/tipc/name_table.c | |||
| @@ -92,6 +92,7 @@ struct sub_seq { | |||
| 92 | * @ns_list: links to adjacent name sequences in hash chain | 92 | * @ns_list: links to adjacent name sequences in hash chain |
| 93 | * @subscriptions: list of subscriptions for this 'type' | 93 | * @subscriptions: list of subscriptions for this 'type' |
| 94 | * @lock: spinlock controlling access to publication lists of all sub-sequences | 94 | * @lock: spinlock controlling access to publication lists of all sub-sequences |
| 95 | * @rcu: RCU callback head used for deferred freeing | ||
| 95 | */ | 96 | */ |
| 96 | struct name_seq { | 97 | struct name_seq { |
| 97 | u32 type; | 98 | u32 type; |
| @@ -101,10 +102,11 @@ struct name_seq { | |||
| 101 | struct hlist_node ns_list; | 102 | struct hlist_node ns_list; |
| 102 | struct list_head subscriptions; | 103 | struct list_head subscriptions; |
| 103 | spinlock_t lock; | 104 | spinlock_t lock; |
| 105 | struct rcu_head rcu; | ||
| 104 | }; | 106 | }; |
| 105 | 107 | ||
| 106 | struct name_table *tipc_nametbl; | 108 | struct name_table *tipc_nametbl; |
| 107 | DEFINE_RWLOCK(tipc_nametbl_lock); | 109 | DEFINE_SPINLOCK(tipc_nametbl_lock); |
| 108 | 110 | ||
| 109 | static int hash(int x) | 111 | static int hash(int x) |
| 110 | { | 112 | { |
| @@ -166,7 +168,7 @@ static struct name_seq *tipc_nameseq_create(u32 type, struct hlist_head *seq_hea | |||
| 166 | nseq->alloc = 1; | 168 | nseq->alloc = 1; |
| 167 | INIT_HLIST_NODE(&nseq->ns_list); | 169 | INIT_HLIST_NODE(&nseq->ns_list); |
| 168 | INIT_LIST_HEAD(&nseq->subscriptions); | 170 | INIT_LIST_HEAD(&nseq->subscriptions); |
| 169 | hlist_add_head(&nseq->ns_list, seq_head); | 171 | hlist_add_head_rcu(&nseq->ns_list, seq_head); |
| 170 | return nseq; | 172 | return nseq; |
| 171 | } | 173 | } |
| 172 | 174 | ||
| @@ -451,7 +453,7 @@ static struct name_seq *nametbl_find_seq(u32 type) | |||
| 451 | struct name_seq *ns; | 453 | struct name_seq *ns; |
| 452 | 454 | ||
| 453 | seq_head = &tipc_nametbl->seq_hlist[hash(type)]; | 455 | seq_head = &tipc_nametbl->seq_hlist[hash(type)]; |
| 454 | hlist_for_each_entry(ns, seq_head, ns_list) { | 456 | hlist_for_each_entry_rcu(ns, seq_head, ns_list) { |
| 455 | if (ns->type == type) | 457 | if (ns->type == type) |
| 456 | return ns; | 458 | return ns; |
| 457 | } | 459 | } |
| @@ -498,10 +500,10 @@ struct publication *tipc_nametbl_remove_publ(u32 type, u32 lower, | |||
| 498 | spin_lock_bh(&seq->lock); | 500 | spin_lock_bh(&seq->lock); |
| 499 | publ = tipc_nameseq_remove_publ(seq, lower, node, ref, key); | 501 | publ = tipc_nameseq_remove_publ(seq, lower, node, ref, key); |
| 500 | if (!seq->first_free && list_empty(&seq->subscriptions)) { | 502 | if (!seq->first_free && list_empty(&seq->subscriptions)) { |
| 501 | hlist_del_init(&seq->ns_list); | 503 | hlist_del_init_rcu(&seq->ns_list); |
| 502 | spin_unlock_bh(&seq->lock); | ||
| 503 | kfree(seq->sseqs); | 504 | kfree(seq->sseqs); |
| 504 | kfree(seq); | 505 | spin_unlock_bh(&seq->lock); |
| 506 | kfree_rcu(seq, rcu); | ||
| 505 | return publ; | 507 | return publ; |
| 506 | } | 508 | } |
| 507 | spin_unlock_bh(&seq->lock); | 509 | spin_unlock_bh(&seq->lock); |
| @@ -533,7 +535,7 @@ u32 tipc_nametbl_translate(u32 type, u32 instance, u32 *destnode) | |||
| 533 | if (!tipc_in_scope(*destnode, tipc_own_addr)) | 535 | if (!tipc_in_scope(*destnode, tipc_own_addr)) |
| 534 | return 0; | 536 | return 0; |
| 535 | 537 | ||
| 536 | read_lock_bh(&tipc_nametbl_lock); | 538 | rcu_read_lock(); |
| 537 | seq = nametbl_find_seq(type); | 539 | seq = nametbl_find_seq(type); |
| 538 | if (unlikely(!seq)) | 540 | if (unlikely(!seq)) |
| 539 | goto not_found; | 541 | goto not_found; |
| @@ -590,7 +592,7 @@ u32 tipc_nametbl_translate(u32 type, u32 instance, u32 *destnode) | |||
| 590 | no_match: | 592 | no_match: |
| 591 | spin_unlock_bh(&seq->lock); | 593 | spin_unlock_bh(&seq->lock); |
| 592 | not_found: | 594 | not_found: |
| 593 | read_unlock_bh(&tipc_nametbl_lock); | 595 | rcu_read_unlock(); |
| 594 | *destnode = node; | 596 | *destnode = node; |
| 595 | return ref; | 597 | return ref; |
| 596 | } | 598 | } |
| @@ -616,7 +618,7 @@ int tipc_nametbl_mc_translate(u32 type, u32 lower, u32 upper, u32 limit, | |||
| 616 | struct name_info *info; | 618 | struct name_info *info; |
| 617 | int res = 0; | 619 | int res = 0; |
| 618 | 620 | ||
| 619 | read_lock_bh(&tipc_nametbl_lock); | 621 | rcu_read_lock(); |
| 620 | seq = nametbl_find_seq(type); | 622 | seq = nametbl_find_seq(type); |
| 621 | if (!seq) | 623 | if (!seq) |
| 622 | goto exit; | 624 | goto exit; |
| @@ -641,7 +643,7 @@ int tipc_nametbl_mc_translate(u32 type, u32 lower, u32 upper, u32 limit, | |||
| 641 | } | 643 | } |
| 642 | spin_unlock_bh(&seq->lock); | 644 | spin_unlock_bh(&seq->lock); |
| 643 | exit: | 645 | exit: |
| 644 | read_unlock_bh(&tipc_nametbl_lock); | 646 | rcu_read_unlock(); |
| 645 | return res; | 647 | return res; |
| 646 | } | 648 | } |
| 647 | 649 | ||
| @@ -654,11 +656,11 @@ struct publication *tipc_nametbl_publish(u32 type, u32 lower, u32 upper, | |||
| 654 | struct publication *publ; | 656 | struct publication *publ; |
| 655 | struct sk_buff *buf = NULL; | 657 | struct sk_buff *buf = NULL; |
| 656 | 658 | ||
| 657 | write_lock_bh(&tipc_nametbl_lock); | 659 | spin_lock_bh(&tipc_nametbl_lock); |
| 658 | if (tipc_nametbl->local_publ_count >= TIPC_MAX_PUBLICATIONS) { | 660 | if (tipc_nametbl->local_publ_count >= TIPC_MAX_PUBLICATIONS) { |
| 659 | pr_warn("Publication failed, local publication limit reached (%u)\n", | 661 | pr_warn("Publication failed, local publication limit reached (%u)\n", |
| 660 | TIPC_MAX_PUBLICATIONS); | 662 | TIPC_MAX_PUBLICATIONS); |
| 661 | write_unlock_bh(&tipc_nametbl_lock); | 663 | spin_unlock_bh(&tipc_nametbl_lock); |
| 662 | return NULL; | 664 | return NULL; |
| 663 | } | 665 | } |
| 664 | 666 | ||
| @@ -670,7 +672,7 @@ struct publication *tipc_nametbl_publish(u32 type, u32 lower, u32 upper, | |||
| 670 | /* Any pending external events? */ | 672 | /* Any pending external events? */ |
| 671 | tipc_named_process_backlog(); | 673 | tipc_named_process_backlog(); |
| 672 | } | 674 | } |
| 673 | write_unlock_bh(&tipc_nametbl_lock); | 675 | spin_unlock_bh(&tipc_nametbl_lock); |
| 674 | 676 | ||
| 675 | if (buf) | 677 | if (buf) |
| 676 | named_cluster_distribute(buf); | 678 | named_cluster_distribute(buf); |
| @@ -685,7 +687,7 @@ int tipc_nametbl_withdraw(u32 type, u32 lower, u32 ref, u32 key) | |||
| 685 | struct publication *publ; | 687 | struct publication *publ; |
| 686 | struct sk_buff *skb = NULL; | 688 | struct sk_buff *skb = NULL; |
| 687 | 689 | ||
| 688 | write_lock_bh(&tipc_nametbl_lock); | 690 | spin_lock_bh(&tipc_nametbl_lock); |
| 689 | publ = tipc_nametbl_remove_publ(type, lower, tipc_own_addr, ref, key); | 691 | publ = tipc_nametbl_remove_publ(type, lower, tipc_own_addr, ref, key); |
| 690 | if (likely(publ)) { | 692 | if (likely(publ)) { |
| 691 | tipc_nametbl->local_publ_count--; | 693 | tipc_nametbl->local_publ_count--; |
| @@ -693,13 +695,13 @@ int tipc_nametbl_withdraw(u32 type, u32 lower, u32 ref, u32 key) | |||
| 693 | /* Any pending external events? */ | 695 | /* Any pending external events? */ |
| 694 | tipc_named_process_backlog(); | 696 | tipc_named_process_backlog(); |
| 695 | list_del_init(&publ->pport_list); | 697 | list_del_init(&publ->pport_list); |
| 696 | kfree(publ); | 698 | kfree_rcu(publ, rcu); |
| 697 | } else { | 699 | } else { |
| 698 | pr_err("Unable to remove local publication\n" | 700 | pr_err("Unable to remove local publication\n" |
| 699 | "(type=%u, lower=%u, ref=%u, key=%u)\n", | 701 | "(type=%u, lower=%u, ref=%u, key=%u)\n", |
| 700 | type, lower, ref, key); | 702 | type, lower, ref, key); |
| 701 | } | 703 | } |
| 702 | write_unlock_bh(&tipc_nametbl_lock); | 704 | spin_unlock_bh(&tipc_nametbl_lock); |
| 703 | 705 | ||
| 704 | if (skb) { | 706 | if (skb) { |
| 705 | named_cluster_distribute(skb); | 707 | named_cluster_distribute(skb); |
| @@ -717,7 +719,7 @@ void tipc_nametbl_subscribe(struct tipc_subscription *s) | |||
| 717 | int index = hash(type); | 719 | int index = hash(type); |
| 718 | struct name_seq *seq; | 720 | struct name_seq *seq; |
| 719 | 721 | ||
| 720 | write_lock_bh(&tipc_nametbl_lock); | 722 | spin_lock_bh(&tipc_nametbl_lock); |
| 721 | seq = nametbl_find_seq(type); | 723 | seq = nametbl_find_seq(type); |
| 722 | if (!seq) | 724 | if (!seq) |
| 723 | seq = tipc_nameseq_create(type, | 725 | seq = tipc_nameseq_create(type, |
| @@ -730,7 +732,7 @@ void tipc_nametbl_subscribe(struct tipc_subscription *s) | |||
| 730 | pr_warn("Failed to create subscription for {%u,%u,%u}\n", | 732 | pr_warn("Failed to create subscription for {%u,%u,%u}\n", |
| 731 | s->seq.type, s->seq.lower, s->seq.upper); | 733 | s->seq.type, s->seq.lower, s->seq.upper); |
| 732 | } | 734 | } |
| 733 | write_unlock_bh(&tipc_nametbl_lock); | 735 | spin_unlock_bh(&tipc_nametbl_lock); |
| 734 | } | 736 | } |
| 735 | 737 | ||
| 736 | /** | 738 | /** |
| @@ -740,24 +742,23 @@ void tipc_nametbl_unsubscribe(struct tipc_subscription *s) | |||
| 740 | { | 742 | { |
| 741 | struct name_seq *seq; | 743 | struct name_seq *seq; |
| 742 | 744 | ||
| 743 | write_lock_bh(&tipc_nametbl_lock); | 745 | spin_lock_bh(&tipc_nametbl_lock); |
| 744 | seq = nametbl_find_seq(s->seq.type); | 746 | seq = nametbl_find_seq(s->seq.type); |
| 745 | if (seq != NULL) { | 747 | if (seq != NULL) { |
| 746 | spin_lock_bh(&seq->lock); | 748 | spin_lock_bh(&seq->lock); |
| 747 | list_del_init(&s->nameseq_list); | 749 | list_del_init(&s->nameseq_list); |
| 748 | if (!seq->first_free && list_empty(&seq->subscriptions)) { | 750 | if (!seq->first_free && list_empty(&seq->subscriptions)) { |
| 749 | hlist_del_init(&seq->ns_list); | 751 | hlist_del_init_rcu(&seq->ns_list); |
| 750 | spin_unlock_bh(&seq->lock); | ||
| 751 | kfree(seq->sseqs); | 752 | kfree(seq->sseqs); |
| 752 | kfree(seq); | 753 | spin_unlock_bh(&seq->lock); |
| 754 | kfree_rcu(seq, rcu); | ||
| 753 | } else { | 755 | } else { |
| 754 | spin_unlock_bh(&seq->lock); | 756 | spin_unlock_bh(&seq->lock); |
| 755 | } | 757 | } |
| 756 | } | 758 | } |
| 757 | write_unlock_bh(&tipc_nametbl_lock); | 759 | spin_unlock_bh(&tipc_nametbl_lock); |
| 758 | } | 760 | } |
| 759 | 761 | ||
| 760 | |||
| 761 | /** | 762 | /** |
| 762 | * subseq_list - print specified sub-sequence contents into the given buffer | 763 | * subseq_list - print specified sub-sequence contents into the given buffer |
| 763 | */ | 764 | */ |
| @@ -880,7 +881,7 @@ static int nametbl_list(char *buf, int len, u32 depth_info, | |||
| 880 | upbound = ~0; | 881 | upbound = ~0; |
| 881 | for (i = 0; i < TIPC_NAMETBL_SIZE; i++) { | 882 | for (i = 0; i < TIPC_NAMETBL_SIZE; i++) { |
| 882 | seq_head = &tipc_nametbl->seq_hlist[i]; | 883 | seq_head = &tipc_nametbl->seq_hlist[i]; |
| 883 | hlist_for_each_entry(seq, seq_head, ns_list) { | 884 | hlist_for_each_entry_rcu(seq, seq_head, ns_list) { |
| 884 | ret += nameseq_list(seq, buf + ret, len - ret, | 885 | ret += nameseq_list(seq, buf + ret, len - ret, |
| 885 | depth, seq->type, | 886 | depth, seq->type, |
| 886 | lowbound, upbound, i); | 887 | lowbound, upbound, i); |
| @@ -896,7 +897,7 @@ static int nametbl_list(char *buf, int len, u32 depth_info, | |||
| 896 | ret += nametbl_header(buf + ret, len - ret, depth); | 897 | ret += nametbl_header(buf + ret, len - ret, depth); |
| 897 | i = hash(type); | 898 | i = hash(type); |
| 898 | seq_head = &tipc_nametbl->seq_hlist[i]; | 899 | seq_head = &tipc_nametbl->seq_hlist[i]; |
| 899 | hlist_for_each_entry(seq, seq_head, ns_list) { | 900 | hlist_for_each_entry_rcu(seq, seq_head, ns_list) { |
| 900 | if (seq->type == type) { | 901 | if (seq->type == type) { |
| 901 | ret += nameseq_list(seq, buf + ret, len - ret, | 902 | ret += nameseq_list(seq, buf + ret, len - ret, |
| 902 | depth, type, | 903 | depth, type, |
| @@ -928,11 +929,11 @@ struct sk_buff *tipc_nametbl_get(const void *req_tlv_area, int req_tlv_space) | |||
| 928 | pb = TLV_DATA(rep_tlv); | 929 | pb = TLV_DATA(rep_tlv); |
| 929 | pb_len = ULTRA_STRING_MAX_LEN; | 930 | pb_len = ULTRA_STRING_MAX_LEN; |
| 930 | argv = (struct tipc_name_table_query *)TLV_DATA(req_tlv_area); | 931 | argv = (struct tipc_name_table_query *)TLV_DATA(req_tlv_area); |
| 931 | read_lock_bh(&tipc_nametbl_lock); | 932 | rcu_read_lock(); |
| 932 | str_len = nametbl_list(pb, pb_len, ntohl(argv->depth), | 933 | str_len = nametbl_list(pb, pb_len, ntohl(argv->depth), |
| 933 | ntohl(argv->type), | 934 | ntohl(argv->type), |
| 934 | ntohl(argv->lowbound), ntohl(argv->upbound)); | 935 | ntohl(argv->lowbound), ntohl(argv->upbound)); |
| 935 | read_unlock_bh(&tipc_nametbl_lock); | 936 | rcu_read_unlock(); |
| 936 | str_len += 1; /* for "\0" */ | 937 | str_len += 1; /* for "\0" */ |
| 937 | skb_put(buf, TLV_SPACE(str_len)); | 938 | skb_put(buf, TLV_SPACE(str_len)); |
| 938 | TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len); | 939 | TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len); |
| @@ -974,13 +975,13 @@ static void tipc_purge_publications(struct name_seq *seq) | |||
| 974 | list_for_each_entry_safe(publ, safe, &info->zone_list, zone_list) { | 975 | list_for_each_entry_safe(publ, safe, &info->zone_list, zone_list) { |
| 975 | tipc_nametbl_remove_publ(publ->type, publ->lower, publ->node, | 976 | tipc_nametbl_remove_publ(publ->type, publ->lower, publ->node, |
| 976 | publ->ref, publ->key); | 977 | publ->ref, publ->key); |
| 977 | kfree(publ); | 978 | kfree_rcu(publ, rcu); |
| 978 | } | 979 | } |
| 979 | hlist_del_init(&seq->ns_list); | 980 | hlist_del_init_rcu(&seq->ns_list); |
| 981 | kfree(seq->sseqs); | ||
| 980 | spin_lock_bh(&seq->lock); | 982 | spin_lock_bh(&seq->lock); |
| 981 | 983 | ||
| 982 | kfree(seq->sseqs); | 984 | kfree_rcu(seq, rcu); |
| 983 | kfree(seq); | ||
| 984 | } | 985 | } |
| 985 | 986 | ||
| 986 | void tipc_nametbl_stop(void) | 987 | void tipc_nametbl_stop(void) |
| @@ -988,22 +989,22 @@ void tipc_nametbl_stop(void) | |||
| 988 | u32 i; | 989 | u32 i; |
| 989 | struct name_seq *seq; | 990 | struct name_seq *seq; |
| 990 | struct hlist_head *seq_head; | 991 | struct hlist_head *seq_head; |
| 991 | struct hlist_node *safe; | ||
| 992 | 992 | ||
| 993 | /* Verify name table is empty and purge any lingering | 993 | /* Verify name table is empty and purge any lingering |
| 994 | * publications, then release the name table | 994 | * publications, then release the name table |
| 995 | */ | 995 | */ |
| 996 | write_lock_bh(&tipc_nametbl_lock); | 996 | spin_lock_bh(&tipc_nametbl_lock); |
| 997 | for (i = 0; i < TIPC_NAMETBL_SIZE; i++) { | 997 | for (i = 0; i < TIPC_NAMETBL_SIZE; i++) { |
| 998 | if (hlist_empty(&tipc_nametbl->seq_hlist[i])) | 998 | if (hlist_empty(&tipc_nametbl->seq_hlist[i])) |
| 999 | continue; | 999 | continue; |
| 1000 | seq_head = &tipc_nametbl->seq_hlist[i]; | 1000 | seq_head = &tipc_nametbl->seq_hlist[i]; |
| 1001 | hlist_for_each_entry_safe(seq, safe, seq_head, ns_list) { | 1001 | hlist_for_each_entry_rcu(seq, seq_head, ns_list) { |
| 1002 | tipc_purge_publications(seq); | 1002 | tipc_purge_publications(seq); |
| 1003 | } | 1003 | } |
| 1004 | } | 1004 | } |
| 1005 | write_unlock_bh(&tipc_nametbl_lock); | 1005 | spin_unlock_bh(&tipc_nametbl_lock); |
| 1006 | 1006 | ||
| 1007 | synchronize_net(); | ||
| 1007 | kfree(tipc_nametbl); | 1008 | kfree(tipc_nametbl); |
| 1008 | 1009 | ||
| 1009 | } | 1010 | } |
| @@ -1109,7 +1110,7 @@ static int __tipc_nl_seq_list(struct tipc_nl_msg *msg, u32 *last_type, | |||
| 1109 | u32 *last_lower, u32 *last_publ) | 1110 | u32 *last_lower, u32 *last_publ) |
| 1110 | { | 1111 | { |
| 1111 | struct hlist_head *seq_head; | 1112 | struct hlist_head *seq_head; |
| 1112 | struct name_seq *seq; | 1113 | struct name_seq *seq = NULL; |
| 1113 | int err; | 1114 | int err; |
| 1114 | int i; | 1115 | int i; |
| 1115 | 1116 | ||
| @@ -1126,13 +1127,13 @@ static int __tipc_nl_seq_list(struct tipc_nl_msg *msg, u32 *last_type, | |||
| 1126 | if (!seq) | 1127 | if (!seq) |
| 1127 | return -EPIPE; | 1128 | return -EPIPE; |
| 1128 | } else { | 1129 | } else { |
| 1129 | seq = hlist_entry_safe((seq_head)->first, | 1130 | hlist_for_each_entry_rcu(seq, seq_head, ns_list) |
| 1130 | struct name_seq, ns_list); | 1131 | break; |
| 1131 | if (!seq) | 1132 | if (!seq) |
| 1132 | continue; | 1133 | continue; |
| 1133 | } | 1134 | } |
| 1134 | 1135 | ||
| 1135 | hlist_for_each_entry_from(seq, ns_list) { | 1136 | hlist_for_each_entry_from_rcu(seq, ns_list) { |
| 1136 | spin_lock_bh(&seq->lock); | 1137 | spin_lock_bh(&seq->lock); |
| 1137 | err = __tipc_nl_subseq_list(msg, seq, last_lower, | 1138 | err = __tipc_nl_subseq_list(msg, seq, last_lower, |
| 1138 | last_publ); | 1139 | last_publ); |
| @@ -1165,8 +1166,7 @@ int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
| 1165 | msg.portid = NETLINK_CB(cb->skb).portid; | 1166 | msg.portid = NETLINK_CB(cb->skb).portid; |
| 1166 | msg.seq = cb->nlh->nlmsg_seq; | 1167 | msg.seq = cb->nlh->nlmsg_seq; |
| 1167 | 1168 | ||
| 1168 | read_lock_bh(&tipc_nametbl_lock); | 1169 | rcu_read_lock(); |
| 1169 | |||
| 1170 | err = __tipc_nl_seq_list(&msg, &last_type, &last_lower, &last_publ); | 1170 | err = __tipc_nl_seq_list(&msg, &last_type, &last_lower, &last_publ); |
| 1171 | if (!err) { | 1171 | if (!err) { |
| 1172 | done = 1; | 1172 | done = 1; |
| @@ -1179,8 +1179,7 @@ int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
| 1179 | */ | 1179 | */ |
| 1180 | cb->prev_seq = 1; | 1180 | cb->prev_seq = 1; |
| 1181 | } | 1181 | } |
| 1182 | 1182 | rcu_read_unlock(); | |
| 1183 | read_unlock_bh(&tipc_nametbl_lock); | ||
| 1184 | 1183 | ||
| 1185 | cb->args[0] = last_type; | 1184 | cb->args[0] = last_type; |
| 1186 | cb->args[1] = last_lower; | 1185 | cb->args[1] = last_lower; |
diff --git a/net/tipc/name_table.h b/net/tipc/name_table.h index c1fd734eb0d5..5f0dee92010d 100644 --- a/net/tipc/name_table.h +++ b/net/tipc/name_table.h | |||
| @@ -62,6 +62,7 @@ struct tipc_port_list; | |||
| 62 | * @node_list: adjacent matching name seq publications with >= node scope | 62 | * @node_list: adjacent matching name seq publications with >= node scope |
| 63 | * @cluster_list: adjacent matching name seq publications with >= cluster scope | 63 | * @cluster_list: adjacent matching name seq publications with >= cluster scope |
| 64 | * @zone_list: adjacent matching name seq publications with >= zone scope | 64 | * @zone_list: adjacent matching name seq publications with >= zone scope |
| 65 | * @rcu: RCU callback head used for deferred freeing | ||
| 65 | * | 66 | * |
| 66 | * Note that the node list, cluster list, and zone list are circular lists. | 67 | * Note that the node list, cluster list, and zone list are circular lists. |
| 67 | */ | 68 | */ |
| @@ -79,6 +80,7 @@ struct publication { | |||
| 79 | struct list_head node_list; | 80 | struct list_head node_list; |
| 80 | struct list_head cluster_list; | 81 | struct list_head cluster_list; |
| 81 | struct list_head zone_list; | 82 | struct list_head zone_list; |
| 83 | struct rcu_head rcu; | ||
| 82 | }; | 84 | }; |
| 83 | 85 | ||
| 84 | /** | 86 | /** |
| @@ -93,7 +95,7 @@ struct name_table { | |||
| 93 | u32 local_publ_count; | 95 | u32 local_publ_count; |
| 94 | }; | 96 | }; |
| 95 | 97 | ||
| 96 | extern rwlock_t tipc_nametbl_lock; | 98 | extern spinlock_t tipc_nametbl_lock; |
| 97 | extern struct name_table *tipc_nametbl; | 99 | extern struct name_table *tipc_nametbl; |
| 98 | 100 | ||
| 99 | int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb); | 101 | int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb); |
