Skip to contentSkip to conversation

RDMA/erdma: Add verbs implementation

bug report Dan Carpenter 2 participants 3 messages Jun 8, 2022 – Jun 9, 2022 InfiniBand

lore
Share & tools
lore
#0 lore raw

Hello Cheng Xu,

The patch c4612e83c14b: "RDMA/erdma: Add verbs implementation" from May 23, 2022, leads to the following Smatch static checker warning:

drivers/infiniband/hw/erdma/erdma_verbs.c:111 create_qp_cmd()
error: uninitialized symbol 'resp0'.

drivers/infiniband/hw/erdma/erdma_verbs.c

    100                 req.sq_buf_addr = user_qp->sq_mtt.mtt_entry[0];
    101                 req.rq_buf_addr = user_qp->rq_mtt.mtt_entry[0];
    102 
    103                 req.sq_db_info_dma_addr = user_qp->sq_db_info_dma_addr;
    104                 req.rq_db_info_dma_addr = user_qp->rq_db_info_dma_addr;
    105         }
    106 
    107         err = erdma_post_cmd_wait(&dev->cmdq, (u64 *)&req, sizeof(req), &resp0,
    108                                   &resp1);

The erdma_post_cmd_wait() function does not initialize erdma_post_cmd_wait() on the error paths.

Also it returns comp_wait->comp_status which is a u8. I guess that's some kind of custom error code. Mixing kernel and custom error codes is dangerous. I think it's a bug in this case.

    109 
    110         qp->attrs.cookie =
--> 111                 FIELD_GET(ERDMA_CMDQ_CREATE_QP_RESP_COOKIE_MASK, resp0);
    112 
    113         return err;
    114 }

regards,
dan carpenter

#1 lore raw
Quoted 19 lines · Dan Carpenter

Hello Cheng Xu,

The patch c4612e83c14b: "RDMA/erdma: Add verbs implementation" from May 23, 2022, leads to the following Smatch static checker warning:

drivers/infiniband/hw/erdma/erdma_verbs.c:111 create_qp_cmd()
error: uninitialized symbol 'resp0'.

drivers/infiniband/hw/erdma/erdma_verbs.c

     100                 req.sq_buf_addr = user_qp->sq_mtt.mtt_entry[0];
     101                 req.rq_buf_addr = user_qp->rq_mtt.mtt_entry[0];
     102
     103                 req.sq_db_info_dma_addr = user_qp->sq_db_info_dma_addr;
     104                 req.rq_db_info_dma_addr = user_qp->rq_db_info_dma_addr;
     105         }
     106
     107         err = erdma_post_cmd_wait(&dev->cmdq, (u64 *)&req, sizeof(req), &resp0,
     108                                   &resp1);
Quoted 2 lines

The erdma_post_cmd_wait() function does not initialize erdma_post_cmd_wait() on the error paths.

Oh, I knew this before: since erdma_post_cmd_wait returns error, the qp 's resource will destroy soon, the uninitialized value of resp0 will influence nothing. So here I reduce a condition judgement.

Anyway, I will fix it to eliminate the static checker warning.

Quoted 4 lines

Also it returns comp_wait->comp_status which is a u8. I guess that's some kind of custom error code. Mixing kernel and custom error codes is dangerous. I think it's a bug in this case.

I will fix it in the next version of our patches.

Thanks,
Cheng Xu

#2 lore raw
Quoted 22 lines · Cheng Xu
Quoted 19 lines · Dan Carpenter

Hello Cheng Xu,

The patch c4612e83c14b: "RDMA/erdma: Add verbs implementation" from May 23, 2022, leads to the following Smatch static checker warning:

drivers/infiniband/hw/erdma/erdma_verbs.c:111 create_qp_cmd()
error: uninitialized symbol 'resp0'.

drivers/infiniband/hw/erdma/erdma_verbs.c

     100                 req.sq_buf_addr = user_qp->sq_mtt.mtt_entry[0];
     101                 req.rq_buf_addr = user_qp->rq_mtt.mtt_entry[0];
     102
     103                 req.sq_db_info_dma_addr = user_qp->sq_db_info_dma_addr;
     104                 req.rq_db_info_dma_addr = user_qp->rq_db_info_dma_addr;
     105         }
     106
     107         err = erdma_post_cmd_wait(&dev->cmdq, (u64 *)&req, sizeof(req), &resp0,
     108                                   &resp1);
Quoted 8 lines
Quoted 2 lines

The erdma_post_cmd_wait() function does not initialize erdma_post_cmd_wait() on the error paths.

Oh, I knew this before: since erdma_post_cmd_wait returns error, the qp 's resource will destroy soon, the uninitialized value of resp0 will influence nothing. So here I reduce a condition judgement.

Anyway, I will fix it to eliminate the static checker warning.

Thanks!

I am pretty sure it will trigger a KMEMsan warning at runtime once someone upgrae sysbot to test RDMA.

Another idea would be to initialize resp0 at the top of the function. Soon the compiler will start initializing to zero anyway so doing it manually is a zero cost approach.

regards,
dan carpenter