[openib-general] ipoib_mcast_send.patch

Michael S. Tsirkin mst at mellanox.co.il
Tue Jan 17 11:21:07 PST 2006


Quoting r. Michael S. Tsirkin <mst at mellanox.co.il>:
> Subject: Re: Re: ipoib: outstanding patches
> 
> Quoting Roland Dreier <rdreier at cisco.com>:
> > > ipoib_mcast_send.patch
> > 
> > Could we reuse the IPOIB_MCAST_RUN bit rather than adding a new bit?
> > It seems that we could kill mcast_mutex and replace uses with
> > priv->lock instead -- I don't see anything that sleeps inside mcast_mutex.
> 
> Yes, I now believe that we should be able to do it this way.

Something like this?

---

Fix the following race scenario:
Device is up.
Port event or set mcast list triggers ipoib_mcast_stop_thread,
this cancels the query and waits on mcast "done" completion.
Completion is called and "done" is set.
Meanwhile, ipoib_mcast_send arrives and starts a new query,
re-initializing "done".

Further, there's an additional issue that I saw in testing:
ipoib_mcast_send may get called when priv->broadcast is NULL
(e.g. if the device was downed and then upped internally because
of a port event).
If this happends and the sendonly join request gets completed before
priv->broadcast is set, we get an oops

----
Do not send multicasts if mcast thread is stopped or if
priv->broadcast is not set.

Signed-off-by: Michael S. Tsirkin <mst at mellanox.co.il>

Index: openib/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
===================================================================
--- openib.orig/drivers/infiniband/ulp/ipoib/ipoib_multicast.c	2006-01-17 21:13:43.000000000 +0200
+++ openib/drivers/infiniband/ulp/ipoib/ipoib_multicast.c	2006-01-17 21:18:36.000000000 +0200
@@ -55,8 +55,6 @@ MODULE_PARM_DESC(mcast_debug_level,
 		 "Enable multicast debug tracing if > 0");
 #endif
 
-static DEFINE_MUTEX(mcast_mutex);
-
 /* Used for all multicast joins (broadcast, IPv4 mcast and IPv6 mcast) */
 struct ipoib_mcast {
 	struct ib_sa_mcmember_rec mcmember;
@@ -385,10 +383,10 @@ static void ipoib_mcast_join_complete(in
 
 	if (!status && !ipoib_mcast_join_finish(mcast, mcmember)) {
 		mcast->backoff = 1;
-		mutex_lock(&mcast_mutex);
+		spin_lock_irq(&priv->lock);
 		if (test_bit(IPOIB_MCAST_RUN, &priv->flags))
 			queue_work(ipoib_workqueue, &priv->mcast_task);
-		mutex_unlock(&mcast_mutex);
+		spin_unlock_irq(&priv->lock);
 		complete(&mcast->done);
 		return;
 	}
@@ -418,7 +416,7 @@ static void ipoib_mcast_join_complete(in
 
 	mcast->query = NULL;
 
-	mutex_lock(&mcast_mutex);
+	spin_lock_irq(&priv->lock);
 	if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) {
 		if (status == -ETIMEDOUT)
 			queue_work(ipoib_workqueue, &priv->mcast_task);
@@ -427,7 +425,7 @@ static void ipoib_mcast_join_complete(in
 					   mcast->backoff * HZ);
 	} else
 		complete(&mcast->done);
-	mutex_unlock(&mcast_mutex);
+	spin_unlock_irq(&priv->lock);
 
 	return;
 }
@@ -482,12 +480,12 @@ static void ipoib_mcast_join(struct net_
 		if (mcast->backoff > IPOIB_MAX_BACKOFF_SECONDS)
 			mcast->backoff = IPOIB_MAX_BACKOFF_SECONDS;
 
-		mutex_lock(&mcast_mutex);
+		spin_lock_irq(&priv->lock);
 		if (test_bit(IPOIB_MCAST_RUN, &priv->flags))
 			queue_delayed_work(ipoib_workqueue,
 					   &priv->mcast_task,
 					   mcast->backoff * HZ);
-		mutex_unlock(&mcast_mutex);
+		spin_unlock_irq(&priv->lock);
 	} else
 		mcast->query_id = ret;
 }
@@ -520,11 +518,11 @@ void ipoib_mcast_join_task(void *dev_ptr
 		priv->broadcast = ipoib_mcast_alloc(dev, 1);
 		if (!priv->broadcast) {
 			ipoib_warn(priv, "failed to allocate broadcast group\n");
-			mutex_lock(&mcast_mutex);
+			spin_lock_irq(&priv->lock);
 			if (test_bit(IPOIB_MCAST_RUN, &priv->flags))
 				queue_delayed_work(ipoib_workqueue,
 						   &priv->mcast_task, HZ);
-			mutex_unlock(&mcast_mutex);
+			spin_unlock_irq(&priv->lock);
 			return;
 		}
 
@@ -580,10 +578,10 @@ int ipoib_mcast_start_thread(struct net_
 
 	ipoib_dbg_mcast(priv, "starting multicast thread\n");
 
-	mutex_lock(&mcast_mutex);
+	spin_lock_irq(&priv->lock);
 	if (!test_and_set_bit(IPOIB_MCAST_RUN, &priv->flags))
 		queue_work(ipoib_workqueue, &priv->mcast_task);
-	mutex_unlock(&mcast_mutex);
+	spin_unlock_irq(&priv->lock);
 
 	return 0;
 }
@@ -595,10 +593,10 @@ int ipoib_mcast_stop_thread(struct net_d
 
 	ipoib_dbg_mcast(priv, "stopping multicast thread\n");
 
-	mutex_lock(&mcast_mutex);
+	spin_lock_irq(&priv->lock);
 	clear_bit(IPOIB_MCAST_RUN, &priv->flags);
 	cancel_delayed_work(&priv->mcast_task);
-	mutex_unlock(&mcast_mutex);
+	spin_unlock_irq(&priv->lock);
 
 	if (flush)
 		flush_workqueue(ipoib_workqueue);
@@ -677,6 +675,11 @@ void ipoib_mcast_send(struct net_device 
 	 */
 	spin_lock(&priv->lock);
 
+	if (!test_bit(IPOIB_MCAST_RUN, &priv->flags) || !priv->broadcast) {
+		dev_kfree_skb_any(skb);
+		goto unlock;
+	}
+
 	mcast = __ipoib_mcast_find(dev, mgid);
 	if (!mcast) {
 		/* Let's create a new send only group now */
@@ -735,6 +738,7 @@ out:
 		ipoib_send(dev, skb, mcast->ah, IB_MULTICAST_QPN);
 	}
 
+unlock:
 	spin_unlock(&priv->lock);
 }
 

-- 
MST



More information about the general mailing list