SHA256
1
0
forked from pool/dapl
dapl/dapl-fix_type_punning.patch

300 lines
12 KiB
Diff

---
dapl/openib_scm/cm.c | 38 ++++++++++++++++++++++++--------------
dapl/openib_ucm/cm.c | 29 +++++++++++++++++++++--------
dapl/openib_ucm/device.c | 8 ++++----
test/dapltest/test/dapl_limit.c | 11 +++++++----
4 files changed, 56 insertions(+), 30 deletions(-)
Index: dapl/openib_scm/cm.c
===================================================================
--- dapl/openib_scm/cm.c.orig 2014-04-07 19:27:35.000000000 +0200
+++ dapl/openib_scm/cm.c 2014-06-27 14:10:00.894759920 +0200
@@ -518,6 +518,7 @@ static void dapli_socket_connected(dp_ib
int len, exp;
struct iovec iov[2];
struct dapl_ep *ep_ptr = cm_ptr->ep;
+ uint64_t tmp, tmp2;
if (err) {
dapl_log(DAPL_DBG_TYPE_CM_WARN,
@@ -582,12 +583,12 @@ static void dapli_socket_connected(dp_ib
ntohs(cm_ptr->msg.saddr.ib.lid),
ntohl(cm_ptr->msg.saddr.ib.qpn),
ntohs(cm_ptr->msg.p_size));
+ memcpy(&tmp, &cm_ptr->msg.saddr.ib.gid[0], sizeof(uint64_t));
+ memcpy(&tmp2, &cm_ptr->msg.saddr.ib.gid[8], sizeof(uint64_t));
dapl_dbg_log(DAPL_DBG_TYPE_CM,
" CONN_PENDING: SRC GID subnet %016llx id %016llx\n",
- (unsigned long long)
- htonll(*(uint64_t*)&cm_ptr->msg.saddr.ib.gid[0]),
- (unsigned long long)
- htonll(*(uint64_t*)&cm_ptr->msg.saddr.ib.gid[8]));
+ (unsigned long long) htonll(tmp),
+ (unsigned long long) htonll(tmp2));
DAPL_CNTR(((DAPL_IA *)dapl_llist_peek_head(&cm_ptr->hca->ia_list_head)), DCNT_IA_CM_REQ_TX);
return;
@@ -614,6 +615,9 @@ dapli_socket_connect(DAPL_EP * ep_ptr,
socklen_t sl;
DAPL_IA *ia_ptr = ep_ptr->header.owner_ia;
DAT_RETURN dat_ret = DAT_INSUFFICIENT_RESOURCES;
+#ifdef DAPL_DBG
+ union{ uint8_t *u8p; uint16_t *u16p; }pun;
+#endif
dapl_dbg_log(DAPL_DBG_TYPE_EP, " connect: r_qual %d p_size=%d\n",
r_qual, p_size);
@@ -649,8 +653,10 @@ dapli_socket_connect(DAPL_EP * ep_ptr,
#ifdef DAPL_DBG
/* DBG: Active PID [0], PASSIVE PID [2]*/
- *(uint16_t*)&cm_ptr->msg.resv[0] = htons((uint16_t)dapl_os_getpid());
- *(uint16_t*)&cm_ptr->msg.resv[2] = ((struct sockaddr_in *)&cm_ptr->addr)->sin_port;
+ pun.u8p = &cm_ptr->msg.resv[0];
+ *pun.u16p = htons((uint16_t)dapl_os_getpid());
+ pun.u8p += 2;
+ *pun.u16p = ((struct sockaddr_in *)&cm_ptr->addr)->sin_port;
#endif
((struct sockaddr_in *)&cm_ptr->addr)->sin_port = htons(r_qual + 1000);
ret = dapl_connect_socket(cm_ptr->socket, (struct sockaddr *)&cm_ptr->addr,
@@ -736,6 +742,8 @@ static void dapli_socket_connect_rtu(dp_
len = recv(cm_ptr->socket, (char *)&cm_ptr->msg, exp, 0);
if (len != exp || ntohs(cm_ptr->msg.ver) < DCM_VER_MIN) {
int err = dapl_socket_errno();
+ union{ uint8_t *ui8p; uint16_t *ui16p; }pun = { &cm_ptr->msg.resv[0] };
+ union{ uint8_t *ui8p; uint16_t *ui16p; }pun2 = { &cm_ptr->msg.resv[2] };
dapl_log(DAPL_DBG_TYPE_CM_WARN,
" CONN_REP_PENDING: sk %d ERR 0x%x, rcnt=%d, v=%d ->"
" %s PORT L-%x R-%x PID L-%x R-%x %d\n",
@@ -743,8 +751,8 @@ static void dapli_socket_connect_rtu(dp_
inet_ntoa(((struct sockaddr_in *)&cm_ptr->addr)->sin_addr),
ntohs(((struct sockaddr_in *)&cm_ptr->msg.daddr.so)->sin_port),
ntohs(((struct sockaddr_in *)&cm_ptr->addr)->sin_port),
- ntohs(*(uint16_t*)&cm_ptr->msg.resv[0]),
- ntohs(*(uint16_t*)&cm_ptr->msg.resv[2]),cm_ptr->retry);
+ ntohs(*pun.ui16p), ntohs(*pun2.ui16p),
+ cm_ptr->retry);
/* Retry; corner case where server tcp stack resets under load */
if (err == ECONNRESET && --cm_ptr->retry) {
@@ -1215,7 +1223,11 @@ dapli_socket_accept_usr(DAPL_EP * ep_ptr
int len, exp = sizeof(ib_cm_msg_t) - DCM_MAX_PDATA_SIZE;
DAT_RETURN ret = DAT_INTERNAL_ERROR;
socklen_t sl;
-
+ union{ uint8_t *u8p; uint64_t *u64p; }pun = { &local.saddr.ib.gid[0] };
+ union{ uint8_t *u8p; uint64_t *u64p; }pun2 = { &local.saddr.ib.gid[8] };
+#ifdef DAPL_DBG
+ union{ uint8_t *u8p; uint16_t *u16p; }pun3 = { &cm_ptr->msg.resv[2] };
+#endif
if (p_size > DCM_MAX_PDATA_SIZE) {
dapl_log(DAPL_DBG_TYPE_ERR,
" accept_usr: psize(%d) too large\n", p_size);
@@ -1304,7 +1316,7 @@ dapli_socket_accept_usr(DAPL_EP * ep_ptr
#ifdef DAPL_DBG
/* DBG: Active PID [0], PASSIVE PID [2] */
- *(uint16_t*)&cm_ptr->msg.resv[2] = htons((uint16_t)dapl_os_getpid());
+ *pun3.u16p = htons((uint16_t)dapl_os_getpid());
dapl_os_memcpy(local.resv, cm_ptr->msg.resv, 4);
#endif
cm_ptr->hca = ia_ptr->hca_ptr;
@@ -1346,10 +1358,8 @@ dapli_socket_accept_usr(DAPL_EP * ep_ptr
ntohl(local.saddr.ib.qpn), ntohs(local.p_size));
dapl_dbg_log(DAPL_DBG_TYPE_CM,
" ACCEPT_USR: local GID subnet %016llx id %016llx\n",
- (unsigned long long)
- htonll(*(uint64_t*)&local.saddr.ib.gid[0]),
- (unsigned long long)
- htonll(*(uint64_t*)&local.saddr.ib.gid[8]));
+ (unsigned long long) htonll(*pun.u64p),
+ (unsigned long long) htonll(*pun2.u64p));
dapl_dbg_log(DAPL_DBG_TYPE_EP, " PASSIVE: accepted!\n");
Index: dapl/openib_ucm/cm.c
===================================================================
--- dapl/openib_ucm/cm.c.orig 2014-04-07 19:27:35.000000000 +0200
+++ dapl/openib_ucm/cm.c 2014-06-27 13:44:42.207746121 +0200
@@ -154,6 +154,7 @@ static void ucm_free_port(ib_hca_transpo
static void ucm_check_timers(dp_ib_cm_handle_t cm, int *timer)
{
DAPL_OS_TIMEVAL time;
+ union{ uint8_t *ui8p; DAT_UINT32 *duip; }pun = { &cm->msg.resv[0] };
dapl_os_lock(&cm->lock);
dapl_os_get_time(&time);
@@ -716,12 +717,15 @@ void dapls_cm_release(dp_ib_cm_handle_t
dp_ib_cm_handle_t dapls_ib_cm_create(DAPL_EP *ep)
{
dp_ib_cm_handle_t cm;
+ union{ uint8_t *ui8p; DAT_UINT32 *duip; }pun;
/* Allocate CM, init lock, and initialize */
if ((cm = dapl_os_alloc(sizeof(*cm))) == NULL)
return NULL;
(void)dapl_os_memzero(cm, sizeof(*cm));
+ pun.ui8p = &cm->msg.resv[0];
+
if (dapl_os_lock_init(&cm->lock))
goto bail;
@@ -903,6 +907,8 @@ DAT_RETURN dapli_cm_disconnect(dp_ib_cm_
{
int finalize = 1;
int wakeup = 0;
+ union{ uint8_t *ui8p; DAT_UINT32 *duip; }pun = { &cm->msg.resv[0] };
+
dapl_os_lock(&cm->lock);
switch (cm->state) {
@@ -1062,6 +1068,11 @@ bail:
*/
static void ucm_connect_rtu(dp_ib_cm_handle_t cm, ib_cm_msg_t *msg)
{
+#ifdef DAT_EXTENSIONS
+ union{ uint8_t *u8p; uint64_t *u64p; }pun = { &cm->msg.daddr.ib.gid[0] };
+ union{ uint8_t *u8p; uint64_t *u64p; }pun2 = { &cm->msg.daddr.ib.gid[8] };
+#endif
+
DAPL_EP *ep = cm->ep;
ib_cm_events_t event = IB_CME_CONNECTED;
@@ -1246,8 +1257,7 @@ ud_bail:
&xevent.remote_ah.ia_addr)->ib.lid),
ntohl(((union dcm_addr*)
&xevent.remote_ah.ia_addr)->ib.qpn),
- ntohll(*(uint64_t*)&cm->msg.daddr.ib.gid[0]),
- ntohll(*(uint64_t*)&cm->msg.daddr.ib.gid[8]));
+ ntohll(*pun.u64p), ntohll(*pun2.u64p));
if (event == IB_CME_CONNECTED)
event = DAT_IB_UD_CONNECTION_EVENT_ESTABLISHED;
@@ -1375,6 +1385,10 @@ bail:
*/
static void ucm_accept_rtu(dp_ib_cm_handle_t cm, ib_cm_msg_t *msg)
{
+#ifdef DAT_EXTENSIONS
+ union{ uint8_t *u8p; uint64_t *u64p; }pun = { &cm->msg.daddr.ib.gid[0] };
+ union{ uint8_t *u8p; uint64_t *u64p; }pun2 = { &cm->msg.daddr.ib.gid[8] };
+#endif
dapl_os_lock(&cm->lock);
if ((ntohs(msg->op) != DCM_RTU) || (cm->state != DCM_RTU_PENDING)) {
dapl_log(DAPL_DBG_TYPE_WARN,
@@ -1435,8 +1449,7 @@ static void ucm_accept_rtu(dp_ib_cm_hand
&xevent.remote_ah.ia_addr)->ib.lid),
ntohl(((union dcm_addr*)
&xevent.remote_ah.ia_addr)->ib.qpn),
- ntohll(*(uint64_t*)&cm->msg.daddr.ib.gid[0]),
- ntohll(*(uint64_t*)&cm->msg.daddr.ib.gid[8]));
+ ntohll(*pun.u64p), ntohll(*pun2.u64p));
dapls_evd_post_connection_event_ext(
(DAPL_EVD *)cm->ep->param.connect_evd_handle,
@@ -1552,6 +1565,8 @@ dapli_accept_usr(DAPL_EP *ep, DAPL_CR *c
{
DAPL_IA *ia = ep->header.owner_ia;
dp_ib_cm_handle_t cm = cr->ib_cm_handle;
+ union{ uint8_t *u8p; uint64_t *u64p; }pun = { &cm->msg.daddr.ib.gid[0] };
+ union{ uint8_t *u8p; uint64_t *u64p; }pun2 = { &cm->msg.daddr.ib.gid[8] };
if (p_size > DCM_MAX_PDATA_SIZE)
return DAT_LENGTH_ERROR;
@@ -1585,10 +1600,8 @@ dapli_accept_usr(DAPL_EP *ep, DAPL_CR *c
dapl_dbg_log(DAPL_DBG_TYPE_CM,
" ACCEPT_USR: remote GID subnet %016llx id %016llx\n",
- (unsigned long long)
- htonll(*(uint64_t*)&cm->msg.daddr.ib.gid[0]),
- (unsigned long long)
- htonll(*(uint64_t*)&cm->msg.daddr.ib.gid[8]));
+ (unsigned long long) htonll(*pun.u64p),
+ (unsigned long long) htonll(*pun2.u64p));
#ifdef DAT_EXTENSIONS
if (cm->msg.daddr.ib.qp_type == IBV_QPT_UD &&
Index: dapl/openib_ucm/device.c
===================================================================
--- dapl/openib_ucm/device.c.orig 2014-04-07 19:27:35.000000000 +0200
+++ dapl/openib_ucm/device.c 2014-06-27 13:44:42.207746121 +0200
@@ -197,6 +197,8 @@ DAT_RETURN dapls_ib_open_hca(IN IB_HCA_N
struct ibv_port_attr port_attr;
int i;
DAT_RETURN dat_status;
+ union{ uint8_t *u8p; uint64_t *u64p; }pun = { &hca_ptr->ib_trans.addr.ib.gid[0] };
+ union{ uint8_t *u8p; uint64_t *u64p; }pun2 = { &hca_ptr->ib_trans.addr.ib.gid[8] };
/* Get list of all IB devices, find match, open */
dev_list = ibv_get_device_list(NULL);
@@ -337,10 +339,8 @@ found:
" ID 0x" F64x "\n",
ntohl(hca_ptr->ib_trans.addr.ib.qpn),
ntohs(hca_ptr->ib_trans.addr.ib.lid),
- (unsigned long long)
- ntohll(*(uint64_t*)&hca_ptr->ib_trans.addr.ib.gid[0]),
- (unsigned long long)
- ntohll(*(uint64_t*)&hca_ptr->ib_trans.addr.ib.gid[8]));
+ (unsigned long long) ntohll(*pun.u64p),
+ (unsigned long long) ntohll(*pun2.u64p));
/* save LID, GID, QPN, PORT address information, for ia_queries */
/* Set AF_INET6 to insure callee address storage of 28 bytes */
Index: test/dapltest/test/dapl_limit.c
===================================================================
--- test/dapltest/test/dapl_limit.c.orig 2014-05-05 18:11:33.000000000 +0200
+++ test/dapltest/test/dapl_limit.c 2014-06-27 13:44:42.208746108 +0200
@@ -162,6 +162,7 @@ limit_test(DT_Tdep_Print_Head * phead, L
unsigned int count = START_COUNT;
OneOpen *hdlptr = (OneOpen *)
DT_Mdep_Malloc(count * sizeof(*hdlptr));
+ union { OneOpen **oop; DAT_HANDLE **dhpp; }pun = { &hdlptr };
/* IA Exhaustion test loop */
if (hdlptr) {
@@ -175,7 +176,7 @@ limit_test(DT_Tdep_Print_Head * phead, L
DT_Mdep_Schedule();
if (w == count
&& !more_handles(phead,
- (DAT_HANDLE **) & hdlptr,
+ pun.dhpp,
&count, sizeof(*hdlptr))) {
DT_Tdep_PT_Printf(phead,
"%s: IAs opened: %d\n",
@@ -947,6 +948,7 @@ limit_test(DT_Tdep_Print_Head * phead, L
unsigned int count = START_COUNT;
Bpool **hdlptr = (Bpool **)
DT_Mdep_Malloc(count * sizeof(*hdlptr));
+ union { Bpool ***bpppp; DAT_HANDLE **dhpp; }pun = { &hdlptr };
/* LMR Exhaustion test loop */
if (hdlptr) {
@@ -961,7 +963,7 @@ limit_test(DT_Tdep_Print_Head * phead, L
DT_Mdep_Schedule();
if (w == count
&& !more_handles(phead,
- (DAT_HANDLE **) & hdlptr,
+ pun.dhpp,
&count, sizeof(*hdlptr))) {
DT_Tdep_PT_Printf(phead,
"%s: no memory for LMR handles\n",
@@ -1035,6 +1037,8 @@ limit_test(DT_Tdep_Print_Head * phead, L
unsigned int count = START_COUNT;
DAT_LMR_TRIPLET *hdlptr = (DAT_LMR_TRIPLET *)
DT_Mdep_Malloc(count * cmd->width * sizeof(*hdlptr));
+ union { DAT_LMR_TRIPLET **dltp; DAT_HANDLE **dhpp; }pun =
+ { &hdlptr };
/* Recv-Post Exhaustion test loop */
if (hdlptr) {
@@ -1049,8 +1053,7 @@ limit_test(DT_Tdep_Print_Head * phead, L
for (w = 0; w < cmd->maximum && !done; w++) {
DT_Mdep_Schedule();
if (w == count
- && !more_handles(phead,
- (DAT_HANDLE **) & hdlptr,
+ && !more_handles(phead, pun.dhpp,
&count,
cmd->width *
sizeof(*hdlptr))) {