Commit dc563e5a authored by Norio Yamaguchi's avatar Norio Yamaguchi Committed by Huiwei Lu
Browse files

Fix invalid access before connection established


Signed-off-by: default avatarHuiwei Lu <huiweilu@mcs.anl.gov>
parent 3093fe70
......@@ -36,6 +36,7 @@ static int maxcon;
static struct ibv_device **ib_devlist;
static struct ibv_context *ib_ctx;
struct ibv_context *MPID_nem_ib_ctx_export; /* for SC13 demo connector */
static struct ibv_port_attr ib_pattr;
static struct ibv_pd *ib_pd;
struct ibv_pd *MPID_nem_ib_pd_export; /* for SC13 demo connector */
struct ibv_cq *MPID_nem_ib_rc_shared_scq;
......@@ -275,6 +276,7 @@ static int MPID_nem_ib_com_device_init()
int dev_num;
char *dev_name;
int i;
int ib_port = 1;
if (ib_initialized == 1) {
dprintf("MPID_nem_ib_com_device_init,already initialized\n");
......@@ -314,6 +316,14 @@ static int MPID_nem_ib_com_device_init()
}
else {
ib_ctx = ibv_open_device(ib_devlist[i]);
if (ib_ctx) {
/* get port attribute */
if (ibv_query_port(ib_ctx, ib_port, &ib_pattr)) {
dprintf("ibv_query_port on port %d failed\n", ib_port);
goto err_exit;
}
}
}
dprintf("MPID_nem_ib_com_device_init,MPID_nem_ib_ctx_export=%p,ib_ctx=%p\n",
MPID_nem_ib_ctx_export, ib_ctx);
......@@ -2282,6 +2292,30 @@ int MPID_nem_ib_com_get_info_conn(int condesc, int key, void *out, uint32_t out_
goto fn_exit;
}
int MPID_nem_ib_com_get_info_pattr(int key, void *out, uint32_t out_len)
{
int ibcom_errno = 0;
switch (key) {
case MPID_NEM_IB_COM_INFOKEY_PATTR_MAX_MSG_SZ:{
#ifdef HAVE_LIBDCFA
uint32_t max_msg_sz = 1073741824; /* ConnectX-3 */
memcpy(out, &max_msg_sz, out_len);
#else
memcpy(out, &ib_pattr.max_msg_sz, out_len);
#endif
break;
}
default:
ibcom_errno = -1;
break;
}
fn_exit:
return ibcom_errno;
fn_fail:
goto fn_exit;
}
int MPID_nem_ib_com_get_info_mr(int condesc, int memid, int key, void *out, int out_len)
{
int ibcom_errno = 0;
......
......@@ -559,6 +559,7 @@ extern int MPID_nem_ib_com_reg_mr(void *addr, long len, struct ibv_mr **mr,
extern int MPID_nem_ib_com_dereg_mr(struct ibv_mr *mr);
extern int MPID_nem_ib_com_get_info_conn(int condesc, int key, void *out, uint32_t out_len);
extern int MPID_nem_ib_com_get_info_pattr(int key, void *out, uint32_t out_len);
extern int MPID_nem_ib_com_get_info_mr(int condesc, int memid, int key, void *out, int out_len);
extern int MPID_nem_ib_com_rdmabuf_occupancy_notify_rate_get(int condesc, int *notify_rate);
......
......@@ -101,8 +101,16 @@ int MPID_nem_ib_lmt_initiate_lmt(struct MPIDI_VC *vc, union MPIDI_CH3_Pkt *rts_p
int post_num;
uint32_t max_msg_sz;
MPID_nem_ib_vc_area *vc_ib = VC_IB(vc);
MPID_nem_ib_com_get_info_conn(vc_ib->sc->fd, MPID_NEM_IB_COM_INFOKEY_PATTR_MAX_MSG_SZ,
&max_msg_sz, sizeof(uint32_t));
if (vc_ib->connection_state == MPID_NEM_IB_CM_ESTABLISHED) {
MPID_nem_ib_com_get_info_conn(vc_ib->sc->fd, MPID_NEM_IB_COM_INFOKEY_PATTR_MAX_MSG_SZ,
&max_msg_sz, sizeof(uint32_t));
}
else {
/* If connection is not established, get max_msg_sz from the global value. */
MPID_nem_ib_com_get_info_pattr(MPID_NEM_IB_COM_INFOKEY_PATTR_MAX_MSG_SZ, &max_msg_sz,
sizeof(uint32_t));
}
/* Type of max_msg_sz is uint32_t. */
post_num = (data_sz + (long) max_msg_sz - 1) / (long) max_msg_sz;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment