[ewg] [PATCH] IB/libipathverbs - Limit amount of memory ibv_cmd_post_send() needs

Ralph Campbell ralph.campbell at qlogic.com
Fri Nov 16 15:40:15 PST 2007


The gen2_basic test program attempts to post thousands of WRs
in one call. The ibv_cmd_post_send() function then tried to allocate
enough memory on the stack in order to write this to the kernel.
This patch limits the amount of memory needed by posting WRs in
smaller groups.

Signed-off-by: Ralph Campbell <ralph.campbell at qlogic.com>

diff --git a/src/ipathverbs.c b/src/ipathverbs.c
index 293dba8..eb16fb0 100644
--- a/src/ipathverbs.c
+++ b/src/ipathverbs.c
@@ -119,7 +119,7 @@ static struct ibv_context_ops ipath_ctx_ops = {
 	.modify_qp	= ipath_modify_qp,
 	.destroy_qp	= ipath_destroy_qp,
 
-	.post_send	= ibv_cmd_post_send,
+	.post_send	= ipath_post_send,
 	.post_recv	= ipath_post_recv,
 
 	.create_ah	= ipath_create_ah,
diff --git a/src/verbs.c b/src/verbs.c
index 57c78dd..5424e82 100644
--- a/src/verbs.c
+++ b/src/verbs.c
@@ -419,6 +419,40 @@ int ipath_destroy_qp_v1(struct ibv_qp *ibqp)
 	return ret;
 }
 
+int ipath_post_send(struct ibv_qp *qp, struct ibv_send_wr *wr,
+		    struct ibv_send_wr **bad_wr)
+{
+	unsigned wr_count;
+	struct ibv_send_wr *i;
+
+	/* Sanity check the number of WRs being posted */
+	for (i = wr, wr_count = 0; i; i = i->next)
+		if (++wr_count > 10)
+			goto iter;
+
+	return ibv_cmd_post_send(qp, wr, bad_wr);
+
+iter:
+	do {
+		struct ibv_send_wr *next;
+		int ret;
+
+		next = i->next;
+		i->next = NULL;
+		ret = ibv_cmd_post_send(qp, wr, bad_wr);
+		i->next = next;
+		if (ret)
+			return ret;
+		if (next == NULL)
+			break;
+		wr = next;
+		for (i = wr, wr_count = 0; i->next; i = i->next)
+			if (++wr_count > 2)
+				break;
+	} while (1);
+	return 0;
+}
+
 static int post_recv(struct ipath_rq *rq, struct ibv_recv_wr *wr,
 		     struct ibv_recv_wr **bad_wr)
 {





More information about the ewg mailing list