svcrdma: clean up error paths.
Subsystems (3)
PATCH 1/1 svcrdma: clean up error paths.
These fixes resolved crashes due to resource leak BUG_ON checks. The resource leaks were detected by introducing asynchronous transport errors.
---
net/sunrpc/xprtrdma/svc_rdma_sendto.c | 3 +++ net/sunrpc/xprtrdma/svc_rdma_transport.c | 3 ++- 2 files changed, 5 insertions(+), 1 deletions(-)
net/sunrpc/xprtrdma/svc_rdma_sendto.c +3 -0
@@ -183,6 +183,7 @@ static int fast_reg_xdr(struct svcxprt_rdma *xprt, fatal_err:printk ("svcrdma: Error fast registering memory for xprt %p\n" , xprt); + vec->frmr =NULL ;svc_rdma_put_frmr (xprt, frmr);return -EIO ; }
@@ -516,6 +517,7 @@ static int send_reply(struct svcxprt_rdma *rdma,"svcrdma: could not post a receive buffer, err=%d." "Closing transport %p.\n", ret, rdma);set_bit (XPT_CLOSE , &rdma->sc_xprt.xpt_flags); +svc_rdma_put_frmr (rdma, vec->frmr);svc_rdma_put_context (ctxt,0 );return -ENOTCONN ; }
@@ -606,6 +608,7 @@ static int send_reply(struct svcxprt_rdma *rdma,return 0 ; err: +svc_rdma_unmap_dma (ctxt);svc_rdma_put_frmr (rdma, vec->frmr);svc_rdma_put_context (ctxt,1 );return -EIO ;
net/sunrpc/xprtrdma/svc_rdma_transport.c +2 -1
@@ -520,8 +520,9 @@ int svc_rdma_post_recv(struct svcxprt_rdma *xprt)svc_xprt_get (&xprt->sc_xprt); ret =ib_post_recv (xprt->sc_qp, &recv_wr, &bad_recv_wr);if (ret) { -svc_xprt_put (&xprt->sc_xprt); +svc_rdma_unmap_dma (ctxt);svc_rdma_put_context (ctxt,1 ); +svc_xprt_put (&xprt->sc_xprt); }return ret;
A message that is not in the archive (sent off-list or not yet received): 20090429191400.29365.36715.stgit-T4OLL4TyM9aNDNWfRnPdfg@public.gmane.org
J. Bruce Fields
AppliedQuoted 2 lines · Steve Wise
These fixes resolved crashes due to resource leak
BUG_ONchecks. The resource leaks were detected by introducing asynchronous transport errors.
Thanks, applied for 2.6.30. (And also appropriate for stable (2.6.29), I assume?)
But, could someone take a closer look at the error paths here? Questions:
- svc_rdma_post_recv() does a svc_rdma_put_context() on error-- are you sure its caller needs to as well?
- In send_reply, some of the cleanout is shared between the first return -ENOTCONN and the final err: cleanup. Could we add another err: label and share some of that cleanup?
--b.
Quoted 53 lines
Signed-off-by Steve Wise <[email protected]>Signed-off-by Tom Tucker <[email protected]>---
net/sunrpc/xprtrdma/svc_rdma_sendto.c | 3 +++ net/sunrpc/xprtrdma/svc_rdma_transport.c | 3 ++- 2 files changed, 5 insertions(+), 1 deletions(-)net/sunrpc/xprtrdma/svc_rdma_sendto.c +3
-0@@ -183,6 +183,7 @@ static int fast_reg_xdr(struct svcxprt_rdma *xprt, fatal_err:printk ("svcrdma: Error fast registering memory for xprt %p\n" , xprt); + vec->frmr =NULL ;svc_rdma_put_frmr (xprt, frmr);return -EIO ; }@@ -516,6 +517,7 @@ static int send_reply(struct svcxprt_rdma *rdma,"svcrdma: could not post a receive buffer, err=%d." "Closing transport %p.\n", ret, rdma);set_bit (XPT_CLOSE , &rdma->sc_xprt.xpt_flags); +svc_rdma_put_frmr (rdma, vec->frmr);svc_rdma_put_context (ctxt,0 );return -ENOTCONN ; }@@ -606,6 +608,7 @@ static int send_reply(struct svcxprt_rdma *rdma,return 0 ; err: +svc_rdma_unmap_dma (ctxt);svc_rdma_put_frmr (rdma, vec->frmr);svc_rdma_put_context (ctxt,1 );return -EIO ;net/sunrpc/xprtrdma/svc_rdma_transport.c +2
-1@@ -520,8 +520,9 @@ int svc_rdma_post_recv(struct svcxprt_rdma *xprt)svc_xprt_get (&xprt->sc_xprt); ret =ib_post_recv (xprt->sc_qp, &recv_wr, &bad_recv_wr);if (ret) { -svc_xprt_put (&xprt->sc_xprt); +svc_rdma_unmap_dma (ctxt);svc_rdma_put_context (ctxt,1 ); +svc_xprt_put (&xprt->sc_xprt); }return ret;
Hey Bruce,
Quoted 6 lines · J. Bruce Fields
Quoted 3 lines · Steve Wise
These fixes resolved crashes due to resource leak
BUG_ONchecks. The resource leaks were detected by introducing asynchronous transport errors.
Quoted 8 lines
Thanks, applied for 2.6.30. (And also appropriate for stable (2.6.29), I assume?)
But, could someone take a closer look at the error paths here? Questions:
-
svc_rdma_post_recv()does asvc_rdma_put_context()on error-- are you sure its caller needs to as well?
The svc_rdma_put_context() call inside svc_rdma_post_recv() is for the recv context that was allocated inside that function. The caller, in this case send_reply() also does a svc_rdma_put_context(), but that is for the send context. So I think this is correct.
Quoted 4 lines
- In
send_reply, some of the cleanout is shared between the first return-ENOTCONNand the final err: cleanup. Could we add another err: label and share some of that cleanup?
The only common logic I see is the svc_rdma_put_context() call that could be shared. But one case calls it with free_pages == 1 after the pages have been mapped, and the other with 0 since no pages are mapped at that point (when the call to svc_rdma_post_recv() fails). So I'm not sure its worth doing?
Steve.
Quoted 28 lines · Steve Wise
Hey Bruce,
Quoted 6 lines · J. Bruce Fields
Quoted 3 lines · Steve Wise
These fixes resolved crashes due to resource leak
BUG_ONchecks. The resource leaks were detected by introducing asynchronous transport errors.Quoted 8 lines
Thanks, applied for 2.6.30. (And also appropriate for stable (2.6.29), I assume?)
But, could someone take a closer look at the error paths here? Questions:
-
svc_rdma_post_recv()does asvc_rdma_put_context()on error-- are you sure its caller needs to as well?The
svc_rdma_put_context()call insidesvc_rdma_post_recv()is for the recv context that was allocated inside that function. The caller, in this casesend_reply()also does asvc_rdma_put_context(), but that is
for the send context. So I think this is correct.Quoted 4 lines
- In
send_reply, some of the cleanout is shared between the first return-ENOTCONNand the final err: cleanup. Could we add another err: label and share some of that cleanup?
Quoted 5 lines
The only common logic I see is the
svc_rdma_put_context()call that could be shared. But one case calls it withfree_pages== 1 after the pages have been mapped, and the other with 0 since no pages are mapped
at that point (when the call tosvc_rdma_post_recv()fails). So I'm
not sure its worth doing?
No, I think you're probably right about both of these. Thanks for taking a look.
--b.