Skip to contentSkip to conversation

IPoIB: Take dev->xmit_lock around mc_list accesses

PATCH New Roland Dreier 1 participant 6 messages Jan 13, 2006 InfiniBand

lore
Share & tools
lore
#0 lore raw

PATCH 1/6 IPoIB: Take dev->xmit_lock around mc_list accesses

dev->mc_list accesses must be protected by dev->xmit_lock. Found by Eli Cohen <[email protected]>.

---

 drivers/infiniband/ulp/ipoib/ipoib_multicast.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

78bfe0b5b67fe126ed98608e42e42fb6ed9aabd4

drivers/infiniband/ulp/ipoib/ipoib_multicast.c +5 -2
index 03b2ca6..bf1c08c 100644
@@ -827,7 +827,8 @@ void ipoib_mcast_restart_task(void *dev_
 
 	ipoib_mcast_stop_thread(dev, 0);
 
-	spin_lock_irqsave(&priv->lock, flags);
+	spin_lock_irqsave(&dev->xmit_lock, flags);
+	spin_lock(&priv->lock);
 
 	/*
 	 * Unfortunately, the networking core only gives us a list of all of
@@ -899,7 +900,9 @@ void ipoib_mcast_restart_task(void *dev_
 			list_add_tail(&mcast->list, &remove_list);
 		}
 	}
-	spin_unlock_irqrestore(&priv->lock, flags);
+
+	spin_unlock(&priv->lock);
+	spin_unlock_irqrestore(&dev->xmit_lock, flags);
 
 	/* We have to cancel outside of the spinlock */
 	list_for_each_entry_safe(mcast, tmcast, &remove_list, list) {
Signature · 1 line
1.0.7
#1 lore raw

PATCH 2/6 IPoIB: Fix memory leak of multicast group structures

The current handling of multicast groups in IPoIB ends up never freeing send-only multicast groups. It turns out the logic was much more complicated than it needed to be; we can fix this bug and completely kill ipoib_mcast_dev_down() at the same time.

---

 drivers/infiniband/ulp/ipoib/ipoib_ib.c        |   13 -----
 drivers/infiniband/ulp/ipoib/ipoib_multicast.c |   61 +++---------------------
 2 files changed, 9 insertions(+), 65 deletions(-)

988bd50300ef2e2d5cb8563e2ac99453dd9acd86

drivers/infiniband/ulp/ipoib/ipoib_ib.c +1 -12
index 2388580..f7e8489 100644
@@ -453,17 +453,8 @@ int ipoib_ib_dev_down(struct net_device 
 	}
 
 	ipoib_mcast_stop_thread(dev, 1);
-
-	/*
-	 * Flush the multicast groups first so we stop any multicast joins. The
-	 * completion thread may have already died and we may deadlock waiting
-	 * for the completion thread to finish some multicast joins.
-	 */
 	ipoib_mcast_dev_flush(dev);
 
-	/* Delete broadcast and local addresses since they will be recreated */
-	ipoib_mcast_dev_down(dev);
-
 	ipoib_flush_paths(dev);
 
 	return 0;
@@ -624,9 +615,7 @@ void ipoib_ib_dev_cleanup(struct net_dev
 	ipoib_dbg(priv, "cleaning up ib_dev\n");
 
 	ipoib_mcast_stop_thread(dev, 1);
-
-	/* Delete the broadcast address and the local address */
-	ipoib_mcast_dev_down(dev);
+	ipoib_mcast_dev_flush(dev);
 
 	ipoib_transport_dev_cleanup(dev);
 }
drivers/infiniband/ulp/ipoib/ipoib_multicast.c +8 -53

82 lines not on this page · raw message

Signature · 1 line
1.0.7
#2 lore raw

PATCH 3/6 IB/mthca: Fix memory leak of multicast group structures

Convert "/ (1 << lg)" to ">> lg" for a slight code size reduction.

add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-24 (-24)

function                                     old     new   delta
mthca_map_cmd                                613     589     -24

---

 drivers/infiniband/hw/mthca/mthca_cmd.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

59f174faffd5dfee709fa0ead320cc6daf827e93

drivers/infiniband/hw/mthca/mthca_cmd.c +1 -1
index 22ac72b..f69e489 100644
@@ -606,7 +606,7 @@ static int mthca_map_cmd(struct mthca_de
 			err = -EINVAL;
 			goto out;
 		}
-		for (i = 0; i < mthca_icm_size(&iter) / (1 << lg); ++i) {
+		for (i = 0; i < mthca_icm_size(&iter) >> lg; ++i) {
 			if (virt != -1) {
 				pages[nent * 2] = cpu_to_be64(virt);
 				virt += 1 << lg;
Signature · 1 line
1.0.7
#3 lore raw

PATCH 4/6 IB/mthca: Fix memory leaks in error handling

Fix memory leaks in mthca_create_qp() and mthca_create_srq() error handling.

---

 drivers/infiniband/hw/mthca/mthca_provider.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

17e2e819517d75f2f3407e59c5f7f6f0ef305d14

drivers/infiniband/hw/mthca/mthca_provider.c +7 -3
index db35690..484a7e6 100644
@@ -445,8 +445,10 @@ static struct ib_srq *mthca_create_srq(s
 	if (pd->uobject) {
 		context = to_mucontext(pd->uobject->context);
 
-		if (ib_copy_from_udata(&ucmd, udata, sizeof ucmd))
-			return ERR_PTR(-EFAULT);
+		if (ib_copy_from_udata(&ucmd, udata, sizeof ucmd)) {
+			err = -EFAULT;
+			goto err_free;
+		}
 
 		err = mthca_map_user_db(to_mdev(pd->device), &context->uar,
 					context->db_tab, ucmd.db_index,
@@ -522,8 +524,10 @@ static struct ib_qp *mthca_create_qp(str
 		if (pd->uobject) {
 			context = to_mucontext(pd->uobject->context);
 
-			if (ib_copy_from_udata(&ucmd, udata, sizeof ucmd))
+			if (ib_copy_from_udata(&ucmd, udata, sizeof ucmd)) {
+				kfree(qp);
 				return ERR_PTR(-EFAULT);
+			}
 
 			err = mthca_map_user_db(to_mdev(pd->device), &context->uar,
 						context->db_tab,
Signature · 1 line
1.0.7
#4 lore raw

PATCH 5/6 IB/mthca: Cosmetic: use the ALIGN macro

Use the ALIGN macro to simplify some rounding code.

---

 drivers/infiniband/hw/mthca/mthca_cmd.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

c063a06835d3ccfa6c039d3a3869fcf22249c862

drivers/infiniband/hw/mthca/mthca_cmd.c +3 -2
index f69e489..be1791b 100644
@@ -727,8 +727,8 @@ int mthca_QUERY_FW(struct mthca_dev *dev
 		 * system pages needed.
 		 */
 		dev->fw.arbel.fw_pages =
-			(dev->fw.arbel.fw_pages + (1 << (PAGE_SHIFT - 12)) - 1) >>
-			(PAGE_SHIFT - 12);
+			ALIGN(dev->fw.arbel.fw_pages, PAGE_SIZE >> 12) >>
+				(PAGE_SHIFT - 12);
 
 		mthca_dbg(dev, "Clear int @ %llx, EQ arm @ %llx, EQ set CI @ %llx\n",
 			  (unsigned long long) dev->fw.arbel.clr_int_base,
@@ -1445,6 +1445,7 @@ int mthca_SET_ICM_SIZE(struct mthca_dev 
 	 * pages needed.
 	 */
 	*aux_pages = (*aux_pages + (1 << (PAGE_SHIFT - 12)) - 1) >> (PAGE_SHIFT - 12);
+	*aux_pages = ALIGN(*aux_pages, PAGE_SIZE >> 12) >> (PAGE_SHIFT - 12);
 
 	return 0;
 }
Signature · 1 line
1.0.7
#5 lore raw

PATCH 6/6 IB/mthca: Initialize grh_present before using it

build_mlx_header() was using sqp->ud_header.grh_present before it was initialized by mthca_read_ah(). Furthermore, header->grh_present is set by ib_ud_header_init, so there's no need to set it again in mthca_read_ah().

---

 drivers/infiniband/hw/mthca/mthca_av.c  |   10 ++++++----
 drivers/infiniband/hw/mthca/mthca_dev.h |    1 +
 drivers/infiniband/hw/mthca/mthca_qp.c  |    2 +-
 3 files changed, 8 insertions(+), 5 deletions(-)

9eacee2ac624bfa9740d49355dbe6ee88d0cba0a

drivers/infiniband/hw/mthca/mthca_av.c +6 -4
index 22fdc44..a14eed0 100644
@@ -163,6 +163,11 @@ int mthca_destroy_ah(struct mthca_dev *d
 	return 0;
 }
 
+int mthca_ah_grh_present(struct mthca_ah *ah)
+{
+	return !!(ah->av->g_slid & 0x80);
+}
+
 int mthca_read_ah(struct mthca_dev *dev, struct mthca_ah *ah,
 		  struct ib_ud_header *header)
 {
@@ -172,8 +177,7 @@ int mthca_read_ah(struct mthca_dev *dev,
 	header->lrh.service_level   = be32_to_cpu(ah->av->sl_tclass_flowlabel) >> 28;
 	header->lrh.destination_lid = ah->av->dlid;
 	header->lrh.source_lid      = cpu_to_be16(ah->av->g_slid & 0x7f);
-	if (ah->av->g_slid & 0x80) {
-		header->grh_present = 1;
+	if (mthca_ah_grh_present(ah)) {
 		header->grh.traffic_class =
 			(be32_to_cpu(ah->av->sl_tclass_flowlabel) >> 20) & 0xff;
 		header->grh.flow_label    =
@@ -184,8 +188,6 @@ int mthca_read_ah(struct mthca_dev *dev,
 				  &header->grh.source_gid);
 		memcpy(header->grh.destination_gid.raw,
 		       ah->av->dgid, 16);
-	} else {
-		header->grh_present = 0;
 	}
 
 	return 0;
drivers/infiniband/hw/mthca/mthca_dev.h +1 -0
index 795b379..a104ab0 100644
@@ -520,6 +520,7 @@ int mthca_create_ah(struct mthca_dev *de
 int mthca_destroy_ah(struct mthca_dev *dev, struct mthca_ah *ah);
 int mthca_read_ah(struct mthca_dev *dev, struct mthca_ah *ah,
 		  struct ib_ud_header *header);
+int mthca_ah_grh_present(struct mthca_ah *ah);
 
 int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);
 int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);
drivers/infiniband/hw/mthca/mthca_qp.c +1 -1
index 564b6d5..fba608e 100644
@@ -1434,7 +1434,7 @@ static int build_mlx_header(struct mthca
 	u16 pkey;
 
 	ib_ud_header_init(256, /* assume a MAD */
-			  sqp->ud_header.grh_present,
+			  mthca_ah_grh_present(to_mah(wr->wr.ud.ah)),
 			  &sqp->ud_header);
 
 	err = mthca_read_ah(dev, to_mah(wr->wr.ud.ah), &sqp->ud_header);
Signature · 1 line
1.0.7