Skip to content

Commit 1b9b61a

Browse files
committed
btl/sm: fix crash on put/get to self
This commit fixes an issue that can occur if the sm btl is used to either get or put to self. In this case there is no smsc endpoint since none is needed to access the local addess space. Since the smsc endpoint is NULL the process would SEGV. Signed-off-by: Nathan Hjelm <hjelmn@google.com>
1 parent b3e52f9 commit 1b9b61a

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

opal/mca/btl/sm/btl_sm.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ mca_btl_base_descriptor_t *mca_btl_sm_alloc(struct mca_btl_base_module_t *btl,
157157
*/
158158
int mca_btl_sm_free(struct mca_btl_base_module_t *btl, mca_btl_base_descriptor_t *des);
159159

160+
static inline bool mca_btl_is_self_endpoint(mca_btl_base_endpoint_t *endpoint) {
161+
return endpoint->peer_smp_rank == MCA_BTL_SM_LOCAL_RANK;
162+
}
163+
160164
END_C_DECLS
161165

162166
#endif

opal/mca/btl/sm/btl_sm_get.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* reserved.
55
* Copyright (c) 2018 Research Organization for Information Science
66
* and Technology (RIST). All rights reserved.
7-
* Copyright (c) 2019-2021 Google, Inc. All rights reserved.
7+
* Copyright (c) 2019-2022 Google, Inc. All rights reserved.
88
* Copyright (c) 2020 The University of Tennessee and The University
99
* of Tennessee Research Foundation. All rights
1010
* reserved.
@@ -36,10 +36,14 @@ int mca_btl_sm_get(mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint
3636
int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext,
3737
void *cbdata)
3838
{
39-
int ret = MCA_SMSC_CALL(copy_from, endpoint->smsc_endpoint, local_address,
40-
(void *) (intptr_t) remote_address, size, remote_handle);
41-
if (OPAL_UNLIKELY(OPAL_SUCCESS != ret)) {
42-
return ret;
39+
if (!mca_btl_is_self_endpoint(endpoint)) {
40+
int ret = MCA_SMSC_CALL(copy_from, endpoint->smsc_endpoint, local_address,
41+
(void *) (intptr_t) remote_address, size, remote_handle);
42+
if (OPAL_UNLIKELY(OPAL_SUCCESS != ret)) {
43+
return ret;
44+
}
45+
} else {
46+
memcpy(local_address, (void *)(uintptr_t) remote_address, size);
4347
}
4448

4549
/* always call the callback function */

opal/mca/btl/sm/btl_sm_module.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* and Technology (RIST). All rights reserved.
2020
* Copyright (c) 2018-2019 Triad National Security, LLC. All rights
2121
* reserved.
22-
* Copyright (c) 2020-2021 Google, LLC. All rights reserved.
22+
* Copyright (c) 2020-2022 Google, LLC. All rights reserved.
2323
* Copyright (c) 2021 Nanook Consulting. All rights reserved.
2424
* $COPYRIGHT$
2525
*
@@ -167,7 +167,7 @@ static int init_sm_endpoint(struct mca_btl_base_endpoint_t **ep_out, struct opal
167167

168168
ep->peer_smp_rank = peer_local_rank;
169169

170-
if (peer_local_rank != MCA_BTL_SM_LOCAL_RANK) {
170+
if (!mca_btl_is_self_endpoint(ep)) {
171171
OPAL_MODEX_RECV_IMMEDIATE(rc, &component->super.btl_version, &proc->proc_name,
172172
(void **) &modex, &msg_size);
173173
if (OPAL_SUCCESS != rc) {

opal/mca/btl/sm/btl_sm_put.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* reserved.
55
* Copyright (c) 2014-2018 Research Organization for Information Science
66
* and Technology (RIST). All rights reserved.
7-
* Copyright (c) 2019-2021 Google, Inc. All rights reserved.
7+
* Copyright (c) 2019-2022 Google, Inc. All rights reserved.
88
* Copyright (c) 2020 The University of Tennessee and The University
99
* of Tennessee Research Foundation. All rights
1010
* reserved.
@@ -36,10 +36,14 @@ int mca_btl_sm_put(mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint
3636
int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext,
3737
void *cbdata)
3838
{
39-
int ret = MCA_SMSC_CALL(copy_to, endpoint->smsc_endpoint, local_address,
40-
(void *) (intptr_t) remote_address, size, remote_handle);
41-
if (OPAL_UNLIKELY(OPAL_SUCCESS != ret)) {
42-
return ret;
39+
if (!mca_btl_is_self_endpoint(endpoint)) {
40+
int ret = MCA_SMSC_CALL(copy_to, endpoint->smsc_endpoint, local_address,
41+
(void *) (intptr_t) remote_address, size, remote_handle);
42+
if (OPAL_UNLIKELY(OPAL_SUCCESS != ret)) {
43+
return ret;
44+
}
45+
} else {
46+
memcpy((void *)(uintptr_t) remote_address, local_address, size);
4347
}
4448

4549
/* always call the callback function */

0 commit comments

Comments
 (0)