16223428 ibv_register_sm_events/ibv_gid_reachable should return 0 if succeeds s11-update
authorBoris Chiu <boris.chiu@oracle.com>
Mon, 23 Dec 2013 14:14:12 -0800
branchs11-update
changeset 2871 899d41b03a8e
parent 2870 ae0795af7dd9
child 2872 5f6aed21119f
16223428 ibv_register_sm_events/ibv_gid_reachable should return 0 if succeeds 16382598 ibv_register_sm_events/ibv_unregister_sm_events should validate MGID format
components/open-fabrics/libibverbs/patches/base.patch
--- a/components/open-fabrics/libibverbs/patches/base.patch	Mon Dec 23 14:14:12 2013 -0800
+++ b/components/open-fabrics/libibverbs/patches/base.patch	Mon Dec 23 14:14:12 2013 -0800
@@ -531,7 +531,7 @@
 diff -r -u /tmp/846623/libibverbs-1.1.4/src/verbs.c libibverbs-1.1.4/src/verbs.c
 --- /tmp/846623/libibverbs-1.1.4/src/verbs.c	Thu Feb  3 01:53:17 2011
 +++ libibverbs-1.1.4/src/verbs.c	Fri Feb 11 04:02:33 2011
[email protected]@ -41,6 +41,11 @@
[email protected]@ -41,9 +41,24 @@
  #include <stdlib.h>
  #include <errno.h>
  #include <string.h>
@@ -543,7 +543,20 @@
  
  #include "ibverbs.h"
  
[email protected]@ -93,6 +98,12 @@
++#define	IBV_IS_VALID_UGID(gid)	\
++	(gid->raw[0] != 0xff)
++
++#define	IBV_IS_VALID_MGID(gid)					\
++	((gids->raw[0] == 0xff) &&				\
++	((gids->raw[1] == 0x0e) || (gids->raw[1] == 0x02) ||	\
++	(gids->raw[1] == 0x05)  || (gids->raw[1] == 0x08) ||	\
++	(gids->raw[1] == 0x1e)  || (gids->raw[1] == 0x12) ||	\
++	(gids->raw[1] == 0x15)  || (gids->raw[1] == 0x18)))
++
+ int ibv_rate_to_mult(enum ibv_rate rate)
+ {
+ 	switch (rate) {
[email protected]@ -93,6 +108,12 @@
  int __ibv_query_gid(struct ibv_context *context, uint8_t port_num,
  		    int index, union ibv_gid *gid)
  {
@@ -556,7 +569,7 @@
  	char name[24];
  	char attr[41];
  	uint16_t val;
[email protected]@ -112,6 +123,7 @@
[email protected]@ -112,6 +133,7 @@
  	}
  
  	return 0;
@@ -564,7 +577,7 @@
  }
  default_symver(__ibv_query_gid, ibv_query_gid);
  
[email protected]@ -118,6 +130,12 @@
[email protected]@ -118,6 +140,12 @@
  int __ibv_query_pkey(struct ibv_context *context, uint8_t port_num,
  		     int index, uint16_t *pkey)
  {
@@ -577,7 +590,7 @@
  	char name[24];
  	char attr[8];
  	uint16_t val;
[email protected]@ -133,9 +151,142 @@
[email protected]@ -133,9 +161,159 @@
  
  	*pkey = htons(val);
  	return 0;
@@ -589,7 +602,7 @@
 +    ibv_sm_event_type_t event, uint_t gid_num, union ibv_gid *gids)
 +{
 +	struct ibv_reg_sm_event		*cmd;
-+	int				rc, cmd_size, data_size;
++	int				cmd_size, data_size;
 +	void				*data_p;
 +
 +	if (((gid_num > 0) && (gids == NULL)) ||
@@ -624,26 +637,35 @@
 +	cmd  = alloca(cmd_size);
 +	cmd->data_num = gid_num;
 +
++	if ((event == IBV_SM_EVENT_UGID) && (!IBV_IS_VALID_UGID(gids))) { 
++		errno = EINVAL;
++		return (-1);
++	}
++
++	if ((event == IBV_SM_EVENT_MGID) && (!IBV_IS_VALID_MGID(gids))) { 
++		errno = EINVAL;
++		return (-1);
++	}
++
 +	IBV_INIT_CMD(cmd, cmd_size, REG_SM_EVENT);
 +
 +	cmd->events = event;
 +	if (gid_num > 0)
 +		memcpy(cmd->driver_data, data_p, data_size);
 +
-+	rc = write(context->cmd_fd, cmd, cmd_size);
-+	if (rc < 0) {
-+		errno = -rc;
-+		rc = -1;
++	if (write(context->cmd_fd, cmd, cmd_size) != cmd_size) {
++		errno = EINVAL;
++		return (-1);
 +	}
 +
-+	return (rc);
++	return (0);
 +}
 +
 +int ibv_unregister_sm_events(struct ibv_context *context,
 +    ibv_sm_event_type_t event, uint_t gid_num, union ibv_gid *gids)
 +{
 +	struct ibv_unreg_sm_event	*cmd;
-+	int				rc, cmd_size, data_size;
++	int				cmd_size, data_size;
 +	void				*data_p;
 +
 +	if (((gid_num > 0) && (gids == NULL)) ||
@@ -678,19 +700,28 @@
 +	cmd  = alloca(cmd_size);
 +	cmd->data_num = gid_num;
 +
++	if ((event == IBV_SM_EVENT_UGID) && (!IBV_IS_VALID_UGID(gids))) { 
++		errno = EINVAL;
++		return (-1);
++	}
++
++	if ((event == IBV_SM_EVENT_MGID) && (!IBV_IS_VALID_MGID(gids))) { 
++		errno = EINVAL;
++		return (-1);
++	}
++
 +	IBV_INIT_CMD(cmd, cmd_size, UNREG_SM_EVENT);
 +
 +	cmd->events = event;
 +	if (gid_num > 0)
 +		memcpy(cmd->driver_data, data_p, data_size);
 +
-+	rc = write(context->cmd_fd, cmd, cmd_size);
-+	if (rc < 0) {
-+		errno = -rc;
-+		rc = -1;
++	if (write(context->cmd_fd, cmd, cmd_size) != cmd_size) {
++		errno = EINVAL;
++		return (-1);
 +	}
 +
-+	return (rc);
++	return (0);
 +}
 +
 +int ibv_gid_reachable(struct ibv_context *context,
@@ -710,17 +741,16 @@
 +
 +	rc = write(context->cmd_fd, cmd, sizeof(struct ibv_gid_reachable));
 +	if (rc < 0) {
-+		errno = -rc;
-+		rc = -1;
++		return (-1);
 +	}
 +
-+	return (rc);
++	return (0);
 +}
 +
  struct ibv_pd *__ibv_alloc_pd(struct ibv_context *context)
  {
  	struct ibv_pd *pd;
[email protected]@ -148,6 +299,27 @@
[email protected]@ -148,6 +326,27 @@
  }
  default_symver(__ibv_alloc_pd, ibv_alloc_pd);
  
@@ -748,7 +778,7 @@
  int __ibv_dealloc_pd(struct ibv_pd *pd)
  {
  	return pd->context->ops.dealloc_pd(pd);
[email protected]@ -175,6 +347,27 @@
[email protected]@ -175,6 +374,27 @@
  }
  default_symver(__ibv_reg_mr, ibv_reg_mr);
  
@@ -776,7 +806,7 @@
  int __ibv_dereg_mr(struct ibv_mr *mr)
  {
  	int ret;
[email protected]@ -189,6 +382,26 @@
[email protected]@ -189,6 +409,26 @@
  }
  default_symver(__ibv_dereg_mr, ibv_dereg_mr);
  
@@ -803,7 +833,7 @@
  static struct ibv_comp_channel *ibv_create_comp_channel_v2(struct ibv_context *context)
  {
  	struct ibv_abi_compat_v2 *t = context->abi_compat;
[email protected]@ -212,6 +425,10 @@
[email protected]@ -212,6 +452,10 @@
  	struct ibv_comp_channel            *channel;
  	struct ibv_create_comp_channel      cmd;
  	struct ibv_create_comp_channel_resp resp;
@@ -814,7 +844,7 @@
  
  	if (abi_ver <= 2)
  		return ibv_create_comp_channel_v2(context);
[email protected]@ -221,7 +438,23 @@
[email protected]@ -221,7 +465,23 @@
  		return NULL;
  
  	IBV_INIT_CMD_RESP(&cmd, sizeof cmd, CREATE_COMP_CHANNEL, &resp, sizeof resp);
@@ -838,7 +868,7 @@
  		free(channel);
  		return NULL;
  	}
[email protected]@ -228,6 +461,9 @@
[email protected]@ -228,6 +488,9 @@
  
  	VALGRIND_MAKE_MEM_DEFINED(&resp, sizeof resp);