Skip to content
/ linux Public
forked from torvalds/linux

Commit

Permalink
IB/iser: add safety checks for state_mutex lock
Browse files Browse the repository at this point in the history
In some cases, we need to make sure that state_mutex is taken. Use
lockdep_assert_held to warn us in case it doesn't while it should.

Signed-off-by: Max Gurtovoy <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Reviewed-by: Sergey Gorenko <[email protected]>
Reviewed-by: Sagi Grimberg <[email protected]>
Signed-off-by: Leon Romanovsky <[email protected]>
  • Loading branch information
mgurtovoy authored and rleon committed Oct 19, 2022
1 parent acc7d94 commit a75243a
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions drivers/infiniband/ulp/iser/iser_verbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,8 @@ int iser_conn_terminate(struct iser_conn *iser_conn)
struct ib_conn *ib_conn = &iser_conn->ib_conn;
int err = 0;

lockdep_assert_held(&iser_conn->state_mutex);

/* terminate the iser conn only if the conn state is UP */
if (iser_conn->state != ISER_CONN_UP)
return 0;
Expand Down Expand Up @@ -482,9 +484,10 @@ int iser_conn_terminate(struct iser_conn *iser_conn)
*/
static void iser_connect_error(struct rdma_cm_id *cma_id)
{
struct iser_conn *iser_conn;
struct iser_conn *iser_conn = cma_id->context;

lockdep_assert_held(&iser_conn->state_mutex);

iser_conn = cma_id->context;
iser_conn->state = ISER_CONN_TERMINATING;
}

Expand Down Expand Up @@ -526,12 +529,13 @@ static void iser_calc_scsi_params(struct iser_conn *iser_conn,
*/
static void iser_addr_handler(struct rdma_cm_id *cma_id)
{
struct iser_conn *iser_conn = cma_id->context;
struct iser_device *device;
struct iser_conn *iser_conn;
struct ib_conn *ib_conn;
int ret;

iser_conn = cma_id->context;
lockdep_assert_held(&iser_conn->state_mutex);

if (iser_conn->state != ISER_CONN_PENDING)
/* bailout */
return;
Expand Down Expand Up @@ -581,6 +585,8 @@ static void iser_route_handler(struct rdma_cm_id *cma_id)
struct ib_conn *ib_conn = &iser_conn->ib_conn;
struct ib_device *ib_dev = ib_conn->device->ib_device;

lockdep_assert_held(&iser_conn->state_mutex);

if (iser_conn->state != ISER_CONN_PENDING)
/* bailout */
return;
Expand Down Expand Up @@ -613,14 +619,18 @@ static void iser_route_handler(struct rdma_cm_id *cma_id)
iser_connect_error(cma_id);
}

/*
* Called with state mutex held
*/
static void iser_connected_handler(struct rdma_cm_id *cma_id,
const void *private_data)
{
struct iser_conn *iser_conn;
struct iser_conn *iser_conn = cma_id->context;
struct ib_qp_attr attr;
struct ib_qp_init_attr init_attr;

iser_conn = cma_id->context;
lockdep_assert_held(&iser_conn->state_mutex);

if (iser_conn->state != ISER_CONN_PENDING)
/* bailout */
return;
Expand Down Expand Up @@ -654,11 +664,15 @@ static void iser_disconnected_handler(struct rdma_cm_id *cma_id)
}
}

/*
* Called with state mutex held
*/
static void iser_cleanup_handler(struct rdma_cm_id *cma_id,
bool destroy)
{
struct iser_conn *iser_conn = cma_id->context;

lockdep_assert_held(&iser_conn->state_mutex);
/*
* We are not guaranteed that we visited disconnected_handler
* by now, call it here to be safe that we handle CM drep
Expand Down

0 comments on commit a75243a

Please sign in to comment.