Skip to contentSkip to conversation

IB/iser: Fix blocking connect hang and endpoint double free

PATCH New Ziyu Zhang 2 participants 2 messages Nov 24

Subsystems (2)
lore
Share & tools
lore

Ziyu Zhang

author
#0 lore raw

PATCH v2 1/1 IB/iser: Fix blocking connect hang and endpoint double free

iser_connect() waits for up_completion while holding iser_conn->state_mutex. The RDMA CM callback that advances the connection state machine needs the same mutex, so a blocking connect can never finish establishing and the wait only returns when a signal arrives. The caller then sits there with rx_queue_mutex held, which stalls the iscsi netlink path for the whole daemon.

Dropping the mutex around the wait is not enough on its own:
up_completion is only completed on RDMA_CM_EVENT_ESTABLISHED, so an address, route, connect or reject error still leaves the waiter asleep forever; complete it from iser_connect_error() as well. The cleanup events are the other way an attempt can end without an establishment:
DISCONNECTED, ADDR_CHANGE, TIMEWAIT_EXIT and DEVICE_REMOVAL reach iser_cleanup_handler() with the connection still ISER_CONN_PENDING, where iser_conn_terminate() does nothing because it only acts on an established connection. Terminate a PENDING connection there and wake the waiter, leaving the established-connection cleanup unchanged. iscsi_iser_ep_poll() must then look at the connection state when the completion fires, otherwise a failed attempt is reported as a successful connection.

Finally, the failure paths left the connection in ISER_CONN_PENDING or ISER_CONN_TERMINATING. iser_conn_release() destroys iser_conn->ep when the state is not DOWN, and iscsi_iser_ep_connect() destroys the same endpoint again on the error return, so the endpoint was freed twice. Terminate the connection and mark it DOWN under the state mutex instead, so the endpoint keeps a single owner, and so that no handler can keep operating on a connection that is being torn down.

DOWN is terminal: iser_connect() drops state_mutex before the cma_id is destroyed, so a late CM error event can still reach iser_connect_error(). That handler used to move the state to TERMINATING unconditionally, so iser_conn_release() destroyed the endpoint first and iscsi_iser_ep_connect() destroyed it again when iser_connect() returned. Leave a DOWN connection alone there.

Fixes 504130c039f9 ("IB/iser: Protect iser state machine with a mutex")
Fixes 9a3119e4b787 ("IB/iser: Release the iscsi endpoint if ep_disconnect wasn't called")

---
Changes in v2:
- Wake up the blocking waiter on connection errors and on cleanup events received while the connection is PENDING, including device removal.
- Check the return value of wait_for_completion_interruptible() and propagate signal interruption errors.
- Terminate the connection and set its state to DOWN under state_mutex on connect failure, leaving endpoint destruction to the caller.
- Keep DOWN terminal in iser_connect_error() so a late CM error cannot trigger endpoint destruction in iser_conn_release().
- Check the connection state after a positive completion result in iscsi_iser_ep_poll() to distinguish successful and failed connections.
- Expand the commit message to explain the failure wakeups and endpoint cleanup ordering.

v1: https://lore.kernel.org/linux-rdma/[email protected]/

 drivers/infiniband/ulp/iser/iscsi_iser.c | 11 +++++-
 drivers/infiniband/ulp/iser/iser_verbs.c | 50 +++++++++++++++++++++++-
 2 files changed, 58 insertions(+), 3 deletions(-)
drivers/infiniband/ulp/iser/iscsi_iser.c +10 -1
index 7df441685780..47c264cb9aff 100644
@@ -843,7 +843,16 @@ static int iscsi_iser_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
 	rc = wait_for_completion_interruptible_timeout(&iser_conn->up_completion,
 						       msecs_to_jiffies(timeout_ms));
 	/* if conn establishment failed, return error code to iscsi */
-	if (rc == 0) {
+	if (rc > 0) {
+		/*
+		 * up_completion is also signalled when the connection attempt
+		 * failed, don't report that as a successful connection.
+		 */
+		mutex_lock(&iser_conn->state_mutex);
+		if (iser_conn->state != ISER_CONN_UP)
+			rc = -1;
+		mutex_unlock(&iser_conn->state_mutex);
+	} else if (rc == 0) {
 		mutex_lock(&iser_conn->state_mutex);
 		if (iser_conn->state == ISER_CONN_TERMINATING ||
 		    iser_conn->state == ISER_CONN_DOWN)
drivers/infiniband/ulp/iser/iser_verbs.c +48 -2

76 lines not on this page · raw message

Signature · 1 line
2.34.1
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 17 lines

iser_connect() waits for up_completion while holding iser_conn->state_mutex. The RDMA CM callback that advances the connection state machine needs the same mutex, so a blocking connect can never finish establishing and the wait only returns when a signal arrives. The caller then sits there with rx_queue_mutex held, which stalls the iscsi netlink path for the whole daemon.

Dropping the mutex around the wait is not enough on its own:
up_completion is only completed on RDMA_CM_EVENT_ESTABLISHED, so an address, route, connect or reject error still leaves the waiter asleep forever; complete it from iser_connect_error() as well. The cleanup events are the other way an attempt can end without an establishment:
DISCONNECTED, ADDR_CHANGE, TIMEWAIT_EXIT and DEVICE_REMOVAL reach iser_cleanup_handler() with the connection still ISER_CONN_PENDING, where iser_conn_terminate() does nothing because it only acts on an [ ... ]

Quoted 4 lines
Fixes 504130c039f9 ("IB/iser: Protect iser state machine with a mutex")
Fixes 9a3119e4b787 ("IB/iser: Release the iscsi endpoint if ep_disconnect wasn't called")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1