Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UCT/IB: Fix teardown path on memory handler callback #10171

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
23 changes: 19 additions & 4 deletions src/uct/ib/base/ib_md.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ void *uct_ib_md_mem_handle_thread_func(void *arg)
void UCS_V_UNUSED *start = ctx->address;
int mr_idx = 0;
size_t length = ctx->first_mr_size;
int i;
ucs_status_t status;

while (ctx->length > 0) {
Expand All @@ -304,6 +305,8 @@ void *uct_ib_md_mem_handle_thread_func(void *arg)
if (status != UCS_OK) {
goto err;
}

ctx->mrs[mr_idx] = NULL;
}
ctx->address = UCS_PTR_BYTE_OFFSET(ctx->address, length);
ctx->length -= length;
Expand All @@ -318,9 +321,18 @@ void *uct_ib_md_mem_handle_thread_func(void *arg)
return UCS_STATUS_PTR(UCS_OK);

err_dereg:
for (; mr_idx >= 0; --mr_idx) {
uct_ib_dereg_mr(ctx->mrs[mr_idx]);
for (i = 0; i < mr_idx; i++) {
uct_ib_dereg_mr(ctx->mrs[i]);
ctx->mrs[i] = NULL;
}

while (ctx->length > 0) {
ctx->mrs[mr_idx] = NULL;
tvegas1 marked this conversation as resolved.
Show resolved Hide resolved
ctx->length -= length;
length = ucs_min(ctx->length, chunk_size);
mr_idx++;
}

err:
return UCS_STATUS_PTR(status);
}
Expand Down Expand Up @@ -413,6 +425,7 @@ uct_ib_md_handle_mr_list_mt(uct_ib_md_t *md, void *address, size_t length,
ucs_error("pthread_create() failed: %m");
status = UCS_ERR_IO_ERROR;
thread_num = thread_idx;
mr_num = mr_idx;
break;
}

Expand All @@ -432,8 +445,10 @@ uct_ib_md_handle_mr_list_mt(uct_ib_md_t *md, void *address, size_t length,

if (status != UCS_OK) {
for (mr_idx = 0; mr_idx < mr_num; mr_idx++) {
/* coverity[check_return] */
uct_ib_dereg_mr(mrs[mr_idx]);
if (mrs[mr_idx] != NULL) {
/* coverity[check_return] */
uct_ib_dereg_mr(mrs[mr_idx]);
}
iyastreb marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
Loading