Skip to content

Commit 239b0e5

Browse files
Kameneejgunthorpe
authored andcommitted
IB/hfi1: Move rvt_cq_wc struct into uapi directory
The rvt_cq_wc struct elements are shared between rdmavt and the providers but not in uapi directory. As per the comment in https://marc.info/?l=linux-rdma&m=152296522708522&w=2 The hfi1 driver and the rdma core driver are not using shared structures in the uapi directory. In that case, move rvt_cq_wc struct into the rvt-abi.h header file and create a rvt_k_cq_w for the kernel completion queue. Signed-off-by: Kamenee Arumugam <kamenee.arumugam@intel.com> Reviewed-by: Mike Marciniszyn <mike.marciniszyn@intel.com> Signed-off-by: Mike Marciniszyn <mike.marciniszyn@intel.com> Signed-off-by: Dennis Dalessandro <dennis.dalessandro@intel.com> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
1 parent 371bb62 commit 239b0e5

5 files changed

Lines changed: 205 additions & 77 deletions

File tree

‎drivers/infiniband/hw/hfi1/qp.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,8 +702,8 @@ void qp_iter_print(struct seq_file *s, struct rvt_qp_iter *iter)
702702
sde ? sde->this_idx : 0,
703703
send_context,
704704
send_context ? send_context->sw_index : 0,
705-
ibcq_to_rvtcq(qp->ibqp.send_cq)->queue->head,
706-
ibcq_to_rvtcq(qp->ibqp.send_cq)->queue->tail,
705+
ib_cq_head(qp->ibqp.send_cq),
706+
ib_cq_tail(qp->ibqp.send_cq),
707707
qp->pid,
708708
qp->s_state,
709709
qp->s_ack_state,

‎drivers/infiniband/sw/rdmavt/cq.c‎

Lines changed: 123 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -63,27 +63,41 @@ static struct workqueue_struct *comp_vector_wq;
6363
*/
6464
void rvt_cq_enter(struct rvt_cq *cq, struct ib_wc *entry, bool solicited)
6565
{
66-
struct rvt_cq_wc *wc;
66+
struct ib_uverbs_wc *uqueue = NULL;
67+
struct ib_wc *kqueue = NULL;
68+
struct rvt_cq_wc *u_wc = NULL;
69+
struct rvt_k_cq_wc *k_wc = NULL;
6770
unsigned long flags;
6871
u32 head;
6972
u32 next;
73+
u32 tail;
7074

7175
spin_lock_irqsave(&cq->lock, flags);
7276

77+
if (cq->ip) {
78+
u_wc = cq->queue;
79+
uqueue = &u_wc->uqueue[0];
80+
head = RDMA_READ_UAPI_ATOMIC(u_wc->head);
81+
tail = RDMA_READ_UAPI_ATOMIC(u_wc->tail);
82+
} else {
83+
k_wc = cq->kqueue;
84+
kqueue = &k_wc->kqueue[0];
85+
head = k_wc->head;
86+
tail = k_wc->tail;
87+
}
88+
7389
/*
74-
* Note that the head pointer might be writable by user processes.
75-
* Take care to verify it is a sane value.
90+
* Note that the head pointer might be writable by
91+
* user processes.Take care to verify it is a sane value.
7692
*/
77-
wc = cq->queue;
78-
head = wc->head;
7993
if (head >= (unsigned)cq->ibcq.cqe) {
8094
head = cq->ibcq.cqe;
8195
next = 0;
8296
} else {
8397
next = head + 1;
8498
}
8599

86-
if (unlikely(next == wc->tail)) {
100+
if (unlikely(next == tail)) {
87101
spin_unlock_irqrestore(&cq->lock, flags);
88102
if (cq->ibcq.event_handler) {
89103
struct ib_event ev;
@@ -96,27 +110,27 @@ void rvt_cq_enter(struct rvt_cq *cq, struct ib_wc *entry, bool solicited)
96110
return;
97111
}
98112
trace_rvt_cq_enter(cq, entry, head);
99-
if (cq->ip) {
100-
wc->uqueue[head].wr_id = entry->wr_id;
101-
wc->uqueue[head].status = entry->status;
102-
wc->uqueue[head].opcode = entry->opcode;
103-
wc->uqueue[head].vendor_err = entry->vendor_err;
104-
wc->uqueue[head].byte_len = entry->byte_len;
105-
wc->uqueue[head].ex.imm_data = entry->ex.imm_data;
106-
wc->uqueue[head].qp_num = entry->qp->qp_num;
107-
wc->uqueue[head].src_qp = entry->src_qp;
108-
wc->uqueue[head].wc_flags = entry->wc_flags;
109-
wc->uqueue[head].pkey_index = entry->pkey_index;
110-
wc->uqueue[head].slid = ib_lid_cpu16(entry->slid);
111-
wc->uqueue[head].sl = entry->sl;
112-
wc->uqueue[head].dlid_path_bits = entry->dlid_path_bits;
113-
wc->uqueue[head].port_num = entry->port_num;
113+
if (uqueue) {
114+
uqueue[head].wr_id = entry->wr_id;
115+
uqueue[head].status = entry->status;
116+
uqueue[head].opcode = entry->opcode;
117+
uqueue[head].vendor_err = entry->vendor_err;
118+
uqueue[head].byte_len = entry->byte_len;
119+
uqueue[head].ex.imm_data = entry->ex.imm_data;
120+
uqueue[head].qp_num = entry->qp->qp_num;
121+
uqueue[head].src_qp = entry->src_qp;
122+
uqueue[head].wc_flags = entry->wc_flags;
123+
uqueue[head].pkey_index = entry->pkey_index;
124+
uqueue[head].slid = ib_lid_cpu16(entry->slid);
125+
uqueue[head].sl = entry->sl;
126+
uqueue[head].dlid_path_bits = entry->dlid_path_bits;
127+
uqueue[head].port_num = entry->port_num;
114128
/* Make sure entry is written before the head index. */
115-
smp_wmb();
129+
RDMA_WRITE_UAPI_ATOMIC(u_wc->head, next);
116130
} else {
117-
wc->kqueue[head] = *entry;
131+
kqueue[head] = *entry;
132+
k_wc->head = next;
118133
}
119-
wc->head = next;
120134

121135
if (cq->notify == IB_CQ_NEXT_COMP ||
122136
(cq->notify == IB_CQ_SOLICITED &&
@@ -179,8 +193,9 @@ int rvt_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
179193
{
180194
struct ib_device *ibdev = ibcq->device;
181195
struct rvt_dev_info *rdi = ib_to_rvt(ibdev);
182-
struct rvt_cq *cq = container_of(ibcq, struct rvt_cq, ibcq);
183-
struct rvt_cq_wc *wc;
196+
struct rvt_cq *cq = ibcq_to_rvtcq(ibcq);
197+
struct rvt_cq_wc *u_wc = NULL;
198+
struct rvt_k_cq_wc *k_wc = NULL;
184199
u32 sz;
185200
unsigned int entries = attr->cqe;
186201
int comp_vector = attr->comp_vector;
@@ -204,22 +219,28 @@ int rvt_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
204219
* We need to use vmalloc() in order to support mmap and large
205220
* numbers of entries.
206221
*/
207-
sz = sizeof(*wc);
208-
if (udata && udata->outlen >= sizeof(__u64))
209-
sz += sizeof(struct ib_uverbs_wc) * (entries + 1);
210-
else
211-
sz += sizeof(struct ib_wc) * (entries + 1);
212-
wc = udata ?
213-
vmalloc_user(sz) :
214-
vzalloc_node(sz, rdi->dparms.node);
215-
if (!wc)
216-
return -ENOMEM;
222+
if (udata && udata->outlen >= sizeof(__u64)) {
223+
sz = sizeof(struct ib_uverbs_wc) * (entries + 1);
224+
sz += sizeof(*u_wc);
225+
u_wc = vmalloc_user(sz);
226+
if (!u_wc)
227+
return -ENOMEM;
228+
} else {
229+
sz = sizeof(struct ib_wc) * (entries + 1);
230+
sz += sizeof(*k_wc);
231+
k_wc = vzalloc_node(sz, rdi->dparms.node);
232+
if (!k_wc)
233+
return -ENOMEM;
234+
}
235+
217236
/*
218237
* Return the address of the WC as the offset to mmap.
219238
* See rvt_mmap() for details.
220239
*/
221240
if (udata && udata->outlen >= sizeof(__u64)) {
222-
cq->ip = rvt_create_mmap_info(rdi, sz, udata, wc);
241+
int err;
242+
243+
cq->ip = rvt_create_mmap_info(rdi, sz, udata, u_wc);
223244
if (!cq->ip) {
224245
err = -ENOMEM;
225246
goto bail_wc;
@@ -264,15 +285,19 @@ int rvt_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
264285
cq->notify = RVT_CQ_NONE;
265286
spin_lock_init(&cq->lock);
266287
INIT_WORK(&cq->comptask, send_complete);
267-
cq->queue = wc;
288+
if (u_wc)
289+
cq->queue = u_wc;
290+
else
291+
cq->kqueue = k_wc;
268292

269293
trace_rvt_create_cq(cq, attr);
270294
return 0;
271295

272296
bail_ip:
273297
kfree(cq->ip);
274298
bail_wc:
275-
vfree(wc);
299+
vfree(u_wc);
300+
vfree(k_wc);
276301
return err;
277302
}
278303

@@ -322,9 +347,16 @@ int rvt_req_notify_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags notify_flags)
322347
if (cq->notify != IB_CQ_NEXT_COMP)
323348
cq->notify = notify_flags & IB_CQ_SOLICITED_MASK;
324349

325-
if ((notify_flags & IB_CQ_REPORT_MISSED_EVENTS) &&
326-
cq->queue->head != cq->queue->tail)
327-
ret = 1;
350+
if (notify_flags & IB_CQ_REPORT_MISSED_EVENTS) {
351+
if (cq->queue) {
352+
if (RDMA_READ_UAPI_ATOMIC(cq->queue->head) !=
353+
RDMA_READ_UAPI_ATOMIC(cq->queue->tail))
354+
ret = 1;
355+
} else {
356+
if (cq->kqueue->head != cq->kqueue->tail)
357+
ret = 1;
358+
}
359+
}
328360

329361
spin_unlock_irqrestore(&cq->lock, flags);
330362

@@ -340,30 +372,34 @@ int rvt_req_notify_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags notify_flags)
340372
int rvt_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata)
341373
{
342374
struct rvt_cq *cq = ibcq_to_rvtcq(ibcq);
343-
struct rvt_cq_wc *old_wc;
344-
struct rvt_cq_wc *wc;
345375
u32 head, tail, n;
346376
int ret;
347377
u32 sz;
348378
struct rvt_dev_info *rdi = cq->rdi;
379+
struct rvt_cq_wc *u_wc = NULL;
380+
struct rvt_cq_wc *old_u_wc = NULL;
381+
struct rvt_k_cq_wc *k_wc = NULL;
382+
struct rvt_k_cq_wc *old_k_wc = NULL;
349383

350384
if (cqe < 1 || cqe > rdi->dparms.props.max_cqe)
351385
return -EINVAL;
352386

353387
/*
354388
* Need to use vmalloc() if we want to support large #s of entries.
355389
*/
356-
sz = sizeof(*wc);
357-
if (udata && udata->outlen >= sizeof(__u64))
358-
sz += sizeof(struct ib_uverbs_wc) * (cqe + 1);
359-
else
360-
sz += sizeof(struct ib_wc) * (cqe + 1);
361-
wc = udata ?
362-
vmalloc_user(sz) :
363-
vzalloc_node(sz, rdi->dparms.node);
364-
if (!wc)
365-
return -ENOMEM;
366-
390+
if (udata && udata->outlen >= sizeof(__u64)) {
391+
sz = sizeof(struct ib_uverbs_wc) * (cqe + 1);
392+
sz += sizeof(*u_wc);
393+
u_wc = vmalloc_user(sz);
394+
if (!u_wc)
395+
return -ENOMEM;
396+
} else {
397+
sz = sizeof(struct ib_wc) * (cqe + 1);
398+
sz += sizeof(*k_wc);
399+
k_wc = vzalloc_node(sz, rdi->dparms.node);
400+
if (!k_wc)
401+
return -ENOMEM;
402+
}
367403
/* Check that we can write the offset to mmap. */
368404
if (udata && udata->outlen >= sizeof(__u64)) {
369405
__u64 offset = 0;
@@ -378,11 +414,18 @@ int rvt_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata)
378414
* Make sure head and tail are sane since they
379415
* might be user writable.
380416
*/
381-
old_wc = cq->queue;
382-
head = old_wc->head;
417+
if (u_wc) {
418+
old_u_wc = cq->queue;
419+
head = RDMA_READ_UAPI_ATOMIC(old_u_wc->head);
420+
tail = RDMA_READ_UAPI_ATOMIC(old_u_wc->tail);
421+
} else {
422+
old_k_wc = cq->kqueue;
423+
head = old_k_wc->head;
424+
tail = old_k_wc->tail;
425+
}
426+
383427
if (head > (u32)cq->ibcq.cqe)
384428
head = (u32)cq->ibcq.cqe;
385-
tail = old_wc->tail;
386429
if (tail > (u32)cq->ibcq.cqe)
387430
tail = (u32)cq->ibcq.cqe;
388431
if (head < tail)
@@ -394,27 +437,36 @@ int rvt_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata)
394437
goto bail_unlock;
395438
}
396439
for (n = 0; tail != head; n++) {
397-
if (cq->ip)
398-
wc->uqueue[n] = old_wc->uqueue[tail];
440+
if (u_wc)
441+
u_wc->uqueue[n] = old_u_wc->uqueue[tail];
399442
else
400-
wc->kqueue[n] = old_wc->kqueue[tail];
443+
k_wc->kqueue[n] = old_k_wc->kqueue[tail];
401444
if (tail == (u32)cq->ibcq.cqe)
402445
tail = 0;
403446
else
404447
tail++;
405448
}
406449
cq->ibcq.cqe = cqe;
407-
wc->head = n;
408-
wc->tail = 0;
409-
cq->queue = wc;
450+
if (u_wc) {
451+
RDMA_WRITE_UAPI_ATOMIC(u_wc->head, n);
452+
RDMA_WRITE_UAPI_ATOMIC(u_wc->tail, 0);
453+
cq->queue = u_wc;
454+
} else {
455+
k_wc->head = n;
456+
k_wc->tail = 0;
457+
cq->kqueue = k_wc;
458+
}
410459
spin_unlock_irq(&cq->lock);
411460

412-
vfree(old_wc);
461+
if (u_wc)
462+
vfree(old_u_wc);
463+
else
464+
vfree(old_k_wc);
413465

414466
if (cq->ip) {
415467
struct rvt_mmap_info *ip = cq->ip;
416468

417-
rvt_update_mmap_info(rdi, ip, sz, wc);
469+
rvt_update_mmap_info(rdi, ip, sz, u_wc);
418470

419471
/*
420472
* Return the offset to mmap.
@@ -438,7 +490,9 @@ int rvt_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata)
438490
bail_unlock:
439491
spin_unlock_irq(&cq->lock);
440492
bail_free:
441-
vfree(wc);
493+
vfree(u_wc);
494+
vfree(k_wc);
495+
442496
return ret;
443497
}
444498

@@ -456,7 +510,7 @@ int rvt_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata)
456510
int rvt_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *entry)
457511
{
458512
struct rvt_cq *cq = ibcq_to_rvtcq(ibcq);
459-
struct rvt_cq_wc *wc;
513+
struct rvt_k_cq_wc *wc;
460514
unsigned long flags;
461515
int npolled;
462516
u32 tail;
@@ -467,7 +521,7 @@ int rvt_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *entry)
467521

468522
spin_lock_irqsave(&cq->lock, flags);
469523

470-
wc = cq->queue;
524+
wc = cq->kqueue;
471525
tail = wc->tail;
472526
if (tail > (u32)cq->ibcq.cqe)
473527
tail = (u32)cq->ibcq.cqe;

‎include/rdma/rdmavt_cq.h‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,28 @@
6060
*/
6161
#define RVT_CQ_NONE (IB_CQ_NEXT_COMP + 1)
6262

63+
/*
64+
* Define read macro that apply smp_load_acquire memory barrier
65+
* when reading indice of circular buffer that mmaped to user space.
66+
*/
67+
#define RDMA_READ_UAPI_ATOMIC(member) smp_load_acquire(&(member).val)
68+
69+
/*
70+
* Define write macro that uses smp_store_release memory barrier
71+
* when writing indice of circular buffer that mmaped to user space.
72+
*/
73+
#define RDMA_WRITE_UAPI_ATOMIC(member, x) smp_store_release(&(member).val, x)
74+
#include <rdma/rvt-abi.h>
75+
6376
/*
6477
* This structure is used to contain the head pointer, tail pointer,
6578
* and completion queue entries as a single memory allocation so
6679
* it can be mmap'ed into user space.
6780
*/
68-
struct rvt_cq_wc {
81+
struct rvt_k_cq_wc {
6982
u32 head; /* index of next entry to fill */
7083
u32 tail; /* index of next ib_poll_cq() entry */
71-
union {
72-
/* these are actually size ibcq.cqe + 1 */
73-
struct ib_uverbs_wc uqueue[0];
74-
struct ib_wc kqueue[0];
75-
};
84+
struct ib_wc kqueue[];
7685
};
7786

7887
/*
@@ -88,6 +97,7 @@ struct rvt_cq {
8897
struct rvt_dev_info *rdi;
8998
struct rvt_cq_wc *queue;
9099
struct rvt_mmap_info *ip;
100+
struct rvt_k_cq_wc *kqueue;
91101
};
92102

93103
static inline struct rvt_cq *ibcq_to_rvtcq(struct ib_cq *ibcq)

0 commit comments

Comments
 (0)