Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: fc79d4b104f0 ("9p: rdma: RDMA Transport Support for 9P")
Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
Signed-off-by: Eric Van Hensbergen <ericvh@kernel.org>

authored by

Zhengchao Shao and committed by
Eric Van Hensbergen
74a25e6e c15fe55d

+12 -3
+12 -3
net/9p/trans_rdma.c
··· 385 385 struct p9_trans_rdma *rdma = client->trans; 386 386 struct ib_recv_wr wr; 387 387 struct ib_sge sge; 388 + int ret; 388 389 389 390 c->busa = ib_dma_map_single(rdma->cm_id->device, 390 391 c->rc.sdata, client->msize, ··· 403 402 wr.wr_cqe = &c->cqe; 404 403 wr.sg_list = &sge; 405 404 wr.num_sge = 1; 406 - return ib_post_recv(rdma->qp, &wr, NULL); 405 + 406 + ret = ib_post_recv(rdma->qp, &wr, NULL); 407 + if (ret) 408 + ib_dma_unmap_single(rdma->cm_id->device, c->busa, 409 + client->msize, DMA_FROM_DEVICE); 410 + return ret; 407 411 408 412 error: 409 413 p9_debug(P9_DEBUG_ERROR, "EIO\n"); ··· 505 499 506 500 if (down_interruptible(&rdma->sq_sem)) { 507 501 err = -EINTR; 508 - goto send_error; 502 + goto dma_unmap; 509 503 } 510 504 511 505 /* Mark request as `sent' *before* we actually send it, ··· 515 509 WRITE_ONCE(req->status, REQ_STATUS_SENT); 516 510 err = ib_post_send(rdma->qp, &wr, NULL); 517 511 if (err) 518 - goto send_error; 512 + goto dma_unmap; 519 513 520 514 /* Success */ 521 515 return 0; 522 516 517 + dma_unmap: 518 + ib_dma_unmap_single(rdma->cm_id->device, c->busa, 519 + c->req->tc.size, DMA_TO_DEVICE); 523 520 /* Handle errors that happened during or while preparing the send: */ 524 521 send_error: 525 522 WRITE_ONCE(req->status, REQ_STATUS_ERROR);