Skip to content

Commit 74a25e6

Browse files
zhengchaoshaoericvh
authored andcommitted
9p/rdma: unmap receive dma buffer in rdma_request()/post_recv()
When down_interruptible() or ib_post_send() failed in rdma_request(), receive dma buffer is not unmapped. Add unmap action to error path. Also if ib_post_recv() failed in post_recv(), dma buffer is not unmapped. Add unmap action to error path. Link: https://lkml.kernel.org/r/[email protected] Fixes: fc79d4b ("9p: rdma: RDMA Transport Support for 9P") Signed-off-by: Zhengchao Shao <[email protected]> Reviewed-by: Leon Romanovsky <[email protected]> Signed-off-by: Dominique Martinet <[email protected]> Signed-off-by: Eric Van Hensbergen <[email protected]>
1 parent c15fe55 commit 74a25e6

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

net/9p/trans_rdma.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ post_recv(struct p9_client *client, struct p9_rdma_context *c)
385385
struct p9_trans_rdma *rdma = client->trans;
386386
struct ib_recv_wr wr;
387387
struct ib_sge sge;
388+
int ret;
388389

389390
c->busa = ib_dma_map_single(rdma->cm_id->device,
390391
c->rc.sdata, client->msize,
@@ -402,7 +403,12 @@ post_recv(struct p9_client *client, struct p9_rdma_context *c)
402403
wr.wr_cqe = &c->cqe;
403404
wr.sg_list = &sge;
404405
wr.num_sge = 1;
405-
return ib_post_recv(rdma->qp, &wr, NULL);
406+
407+
ret = ib_post_recv(rdma->qp, &wr, NULL);
408+
if (ret)
409+
ib_dma_unmap_single(rdma->cm_id->device, c->busa,
410+
client->msize, DMA_FROM_DEVICE);
411+
return ret;
406412

407413
error:
408414
p9_debug(P9_DEBUG_ERROR, "EIO\n");
@@ -499,7 +505,7 @@ static int rdma_request(struct p9_client *client, struct p9_req_t *req)
499505

500506
if (down_interruptible(&rdma->sq_sem)) {
501507
err = -EINTR;
502-
goto send_error;
508+
goto dma_unmap;
503509
}
504510

505511
/* Mark request as `sent' *before* we actually send it,
@@ -509,11 +515,14 @@ static int rdma_request(struct p9_client *client, struct p9_req_t *req)
509515
WRITE_ONCE(req->status, REQ_STATUS_SENT);
510516
err = ib_post_send(rdma->qp, &wr, NULL);
511517
if (err)
512-
goto send_error;
518+
goto dma_unmap;
513519

514520
/* Success */
515521
return 0;
516522

523+
dma_unmap:
524+
ib_dma_unmap_single(rdma->cm_id->device, c->busa,
525+
c->req->tc.size, DMA_TO_DEVICE);
517526
/* Handle errors that happened during or while preparing the send: */
518527
send_error:
519528
WRITE_ONCE(req->status, REQ_STATUS_ERROR);

0 commit comments

Comments
 (0)