Skip to content

Commit 4cf44be

Browse files
chuckleveramschuma-ntap
authored andcommitted
xprtrdma: Fix recursion into rpcrdma_xprt_disconnect()
Both Dan and I have observed two processes invoking rpcrdma_xprt_disconnect() concurrently. In my case: 1. The connect worker invokes rpcrdma_xprt_disconnect(), which drains the QP and waits for the final completion 2. This causes the newly posted Receive to flush and invoke xprt_force_disconnect() 3. xprt_force_disconnect() sets CLOSE_WAIT and wakes up the RPC task that is holding the transport lock 4. The RPC task invokes xprt_connect(), which calls ->ops->close 5. xprt_rdma_close() invokes rpcrdma_xprt_disconnect(), which tries to destroy the QP. Deadlock. To prevent xprt_force_disconnect() from waking anything, handle the clean up after a failed connection attempt in the xprt's sndtask. The retry loop is removed from rpcrdma_xprt_connect() to ensure that the newly allocated ep and id are properly released before a REJECTED connection attempt can be retried. Reported-by: Dan Aloni <dan@kernelim.com> Fixes: e28ce90 ("xprtrdma: kmalloc rpcrdma_ep separate from rpcrdma_xprt") Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
1 parent 85bfd71 commit 4cf44be

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

‎net/sunrpc/xprtrdma/transport.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ xprt_rdma_connect_worker(struct work_struct *work)
249249
xprt->stat.connect_start;
250250
xprt_set_connected(xprt);
251251
rc = -EAGAIN;
252+
} else {
253+
/* Force a call to xprt_rdma_close to clean up */
254+
spin_lock(&xprt->transport_lock);
255+
set_bit(XPRT_CLOSE_WAIT, &xprt->state);
256+
spin_unlock(&xprt->transport_lock);
252257
}
253258
xprt_wake_pending_tasks(xprt, rc);
254259
}

‎net/sunrpc/xprtrdma/verbs.c‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ rpcrdma_cm_event_handler(struct rdma_cm_id *id, struct rdma_cm_event *event)
290290
sap, rdma_reject_msg(id, event->status));
291291
ep->re_connect_status = -ECONNREFUSED;
292292
if (event->status == IB_CM_REJ_STALE_CONN)
293-
ep->re_connect_status = -EAGAIN;
293+
ep->re_connect_status = -ENOTCONN;
294294
goto disconnected;
295295
case RDMA_CM_EVENT_DISCONNECTED:
296296
ep->re_connect_status = -ECONNABORTED;
@@ -521,8 +521,6 @@ int rpcrdma_xprt_connect(struct rpcrdma_xprt *r_xprt)
521521
struct rpcrdma_ep *ep;
522522
int rc;
523523

524-
retry:
525-
rpcrdma_xprt_disconnect(r_xprt);
526524
rc = rpcrdma_ep_create(r_xprt);
527525
if (rc)
528526
return rc;
@@ -550,17 +548,13 @@ int rpcrdma_xprt_connect(struct rpcrdma_xprt *r_xprt)
550548
wait_event_interruptible(ep->re_connect_wait,
551549
ep->re_connect_status != 0);
552550
if (ep->re_connect_status <= 0) {
553-
if (ep->re_connect_status == -EAGAIN)
554-
goto retry;
555551
rc = ep->re_connect_status;
556552
goto out;
557553
}
558554

559555
rc = rpcrdma_reqs_setup(r_xprt);
560-
if (rc) {
561-
rpcrdma_xprt_disconnect(r_xprt);
556+
if (rc)
562557
goto out;
563-
}
564558
rpcrdma_mrs_create(r_xprt);
565559

566560
out:

0 commit comments

Comments
 (0)