Skip to contentSkip to conversation

Minor updates

PATCH New Doug Ledford 1 participant 6 messages Oct 14, 2012 1 message not in the archive InfiniBand

lore
Share & tools
lore
#0 lore raw

cover Minor updates

This is a short series of fixes for minor issues. The most important being a memcpy buffer overrun on ppc arch for the compatibility wrapper. The rest are usability fixes for the example programs.

Doug Ledford (5):
Add an error when the user specifies an invalid port Don't allow port == 0 as an option
Fix the compatibility wrapper on ppc
Don't print link phys state on iWARP
Don't try to send UD messages larger than MTU

 examples/devinfo.c     |   15 +++++++++++----
 examples/ud_pingpong.c |   14 ++++++++++++++
 src/compat-1_0.c       |   42 ++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 65 insertions(+), 6 deletions(-)
Signature · 6 lines
1.7.7.6

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): cover.1350234101.git.dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org

#2 lore raw

PATCH 1/5 Add an error when the user specifies an invalid port

---
 examples/devinfo.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
examples/devinfo.c +7 -1
index 7dc0463..b1a3b2e 100644
@@ -218,10 +218,16 @@ static int print_hca_cap(struct ibv_device *ib_dev, uint8_t ib_port)
 		goto cleanup;
 	}
 	if (ibv_query_device(ctx, &device_attr)) {
-		fprintf(stderr, "Failed to query device props");
+		fprintf(stderr, "Failed to query device props\n");
 		rc = 2;
 		goto cleanup;
 	}
+	if (ib_port && ib_port > device_attr.phys_port_cnt) {
+		fprintf(stderr, "Invalid port requested for device\n");
+		/* rc = 3 is taken by failure to clean up */
+		rc = 4;
+		goto cleanup;
+	}
 
 	printf("hca_id:\t%s\n", ibv_get_device_name(ib_dev));
 	printf("\ttransport:\t\t\t%s (%d)\n",
Signature · 6 lines
1.7.7.6

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw

PATCH 2/5 Don't allow port == 0 as an option

In reply to a message not in the archive

We special case port == 0 to mean all ports, and it's the default, so if a user passes in 0, they likely meant 1 instead. Throw an error because they probably didn't mean to specify the default behavior of scan all ports. Path of least surprise and all that.

---
 examples/devinfo.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
examples/devinfo.c +1 -1
index b1a3b2e..d6e9218 100644
@@ -385,7 +385,7 @@ int main(int argc, char *argv[])
 
 		case 'i':
 			ib_port = strtol(optarg, NULL, 0);
-			if (ib_port < 0) {
+			if (ib_port <= 0) {
 				usage(argv[0]);
 				return 1;
 			}
Signature · 6 lines
1.7.7.6

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#4 lore raw

PATCH 3/5 Fix the compatibility wrapper on ppc

In reply to a message not in the archive

The ppc arch packs the work request struct 1.0 in such a way that a straight memcpy won't work. Instead, break the copy out into chunks whenever the sizes don't match for given portions of the struct.

Found by built in gcc memcpy buffer overflow checks.

Help on the right fix provided by Jakub Jelinek from the gcc team inside Red Hat.

---
 src/compat-1_0.c |   42 ++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 40 insertions(+), 2 deletions(-)
src/compat-1_0.c +40 -2
index fff6412..36884bb 100644
@@ -353,8 +353,46 @@ static int post_send_wrapper_1_0(struct ibv_qp_1_0 *qp, struct ibv_send_wr_1_0 *
 		real_wr->wr_id = w->wr_id;
 		real_wr->next  = NULL;
 
-		memcpy(&real_wr->sg_list, &w->sg_list,
-		       sizeof *w - offsetof(struct ibv_send_wr, sg_list));
+#define TEST_SIZE_2_POINT(f1, f2) \
+((offsetof(struct ibv_send_wr, f1) - offsetof(struct ibv_send_wr, f2)) \
+== offsetof(struct ibv_send_wr_1_0, f1) - offsetof(struct ibv_send_wr_1_0, f2))
+#define TEST_SIZE_TO_END(f1) \
+((sizeof(struct ibv_send_wr) - offsetof(struct ibv_send_wr, f1)) == \
+ (sizeof(struct ibv_send_wr_1_0) - offsetof(struct ibv_send_wr_1_0, f1)))
+
+		if (TEST_SIZE_TO_END (sg_list))
+			memcpy(&real_wr->sg_list, &w->sg_list, sizeof *real_wr
+			       - offsetof(struct ibv_send_wr, sg_list));
+		else if (TEST_SIZE_2_POINT (imm_data, sg_list) &&
+			 TEST_SIZE_TO_END (wr)) {
+			/* we have alignment up to wr, but padding between
+			 * imm_data and wr, and we know wr itself is the
+			 * same size */
+			memcpy(&real_wr->sg_list, &w->sg_list,
+			       offsetof(struct ibv_send_wr, imm_data) -
+			       offsetof(struct ibv_send_wr, sg_list) +
+			       sizeof real_wr->imm_data);
+			memcpy(&real_wr->wr, &w->wr, sizeof real_wr->wr);
+		} else {
+			real_wr->sg_list = w->sg_list;
+			real_wr->num_sge = w->num_sge;
+			real_wr->opcode = w->opcode;
+			real_wr->send_flags = w->send_flags;
+			real_wr->imm_data = w->imm_data;
+			if (TEST_SIZE_TO_END (wr))
+				memcpy(&real_wr->wr, &w->wr,
+				       sizeof real_wr->wr);
+			else {
+				real_wr->wr.atomic.remote_addr = 
+					w->wr.atomic.remote_addr;
+				real_wr->wr.atomic.compare_add = 
+					w->wr.atomic.compare_add;
+				real_wr->wr.atomic.swap = 
+					w->wr.atomic.swap;
+				real_wr->wr.atomic.rkey = 
+					w->wr.atomic.rkey;
+			}
+		}
 
 		if (is_ud)
 			real_wr->wr.ud.ah = w->wr.ud.ah->real_ah;
Signature · 6 lines
1.7.7.6

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#5 lore raw

PATCH 4/5 Don't print link phys state on iWARP

In reply to a message not in the archive

The physical link state on iWARP transports has no meaning, so don't print it out at all.

---
 examples/devinfo.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
examples/devinfo.c +3 -2
index d6e9218..ff078e4 100644
@@ -327,8 +327,9 @@ static int print_hca_cap(struct ibv_device *ib_dev, uint8_t ib_port)
 			       width_str(port_attr.active_width), port_attr.active_width);
 			printf("\t\t\tactive_speed:\t\t%s (%d)\n",
 			       speed_str(port_attr.active_speed), port_attr.active_speed);
-			printf("\t\t\tphys_state:\t\t%s (%d)\n",
-			       port_phy_state_str(port_attr.phys_state), port_attr.phys_state);
+			if (ib_dev->transport_type == IBV_TRANSPORT_IB)
+				printf("\t\t\tphys_state:\t\t%s (%d)\n",
+				       port_phy_state_str(port_attr.phys_state), port_attr.phys_state);
 
 			if (print_all_port_gids(ctx, port, port_attr.gid_tbl_len))
 				goto cleanup;
Signature · 6 lines
1.7.7.6

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#6 lore raw

PATCH 5/5 Don't try to send UD messages larger than MTU

In reply to a message not in the archive

The UD protocol doesn't support message sizes larger than the path MTU. We don't go so far as to check path MTU, but we do check port MTU. This prevents failed runs of the pingpong_ud program with large MTUs.

---
 examples/ud_pingpong.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
examples/ud_pingpong.c +14 -0
index 71b152d..9a1ae13 100644
@@ -323,6 +323,20 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
 			ibv_get_device_name(ib_dev));
 		return NULL;
 	}
+	{
+		struct ibv_port_attr port_info = { 0 };
+		int mtu;
+
+		if (ibv_query_port(ctx->context, port, &port_info)) {
+			fprintf(stderr, "Unable to query port info for port %d\n", port);
+			return NULL;
+		}
+		mtu = 1 << (port_info.active_mtu + 7);
+		if (size > mtu) {
+			fprintf(stderr, "Requested size larger than port MTU (%d)\n", mtu);
+			return NULL;
+		}
+	}
 
 	if (use_event) {
 		ctx->channel = ibv_create_comp_channel(ctx->context);
Signature · 6 lines
1.7.7.6

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html