Skip to content

Commit e2b3dcf

Browse files
committed
perftest: Fix seg-fault during clean-up for cm retry flow
Signed-off-by: Ruizhe Zhou <zhouruizhe@resnics.com>
1 parent 4ae6564 commit e2b3dcf

1 file changed

Lines changed: 40 additions & 13 deletions

File tree

src/perftest_resources.c

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,15 +1481,21 @@ int destroy_ctx(struct pingpong_context *ctx,
14811481
(user_param->tst == LAT || user_param->machine == CLIENT || user_param->duplex)) ||
14821482
(user_param->connection_type == SRD && (user_param->verb == READ || user_param->verb == WRITE || user_param->verb == WRITE_IMM))) {
14831483

1484-
if (user_param->ah_allocated == 1 && ctx->ah && ctx->ah[i] && ibv_destroy_ah(ctx->ah[i])) {
1485-
fprintf(stderr, "Failed to destroy AH\n");
1486-
test_result = 1;
1484+
if (user_param->ah_allocated == 1 && ctx->ah && ctx->ah[i]) {
1485+
if (ibv_destroy_ah(ctx->ah[i])) {
1486+
fprintf(stderr, "Failed to destroy AH\n");
1487+
test_result = 1;
1488+
}
1489+
ctx->ah[i] = NULL;
14871490
}
14881491
}
14891492
if (user_param->work_rdma_cm == OFF) {
1490-
if (ctx->qp && ctx->qp[i] && ibv_destroy_qp(ctx->qp[i])) {
1491-
fprintf(stderr, "Couldn't destroy QP - %s\n", strerror(errno));
1492-
test_result = 1;
1493+
if (ctx->qp && ctx->qp[i]) {
1494+
if (ibv_destroy_qp(ctx->qp[i])) {
1495+
fprintf(stderr, "Couldn't destroy QP - %s\n", strerror(errno));
1496+
test_result = 1;
1497+
}
1498+
ctx->qp[i] = NULL;
14931499
}
14941500
}
14951501
}
@@ -1621,30 +1627,35 @@ int destroy_ctx(struct pingpong_context *ctx,
16211627
}
16221628

16231629
if (user_param->use_rdma_cm == OFF) {
1624-
16251630
if (ibv_close_device(ctx->context)) {
16261631
fprintf(stderr, "Failed to close device context\n");
16271632
test_result = 1;
16281633
}
16291634
}
16301635

16311636
free(ctx->qp);
1637+
ctx->qp = NULL;
1638+
16321639
#ifdef HAVE_IBV_WR_API
16331640
free(ctx->qpx);
1641+
ctx->qpx = NULL;
16341642
free(ctx->r_dctn);
1643+
ctx->r_dctn = NULL;
16351644
#ifdef HAVE_DCS
16361645
free(ctx->dci_stream_id);
1646+
ctx->dci_stream_id = NULL;
16371647
#endif
16381648
#endif
16391649
#ifdef HAVE_AES_XTS
16401650
if(user_param->aes_xts) {
16411651
free(ctx->dek);
1652+
ctx->dek = NULL;
16421653
free(ctx->mkey);
1654+
ctx->mkey = NULL;
16431655
}
16441656
#endif
16451657

16461658
if ((user_param->tst == BW || user_param->tst == LAT_BY_BW ) && (user_param->machine == CLIENT || user_param->duplex)) {
1647-
16481659
free(user_param->tposted);
16491660
free(user_param->tcompleted);
16501661
free(ctx->my_addr);
@@ -1678,6 +1689,9 @@ int destroy_ctx(struct pingpong_context *ctx,
16781689
}
16791690

16801691
if (user_param->work_rdma_cm == ON) {
1692+
for (i = 0; i < user_param->num_of_qps; i++) {
1693+
ctx->cma_master.nodes[i].connected = 0;
1694+
}
16811695
rdma_cm_destroy_cma(ctx, user_param);
16821696
rdma_cm_destroy_master(ctx);
16831697
}
@@ -6897,9 +6911,12 @@ void rdma_cm_destroy_qps(struct pingpong_context *ctx,
68976911

68986912
for (i = 0; i < user_param->num_of_qps; i++) {
68996913
struct cma_node *cm_node = &ctx->cma_master.nodes[i];
6900-
if (cm_node->cma_id->qp) {
6914+
if (cm_node->cma_id && cm_node->cma_id->qp) {
69016915
rdma_destroy_qp(cm_node->cma_id);
69026916
}
6917+
if (ctx->qp && ctx->qp[i]) {
6918+
ctx->qp[i] = NULL;
6919+
}
69036920
}
69046921
}
69056922

@@ -6920,11 +6937,24 @@ int rdma_cm_destroy_cma(struct pingpong_context *ctx,
69206937
if (cm_node->connected) {
69216938
continue;
69226939
}
6940+
if (ctx->qp && ctx->qp[i]) {
6941+
if (cm_node->cma_id->qp) {
6942+
rdma_destroy_qp(cm_node->cma_id);
6943+
} else {
6944+
ibv_destroy_qp(ctx->qp[i]);
6945+
}
6946+
ctx->qp[i] = NULL;
6947+
}
6948+
if (user_param->ah_allocated && ctx->ah && ctx->ah[i]) {
6949+
ibv_destroy_ah(ctx->ah[i]);
6950+
ctx->ah[i] = NULL;
6951+
}
6952+
69236953
rc = rdma_destroy_id(cm_node->cma_id);
69246954
if (rc) {
69256955
sprintf(error_message,
69266956
"Failed to destroy RDMA CM ID number %d.", i);
6927-
goto error;
6957+
return error_handler(error_message);
69286958
}
69296959
cm_node->cma_id = NULL;
69306960
}
@@ -6938,9 +6968,6 @@ int rdma_cm_destroy_cma(struct pingpong_context *ctx,
69386968
}
69396969
ctx->cma_master.connects_left = user_param->num_of_qps - connected_count;
69406970
return rc;
6941-
6942-
error:
6943-
return error_handler(error_message);
69446971
}
69456972

69466973
int error_handler(char *error_message)

0 commit comments

Comments
 (0)