Skip to content

Commit eddae8b

Browse files
chucklevergregkh
authored andcommitted
xprtrdma: Fix cwnd update ordering
[ Upstream commit 35d8b10 ] After a reconnect, the reply handler is opening the cwnd (and thus enabling more RPC Calls to be sent) /before/ rpcrdma_post_recvs() can post enough Receive WRs to receive their replies. This causes an RNR and the new connection is lost immediately. The race is most clearly exposed when KASAN and disconnect injection are enabled. This slows down rpcrdma_rep_create() enough to allow the send side to post a bunch of RPC Calls before the Receive completion handler can invoke ib_post_recv(). Fixes: 2ae50ad ("xprtrdma: Close window between waking RPC senders and posting Receives") Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 89a31bf commit eddae8b

3 files changed

Lines changed: 8 additions & 7 deletions

File tree

‎net/sunrpc/xprtrdma/rpc_rdma.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1467,9 +1467,10 @@ void rpcrdma_reply_handler(struct rpcrdma_rep *rep)
14671467
credits = 1; /* don't deadlock */
14681468
else if (credits > r_xprt->rx_ep->re_max_requests)
14691469
credits = r_xprt->rx_ep->re_max_requests;
1470+
rpcrdma_post_recvs(r_xprt, credits + (buf->rb_bc_srv_max_requests << 1),
1471+
false);
14701472
if (buf->rb_credits != credits)
14711473
rpcrdma_update_cwnd(r_xprt, credits);
1472-
rpcrdma_post_recvs(r_xprt, false);
14731474

14741475
req = rpcr_to_rdmar(rqst);
14751476
if (req->rl_reply) {

‎net/sunrpc/xprtrdma/verbs.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ int rpcrdma_xprt_connect(struct rpcrdma_xprt *r_xprt)
535535
* outstanding Receives.
536536
*/
537537
rpcrdma_ep_get(ep);
538-
rpcrdma_post_recvs(r_xprt, true);
538+
rpcrdma_post_recvs(r_xprt, 1, true);
539539

540540
rc = rdma_connect(ep->re_id, &ep->re_remote_cma);
541541
if (rc)
@@ -1377,21 +1377,21 @@ int rpcrdma_post_sends(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req)
13771377
/**
13781378
* rpcrdma_post_recvs - Refill the Receive Queue
13791379
* @r_xprt: controlling transport instance
1380-
* @temp: mark Receive buffers to be deleted after use
1380+
* @needed: current credit grant
1381+
* @temp: mark Receive buffers to be deleted after one use
13811382
*
13821383
*/
1383-
void rpcrdma_post_recvs(struct rpcrdma_xprt *r_xprt, bool temp)
1384+
void rpcrdma_post_recvs(struct rpcrdma_xprt *r_xprt, int needed, bool temp)
13841385
{
13851386
struct rpcrdma_buffer *buf = &r_xprt->rx_buf;
13861387
struct rpcrdma_ep *ep = r_xprt->rx_ep;
13871388
struct ib_recv_wr *wr, *bad_wr;
13881389
struct rpcrdma_rep *rep;
1389-
int needed, count, rc;
1390+
int count, rc;
13901391

13911392
rc = 0;
13921393
count = 0;
13931394

1394-
needed = buf->rb_credits + (buf->rb_bc_srv_max_requests << 1);
13951395
if (likely(ep->re_receive_count > needed))
13961396
goto out;
13971397
needed -= ep->re_receive_count;

‎net/sunrpc/xprtrdma/xprt_rdma.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ int rpcrdma_xprt_connect(struct rpcrdma_xprt *r_xprt);
452452
void rpcrdma_xprt_disconnect(struct rpcrdma_xprt *r_xprt);
453453

454454
int rpcrdma_post_sends(struct rpcrdma_xprt *r_xprt, struct rpcrdma_req *req);
455-
void rpcrdma_post_recvs(struct rpcrdma_xprt *r_xprt, bool temp);
455+
void rpcrdma_post_recvs(struct rpcrdma_xprt *r_xprt, int needed, bool temp);
456456

457457
/*
458458
* Buffer calls - xprtrdma/verbs.c

0 commit comments

Comments
 (0)