Commit 74a25e6e authored by Zhengchao Shao's avatar Zhengchao Shao Committed by Eric Van Hensbergen

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/20230104020424.611926-1-shaozhengchao@huawei.com
Fixes: fc79d4b1 ("9p: rdma: RDMA Transport Support for 9P")
Signed-off-by: default avatarZhengchao Shao <shaozhengchao@huawei.com>
Reviewed-by: default avatarLeon Romanovsky <leonro@nvidia.com>
Signed-off-by: default avatarDominique Martinet <asmadeus@codewreck.org>
Signed-off-by: default avatarEric Van Hensbergen <ericvh@kernel.org>
parent c15fe55d
...@@ -385,6 +385,7 @@ post_recv(struct p9_client *client, struct p9_rdma_context *c) ...@@ -385,6 +385,7 @@ post_recv(struct p9_client *client, struct p9_rdma_context *c)
struct p9_trans_rdma *rdma = client->trans; struct p9_trans_rdma *rdma = client->trans;
struct ib_recv_wr wr; struct ib_recv_wr wr;
struct ib_sge sge; struct ib_sge sge;
int ret;
c->busa = ib_dma_map_single(rdma->cm_id->device, c->busa = ib_dma_map_single(rdma->cm_id->device,
c->rc.sdata, client->msize, c->rc.sdata, client->msize,
...@@ -402,7 +403,12 @@ post_recv(struct p9_client *client, struct p9_rdma_context *c) ...@@ -402,7 +403,12 @@ post_recv(struct p9_client *client, struct p9_rdma_context *c)
wr.wr_cqe = &c->cqe; wr.wr_cqe = &c->cqe;
wr.sg_list = &sge; wr.sg_list = &sge;
wr.num_sge = 1; wr.num_sge = 1;
return ib_post_recv(rdma->qp, &wr, NULL);
ret = ib_post_recv(rdma->qp, &wr, NULL);
if (ret)
ib_dma_unmap_single(rdma->cm_id->device, c->busa,
client->msize, DMA_FROM_DEVICE);
return ret;
error: error:
p9_debug(P9_DEBUG_ERROR, "EIO\n"); p9_debug(P9_DEBUG_ERROR, "EIO\n");
...@@ -499,7 +505,7 @@ static int rdma_request(struct p9_client *client, struct p9_req_t *req) ...@@ -499,7 +505,7 @@ static int rdma_request(struct p9_client *client, struct p9_req_t *req)
if (down_interruptible(&rdma->sq_sem)) { if (down_interruptible(&rdma->sq_sem)) {
err = -EINTR; err = -EINTR;
goto send_error; goto dma_unmap;
} }
/* Mark request as `sent' *before* we actually send it, /* 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) ...@@ -509,11 +515,14 @@ static int rdma_request(struct p9_client *client, struct p9_req_t *req)
WRITE_ONCE(req->status, REQ_STATUS_SENT); WRITE_ONCE(req->status, REQ_STATUS_SENT);
err = ib_post_send(rdma->qp, &wr, NULL); err = ib_post_send(rdma->qp, &wr, NULL);
if (err) if (err)
goto send_error; goto dma_unmap;
/* Success */ /* Success */
return 0; return 0;
dma_unmap:
ib_dma_unmap_single(rdma->cm_id->device, c->busa,
c->req->tc.size, DMA_TO_DEVICE);
/* Handle errors that happened during or while preparing the send: */ /* Handle errors that happened during or while preparing the send: */
send_error: send_error:
WRITE_ONCE(req->status, REQ_STATUS_ERROR); WRITE_ONCE(req->status, REQ_STATUS_ERROR);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment