iser-target: release stale iser connections

When receiving a new iser connect request we serialize
the pending requests by adding the newly created iser connection
to the np accept list and let the login thread process the connect
request one by one (np_accept_wait).

In case we received a disconnect request before the iser_conn
has begun processing (still linked in np_accept_list) we should
detach it from the list and clean it up and not have the login
thread process a stale connection. We do it only when the connection
state is not already terminating (initiator driven disconnect) as
this might lead us to access np_accept_mutex after the np was released
in live shutdown scenarios.

Signed-off-by: Sagi Grimberg <sagig@mellanox.com>
Signed-off-by: Jenny Falkovich <jennyf@mellanox.com>
Cc: stable@vger.kernel.org # 3.10+
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>

authored by Sagi Grimberg and committed by Nicholas Bellinger 2f1b6b7d 9253e667

Changed files
+17 -1
drivers
infiniband
ulp
isert
+17 -1
drivers/infiniband/ulp/isert/ib_isert.c
··· 65 65 isert_rdma_accept(struct isert_conn *isert_conn); 66 66 struct rdma_cm_id *isert_setup_id(struct isert_np *isert_np); 67 67 68 + static void isert_release_work(struct work_struct *work); 69 + 68 70 static inline bool 69 71 isert_prot_cmd(struct isert_conn *conn, struct se_cmd *cmd) 70 72 { ··· 650 648 mutex_init(&isert_conn->mutex); 651 649 spin_lock_init(&isert_conn->pool_lock); 652 650 INIT_LIST_HEAD(&isert_conn->fr_pool); 651 + INIT_WORK(&isert_conn->release_work, isert_release_work); 653 652 } 654 653 655 654 static void ··· 928 925 { 929 926 struct isert_np *isert_np = cma_id->context; 930 927 struct isert_conn *isert_conn; 928 + bool terminating = false; 931 929 932 930 if (isert_np->np_cm_id == cma_id) 933 931 return isert_np_cma_handler(cma_id->context, event); ··· 936 932 isert_conn = cma_id->qp->qp_context; 937 933 938 934 mutex_lock(&isert_conn->mutex); 935 + terminating = (isert_conn->state == ISER_CONN_TERMINATING); 939 936 isert_conn_terminate(isert_conn); 940 937 mutex_unlock(&isert_conn->mutex); 941 938 942 939 isert_info("conn %p completing wait\n", isert_conn); 943 940 complete(&isert_conn->wait); 944 941 942 + if (terminating) 943 + goto out; 944 + 945 + mutex_lock(&isert_np->np_accept_mutex); 946 + if (!list_empty(&isert_conn->accept_node)) { 947 + list_del_init(&isert_conn->accept_node); 948 + isert_put_conn(isert_conn); 949 + queue_work(isert_release_wq, &isert_conn->release_work); 950 + } 951 + mutex_unlock(&isert_np->np_accept_mutex); 952 + 953 + out: 945 954 return 0; 946 955 } 947 956 ··· 3385 3368 isert_wait4flush(isert_conn); 3386 3369 isert_wait4logout(isert_conn); 3387 3370 3388 - INIT_WORK(&isert_conn->release_work, isert_release_work); 3389 3371 queue_work(isert_release_wq, &isert_conn->release_work); 3390 3372 } 3391 3373