linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Patch libibverbs 0/5] Minor updates
@ 2012-10-14 17:02 Doug Ledford
       [not found] ` <cover.1350234101.git.dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Doug Ledford @ 2012-10-14 17:02 UTC (permalink / raw)
  To: roland-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA, Doug Ledford

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(-)

-- 
1.7.7.6

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Patch libibverbs 1/5] Add an error when the user specifies an invalid port
       [not found] ` <cover.1350234101.git.dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
@ 2012-10-14 17:02   ` Doug Ledford
  2012-10-14 17:03   ` [Patch libibverbs 2/5] Don't allow port == 0 as an option Doug Ledford
                     ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Doug Ledford @ 2012-10-14 17:02 UTC (permalink / raw)
  To: roland-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA, Doug Ledford

Signed-off-by: Doug Ledford <dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
 examples/devinfo.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/examples/devinfo.c b/examples/devinfo.c
index 7dc0463..b1a3b2e 100644
--- a/examples/devinfo.c
+++ b/examples/devinfo.c
@@ -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",
-- 
1.7.7.6

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Patch libibverbs 2/5] Don't allow port == 0 as an option
       [not found] ` <cover.1350234101.git.dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
  2012-10-14 17:02   ` [Patch libibverbs 1/5] Add an error when the user specifies an invalid port Doug Ledford
@ 2012-10-14 17:03   ` Doug Ledford
  2012-10-14 17:03   ` [Patch libibverbs 3/5] Fix the compatibility wrapper on ppc Doug Ledford
                     ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Doug Ledford @ 2012-10-14 17:03 UTC (permalink / raw)
  To: roland-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA, Doug Ledford

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.

Signed-off-by: Doug Ledford <dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
 examples/devinfo.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/examples/devinfo.c b/examples/devinfo.c
index b1a3b2e..d6e9218 100644
--- a/examples/devinfo.c
+++ b/examples/devinfo.c
@@ -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;
 			}
-- 
1.7.7.6

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Patch libibverbs 3/5] Fix the compatibility wrapper on ppc
       [not found] ` <cover.1350234101.git.dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
  2012-10-14 17:02   ` [Patch libibverbs 1/5] Add an error when the user specifies an invalid port Doug Ledford
  2012-10-14 17:03   ` [Patch libibverbs 2/5] Don't allow port == 0 as an option Doug Ledford
@ 2012-10-14 17:03   ` Doug Ledford
  2012-10-14 17:03   ` [Patch libibverbs 4/5] Don't print link phys state on iWARP Doug Ledford
  2012-10-14 17:03   ` [Patch libibverbs 5/5] Don't try to send UD messages larger than MTU Doug Ledford
  4 siblings, 0 replies; 6+ messages in thread
From: Doug Ledford @ 2012-10-14 17:03 UTC (permalink / raw)
  To: roland-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA, Doug Ledford

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.

Signed-off-by: Doug Ledford <dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
 src/compat-1_0.c |   42 ++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/src/compat-1_0.c b/src/compat-1_0.c
index fff6412..36884bb 100644
--- a/src/compat-1_0.c
+++ b/src/compat-1_0.c
@@ -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;
-- 
1.7.7.6

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Patch libibverbs 4/5] Don't print link phys state on iWARP
       [not found] ` <cover.1350234101.git.dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
                     ` (2 preceding siblings ...)
  2012-10-14 17:03   ` [Patch libibverbs 3/5] Fix the compatibility wrapper on ppc Doug Ledford
@ 2012-10-14 17:03   ` Doug Ledford
  2012-10-14 17:03   ` [Patch libibverbs 5/5] Don't try to send UD messages larger than MTU Doug Ledford
  4 siblings, 0 replies; 6+ messages in thread
From: Doug Ledford @ 2012-10-14 17:03 UTC (permalink / raw)
  To: roland-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA, Doug Ledford

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

Signed-off-by: Doug Ledford <dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
 examples/devinfo.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/examples/devinfo.c b/examples/devinfo.c
index d6e9218..ff078e4 100644
--- a/examples/devinfo.c
+++ b/examples/devinfo.c
@@ -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;
-- 
1.7.7.6

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Patch libibverbs 5/5] Don't try to send UD messages larger than MTU
       [not found] ` <cover.1350234101.git.dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
                     ` (3 preceding siblings ...)
  2012-10-14 17:03   ` [Patch libibverbs 4/5] Don't print link phys state on iWARP Doug Ledford
@ 2012-10-14 17:03   ` Doug Ledford
  4 siblings, 0 replies; 6+ messages in thread
From: Doug Ledford @ 2012-10-14 17:03 UTC (permalink / raw)
  To: roland-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA, Doug Ledford

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.

Signed-off-by: Doug Ledford <dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
 examples/ud_pingpong.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/examples/ud_pingpong.c b/examples/ud_pingpong.c
index 71b152d..9a1ae13 100644
--- a/examples/ud_pingpong.c
+++ b/examples/ud_pingpong.c
@@ -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);
-- 
1.7.7.6

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-10-14 17:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-14 17:02 [Patch libibverbs 0/5] Minor updates Doug Ledford
     [not found] ` <cover.1350234101.git.dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-10-14 17:02   ` [Patch libibverbs 1/5] Add an error when the user specifies an invalid port Doug Ledford
2012-10-14 17:03   ` [Patch libibverbs 2/5] Don't allow port == 0 as an option Doug Ledford
2012-10-14 17:03   ` [Patch libibverbs 3/5] Fix the compatibility wrapper on ppc Doug Ledford
2012-10-14 17:03   ` [Patch libibverbs 4/5] Don't print link phys state on iWARP Doug Ledford
2012-10-14 17:03   ` [Patch libibverbs 5/5] Don't try to send UD messages larger than MTU Doug Ledford

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).