Skip to content

Commit f574069

Browse files
metze-sambasmfrench
authored andcommitted
smb: server: let smb_direct_cm_handler() call ib_drain_qp() after smb_direct_disconnect_rdma_work()
All handlers triggered by ib_drain_qp() should already see the broken connection. smb_direct_cm_handler() is called under a mutex of the rdma_cm, we should make sure ib_drain_qp() and all rdma layer logic completes and unlocks the mutex. It means free_transport() will also already see the connection as SMBDIRECT_SOCKET_DISCONNECTED, so we need to call crdma_[un]lock_handler(sc->rdma.cm_id) around ib_drain_qp(), rdma_destroy_qp(), ib_free_cq() and ib_dealloc_pd(). Otherwise we free resources while the ib_drain_qp() within smb_direct_cm_handler() is still running. We have to unlock before rdma_destroy_id() as it locks again. Fixes: 141fa98 ("ksmbd: call ib_drain_qp when disconnected") Fixes: 4c564f0 ("smb: server: make use of common smbdirect_socket") Cc: Namjae Jeon <[email protected]> Cc: Steve French <[email protected]> Cc: Tom Talpey <[email protected]> Cc: [email protected] Cc: [email protected] Signed-off-by: Stefan Metzmacher <[email protected]> Acked-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 975f05a commit f574069

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

fs/smb/server/transport_rdma.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,9 @@ static void free_transport(struct smb_direct_transport *t)
466466
disable_delayed_work_sync(&sc->idle.timer_work);
467467
disable_work_sync(&sc->idle.immediate_work);
468468

469+
if (sc->rdma.cm_id)
470+
rdma_lock_handler(sc->rdma.cm_id);
471+
469472
if (sc->ib.qp) {
470473
ib_drain_qp(sc->ib.qp);
471474
sc->ib.qp = NULL;
@@ -494,8 +497,10 @@ static void free_transport(struct smb_direct_transport *t)
494497
ib_free_cq(sc->ib.recv_cq);
495498
if (sc->ib.pd)
496499
ib_dealloc_pd(sc->ib.pd);
497-
if (sc->rdma.cm_id)
500+
if (sc->rdma.cm_id) {
501+
rdma_unlock_handler(sc->rdma.cm_id);
498502
rdma_destroy_id(sc->rdma.cm_id);
503+
}
499504

500505
smb_direct_destroy_pools(sc);
501506
ksmbd_conn_free(KSMBD_TRANS(t)->conn);
@@ -1724,10 +1729,10 @@ static int smb_direct_cm_handler(struct rdma_cm_id *cm_id,
17241729
}
17251730
case RDMA_CM_EVENT_DEVICE_REMOVAL:
17261731
case RDMA_CM_EVENT_DISCONNECTED: {
1727-
ib_drain_qp(sc->ib.qp);
1728-
17291732
sc->status = SMBDIRECT_SOCKET_DISCONNECTED;
17301733
smb_direct_disconnect_rdma_work(&sc->disconnect_work);
1734+
if (sc->ib.qp)
1735+
ib_drain_qp(sc->ib.qp);
17311736
break;
17321737
}
17331738
case RDMA_CM_EVENT_CONNECT_ERROR: {

0 commit comments

Comments
 (0)