Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

IPoIB: Consolidate private neighbour data handling

Consolidate IPoIB's private neighbour data handling into
ipoib_neigh_alloc() and ipoib_neigh_free(). This will make it easier
to keep track of the neighbour structures that IPoIB is handling, and
is a nice cleanup of the code:

add/remove: 2/1 grow/shrink: 1/8 up/down: 100/-178 (-78)
function old new delta
ipoib_neigh_alloc - 61 +61
ipoib_neigh_free - 36 +36
ipoib_mcast_join_finish 1288 1291 +3
path_rec_completion 575 573 -2
ipoib_mcast_join_task 664 660 -4
ipoib_neigh_destructor 101 92 -9
ipoib_neigh_setup_dev 14 3 -11
ipoib_neigh_setup 17 - -17
path_free 238 215 -23
ipoib_mcast_free 329 306 -23
ipoib_mcast_send 718 684 -34
neigh_add_path 705 650 -55

Signed-off-by: Michael S. Tsirkin <mst@mellanox.co.il>
Signed-off-by: Roland Dreier <rolandd@cisco.com>

authored by

Michael S. Tsirkin and committed by
Roland Dreier
d2e0655e ce1823f0

+34 -17
+3
drivers/infiniband/ulp/ipoib/ipoib.h
··· 230 230 INFINIBAND_ALEN, sizeof(void *)); 231 231 } 232 232 233 + struct ipoib_neigh *ipoib_neigh_alloc(struct neighbour *neigh); 234 + void ipoib_neigh_free(struct ipoib_neigh *neigh); 235 + 233 236 extern struct workqueue_struct *ipoib_workqueue; 234 237 235 238 /* functions */
+29 -12
drivers/infiniband/ulp/ipoib/ipoib_main.c
··· 252 252 */ 253 253 if (neigh->ah) 254 254 ipoib_put_ah(neigh->ah); 255 - *to_ipoib_neigh(neigh->neighbour) = NULL; 256 - kfree(neigh); 255 + 256 + ipoib_neigh_free(neigh); 257 257 } 258 258 259 259 spin_unlock_irqrestore(&priv->lock, flags); ··· 481 481 struct ipoib_path *path; 482 482 struct ipoib_neigh *neigh; 483 483 484 - neigh = kmalloc(sizeof *neigh, GFP_ATOMIC); 484 + neigh = ipoib_neigh_alloc(skb->dst->neighbour); 485 485 if (!neigh) { 486 486 ++priv->stats.tx_dropped; 487 487 dev_kfree_skb_any(skb); ··· 489 489 } 490 490 491 491 skb_queue_head_init(&neigh->queue); 492 - neigh->neighbour = skb->dst->neighbour; 493 - *to_ipoib_neigh(skb->dst->neighbour) = neigh; 494 492 495 493 /* 496 494 * We can only be called from ipoib_start_xmit, so we're ··· 501 503 path = path_rec_create(dev, 502 504 (union ib_gid *) (skb->dst->neighbour->ha + 4)); 503 505 if (!path) 504 - goto err; 506 + goto err_path; 505 507 506 508 __path_add(dev, path); 507 509 } ··· 519 521 __skb_queue_tail(&neigh->queue, skb); 520 522 521 523 if (!path->query && path_rec_start(dev, path)) 522 - goto err; 524 + goto err_list; 523 525 } 524 526 525 527 spin_unlock(&priv->lock); 526 528 return; 527 529 528 - err: 529 - *to_ipoib_neigh(skb->dst->neighbour) = NULL; 530 + err_list: 530 531 list_del(&neigh->list); 531 - kfree(neigh); 532 532 533 + err_path: 534 + ipoib_neigh_free(neigh); 533 535 ++priv->stats.tx_dropped; 534 536 dev_kfree_skb_any(skb); 535 537 ··· 761 763 if (neigh->ah) 762 764 ah = neigh->ah; 763 765 list_del(&neigh->list); 764 - *to_ipoib_neigh(n) = NULL; 765 - kfree(neigh); 766 + ipoib_neigh_free(neigh); 766 767 } 767 768 768 769 spin_unlock_irqrestore(&priv->lock, flags); 769 770 770 771 if (ah) 771 772 ipoib_put_ah(ah); 773 + } 774 + 775 + struct ipoib_neigh *ipoib_neigh_alloc(struct neighbour *neighbour) 776 + { 777 + struct ipoib_neigh *neigh; 778 + 779 + neigh = kmalloc(sizeof *neigh, GFP_ATOMIC); 780 + if (!neigh) 781 + return NULL; 782 + 783 + neigh->neighbour = neighbour; 784 + *to_ipoib_neigh(neighbour) = neigh; 785 + 786 + return neigh; 787 + } 788 + 789 + void ipoib_neigh_free(struct ipoib_neigh *neigh) 790 + { 791 + *to_ipoib_neigh(neigh->neighbour) = NULL; 792 + kfree(neigh); 772 793 } 773 794 774 795 static int ipoib_neigh_setup_dev(struct net_device *dev, struct neigh_parms *parms)
+2 -5
drivers/infiniband/ulp/ipoib/ipoib_multicast.c
··· 114 114 */ 115 115 if (neigh->ah) 116 116 ipoib_put_ah(neigh->ah); 117 - *to_ipoib_neigh(neigh->neighbour) = NULL; 118 - kfree(neigh); 117 + ipoib_neigh_free(neigh); 119 118 } 120 119 121 120 spin_unlock_irqrestore(&priv->lock, flags); ··· 771 772 if (skb->dst && 772 773 skb->dst->neighbour && 773 774 !*to_ipoib_neigh(skb->dst->neighbour)) { 774 - struct ipoib_neigh *neigh = kmalloc(sizeof *neigh, GFP_ATOMIC); 775 + struct ipoib_neigh *neigh = ipoib_neigh_alloc(skb->dst->neighbour); 775 776 776 777 if (neigh) { 777 778 kref_get(&mcast->ah->ref); 778 779 neigh->ah = mcast->ah; 779 - neigh->neighbour = skb->dst->neighbour; 780 - *to_ipoib_neigh(skb->dst->neighbour) = neigh; 781 780 list_add_tail(&neigh->list, &mcast->neigh_list); 782 781 } 783 782 }