Skip to content

Commit 8628991

Browse files
Bart Van Asschedledford
authored andcommitted
IB/srpt: Use a mutex to protect the channel list
In a later patch a function that can block will be called while iterating over the rch_list. Hence protect that list with a mutex instead of a spinlock. And since it is not allowed to sleep while the task state != TASK_RUNNING, convert the list test in srpt_ch_list_empty() into a lockless test. Signed-off-by: Bart Van Assche <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Cc: Sagi Grimberg <[email protected]> Cc: Alex Estrin <[email protected]> Signed-off-by: Doug Ledford <[email protected]>
1 parent c13c90e commit 8628991

File tree

2 files changed

+17
-29
lines changed

2 files changed

+17
-29
lines changed

drivers/infiniband/ulp/srpt/ib_srpt.c

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,12 +1862,11 @@ static void __srpt_close_ch(struct srpt_rdma_ch *ch)
18621862
*/
18631863
static void srpt_close_ch(struct srpt_rdma_ch *ch)
18641864
{
1865-
struct srpt_device *sdev;
1865+
struct srpt_device *sdev = ch->sport->sdev;
18661866

1867-
sdev = ch->sport->sdev;
1868-
spin_lock_irq(&sdev->spinlock);
1867+
mutex_lock(&sdev->mutex);
18691868
__srpt_close_ch(ch);
1870-
spin_unlock_irq(&sdev->spinlock);
1869+
mutex_unlock(&sdev->mutex);
18711870
}
18721871

18731872
/**
@@ -1954,11 +1953,11 @@ static void srpt_release_channel_work(struct work_struct *w)
19541953
ch->sport->sdev, ch->rq_size,
19551954
ch->rsp_size, DMA_TO_DEVICE);
19561955

1957-
spin_lock_irq(&sdev->spinlock);
1956+
mutex_lock(&sdev->mutex);
19581957
list_del_init(&ch->list);
19591958
if (ch->release_done)
19601959
complete(ch->release_done);
1961-
spin_unlock_irq(&sdev->spinlock);
1960+
mutex_unlock(&sdev->mutex);
19621961

19631962
wake_up(&sdev->ch_releaseQ);
19641963

@@ -2039,7 +2038,7 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id,
20392038
if ((req->req_flags & SRP_MTCH_ACTION) == SRP_MULTICHAN_SINGLE) {
20402039
rsp->rsp_flags = SRP_LOGIN_RSP_MULTICHAN_NO_CHAN;
20412040

2042-
spin_lock_irq(&sdev->spinlock);
2041+
mutex_lock(&sdev->mutex);
20432042

20442043
list_for_each_entry_safe(ch, tmp_ch, &sdev->rch_list, list) {
20452044
if (!memcmp(ch->i_port_id, req->initiator_port_id, 16)
@@ -2063,7 +2062,7 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id,
20632062
}
20642063
}
20652064

2066-
spin_unlock_irq(&sdev->spinlock);
2065+
mutex_unlock(&sdev->mutex);
20672066

20682067
} else
20692068
rsp->rsp_flags = SRP_LOGIN_RSP_MULTICHAN_MAINTAINED;
@@ -2208,9 +2207,9 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id,
22082207
goto release_channel;
22092208
}
22102209

2211-
spin_lock_irq(&sdev->spinlock);
2210+
mutex_lock(&sdev->mutex);
22122211
list_add_tail(&ch->list, &sdev->rch_list);
2213-
spin_unlock_irq(&sdev->spinlock);
2212+
mutex_unlock(&sdev->mutex);
22142213

22152214
goto out;
22162215

@@ -2653,17 +2652,6 @@ static void srpt_refresh_port_work(struct work_struct *work)
26532652
srpt_refresh_port(sport);
26542653
}
26552654

2656-
static int srpt_ch_list_empty(struct srpt_device *sdev)
2657-
{
2658-
int res;
2659-
2660-
spin_lock_irq(&sdev->spinlock);
2661-
res = list_empty(&sdev->rch_list);
2662-
spin_unlock_irq(&sdev->spinlock);
2663-
2664-
return res;
2665-
}
2666-
26672655
/**
26682656
* srpt_release_sdev() - Free the channel resources associated with a target.
26692657
*/
@@ -2676,13 +2664,13 @@ static int srpt_release_sdev(struct srpt_device *sdev)
26762664

26772665
BUG_ON(!sdev);
26782666

2679-
spin_lock_irq(&sdev->spinlock);
2667+
mutex_lock(&sdev->mutex);
26802668
list_for_each_entry_safe(ch, tmp_ch, &sdev->rch_list, list)
26812669
__srpt_close_ch(ch);
2682-
spin_unlock_irq(&sdev->spinlock);
2670+
mutex_unlock(&sdev->mutex);
26832671

26842672
res = wait_event_interruptible(sdev->ch_releaseQ,
2685-
srpt_ch_list_empty(sdev));
2673+
list_empty_careful(&sdev->rch_list));
26862674
if (res)
26872675
pr_err("%s: interrupted.\n", __func__);
26882676

@@ -2743,7 +2731,7 @@ static void srpt_add_one(struct ib_device *device)
27432731
sdev->device = device;
27442732
INIT_LIST_HEAD(&sdev->rch_list);
27452733
init_waitqueue_head(&sdev->ch_releaseQ);
2746-
spin_lock_init(&sdev->spinlock);
2734+
mutex_init(&sdev->mutex);
27472735

27482736
sdev->pd = ib_alloc_pd(device);
27492737
if (IS_ERR(sdev->pd))
@@ -2971,12 +2959,12 @@ static void srpt_close_session(struct se_session *se_sess)
29712959
pr_debug("ch %s-%d state %d\n", ch->sess_name, ch->qp->qp_num,
29722960
ch->state);
29732961

2974-
spin_lock_irq(&sdev->spinlock);
2962+
mutex_lock(&sdev->mutex);
29752963
BUG_ON(ch->release_done);
29762964
ch->release_done = &release_done;
29772965
wait = !list_empty(&ch->list);
29782966
__srpt_close_ch(ch);
2979-
spin_unlock_irq(&sdev->spinlock);
2967+
mutex_unlock(&sdev->mutex);
29802968

29812969
if (!wait)
29822970
return;

drivers/infiniband/ulp/srpt/ib_srpt.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ struct srpt_port {
342342
* @ioctx_ring: Per-HCA SRQ.
343343
* @rch_list: Per-device channel list -- see also srpt_rdma_ch.list.
344344
* @ch_releaseQ: Enables waiting for removal from rch_list.
345-
* @spinlock: Protects rch_list and tpg.
345+
* @mutex: Protects rch_list.
346346
* @port: Information about the ports owned by this HCA.
347347
* @event_handler: Per-HCA asynchronous IB event handler.
348348
* @list: Node in srpt_dev_list.
@@ -356,7 +356,7 @@ struct srpt_device {
356356
struct srpt_recv_ioctx **ioctx_ring;
357357
struct list_head rch_list;
358358
wait_queue_head_t ch_releaseQ;
359-
spinlock_t spinlock;
359+
struct mutex mutex;
360360
struct srpt_port port[2];
361361
struct ib_event_handler event_handler;
362362
struct list_head list;

0 commit comments

Comments
 (0)