svcrdma: NFSRDMA Server fixes for 2.6.37
Subsystems (4)
cover svcrdma: NFSRDMA Server fixes for 2.6.37
Hi Bruce,
These fixes are ready for 2.6.37. They fix two bugs in the server-side NFSRDMA transport.
Thanks,
Tom
---
Tom Tucker (2):
svcrdma: Cleanup DMA unmapping in error paths.
svcrdma: Change DMA mapping logic to avoid the page_address kernel API
net/sunrpc/xprtrdma/svc_rdma_recvfrom.c | 19 ++++--- net/sunrpc/xprtrdma/svc_rdma_sendto.c | 82 ++++++++++++++++++++++-------- net/sunrpc/xprtrdma/svc_rdma_transport.c | 41 +++++++-------- 3 files changed, 92 insertions(+), 50 deletions(-)
Signature · 5 lines
Signed-off-by: Tom Tucker <tom-/Yg/[email protected]> -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/2 svcrdma: Change DMA mapping logic to avoid the page_address kernel API
There was logic in the send path that assumed that a page containing data to send to the client has a KVA. This is not always the case and can result in data corruption when page_address returns zero and we end up DMA mapping zero.
This patch changes the bus mapping logic to avoid page_address() where necessary and converts all calls from ib_dma_map_single to ib_dma_map_page in order to keep the map/unmap calls symmetric.
---
net/sunrpc/xprtrdma/svc_rdma_recvfrom.c | 18 ++++--- net/sunrpc/xprtrdma/svc_rdma_sendto.c | 80 ++++++++++++++++++++++-------- net/sunrpc/xprtrdma/svc_rdma_transport.c | 18 +++---- 3 files changed, 78 insertions(+), 38 deletions(-)
net/sunrpc/xprtrdma/svc_rdma_recvfrom.c +11 -7
@@ -263,9 +263,9 @@ static int fast_reg_read_chunks(struct svcxprt_rdma *xprt, frmr->page_list_len =PAGE_ALIGN (byte_count) >>PAGE_SHIFT ;for (page_no =0 ; page_no < frmr->page_list_len; page_no++) { frmr->page_list->page_list[page_no] = -ib_dma_map_single (xprt->sc_cm_id->device, -page_address (rqstp->rq_arg.pages[page_no]), -PAGE_SIZE ,DMA_FROM_DEVICE ); +ib_dma_map_page (xprt->sc_cm_id->device, + rqstp->rq_arg.pages[page_no],0 , +PAGE_SIZE ,DMA_FROM_DEVICE );if (ib_dma_mapping_error (xprt->sc_cm_id->device, frmr->page_list->page_list[page_no])) goto fatal_err;
@@ -309,17 +309,21 @@ static int rdma_set_ctxt_sge(struct svcxprt_rdma *xprt, int count) {int i; +unsigned long off; ctxt->count = count; ctxt->direction =DMA_FROM_DEVICE ;for (i =0 ; i < count; i++) { ctxt->sge[i].length =0 ;/* in case map fails */ if (!frmr) { +BUG_ON (0 ==virt_to_page (vec[i].iov_base)); + off = (unsigned long )vec[i].iov_base & ~PAGE_MASK ; ctxt->sge[i].addr = -ib_dma_map_single (xprt->sc_cm_id->device, - vec[i].iov_base, - vec[i].iov_len, -DMA_FROM_DEVICE ); +ib_dma_map_page (xprt->sc_cm_id->device, +virt_to_page (vec[i].iov_base), + off, + vec[i].iov_len, +DMA_FROM_DEVICE );if (ib_dma_mapping_error (xprt->sc_cm_id->device, ctxt->sge[i].addr))return -EINVAL ;
net/sunrpc/xprtrdma/svc_rdma_sendto.c +58 -22
150 lines not on this page · raw message
net/sunrpc/xprtrdma/svc_rdma_transport.c +9 -9
@@ -120,7 +120,7 @@ void svc_rdma_unmap_dma(struct svc_rdma_op_ctxt *ctxt)*/ if (ctxt->sge[i].lkey == xprt->sc_dma_lkey) {atomic_dec (&xprt->sc_dma_used); -ib_dma_unmap_single (xprt->sc_cm_id->device, +ib_dma_unmap_page (xprt->sc_cm_id->device, ctxt->sge[i].addr, ctxt->sge[i].length, ctxt->direction);
@@ -502,8 +502,8 @@ int svc_rdma_post_recv(struct svcxprt_rdma *xprt)BUG_ON (sge_no >= xprt->sc_max_sge); page =svc_rdma_get_page (); ctxt->pages[sge_no] = page; - pa =ib_dma_map_single (xprt->sc_cm_id->device, -page_address (page),PAGE_SIZE , + pa =ib_dma_map_page (xprt->sc_cm_id->device, + page,0 ,PAGE_SIZE ,DMA_FROM_DEVICE );if (ib_dma_mapping_error (xprt->sc_cm_id->device, pa)) goto err_put_ctxt;
@@ -798,8 +798,8 @@ static void frmr_unmap_dma(struct svcxprt_rdma *xprt,if (ib_dma_mapping_error (frmr->mr->device, addr))continue ;atomic_dec (&xprt->sc_dma_used); -ib_dma_unmap_single (frmr->mr->device, addr,PAGE_SIZE , - frmr->direction); +ib_dma_unmap_page (frmr->mr->device, addr,PAGE_SIZE , + frmr->direction); } }
@@ -1274,7 +1274,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)atomic_read (&xprt->sc_sq_count) < xprt->sc_sq_depth);if (test_bit (XPT_CLOSE , &xprt->sc_xprt.xpt_flags)) -return 0 ; +return -ENOTCONN ;continue ; }/* Take a transport ref for each WR posted */
@@ -1320,8 +1320,8 @@ void svc_rdma_send_error(struct svcxprt_rdma *xprt, struct rpcrdma_msg *rmsgp, length =svc_rdma_xdr_encode_error (xprt, rmsgp, err, va);/* Prepare SGE for local address */ - sge.addr =ib_dma_map_single (xprt->sc_cm_id->device, -page_address (p),PAGE_SIZE ,DMA_FROM_DEVICE ); + sge.addr =ib_dma_map_page (xprt->sc_cm_id->device, + p,0 ,PAGE_SIZE ,DMA_FROM_DEVICE );if (ib_dma_mapping_error (xprt->sc_cm_id->device, sge.addr)) {put_page (p);return ;
@@ -1348,7 +1348,7 @@ void svc_rdma_send_error(struct svcxprt_rdma *xprt, struct rpcrdma_msg *rmsgp,if (ret) {dprintk ("svcrdma: Error %d posting send for protocol error\n" , ret); -ib_dma_unmap_single (xprt->sc_cm_id->device, +ib_dma_unmap_page (xprt->sc_cm_id->device, sge.addr,PAGE_SIZE ,DMA_FROM_DEVICE );svc_rdma_put_context (ctxt,1 );
Re: [PATCH 1/2] svcrdma: Change DMA mapping logic to avoid the page_address kernel API
Quoted 1 line · Tom Tucker
This patch changes the bus mapping logic to avoid
page_address()where necessary
Hi Tom,
Does "when necessary" comes to say that invocations of page_address which remained in the code after this patch was applied are safe and no kmap call is needed?
Or.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 1/2] svcrdma: Change DMA mapping logic to avoid the page_address kernel API
Quoted 8 lines · Or Gerlitz
Quoted 1 line · Tom Tucker
This patch changes the bus mapping logic to avoid
page_address()where necessaryHi Tom,
Does "when necessary" comes to say that invocations of
page_addresswhich remained in the code after this patch was applied are safe and no kmap call is needed?
That's the premise. Please let me know if something looks suspicious.
Thanks,
Tom
Quoted 5 lines
Or.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 2/2 svcrdma: Cleanup DMA unmapping in error paths.
In reply to Tom TuckerThere are several error paths in the code that do not unmap DMA. This patch adds calls to svc_rdma_unmap_dma to free these DMA contexts.
---
net/sunrpc/xprtrdma/svc_rdma_recvfrom.c | 1 + net/sunrpc/xprtrdma/svc_rdma_sendto.c | 2 ++ net/sunrpc/xprtrdma/svc_rdma_transport.c | 29 ++++++++++++++--------------- 3 files changed, 17 insertions(+), 15 deletions(-)
net/sunrpc/xprtrdma/svc_rdma_recvfrom.c +1 -0
@@ -495,6 +495,7 @@ next_sge:printk (KERN_ERR "svcrdma: Error %d posting RDMA_READ\n" , err);set_bit (XPT_CLOSE , &xprt->sc_xprt.xpt_flags); +svc_rdma_unmap_dma (ctxt);svc_rdma_put_context (ctxt,0 ); goto out; }
net/sunrpc/xprtrdma/svc_rdma_sendto.c +2 -0
@@ -367,6 +367,8 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp, goto err;return 0 ; err: +svc_rdma_unmap_dma (ctxt); +svc_rdma_put_frmr (xprt, vec->frmr);svc_rdma_put_context (ctxt,0 );/* Fatal error, close transport */ return -EIO ;
net/sunrpc/xprtrdma/svc_rdma_transport.c +14 -15
@@ -511,9 +511,9 @@ int svc_rdma_post_recv(struct svcxprt_rdma *xprt) ctxt->sge[sge_no].addr = pa; ctxt->sge[sge_no].length =PAGE_SIZE ; ctxt->sge[sge_no].lkey = xprt->sc_dma_lkey; + ctxt->count = sge_no +1 ; buflen +=PAGE_SIZE ; } - ctxt->count = sge_no; recv_wr.next =NULL ; recv_wr.sg_list = &ctxt->sge[0 ]; recv_wr.num_sge = ctxt->count;
@@ -529,6 +529,7 @@ int svc_rdma_post_recv(struct svcxprt_rdma *xprt)return ret; err_put_ctxt: +svc_rdma_unmap_dma (ctxt);svc_rdma_put_context (ctxt,1 );return -ENOMEM ; }
@@ -1306,7 +1307,6 @@ void svc_rdma_send_error(struct svcxprt_rdma *xprt, struct rpcrdma_msg *rmsgp, enum rpcrdma_errcode err) {struct ib_send_wr err_wr; -struct ib_sge sge;struct page *p;struct svc_rdma_op_ctxt *ctxt;u32 *va;
@@ -1319,26 +1319,27 @@ void svc_rdma_send_error(struct svcxprt_rdma *xprt, struct rpcrdma_msg *rmsgp,/* XDR encode error */ length =svc_rdma_xdr_encode_error (xprt, rmsgp, err, va); + ctxt =svc_rdma_get_context (xprt); + ctxt->direction =DMA_FROM_DEVICE ; + ctxt->count =1 ; + ctxt->pages[0 ] = p; +/* Prepare SGE for local address */ - sge.addr =ib_dma_map_page (xprt->sc_cm_id->device, - p,0 ,PAGE_SIZE ,DMA_FROM_DEVICE ); -if (ib_dma_mapping_error (xprt->sc_cm_id->device, sge.addr)) { + ctxt->sge[0 ].addr =ib_dma_map_page (xprt->sc_cm_id->device, + p,0 , length,DMA_FROM_DEVICE ); +if (ib_dma_mapping_error (xprt->sc_cm_id->device, ctxt->sge[0 ].addr)) {put_page (p);return ; }atomic_inc (&xprt->sc_dma_used); - sge.lkey = xprt->sc_dma_lkey; - sge.length = length; - - ctxt =svc_rdma_get_context (xprt); - ctxt->count =1 ; - ctxt->pages[0 ] = p; + ctxt->sge[0 ].lkey = xprt->sc_dma_lkey; + ctxt->sge[0 ].length = length;/* Prepare SEND WR */ memset (&err_wr,0 ,sizeof err_wr); ctxt->wr_op =IB_WR_SEND ; err_wr.wr_id = (unsigned long )ctxt; - err_wr.sg_list = &sge; + err_wr.sg_list = ctxt->sge; err_wr.num_sge =1 ; err_wr.opcode =IB_WR_SEND ; err_wr.send_flags =IB_SEND_SIGNALED ;
@@ -1348,9 +1349,7 @@ void svc_rdma_send_error(struct svcxprt_rdma *xprt, struct rpcrdma_msg *rmsgp,if (ret) {dprintk ("svcrdma: Error %d posting send for protocol error\n" , ret); -ib_dma_unmap_page (xprt->sc_cm_id->device, - sge.addr,PAGE_SIZE , -DMA_FROM_DEVICE ); +svc_rdma_unmap_dma (ctxt);svc_rdma_put_context (ctxt,1 ); } }
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 20101012203332.22154.37230.stgit-T4OLL4TyM9aNDNWfRnPdfg@public.gmane.org
Quoted 4 lines · Tom Tucker
Hi Bruce,
These fixes are ready for 2.6.37. They fix two bugs in the server-side NFSRDMA transport.
Both applied and pushed out, thanks.
--b.
Quoted 17 lines
Thanks,
Tom
---Tom Tucker (2):
svcrdma: Cleanup DMA unmapping in error paths.
svcrdma: Change DMA mapping logic to avoid thepage_addresskernel APInet/sunrpc/xprtrdma/svc_rdma_recvfrom.c | 19 ++++--- net/sunrpc/xprtrdma/svc_rdma_sendto.c | 82 ++++++++++++++++++++++-------- net/sunrpc/xprtrdma/svc_rdma_transport.c | 41 +++++++-------- 3 files changed, 92 insertions(+), 50 deletions(-)Signature · 1 line
Signed-off-by: Tom Tucker <[email protected]>