Re: [PATCH] IB/iser: Fix deadlock during blocking connect

From: ziyu zhang

Date: Thu Nov 26 2026 - 05:22:53 EST


On Thu, 26 Nov 2026 at 17:24, Leon Romanovsky <leon@xxxxxxxxxx> wrote:
>
> On Mon, Nov 23, 2026 at 10:44:40PM +0800, Ziyu Zhang wrote:
> > iser_connect() holds state_mutex while waiting for up_completion. The
> > CMA handler for the same connection needs state_mutex before it can call
> > iser_connected_handler() and complete up_completion. A blocking connect
> > can therefore prevent its own connection completion and leave the waiter
> > blocked until a signal arrives.
> >
> > Drop state_mutex around the wait and reacquire it before checking the
> > connection state, preserving serialization of state and cleanup paths.
>
> You can't randomly drop locks without any explanation why it is safe.
>
> Thanks

Thanks for pointing this out. I should have explained what keeps the
connection alive while state_mutex is dropped.

iscsi_if_rx() holds rx_queue_mutex for the entire ep_connect() call,
so a netlink bind or disconnect cannot run against this endpoint
during the wait. The endpoint is still unbound, and the connect path
owns iser_conn. RDMA CM callbacks can advance the connection state
or clean up RDMA resources during that window. The only operation
between unlocking and relocking is the wait on up_completion, and
iser_connect() checks the connection state under state_mutex after
reacquiring it.

I sent v2 after the bot review. It also wakes the waiter on
establishment failure and fixes the endpoint double free on the
connect error path.

https://lore.kernel.org/r/20261124090121.77115-1-ziyuzhang201@xxxxxxxxx

>
> >
> > Fixes: 504130c039f9 ("IB/iser: Protect iser state machine with a mutex")
> > Cc: stable@xxxxxxxxxxxxxxx
> > Signed-off-by: Ziyu Zhang <ziyuzhang201@xxxxxxxxx>
> > ---
> > drivers/infiniband/ulp/iser/iser_verbs.c | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> > diff --git a/drivers/infiniband/ulp/iser/iser_verbs.c b/drivers/infiniband/ulp/iser/iser_verbs.c
> > index 55fe68e..9fe2d3f 100644
> > --- a/drivers/infiniband/ulp/iser/iser_verbs.c
> > +++ b/drivers/infiniband/ulp/iser/iser_verbs.c
> > @@ -778,7 +778,9 @@ int iser_connect(struct iser_conn *iser_conn, struct sockaddr *src_addr,
> > }
> >
> > if (!non_blocking) {
> > + mutex_unlock(&iser_conn->state_mutex);
> > wait_for_completion_interruptible(&iser_conn->up_completion);
> > + mutex_lock(&iser_conn->state_mutex);
> >
> > if (iser_conn->state != ISER_CONN_UP) {
> > err = -EIO;
> > --
> > 2.34.1
> >
> >