[openib-general] [PATCH] IB/ipoib: Add field dev to struct ipoib_neigh

Moni Shoua monis at voltaire.com
Tue Jan 23 09:15:30 PST 2007


IPoIB uses a two layer neighboring scheme, such that for each struct neighbour
whose device is an ipoib one, there is a struct ipoib_neigh buddy which is
created on demand at the tx flow by an ipoib_neigh_alloc(skb->dst->neighbour)
call.

When using the bonding driver, neighbours are created by the net stack on behalf
of the bonding (master) device. On the tx flow the bonding code gets an skb such
that skb->dev points to the master device, it changes this skb to point on the
slave device and calls the slave hard_start_xmit function.

Combing these two flows, there is a hole if some code at ipoib
(ipoib_neigh_destructor) assumes that for each struct neighbour it gets, n->dev
is an ipoib device so for example netdev_priv(n->dev) would be of type struct
ipoib_dev_priv.

To fix it, this patch adds a dev field to struct ipoib_neigh which is used
instead of the struct neighbour dev one.

Signed-off-by: Moni Shoua <monis at voltaire.com>
Signed-off-by: Or Gerlitz <ogerlitz at voltaire.com>

 ipoib.h           |    3 ++-
 ipoib_main.c      |   22 +++++++++++-----------
 ipoib_multicast.c |    2 +-
 3 files changed, 14 insertions(+), 13 deletions(-)
---
Index: openib-1.1/drivers/infiniband/ulp/ipoib/ipoib.h
===================================================================
--- openib-1.1.orig/drivers/infiniband/ulp/ipoib/ipoib.h	2007-01-10 17:53:02.744225722 +0200
+++ openib-1.1/drivers/infiniband/ulp/ipoib/ipoib.h	2007-01-10 17:55:04.121544018 +0200
@@ -218,6 +218,7 @@ struct ipoib_neigh {
 	struct sk_buff_head queue;
 
 	struct neighbour   *neighbour;
+	struct net_device *dev;
 
 	struct list_head    all_neigh_list;
 	struct list_head    list;
@@ -235,7 +236,7 @@ static inline struct ipoib_neigh **to_ip
 				     INFINIBAND_ALEN, sizeof(void *));
 }
 
-struct ipoib_neigh *ipoib_neigh_alloc(struct neighbour *neigh);
+struct ipoib_neigh *ipoib_neigh_alloc(struct neighbour *neigh,struct net_device *dev);
 void ipoib_neigh_free(struct ipoib_neigh *neigh);
 
 extern struct workqueue_struct *ipoib_workqueue;
Index: openib-1.1/drivers/infiniband/ulp/ipoib/ipoib_main.c
===================================================================
--- openib-1.1.orig/drivers/infiniband/ulp/ipoib/ipoib_main.c	2007-01-10 17:53:02.717230544 +0200
+++ openib-1.1/drivers/infiniband/ulp/ipoib/ipoib_main.c	2007-01-10 17:58:55.531209253 +0200
@@ -516,7 +516,7 @@ static void neigh_add_path(struct sk_buf
 	struct ipoib_path *path;
 	struct ipoib_neigh *neigh;
 
-	neigh = ipoib_neigh_alloc(skb->dst->neighbour);
+	neigh = ipoib_neigh_alloc(skb->dst->neighbour, skb->dev);
 	if (!neigh) {
 		++priv->stats.tx_dropped;
 		dev_kfree_skb_any(skb);
@@ -799,7 +799,7 @@ static void ipoib_set_mcast_list(struct 
 static void ipoib_neigh_destructor(struct neighbour *n)
 {
 	struct ipoib_neigh *neigh;
-	struct ipoib_dev_priv *priv = netdev_priv(n->dev);
+	struct ipoib_dev_priv *priv;
 	unsigned long flags;
 	struct ipoib_ah *ah = NULL;
 
@@ -808,12 +808,14 @@ static void ipoib_neigh_destructor(struc
 	list_for_each_entry(tn, &ipoib_all_neigh_list, all_neigh_list)
 		if (tn->neighbour == n) {
 			nn = tn;
+			neigh = *to_ipoib_neigh(n);
 			break;
 		}
 	spin_unlock(&ipoib_all_neigh_list_lock);
-	if (!nn)
+	if (!nn || !neigh)
 		return;
 
+	priv = netdev_priv(neigh->dev);
 	ipoib_dbg(priv,
 		  "neigh_destructor for %06x " IPOIB_GID_FMT "\n",
 		  be32_to_cpup((__be32 *) n->ha),
@@ -821,13 +823,9 @@ static void ipoib_neigh_destructor(struc
 
 	spin_lock_irqsave(&priv->lock, flags);
 
-	neigh = *to_ipoib_neigh(n);
-	if (neigh) {
-		if (neigh->ah)
-			ah = neigh->ah;
-		list_del(&neigh->list);
-		ipoib_neigh_free(neigh);
-	}
+	ah = neigh->ah;
+	list_del(&neigh->list);
+	ipoib_neigh_free(neigh);
 
 	spin_unlock_irqrestore(&priv->lock, flags);
 
@@ -835,7 +833,8 @@ static void ipoib_neigh_destructor(struc
 		ipoib_put_ah(ah);
 }
 
-struct ipoib_neigh *ipoib_neigh_alloc(struct neighbour *neighbour)
+struct ipoib_neigh *ipoib_neigh_alloc(struct neighbour *neighbour,
+				      struct net_device *dev)
 {
 	struct ipoib_neigh *neigh;
 
@@ -849,6 +848,7 @@ struct ipoib_neigh *ipoib_neigh_alloc(st
 	spin_lock(&ipoib_all_neigh_list_lock);
 	list_add_tail(&neigh->all_neigh_list, &ipoib_all_neigh_list);
 	neigh->neighbour->ops->destructor = ipoib_neigh_destructor;
+	neigh->dev = dev;
 	spin_unlock(&ipoib_all_neigh_list_lock);
 
 	return neigh;
Index: openib-1.1/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
===================================================================
--- openib-1.1.orig/drivers/infiniband/ulp/ipoib/ipoib_multicast.c	2007-01-10 17:53:01.077523451 +0200
+++ openib-1.1/drivers/infiniband/ulp/ipoib/ipoib_multicast.c	2007-01-10 17:58:04.808269239 +0200
@@ -770,7 +770,7 @@ out:
 		if (skb->dst            &&
 		    skb->dst->neighbour &&
 		    !*to_ipoib_neigh(skb->dst->neighbour)) {
-			struct ipoib_neigh *neigh = ipoib_neigh_alloc(skb->dst->neighbour);
+			struct ipoib_neigh *neigh = ipoib_neigh_alloc(skb->dst->neighbour, skb->dev);
 
 			if (neigh) {
 				kref_get(&mcast->ah->ref);





More information about the general mailing list