Skip to content

Commit 795bc11

Browse files
KAGA-KOKOdledford
authored andcommitted
IB/srpt: Make it safe to use RCU for srpt_device.rch_list
The next patch will iterate over rch_list from a context from which it is not allowed to block. Hence make rch_list RCU-safe. Signed-off-by: Bart Van Assche <[email protected]> Signed-off-by: Doug Ledford <[email protected]>
1 parent 48900a2 commit 795bc11

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

drivers/infiniband/ulp/srpt/ib_srpt.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,7 +1906,7 @@ static void srpt_free_ch(struct kref *kref)
19061906
{
19071907
struct srpt_rdma_ch *ch = container_of(kref, struct srpt_rdma_ch, kref);
19081908

1909-
kfree(ch);
1909+
kfree_rcu(ch, rcu);
19101910
}
19111911

19121912
static void srpt_release_channel_work(struct work_struct *w)
@@ -1945,11 +1945,17 @@ static void srpt_release_channel_work(struct work_struct *w)
19451945
srp_max_req_size, DMA_FROM_DEVICE);
19461946

19471947
mutex_lock(&sdev->mutex);
1948-
list_del_init(&ch->list);
1948+
list_del_rcu(&ch->list);
19491949
if (ch->release_done)
19501950
complete(ch->release_done);
19511951
mutex_unlock(&sdev->mutex);
19521952

1953+
synchronize_rcu();
1954+
1955+
mutex_lock(&sdev->mutex);
1956+
INIT_LIST_HEAD(&ch->list);
1957+
mutex_unlock(&sdev->mutex);
1958+
19531959
wake_up(&sdev->ch_releaseQ);
19541960

19551961
kref_put(&ch->kref, srpt_free_ch);
@@ -2064,6 +2070,7 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id,
20642070
goto reject;
20652071
}
20662072

2073+
init_rcu_head(&ch->rcu);
20672074
kref_init(&ch->kref);
20682075
ch->zw_cqe.done = srpt_zerolength_write_done;
20692076
INIT_WORK(&ch->release_work, srpt_release_channel_work);
@@ -2190,7 +2197,7 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id,
21902197
}
21912198

21922199
mutex_lock(&sdev->mutex);
2193-
list_add_tail(&ch->list, &sdev->rch_list);
2200+
list_add_tail_rcu(&ch->list, &sdev->rch_list);
21942201
mutex_unlock(&sdev->mutex);
21952202

21962203
goto out;

drivers/infiniband/ulp/srpt/ib_srpt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ enum rdma_ch_state {
244244
* @qp: IB queue pair used for communicating over this channel.
245245
* @cq: IB completion queue for this channel.
246246
* @zw_cqe: Zero-length write CQE.
247+
* @rcu: RCU head.
247248
* @kref: kref for this channel.
248249
* @rq_size: IB receive queue size.
249250
* @max_rsp_size: Maximum size of an RSP response message in bytes.
@@ -276,6 +277,7 @@ struct srpt_rdma_ch {
276277
struct ib_qp *qp;
277278
struct ib_cq *cq;
278279
struct ib_cqe zw_cqe;
280+
struct rcu_head rcu;
279281
struct kref kref;
280282
int rq_size;
281283
u32 max_rsp_size;

0 commit comments

Comments
 (0)