[ofa-general] [RFC] [PATCH v4] IB/ipoib: Add bonding support to IPoIB

Moni Shoua monisonlists at gmail.com
Wed Mar 28 05:01:57 PDT 2007


Hi,

The previous version of the patch changed ipoib_neigh_destructor to take 
the pointer to neigh outside the lock. This might be a risk so I wrote a 
new version of this patch so the change would affect only when bonding is used.
Please see below...

-------------------------------------------------------------------------------------
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.

Under this scheme, ipoib_neigh_destructor assumption that for each struct
neighbour it gets, n->dev is an ipoib device and hence netdev_priv(n->dev)
can be casted to struct ipoib_dev_priv is buggy.

To fix it, this patch adds a dev field to struct ipoib_neigh which is used
instead of the struct neighbour dev one, when n->dev->flags has the
IFF_MASTER bit set.

Signed-off-by: Moni Shoua <monis at voltaire.com>
Signed-off-by: Or Gerlitz <ogerlitz at voltaire.com>
---
 ipoib.h           |    4 +++-
 ipoib_main.c      |   17 +++++++++++++++--
 ipoib_multicast.c |    2 +-
 3 files changed, 19 insertions(+), 4 deletions(-)

Index: ofed_1_2/drivers/infiniband/ulp/ipoib/ipoib.h
===================================================================
--- ofed_1_2.orig/drivers/infiniband/ulp/ipoib/ipoib.h	2007-03-28 09:42:44.000000000 +0200
+++ ofed_1_2/drivers/infiniband/ulp/ipoib/ipoib.h	2007-03-28 10:10:28.519867061 +0200
@@ -216,6 +216,7 @@ struct ipoib_neigh {
 	struct sk_buff_head queue;
 
 	struct neighbour   *neighbour;
+	struct net_device *dev;
 
 	struct list_head    list;
 };
@@ -232,7 +233,8 @@ 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 net_device *dev, struct ipoib_neigh *neigh);
 
 extern struct workqueue_struct *ipoib_workqueue;
Index: ofed_1_2/drivers/infiniband/ulp/ipoib/ipoib_main.c
===================================================================
--- ofed_1_2.orig/drivers/infiniband/ulp/ipoib/ipoib_main.c	2007-03-28 09:42:44.000000000 +0200
+++ ofed_1_2/drivers/infiniband/ulp/ipoib/ipoib_main.c	2007-03-28 13:11:21.939306498 +0200
@@ -490,7 +490,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);
@@ -773,6 +773,16 @@ static void ipoib_neigh_destructor(struc
 	unsigned long flags;
 	struct ipoib_ah *ah = NULL;
 
+	if (n->dev->flags & IFF_MASTER) {
+		/* n->dev is not an IPoIB device and we have to take priv from elsewhere */
+		neigh = *to_ipoib_neigh(n);
+		if (neigh){
+			priv = netdev_priv(neigh->dev);
+			ipoib_dbg(priv, "neigh_destructor for bonding device: %s\n",
+				  n->dev->name);
+		} else
+			return;
+	}
 	ipoib_dbg(priv,
 		  "neigh_destructor for %06x " IPOIB_GID_FMT "\n",
 		  IPOIB_QPN(n->ha),
@@ -794,7 +804,9 @@ 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;
 
@@ -803,6 +815,7 @@ struct ipoib_neigh *ipoib_neigh_alloc(st
 		return NULL;
 
 	neigh->neighbour = neighbour;
+	neigh->dev = dev;
 	*to_ipoib_neigh(neighbour) = neigh;
 	skb_queue_head_init(&neigh->queue);
 
Index: ofed_1_2/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
===================================================================
--- ofed_1_2.orig/drivers/infiniband/ulp/ipoib/ipoib_multicast.c	2007-03-28 09:42:44.000000000 +0200
+++ ofed_1_2/drivers/infiniband/ulp/ipoib/ipoib_multicast.c	2007-03-28 10:10:28.521866685 +0200
@@ -774,7 +774,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