2 * Copyright (c) 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005, 2006, 2007 Cisco Systems. All rights reserved.
4 * Copyright (c) 2005 PathScale, Inc. All rights reserved.
5 * Copyright (c) 2006 Mellanox Technologies. All rights reserved.
7 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU
9 * General Public License (GPL) Version 2, available from the file
10 * COPYING in the main directory of this source tree, or the
11 * OpenIB.org BSD license below:
13 * Redistribution and use in source and binary forms, with or
14 * without modification, are permitted provided that the following
17 * - Redistributions of source code must retain the above
18 * copyright notice, this list of conditions and the following
21 * - Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimer in the documentation and/or other materials
24 * provided with the distribution.
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
30 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36 #include <linux/file.h>
38 #include <linux/slab.h>
40 #include <asm/uaccess.h>
44 struct uverbs_lock_class {
45 struct lock_class_key key;
49 static struct uverbs_lock_class pd_lock_class = { .name = "PD-uobj" };
50 static struct uverbs_lock_class mr_lock_class = { .name = "MR-uobj" };
51 static struct uverbs_lock_class cq_lock_class = { .name = "CQ-uobj" };
52 static struct uverbs_lock_class qp_lock_class = { .name = "QP-uobj" };
53 static struct uverbs_lock_class ah_lock_class = { .name = "AH-uobj" };
54 static struct uverbs_lock_class srq_lock_class = { .name = "SRQ-uobj" };
55 static struct uverbs_lock_class xrcd_lock_class = { .name = "XRCD-uobj" };
57 #define INIT_UDATA(udata, ibuf, obuf, ilen, olen) \
59 (udata)->inbuf = (void __user *) (ibuf); \
60 (udata)->outbuf = (void __user *) (obuf); \
61 (udata)->inlen = (ilen); \
62 (udata)->outlen = (olen); \
66 * The ib_uobject locking scheme is as follows:
68 * - ib_uverbs_idr_lock protects the uverbs idrs themselves, so it
69 * needs to be held during all idr operations. When an object is
70 * looked up, a reference must be taken on the object's kref before
73 * - Each object also has an rwsem. This rwsem must be held for
74 * reading while an operation that uses the object is performed.
75 * For example, while registering an MR, the associated PD's
76 * uobject.mutex must be held for reading. The rwsem must be held
77 * for writing while initializing or destroying an object.
79 * - In addition, each object has a "live" flag. If this flag is not
80 * set, then lookups of the object will fail even if it is found in
81 * the idr. This handles a reader that blocks and does not acquire
82 * the rwsem until after the object is destroyed. The destroy
83 * operation will set the live flag to 0 and then drop the rwsem;
84 * this will allow the reader to acquire the rwsem, see that the
85 * live flag is 0, and then drop the rwsem and its reference to
86 * object. The underlying storage will not be freed until the last
87 * reference to the object is dropped.
90 static void init_uobj(struct ib_uobject *uobj, u64 user_handle,
91 struct ib_ucontext *context, struct uverbs_lock_class *c)
93 uobj->user_handle = user_handle;
94 uobj->context = context;
95 kref_init(&uobj->ref);
96 init_rwsem(&uobj->mutex);
97 lockdep_set_class_and_name(&uobj->mutex, &c->key, c->name);
101 static void release_uobj(struct kref *kref)
103 kfree(container_of(kref, struct ib_uobject, ref));
106 static void put_uobj(struct ib_uobject *uobj)
108 kref_put(&uobj->ref, release_uobj);
111 static void put_uobj_read(struct ib_uobject *uobj)
113 up_read(&uobj->mutex);
117 static void put_uobj_write(struct ib_uobject *uobj)
119 up_write(&uobj->mutex);
123 static int idr_add_uobj(struct idr *idr, struct ib_uobject *uobj)
128 if (!idr_pre_get(idr, GFP_KERNEL))
131 spin_lock(&ib_uverbs_idr_lock);
132 ret = idr_get_new(idr, uobj, &uobj->id);
133 spin_unlock(&ib_uverbs_idr_lock);
141 void idr_remove_uobj(struct idr *idr, struct ib_uobject *uobj)
143 spin_lock(&ib_uverbs_idr_lock);
144 idr_remove(idr, uobj->id);
145 spin_unlock(&ib_uverbs_idr_lock);
148 static struct ib_uobject *__idr_get_uobj(struct idr *idr, int id,
149 struct ib_ucontext *context)
151 struct ib_uobject *uobj;
153 spin_lock(&ib_uverbs_idr_lock);
154 uobj = idr_find(idr, id);
156 if (uobj->context == context)
157 kref_get(&uobj->ref);
161 spin_unlock(&ib_uverbs_idr_lock);
166 static struct ib_uobject *idr_read_uobj(struct idr *idr, int id,
167 struct ib_ucontext *context, int nested)
169 struct ib_uobject *uobj;
171 uobj = __idr_get_uobj(idr, id, context);
176 down_read_nested(&uobj->mutex, SINGLE_DEPTH_NESTING);
178 down_read(&uobj->mutex);
187 static struct ib_uobject *idr_write_uobj(struct idr *idr, int id,
188 struct ib_ucontext *context)
190 struct ib_uobject *uobj;
192 uobj = __idr_get_uobj(idr, id, context);
196 down_write(&uobj->mutex);
198 put_uobj_write(uobj);
205 static void *idr_read_obj(struct idr *idr, int id, struct ib_ucontext *context,
208 struct ib_uobject *uobj;
210 uobj = idr_read_uobj(idr, id, context, nested);
211 return uobj ? uobj->object : NULL;
214 static struct ib_pd *idr_read_pd(int pd_handle, struct ib_ucontext *context)
216 return idr_read_obj(&ib_uverbs_pd_idr, pd_handle, context, 0);
219 static void put_pd_read(struct ib_pd *pd)
221 put_uobj_read(pd->uobject);
224 static struct ib_cq *idr_read_cq(int cq_handle, struct ib_ucontext *context, int nested)
226 return idr_read_obj(&ib_uverbs_cq_idr, cq_handle, context, nested);
229 static void put_cq_read(struct ib_cq *cq)
231 put_uobj_read(cq->uobject);
234 static struct ib_ah *idr_read_ah(int ah_handle, struct ib_ucontext *context)
236 return idr_read_obj(&ib_uverbs_ah_idr, ah_handle, context, 0);
239 static void put_ah_read(struct ib_ah *ah)
241 put_uobj_read(ah->uobject);
244 static struct ib_qp *idr_read_qp(int qp_handle, struct ib_ucontext *context)
246 return idr_read_obj(&ib_uverbs_qp_idr, qp_handle, context, 0);
249 static struct ib_qp *idr_write_qp(int qp_handle, struct ib_ucontext *context)
251 struct ib_uobject *uobj;
253 uobj = idr_write_uobj(&ib_uverbs_qp_idr, qp_handle, context);
254 return uobj ? uobj->object : NULL;
257 static void put_qp_read(struct ib_qp *qp)
259 put_uobj_read(qp->uobject);
262 static void put_qp_write(struct ib_qp *qp)
264 put_uobj_write(qp->uobject);
267 static struct ib_srq *idr_read_srq(int srq_handle, struct ib_ucontext *context)
269 return idr_read_obj(&ib_uverbs_srq_idr, srq_handle, context, 0);
272 static void put_srq_read(struct ib_srq *srq)
274 put_uobj_read(srq->uobject);
277 static struct ib_xrcd *idr_read_xrcd(int xrcd_handle, struct ib_ucontext *context,
278 struct ib_uobject **uobj)
280 *uobj = idr_read_uobj(&ib_uverbs_xrcd_idr, xrcd_handle, context, 0);
281 return *uobj ? (*uobj)->object : NULL;
284 static void put_xrcd_read(struct ib_uobject *uobj)
289 ssize_t ib_uverbs_get_context(struct ib_uverbs_file *file,
290 const char __user *buf,
291 int in_len, int out_len)
293 struct ib_uverbs_get_context cmd;
294 struct ib_uverbs_get_context_resp resp;
295 struct ib_udata udata;
296 struct ib_device *ibdev = file->device->ib_dev;
297 struct ib_ucontext *ucontext;
301 if (out_len < sizeof resp)
304 if (copy_from_user(&cmd, buf, sizeof cmd))
307 mutex_lock(&file->mutex);
309 if (file->ucontext) {
314 INIT_UDATA(&udata, buf + sizeof cmd,
315 (unsigned long) cmd.response + sizeof resp,
316 in_len - sizeof cmd, out_len - sizeof resp);
318 ucontext = ibdev->alloc_ucontext(ibdev, &udata);
319 if (IS_ERR(ucontext)) {
320 ret = PTR_ERR(ucontext);
324 ucontext->device = ibdev;
325 INIT_LIST_HEAD(&ucontext->pd_list);
326 INIT_LIST_HEAD(&ucontext->mr_list);
327 INIT_LIST_HEAD(&ucontext->mw_list);
328 INIT_LIST_HEAD(&ucontext->cq_list);
329 INIT_LIST_HEAD(&ucontext->qp_list);
330 INIT_LIST_HEAD(&ucontext->srq_list);
331 INIT_LIST_HEAD(&ucontext->ah_list);
332 INIT_LIST_HEAD(&ucontext->xrcd_list);
333 ucontext->closing = 0;
335 resp.num_comp_vectors = file->device->num_comp_vectors;
337 ret = get_unused_fd();
342 filp = ib_uverbs_alloc_event_file(file, 1);
348 if (copy_to_user((void __user *) (unsigned long) cmd.response,
349 &resp, sizeof resp)) {
354 file->async_file = filp->private_data;
356 INIT_IB_EVENT_HANDLER(&file->event_handler, file->device->ib_dev,
357 ib_uverbs_event_handler);
358 ret = ib_register_event_handler(&file->event_handler);
362 kref_get(&file->async_file->ref);
363 kref_get(&file->ref);
364 file->ucontext = ucontext;
366 fd_install(resp.async_fd, filp);
368 mutex_unlock(&file->mutex);
376 put_unused_fd(resp.async_fd);
379 ibdev->dealloc_ucontext(ucontext);
382 mutex_unlock(&file->mutex);
386 ssize_t ib_uverbs_query_device(struct ib_uverbs_file *file,
387 const char __user *buf,
388 int in_len, int out_len)
390 struct ib_uverbs_query_device cmd;
391 struct ib_uverbs_query_device_resp resp;
392 struct ib_device_attr attr;
395 if (out_len < sizeof resp)
398 if (copy_from_user(&cmd, buf, sizeof cmd))
401 ret = ib_query_device(file->device->ib_dev, &attr);
405 memset(&resp, 0, sizeof resp);
407 resp.fw_ver = attr.fw_ver;
408 resp.node_guid = file->device->ib_dev->node_guid;
409 resp.sys_image_guid = attr.sys_image_guid;
410 resp.max_mr_size = attr.max_mr_size;
411 resp.page_size_cap = attr.page_size_cap;
412 resp.vendor_id = attr.vendor_id;
413 resp.vendor_part_id = attr.vendor_part_id;
414 resp.hw_ver = attr.hw_ver;
415 resp.max_qp = attr.max_qp;
416 resp.max_qp_wr = attr.max_qp_wr;
417 resp.device_cap_flags = attr.device_cap_flags;
418 resp.max_sge = attr.max_sge;
419 resp.max_sge_rd = attr.max_sge_rd;
420 resp.max_cq = attr.max_cq;
421 resp.max_cqe = attr.max_cqe;
422 resp.max_mr = attr.max_mr;
423 resp.max_pd = attr.max_pd;
424 resp.max_qp_rd_atom = attr.max_qp_rd_atom;
425 resp.max_ee_rd_atom = attr.max_ee_rd_atom;
426 resp.max_res_rd_atom = attr.max_res_rd_atom;
427 resp.max_qp_init_rd_atom = attr.max_qp_init_rd_atom;
428 resp.max_ee_init_rd_atom = attr.max_ee_init_rd_atom;
429 resp.atomic_cap = attr.atomic_cap;
430 resp.max_ee = attr.max_ee;
431 resp.max_rdd = attr.max_rdd;
432 resp.max_mw = attr.max_mw;
433 resp.max_raw_ipv6_qp = attr.max_raw_ipv6_qp;
434 resp.max_raw_ethy_qp = attr.max_raw_ethy_qp;
435 resp.max_mcast_grp = attr.max_mcast_grp;
436 resp.max_mcast_qp_attach = attr.max_mcast_qp_attach;
437 resp.max_total_mcast_qp_attach = attr.max_total_mcast_qp_attach;
438 resp.max_ah = attr.max_ah;
439 resp.max_fmr = attr.max_fmr;
440 resp.max_map_per_fmr = attr.max_map_per_fmr;
441 resp.max_srq = attr.max_srq;
442 resp.max_srq_wr = attr.max_srq_wr;
443 resp.max_srq_sge = attr.max_srq_sge;
444 resp.max_pkeys = attr.max_pkeys;
445 resp.local_ca_ack_delay = attr.local_ca_ack_delay;
446 resp.phys_port_cnt = file->device->ib_dev->phys_port_cnt;
448 if (copy_to_user((void __user *) (unsigned long) cmd.response,
455 ssize_t ib_uverbs_query_port(struct ib_uverbs_file *file,
456 const char __user *buf,
457 int in_len, int out_len)
459 struct ib_uverbs_query_port cmd;
460 struct ib_uverbs_query_port_resp resp;
461 struct ib_port_attr attr;
464 if (out_len < sizeof resp)
467 if (copy_from_user(&cmd, buf, sizeof cmd))
470 ret = ib_query_port(file->device->ib_dev, cmd.port_num, &attr);
474 memset(&resp, 0, sizeof resp);
476 resp.state = attr.state;
477 resp.max_mtu = attr.max_mtu;
478 resp.active_mtu = attr.active_mtu;
479 resp.gid_tbl_len = attr.gid_tbl_len;
480 resp.port_cap_flags = attr.port_cap_flags;
481 resp.max_msg_sz = attr.max_msg_sz;
482 resp.bad_pkey_cntr = attr.bad_pkey_cntr;
483 resp.qkey_viol_cntr = attr.qkey_viol_cntr;
484 resp.pkey_tbl_len = attr.pkey_tbl_len;
486 resp.sm_lid = attr.sm_lid;
488 resp.max_vl_num = attr.max_vl_num;
489 resp.sm_sl = attr.sm_sl;
490 resp.subnet_timeout = attr.subnet_timeout;
491 resp.init_type_reply = attr.init_type_reply;
492 resp.active_width = attr.active_width;
493 resp.active_speed = attr.active_speed;
494 resp.phys_state = attr.phys_state;
495 resp.link_layer = rdma_port_get_link_layer(file->device->ib_dev,
498 if (copy_to_user((void __user *) (unsigned long) cmd.response,
505 ssize_t ib_uverbs_alloc_pd(struct ib_uverbs_file *file,
506 const char __user *buf,
507 int in_len, int out_len)
509 struct ib_uverbs_alloc_pd cmd;
510 struct ib_uverbs_alloc_pd_resp resp;
511 struct ib_udata udata;
512 struct ib_uobject *uobj;
516 if (out_len < sizeof resp)
519 if (copy_from_user(&cmd, buf, sizeof cmd))
522 INIT_UDATA(&udata, buf + sizeof cmd,
523 (unsigned long) cmd.response + sizeof resp,
524 in_len - sizeof cmd, out_len - sizeof resp);
526 uobj = kmalloc(sizeof *uobj, GFP_KERNEL);
530 init_uobj(uobj, 0, file->ucontext, &pd_lock_class);
531 down_write(&uobj->mutex);
533 pd = file->device->ib_dev->alloc_pd(file->device->ib_dev,
534 file->ucontext, &udata);
540 pd->device = file->device->ib_dev;
542 atomic_set(&pd->usecnt, 0);
545 ret = idr_add_uobj(&ib_uverbs_pd_idr, uobj);
549 memset(&resp, 0, sizeof resp);
550 resp.pd_handle = uobj->id;
552 if (copy_to_user((void __user *) (unsigned long) cmd.response,
553 &resp, sizeof resp)) {
558 mutex_lock(&file->mutex);
559 list_add_tail(&uobj->list, &file->ucontext->pd_list);
560 mutex_unlock(&file->mutex);
564 up_write(&uobj->mutex);
569 idr_remove_uobj(&ib_uverbs_pd_idr, uobj);
575 put_uobj_write(uobj);
579 ssize_t ib_uverbs_dealloc_pd(struct ib_uverbs_file *file,
580 const char __user *buf,
581 int in_len, int out_len)
583 struct ib_uverbs_dealloc_pd cmd;
584 struct ib_uobject *uobj;
587 if (copy_from_user(&cmd, buf, sizeof cmd))
590 uobj = idr_write_uobj(&ib_uverbs_pd_idr, cmd.pd_handle, file->ucontext);
594 ret = ib_dealloc_pd(uobj->object);
598 put_uobj_write(uobj);
603 idr_remove_uobj(&ib_uverbs_pd_idr, uobj);
605 mutex_lock(&file->mutex);
606 list_del(&uobj->list);
607 mutex_unlock(&file->mutex);
614 struct xrcd_table_entry {
616 struct ib_xrcd *xrcd;
620 static int xrcd_table_insert(struct ib_uverbs_device *dev,
622 struct ib_xrcd *xrcd)
624 struct xrcd_table_entry *entry, *scan;
625 struct rb_node **p = &dev->xrcd_tree.rb_node;
626 struct rb_node *parent = NULL;
628 entry = kmalloc(sizeof *entry, GFP_KERNEL);
633 entry->inode = inode;
637 scan = rb_entry(parent, struct xrcd_table_entry, node);
639 if (inode < scan->inode) {
641 } else if (inode > scan->inode) {
649 rb_link_node(&entry->node, parent, p);
650 rb_insert_color(&entry->node, &dev->xrcd_tree);
655 static struct xrcd_table_entry *xrcd_table_search(struct ib_uverbs_device *dev,
658 struct xrcd_table_entry *entry;
659 struct rb_node *p = dev->xrcd_tree.rb_node;
662 entry = rb_entry(p, struct xrcd_table_entry, node);
664 if (inode < entry->inode)
666 else if (inode > entry->inode)
675 static struct ib_xrcd *find_xrcd(struct ib_uverbs_device *dev, struct inode *inode)
677 struct xrcd_table_entry *entry;
679 entry = xrcd_table_search(dev, inode);
686 static void xrcd_table_delete(struct ib_uverbs_device *dev,
689 struct xrcd_table_entry *entry;
691 entry = xrcd_table_search(dev, inode);
694 rb_erase(&entry->node, &dev->xrcd_tree);
699 ssize_t ib_uverbs_open_xrcd(struct ib_uverbs_file *file,
700 const char __user *buf, int in_len,
703 struct ib_uverbs_open_xrcd cmd;
704 struct ib_uverbs_open_xrcd_resp resp;
705 struct ib_udata udata;
706 struct ib_uxrcd_object *obj;
707 struct ib_xrcd *xrcd = NULL;
708 struct fd f = {NULL, 0};
709 struct inode *inode = NULL;
713 if (out_len < sizeof resp)
716 if (copy_from_user(&cmd, buf, sizeof cmd))
719 INIT_UDATA(&udata, buf + sizeof cmd,
720 (unsigned long) cmd.response + sizeof resp,
721 in_len - sizeof cmd, out_len - sizeof resp);
723 mutex_lock(&file->device->xrcd_tree_mutex);
726 /* search for file descriptor */
730 goto err_tree_mutex_unlock;
733 inode = f.file->f_path.dentry->d_inode;
734 xrcd = find_xrcd(file->device, inode);
735 if (!xrcd && !(cmd.oflags & O_CREAT)) {
736 /* no file descriptor. Need CREATE flag */
738 goto err_tree_mutex_unlock;
741 if (xrcd && cmd.oflags & O_EXCL) {
743 goto err_tree_mutex_unlock;
747 obj = kmalloc(sizeof *obj, GFP_KERNEL);
750 goto err_tree_mutex_unlock;
753 init_uobj(&obj->uobject, 0, file->ucontext, &xrcd_lock_class);
755 down_write(&obj->uobject.mutex);
758 xrcd = file->device->ib_dev->alloc_xrcd(file->device->ib_dev,
759 file->ucontext, &udata);
766 xrcd->device = file->device->ib_dev;
767 atomic_set(&xrcd->usecnt, 0);
768 mutex_init(&xrcd->tgt_qp_mutex);
769 INIT_LIST_HEAD(&xrcd->tgt_qp_list);
773 atomic_set(&obj->refcnt, 0);
774 obj->uobject.object = xrcd;
775 ret = idr_add_uobj(&ib_uverbs_xrcd_idr, &obj->uobject);
779 memset(&resp, 0, sizeof resp);
780 resp.xrcd_handle = obj->uobject.id;
784 /* create new inode/xrcd table entry */
785 ret = xrcd_table_insert(file->device, inode, xrcd);
787 goto err_insert_xrcd;
789 atomic_inc(&xrcd->usecnt);
792 if (copy_to_user((void __user *) (unsigned long) cmd.response,
793 &resp, sizeof resp)) {
801 mutex_lock(&file->mutex);
802 list_add_tail(&obj->uobject.list, &file->ucontext->xrcd_list);
803 mutex_unlock(&file->mutex);
805 obj->uobject.live = 1;
806 up_write(&obj->uobject.mutex);
808 mutex_unlock(&file->device->xrcd_tree_mutex);
814 xrcd_table_delete(file->device, inode);
815 atomic_dec(&xrcd->usecnt);
819 idr_remove_uobj(&ib_uverbs_xrcd_idr, &obj->uobject);
822 ib_dealloc_xrcd(xrcd);
825 put_uobj_write(&obj->uobject);
827 err_tree_mutex_unlock:
831 mutex_unlock(&file->device->xrcd_tree_mutex);
836 ssize_t ib_uverbs_close_xrcd(struct ib_uverbs_file *file,
837 const char __user *buf, int in_len,
840 struct ib_uverbs_close_xrcd cmd;
841 struct ib_uobject *uobj;
842 struct ib_xrcd *xrcd = NULL;
843 struct inode *inode = NULL;
844 struct ib_uxrcd_object *obj;
848 if (copy_from_user(&cmd, buf, sizeof cmd))
851 mutex_lock(&file->device->xrcd_tree_mutex);
852 uobj = idr_write_uobj(&ib_uverbs_xrcd_idr, cmd.xrcd_handle, file->ucontext);
860 obj = container_of(uobj, struct ib_uxrcd_object, uobject);
861 if (atomic_read(&obj->refcnt)) {
862 put_uobj_write(uobj);
867 if (!inode || atomic_dec_and_test(&xrcd->usecnt)) {
868 ret = ib_dealloc_xrcd(uobj->object);
875 atomic_inc(&xrcd->usecnt);
877 put_uobj_write(uobj);
883 xrcd_table_delete(file->device, inode);
885 idr_remove_uobj(&ib_uverbs_xrcd_idr, uobj);
886 mutex_lock(&file->mutex);
887 list_del(&uobj->list);
888 mutex_unlock(&file->mutex);
894 mutex_unlock(&file->device->xrcd_tree_mutex);
898 void ib_uverbs_dealloc_xrcd(struct ib_uverbs_device *dev,
899 struct ib_xrcd *xrcd)
904 if (inode && !atomic_dec_and_test(&xrcd->usecnt))
907 ib_dealloc_xrcd(xrcd);
910 xrcd_table_delete(dev, inode);
913 ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file,
914 const char __user *buf, int in_len,
917 struct ib_uverbs_reg_mr cmd;
918 struct ib_uverbs_reg_mr_resp resp;
919 struct ib_udata udata;
920 struct ib_uobject *uobj;
925 if (out_len < sizeof resp)
928 if (copy_from_user(&cmd, buf, sizeof cmd))
931 INIT_UDATA(&udata, buf + sizeof cmd,
932 (unsigned long) cmd.response + sizeof resp,
933 in_len - sizeof cmd, out_len - sizeof resp);
935 if ((cmd.start & ~PAGE_MASK) != (cmd.hca_va & ~PAGE_MASK))
939 * Local write permission is required if remote write or
940 * remote atomic permission is also requested.
942 if (cmd.access_flags & (IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_REMOTE_WRITE) &&
943 !(cmd.access_flags & IB_ACCESS_LOCAL_WRITE))
946 uobj = kmalloc(sizeof *uobj, GFP_KERNEL);
950 init_uobj(uobj, 0, file->ucontext, &mr_lock_class);
951 down_write(&uobj->mutex);
953 pd = idr_read_pd(cmd.pd_handle, file->ucontext);
959 mr = pd->device->reg_user_mr(pd, cmd.start, cmd.length, cmd.hca_va,
960 cmd.access_flags, &udata);
966 mr->device = pd->device;
969 atomic_inc(&pd->usecnt);
970 atomic_set(&mr->usecnt, 0);
973 ret = idr_add_uobj(&ib_uverbs_mr_idr, uobj);
977 memset(&resp, 0, sizeof resp);
978 resp.lkey = mr->lkey;
979 resp.rkey = mr->rkey;
980 resp.mr_handle = uobj->id;
982 if (copy_to_user((void __user *) (unsigned long) cmd.response,
983 &resp, sizeof resp)) {
990 mutex_lock(&file->mutex);
991 list_add_tail(&uobj->list, &file->ucontext->mr_list);
992 mutex_unlock(&file->mutex);
996 up_write(&uobj->mutex);
1001 idr_remove_uobj(&ib_uverbs_mr_idr, uobj);
1010 put_uobj_write(uobj);
1014 ssize_t ib_uverbs_dereg_mr(struct ib_uverbs_file *file,
1015 const char __user *buf, int in_len,
1018 struct ib_uverbs_dereg_mr cmd;
1020 struct ib_uobject *uobj;
1023 if (copy_from_user(&cmd, buf, sizeof cmd))
1026 uobj = idr_write_uobj(&ib_uverbs_mr_idr, cmd.mr_handle, file->ucontext);
1032 ret = ib_dereg_mr(mr);
1036 put_uobj_write(uobj);
1041 idr_remove_uobj(&ib_uverbs_mr_idr, uobj);
1043 mutex_lock(&file->mutex);
1044 list_del(&uobj->list);
1045 mutex_unlock(&file->mutex);
1052 ssize_t ib_uverbs_create_comp_channel(struct ib_uverbs_file *file,
1053 const char __user *buf, int in_len,
1056 struct ib_uverbs_create_comp_channel cmd;
1057 struct ib_uverbs_create_comp_channel_resp resp;
1061 if (out_len < sizeof resp)
1064 if (copy_from_user(&cmd, buf, sizeof cmd))
1067 ret = get_unused_fd();
1072 filp = ib_uverbs_alloc_event_file(file, 0);
1074 put_unused_fd(resp.fd);
1075 return PTR_ERR(filp);
1078 if (copy_to_user((void __user *) (unsigned long) cmd.response,
1079 &resp, sizeof resp)) {
1080 put_unused_fd(resp.fd);
1085 fd_install(resp.fd, filp);
1089 ssize_t ib_uverbs_create_cq(struct ib_uverbs_file *file,
1090 const char __user *buf, int in_len,
1093 struct ib_uverbs_create_cq cmd;
1094 struct ib_uverbs_create_cq_resp resp;
1095 struct ib_udata udata;
1096 struct ib_ucq_object *obj;
1097 struct ib_uverbs_event_file *ev_file = NULL;
1101 if (out_len < sizeof resp)
1104 if (copy_from_user(&cmd, buf, sizeof cmd))
1107 INIT_UDATA(&udata, buf + sizeof cmd,
1108 (unsigned long) cmd.response + sizeof resp,
1109 in_len - sizeof cmd, out_len - sizeof resp);
1111 if (cmd.comp_vector >= file->device->num_comp_vectors)
1114 obj = kmalloc(sizeof *obj, GFP_KERNEL);
1118 init_uobj(&obj->uobject, cmd.user_handle, file->ucontext, &cq_lock_class);
1119 down_write(&obj->uobject.mutex);
1121 if (cmd.comp_channel >= 0) {
1122 ev_file = ib_uverbs_lookup_comp_file(cmd.comp_channel);
1129 obj->uverbs_file = file;
1130 obj->comp_events_reported = 0;
1131 obj->async_events_reported = 0;
1132 INIT_LIST_HEAD(&obj->comp_list);
1133 INIT_LIST_HEAD(&obj->async_list);
1135 cq = file->device->ib_dev->create_cq(file->device->ib_dev, cmd.cqe,
1137 file->ucontext, &udata);
1143 cq->device = file->device->ib_dev;
1144 cq->uobject = &obj->uobject;
1145 cq->comp_handler = ib_uverbs_comp_handler;
1146 cq->event_handler = ib_uverbs_cq_event_handler;
1147 cq->cq_context = ev_file;
1148 atomic_set(&cq->usecnt, 0);
1150 obj->uobject.object = cq;
1151 ret = idr_add_uobj(&ib_uverbs_cq_idr, &obj->uobject);
1155 memset(&resp, 0, sizeof resp);
1156 resp.cq_handle = obj->uobject.id;
1159 if (copy_to_user((void __user *) (unsigned long) cmd.response,
1160 &resp, sizeof resp)) {
1165 mutex_lock(&file->mutex);
1166 list_add_tail(&obj->uobject.list, &file->ucontext->cq_list);
1167 mutex_unlock(&file->mutex);
1169 obj->uobject.live = 1;
1171 up_write(&obj->uobject.mutex);
1176 idr_remove_uobj(&ib_uverbs_cq_idr, &obj->uobject);
1183 ib_uverbs_release_ucq(file, ev_file, obj);
1186 put_uobj_write(&obj->uobject);
1190 ssize_t ib_uverbs_resize_cq(struct ib_uverbs_file *file,
1191 const char __user *buf, int in_len,
1194 struct ib_uverbs_resize_cq cmd;
1195 struct ib_uverbs_resize_cq_resp resp;
1196 struct ib_udata udata;
1200 if (copy_from_user(&cmd, buf, sizeof cmd))
1203 INIT_UDATA(&udata, buf + sizeof cmd,
1204 (unsigned long) cmd.response + sizeof resp,
1205 in_len - sizeof cmd, out_len - sizeof resp);
1207 cq = idr_read_cq(cmd.cq_handle, file->ucontext, 0);
1211 ret = cq->device->resize_cq(cq, cmd.cqe, &udata);
1217 if (copy_to_user((void __user *) (unsigned long) cmd.response,
1218 &resp, sizeof resp.cqe))
1224 return ret ? ret : in_len;
1227 static int copy_wc_to_user(void __user *dest, struct ib_wc *wc)
1229 struct ib_uverbs_wc tmp;
1231 tmp.wr_id = wc->wr_id;
1232 tmp.status = wc->status;
1233 tmp.opcode = wc->opcode;
1234 tmp.vendor_err = wc->vendor_err;
1235 tmp.byte_len = wc->byte_len;
1236 tmp.ex.imm_data = (__u32 __force) wc->ex.imm_data;
1237 tmp.qp_num = wc->qp->qp_num;
1238 tmp.src_qp = wc->src_qp;
1239 tmp.wc_flags = wc->wc_flags;
1240 tmp.pkey_index = wc->pkey_index;
1241 tmp.slid = wc->slid;
1243 tmp.dlid_path_bits = wc->dlid_path_bits;
1244 tmp.port_num = wc->port_num;
1247 if (copy_to_user(dest, &tmp, sizeof tmp))
1253 ssize_t ib_uverbs_poll_cq(struct ib_uverbs_file *file,
1254 const char __user *buf, int in_len,
1257 struct ib_uverbs_poll_cq cmd;
1258 struct ib_uverbs_poll_cq_resp resp;
1259 u8 __user *header_ptr;
1260 u8 __user *data_ptr;
1265 if (copy_from_user(&cmd, buf, sizeof cmd))
1268 cq = idr_read_cq(cmd.cq_handle, file->ucontext, 0);
1272 /* we copy a struct ib_uverbs_poll_cq_resp to user space */
1273 header_ptr = (void __user *)(unsigned long) cmd.response;
1274 data_ptr = header_ptr + sizeof resp;
1276 memset(&resp, 0, sizeof resp);
1277 while (resp.count < cmd.ne) {
1278 ret = ib_poll_cq(cq, 1, &wc);
1284 ret = copy_wc_to_user(data_ptr, &wc);
1288 data_ptr += sizeof(struct ib_uverbs_wc);
1292 if (copy_to_user(header_ptr, &resp, sizeof resp)) {
1304 ssize_t ib_uverbs_req_notify_cq(struct ib_uverbs_file *file,
1305 const char __user *buf, int in_len,
1308 struct ib_uverbs_req_notify_cq cmd;
1311 if (copy_from_user(&cmd, buf, sizeof cmd))
1314 cq = idr_read_cq(cmd.cq_handle, file->ucontext, 0);
1318 ib_req_notify_cq(cq, cmd.solicited_only ?
1319 IB_CQ_SOLICITED : IB_CQ_NEXT_COMP);
1326 ssize_t ib_uverbs_destroy_cq(struct ib_uverbs_file *file,
1327 const char __user *buf, int in_len,
1330 struct ib_uverbs_destroy_cq cmd;
1331 struct ib_uverbs_destroy_cq_resp resp;
1332 struct ib_uobject *uobj;
1334 struct ib_ucq_object *obj;
1335 struct ib_uverbs_event_file *ev_file;
1338 if (copy_from_user(&cmd, buf, sizeof cmd))
1341 uobj = idr_write_uobj(&ib_uverbs_cq_idr, cmd.cq_handle, file->ucontext);
1345 ev_file = cq->cq_context;
1346 obj = container_of(cq->uobject, struct ib_ucq_object, uobject);
1348 ret = ib_destroy_cq(cq);
1352 put_uobj_write(uobj);
1357 idr_remove_uobj(&ib_uverbs_cq_idr, uobj);
1359 mutex_lock(&file->mutex);
1360 list_del(&uobj->list);
1361 mutex_unlock(&file->mutex);
1363 ib_uverbs_release_ucq(file, ev_file, obj);
1365 memset(&resp, 0, sizeof resp);
1366 resp.comp_events_reported = obj->comp_events_reported;
1367 resp.async_events_reported = obj->async_events_reported;
1371 if (copy_to_user((void __user *) (unsigned long) cmd.response,
1372 &resp, sizeof resp))
1378 ssize_t ib_uverbs_create_qp(struct ib_uverbs_file *file,
1379 const char __user *buf, int in_len,
1382 struct ib_uverbs_create_qp cmd;
1383 struct ib_uverbs_create_qp_resp resp;
1384 struct ib_udata udata;
1385 struct ib_uqp_object *obj;
1386 struct ib_device *device;
1387 struct ib_pd *pd = NULL;
1388 struct ib_xrcd *xrcd = NULL;
1389 struct ib_uobject *uninitialized_var(xrcd_uobj);
1390 struct ib_cq *scq = NULL, *rcq = NULL;
1391 struct ib_srq *srq = NULL;
1393 struct ib_qp_init_attr attr;
1396 if (out_len < sizeof resp)
1399 if (copy_from_user(&cmd, buf, sizeof cmd))
1402 if (cmd.qp_type == IB_QPT_RAW_PACKET && !capable(CAP_NET_RAW))
1405 INIT_UDATA(&udata, buf + sizeof cmd,
1406 (unsigned long) cmd.response + sizeof resp,
1407 in_len - sizeof cmd, out_len - sizeof resp);
1409 obj = kmalloc(sizeof *obj, GFP_KERNEL);
1413 init_uobj(&obj->uevent.uobject, cmd.user_handle, file->ucontext, &qp_lock_class);
1414 down_write(&obj->uevent.uobject.mutex);
1416 if (cmd.qp_type == IB_QPT_XRC_TGT) {
1417 xrcd = idr_read_xrcd(cmd.pd_handle, file->ucontext, &xrcd_uobj);
1422 device = xrcd->device;
1424 if (cmd.qp_type == IB_QPT_XRC_INI) {
1425 cmd.max_recv_wr = cmd.max_recv_sge = 0;
1428 srq = idr_read_srq(cmd.srq_handle, file->ucontext);
1429 if (!srq || srq->srq_type != IB_SRQT_BASIC) {
1435 if (cmd.recv_cq_handle != cmd.send_cq_handle) {
1436 rcq = idr_read_cq(cmd.recv_cq_handle, file->ucontext, 0);
1444 scq = idr_read_cq(cmd.send_cq_handle, file->ucontext, !!rcq);
1446 pd = idr_read_pd(cmd.pd_handle, file->ucontext);
1452 device = pd->device;
1455 attr.event_handler = ib_uverbs_qp_event_handler;
1456 attr.qp_context = file;
1461 attr.sq_sig_type = cmd.sq_sig_all ? IB_SIGNAL_ALL_WR : IB_SIGNAL_REQ_WR;
1462 attr.qp_type = cmd.qp_type;
1463 attr.create_flags = 0;
1465 attr.cap.max_send_wr = cmd.max_send_wr;
1466 attr.cap.max_recv_wr = cmd.max_recv_wr;
1467 attr.cap.max_send_sge = cmd.max_send_sge;
1468 attr.cap.max_recv_sge = cmd.max_recv_sge;
1469 attr.cap.max_inline_data = cmd.max_inline_data;
1471 obj->uevent.events_reported = 0;
1472 INIT_LIST_HEAD(&obj->uevent.event_list);
1473 INIT_LIST_HEAD(&obj->mcast_list);
1475 if (cmd.qp_type == IB_QPT_XRC_TGT)
1476 qp = ib_create_qp(pd, &attr);
1478 qp = device->create_qp(pd, &attr, &udata);
1485 if (cmd.qp_type != IB_QPT_XRC_TGT) {
1487 qp->device = device;
1489 qp->send_cq = attr.send_cq;
1490 qp->recv_cq = attr.recv_cq;
1492 qp->event_handler = attr.event_handler;
1493 qp->qp_context = attr.qp_context;
1494 qp->qp_type = attr.qp_type;
1495 atomic_set(&qp->usecnt, 0);
1496 atomic_inc(&pd->usecnt);
1497 atomic_inc(&attr.send_cq->usecnt);
1499 atomic_inc(&attr.recv_cq->usecnt);
1501 atomic_inc(&attr.srq->usecnt);
1503 qp->uobject = &obj->uevent.uobject;
1505 obj->uevent.uobject.object = qp;
1506 ret = idr_add_uobj(&ib_uverbs_qp_idr, &obj->uevent.uobject);
1510 memset(&resp, 0, sizeof resp);
1511 resp.qpn = qp->qp_num;
1512 resp.qp_handle = obj->uevent.uobject.id;
1513 resp.max_recv_sge = attr.cap.max_recv_sge;
1514 resp.max_send_sge = attr.cap.max_send_sge;
1515 resp.max_recv_wr = attr.cap.max_recv_wr;
1516 resp.max_send_wr = attr.cap.max_send_wr;
1517 resp.max_inline_data = attr.cap.max_inline_data;
1519 if (copy_to_user((void __user *) (unsigned long) cmd.response,
1520 &resp, sizeof resp)) {
1526 put_xrcd_read(xrcd_uobj);
1531 if (rcq && rcq != scq)
1536 mutex_lock(&file->mutex);
1537 list_add_tail(&obj->uevent.uobject.list, &file->ucontext->qp_list);
1538 mutex_unlock(&file->mutex);
1540 obj->uevent.uobject.live = 1;
1542 up_write(&obj->uevent.uobject.mutex);
1547 idr_remove_uobj(&ib_uverbs_qp_idr, &obj->uevent.uobject);
1554 put_xrcd_read(xrcd_uobj);
1559 if (rcq && rcq != scq)
1564 put_uobj_write(&obj->uevent.uobject);
1568 ssize_t ib_uverbs_open_qp(struct ib_uverbs_file *file,
1569 const char __user *buf, int in_len, int out_len)
1571 struct ib_uverbs_open_qp cmd;
1572 struct ib_uverbs_create_qp_resp resp;
1573 struct ib_udata udata;
1574 struct ib_uqp_object *obj;
1575 struct ib_xrcd *xrcd;
1576 struct ib_uobject *uninitialized_var(xrcd_uobj);
1578 struct ib_qp_open_attr attr;
1581 if (out_len < sizeof resp)
1584 if (copy_from_user(&cmd, buf, sizeof cmd))
1587 INIT_UDATA(&udata, buf + sizeof cmd,
1588 (unsigned long) cmd.response + sizeof resp,
1589 in_len - sizeof cmd, out_len - sizeof resp);
1591 obj = kmalloc(sizeof *obj, GFP_KERNEL);
1595 init_uobj(&obj->uevent.uobject, cmd.user_handle, file->ucontext, &qp_lock_class);
1596 down_write(&obj->uevent.uobject.mutex);
1598 xrcd = idr_read_xrcd(cmd.pd_handle, file->ucontext, &xrcd_uobj);
1604 attr.event_handler = ib_uverbs_qp_event_handler;
1605 attr.qp_context = file;
1606 attr.qp_num = cmd.qpn;
1607 attr.qp_type = cmd.qp_type;
1609 obj->uevent.events_reported = 0;
1610 INIT_LIST_HEAD(&obj->uevent.event_list);
1611 INIT_LIST_HEAD(&obj->mcast_list);
1613 qp = ib_open_qp(xrcd, &attr);
1619 qp->uobject = &obj->uevent.uobject;
1621 obj->uevent.uobject.object = qp;
1622 ret = idr_add_uobj(&ib_uverbs_qp_idr, &obj->uevent.uobject);
1626 memset(&resp, 0, sizeof resp);
1627 resp.qpn = qp->qp_num;
1628 resp.qp_handle = obj->uevent.uobject.id;
1630 if (copy_to_user((void __user *) (unsigned long) cmd.response,
1631 &resp, sizeof resp)) {
1636 put_xrcd_read(xrcd_uobj);
1638 mutex_lock(&file->mutex);
1639 list_add_tail(&obj->uevent.uobject.list, &file->ucontext->qp_list);
1640 mutex_unlock(&file->mutex);
1642 obj->uevent.uobject.live = 1;
1644 up_write(&obj->uevent.uobject.mutex);
1649 idr_remove_uobj(&ib_uverbs_qp_idr, &obj->uevent.uobject);
1655 put_xrcd_read(xrcd_uobj);
1656 put_uobj_write(&obj->uevent.uobject);
1660 ssize_t ib_uverbs_query_qp(struct ib_uverbs_file *file,
1661 const char __user *buf, int in_len,
1664 struct ib_uverbs_query_qp cmd;
1665 struct ib_uverbs_query_qp_resp resp;
1667 struct ib_qp_attr *attr;
1668 struct ib_qp_init_attr *init_attr;
1671 if (copy_from_user(&cmd, buf, sizeof cmd))
1674 attr = kmalloc(sizeof *attr, GFP_KERNEL);
1675 init_attr = kmalloc(sizeof *init_attr, GFP_KERNEL);
1676 if (!attr || !init_attr) {
1681 qp = idr_read_qp(cmd.qp_handle, file->ucontext);
1687 ret = ib_query_qp(qp, attr, cmd.attr_mask, init_attr);
1694 memset(&resp, 0, sizeof resp);
1696 resp.qp_state = attr->qp_state;
1697 resp.cur_qp_state = attr->cur_qp_state;
1698 resp.path_mtu = attr->path_mtu;
1699 resp.path_mig_state = attr->path_mig_state;
1700 resp.qkey = attr->qkey;
1701 resp.rq_psn = attr->rq_psn;
1702 resp.sq_psn = attr->sq_psn;
1703 resp.dest_qp_num = attr->dest_qp_num;
1704 resp.qp_access_flags = attr->qp_access_flags;
1705 resp.pkey_index = attr->pkey_index;
1706 resp.alt_pkey_index = attr->alt_pkey_index;
1707 resp.sq_draining = attr->sq_draining;
1708 resp.max_rd_atomic = attr->max_rd_atomic;
1709 resp.max_dest_rd_atomic = attr->max_dest_rd_atomic;
1710 resp.min_rnr_timer = attr->min_rnr_timer;
1711 resp.port_num = attr->port_num;
1712 resp.timeout = attr->timeout;
1713 resp.retry_cnt = attr->retry_cnt;
1714 resp.rnr_retry = attr->rnr_retry;
1715 resp.alt_port_num = attr->alt_port_num;
1716 resp.alt_timeout = attr->alt_timeout;
1718 memcpy(resp.dest.dgid, attr->ah_attr.grh.dgid.raw, 16);
1719 resp.dest.flow_label = attr->ah_attr.grh.flow_label;
1720 resp.dest.sgid_index = attr->ah_attr.grh.sgid_index;
1721 resp.dest.hop_limit = attr->ah_attr.grh.hop_limit;
1722 resp.dest.traffic_class = attr->ah_attr.grh.traffic_class;
1723 resp.dest.dlid = attr->ah_attr.dlid;
1724 resp.dest.sl = attr->ah_attr.sl;
1725 resp.dest.src_path_bits = attr->ah_attr.src_path_bits;
1726 resp.dest.static_rate = attr->ah_attr.static_rate;
1727 resp.dest.is_global = !!(attr->ah_attr.ah_flags & IB_AH_GRH);
1728 resp.dest.port_num = attr->ah_attr.port_num;
1730 memcpy(resp.alt_dest.dgid, attr->alt_ah_attr.grh.dgid.raw, 16);
1731 resp.alt_dest.flow_label = attr->alt_ah_attr.grh.flow_label;
1732 resp.alt_dest.sgid_index = attr->alt_ah_attr.grh.sgid_index;
1733 resp.alt_dest.hop_limit = attr->alt_ah_attr.grh.hop_limit;
1734 resp.alt_dest.traffic_class = attr->alt_ah_attr.grh.traffic_class;
1735 resp.alt_dest.dlid = attr->alt_ah_attr.dlid;
1736 resp.alt_dest.sl = attr->alt_ah_attr.sl;
1737 resp.alt_dest.src_path_bits = attr->alt_ah_attr.src_path_bits;
1738 resp.alt_dest.static_rate = attr->alt_ah_attr.static_rate;
1739 resp.alt_dest.is_global = !!(attr->alt_ah_attr.ah_flags & IB_AH_GRH);
1740 resp.alt_dest.port_num = attr->alt_ah_attr.port_num;
1742 resp.max_send_wr = init_attr->cap.max_send_wr;
1743 resp.max_recv_wr = init_attr->cap.max_recv_wr;
1744 resp.max_send_sge = init_attr->cap.max_send_sge;
1745 resp.max_recv_sge = init_attr->cap.max_recv_sge;
1746 resp.max_inline_data = init_attr->cap.max_inline_data;
1747 resp.sq_sig_all = init_attr->sq_sig_type == IB_SIGNAL_ALL_WR;
1749 if (copy_to_user((void __user *) (unsigned long) cmd.response,
1750 &resp, sizeof resp))
1757 return ret ? ret : in_len;
1760 /* Remove ignored fields set in the attribute mask */
1761 static int modify_qp_mask(enum ib_qp_type qp_type, int mask)
1764 case IB_QPT_XRC_INI:
1765 return mask & ~(IB_QP_MAX_DEST_RD_ATOMIC | IB_QP_MIN_RNR_TIMER);
1766 case IB_QPT_XRC_TGT:
1767 return mask & ~(IB_QP_MAX_QP_RD_ATOMIC | IB_QP_RETRY_CNT |
1774 ssize_t ib_uverbs_modify_qp(struct ib_uverbs_file *file,
1775 const char __user *buf, int in_len,
1778 struct ib_uverbs_modify_qp cmd;
1779 struct ib_udata udata;
1781 struct ib_qp_attr *attr;
1784 if (copy_from_user(&cmd, buf, sizeof cmd))
1787 INIT_UDATA(&udata, buf + sizeof cmd, NULL, in_len - sizeof cmd,
1790 attr = kmalloc(sizeof *attr, GFP_KERNEL);
1794 qp = idr_read_qp(cmd.qp_handle, file->ucontext);
1800 attr->qp_state = cmd.qp_state;
1801 attr->cur_qp_state = cmd.cur_qp_state;
1802 attr->path_mtu = cmd.path_mtu;
1803 attr->path_mig_state = cmd.path_mig_state;
1804 attr->qkey = cmd.qkey;
1805 attr->rq_psn = cmd.rq_psn;
1806 attr->sq_psn = cmd.sq_psn;
1807 attr->dest_qp_num = cmd.dest_qp_num;
1808 attr->qp_access_flags = cmd.qp_access_flags;
1809 attr->pkey_index = cmd.pkey_index;
1810 attr->alt_pkey_index = cmd.alt_pkey_index;
1811 attr->en_sqd_async_notify = cmd.en_sqd_async_notify;
1812 attr->max_rd_atomic = cmd.max_rd_atomic;
1813 attr->max_dest_rd_atomic = cmd.max_dest_rd_atomic;
1814 attr->min_rnr_timer = cmd.min_rnr_timer;
1815 attr->port_num = cmd.port_num;
1816 attr->timeout = cmd.timeout;
1817 attr->retry_cnt = cmd.retry_cnt;
1818 attr->rnr_retry = cmd.rnr_retry;
1819 attr->alt_port_num = cmd.alt_port_num;
1820 attr->alt_timeout = cmd.alt_timeout;
1822 memcpy(attr->ah_attr.grh.dgid.raw, cmd.dest.dgid, 16);
1823 attr->ah_attr.grh.flow_label = cmd.dest.flow_label;
1824 attr->ah_attr.grh.sgid_index = cmd.dest.sgid_index;
1825 attr->ah_attr.grh.hop_limit = cmd.dest.hop_limit;
1826 attr->ah_attr.grh.traffic_class = cmd.dest.traffic_class;
1827 attr->ah_attr.dlid = cmd.dest.dlid;
1828 attr->ah_attr.sl = cmd.dest.sl;
1829 attr->ah_attr.src_path_bits = cmd.dest.src_path_bits;
1830 attr->ah_attr.static_rate = cmd.dest.static_rate;
1831 attr->ah_attr.ah_flags = cmd.dest.is_global ? IB_AH_GRH : 0;
1832 attr->ah_attr.port_num = cmd.dest.port_num;
1834 memcpy(attr->alt_ah_attr.grh.dgid.raw, cmd.alt_dest.dgid, 16);
1835 attr->alt_ah_attr.grh.flow_label = cmd.alt_dest.flow_label;
1836 attr->alt_ah_attr.grh.sgid_index = cmd.alt_dest.sgid_index;
1837 attr->alt_ah_attr.grh.hop_limit = cmd.alt_dest.hop_limit;
1838 attr->alt_ah_attr.grh.traffic_class = cmd.alt_dest.traffic_class;
1839 attr->alt_ah_attr.dlid = cmd.alt_dest.dlid;
1840 attr->alt_ah_attr.sl = cmd.alt_dest.sl;
1841 attr->alt_ah_attr.src_path_bits = cmd.alt_dest.src_path_bits;
1842 attr->alt_ah_attr.static_rate = cmd.alt_dest.static_rate;
1843 attr->alt_ah_attr.ah_flags = cmd.alt_dest.is_global ? IB_AH_GRH : 0;
1844 attr->alt_ah_attr.port_num = cmd.alt_dest.port_num;
1846 if (qp->real_qp == qp) {
1847 ret = qp->device->modify_qp(qp, attr,
1848 modify_qp_mask(qp->qp_type, cmd.attr_mask), &udata);
1850 ret = ib_modify_qp(qp, attr, modify_qp_mask(qp->qp_type, cmd.attr_mask));
1866 ssize_t ib_uverbs_destroy_qp(struct ib_uverbs_file *file,
1867 const char __user *buf, int in_len,
1870 struct ib_uverbs_destroy_qp cmd;
1871 struct ib_uverbs_destroy_qp_resp resp;
1872 struct ib_uobject *uobj;
1874 struct ib_uqp_object *obj;
1877 if (copy_from_user(&cmd, buf, sizeof cmd))
1880 memset(&resp, 0, sizeof resp);
1882 uobj = idr_write_uobj(&ib_uverbs_qp_idr, cmd.qp_handle, file->ucontext);
1886 obj = container_of(uobj, struct ib_uqp_object, uevent.uobject);
1888 if (!list_empty(&obj->mcast_list)) {
1889 put_uobj_write(uobj);
1893 ret = ib_destroy_qp(qp);
1897 put_uobj_write(uobj);
1902 idr_remove_uobj(&ib_uverbs_qp_idr, uobj);
1904 mutex_lock(&file->mutex);
1905 list_del(&uobj->list);
1906 mutex_unlock(&file->mutex);
1908 ib_uverbs_release_uevent(file, &obj->uevent);
1910 resp.events_reported = obj->uevent.events_reported;
1914 if (copy_to_user((void __user *) (unsigned long) cmd.response,
1915 &resp, sizeof resp))
1921 ssize_t ib_uverbs_post_send(struct ib_uverbs_file *file,
1922 const char __user *buf, int in_len,
1925 struct ib_uverbs_post_send cmd;
1926 struct ib_uverbs_post_send_resp resp;
1927 struct ib_uverbs_send_wr *user_wr;
1928 struct ib_send_wr *wr = NULL, *last, *next, *bad_wr;
1932 ssize_t ret = -EINVAL;
1934 if (copy_from_user(&cmd, buf, sizeof cmd))
1937 if (in_len < sizeof cmd + cmd.wqe_size * cmd.wr_count +
1938 cmd.sge_count * sizeof (struct ib_uverbs_sge))
1941 if (cmd.wqe_size < sizeof (struct ib_uverbs_send_wr))
1944 user_wr = kmalloc(cmd.wqe_size, GFP_KERNEL);
1948 qp = idr_read_qp(cmd.qp_handle, file->ucontext);
1952 is_ud = qp->qp_type == IB_QPT_UD;
1955 for (i = 0; i < cmd.wr_count; ++i) {
1956 if (copy_from_user(user_wr,
1957 buf + sizeof cmd + i * cmd.wqe_size,
1963 if (user_wr->num_sge + sg_ind > cmd.sge_count) {
1968 next = kmalloc(ALIGN(sizeof *next, sizeof (struct ib_sge)) +
1969 user_wr->num_sge * sizeof (struct ib_sge),
1983 next->wr_id = user_wr->wr_id;
1984 next->num_sge = user_wr->num_sge;
1985 next->opcode = user_wr->opcode;
1986 next->send_flags = user_wr->send_flags;
1989 next->wr.ud.ah = idr_read_ah(user_wr->wr.ud.ah,
1991 if (!next->wr.ud.ah) {
1995 next->wr.ud.remote_qpn = user_wr->wr.ud.remote_qpn;
1996 next->wr.ud.remote_qkey = user_wr->wr.ud.remote_qkey;
1998 switch (next->opcode) {
1999 case IB_WR_RDMA_WRITE_WITH_IMM:
2001 (__be32 __force) user_wr->ex.imm_data;
2002 case IB_WR_RDMA_WRITE:
2003 case IB_WR_RDMA_READ:
2004 next->wr.rdma.remote_addr =
2005 user_wr->wr.rdma.remote_addr;
2006 next->wr.rdma.rkey =
2007 user_wr->wr.rdma.rkey;
2009 case IB_WR_SEND_WITH_IMM:
2011 (__be32 __force) user_wr->ex.imm_data;
2013 case IB_WR_SEND_WITH_INV:
2014 next->ex.invalidate_rkey =
2015 user_wr->ex.invalidate_rkey;
2017 case IB_WR_ATOMIC_CMP_AND_SWP:
2018 case IB_WR_ATOMIC_FETCH_AND_ADD:
2019 next->wr.atomic.remote_addr =
2020 user_wr->wr.atomic.remote_addr;
2021 next->wr.atomic.compare_add =
2022 user_wr->wr.atomic.compare_add;
2023 next->wr.atomic.swap = user_wr->wr.atomic.swap;
2024 next->wr.atomic.rkey = user_wr->wr.atomic.rkey;
2031 if (next->num_sge) {
2032 next->sg_list = (void *) next +
2033 ALIGN(sizeof *next, sizeof (struct ib_sge));
2034 if (copy_from_user(next->sg_list,
2036 cmd.wr_count * cmd.wqe_size +
2037 sg_ind * sizeof (struct ib_sge),
2038 next->num_sge * sizeof (struct ib_sge))) {
2042 sg_ind += next->num_sge;
2044 next->sg_list = NULL;
2048 ret = qp->device->post_send(qp->real_qp, wr, &bad_wr);
2050 for (next = wr; next; next = next->next) {
2056 if (copy_to_user((void __user *) (unsigned long) cmd.response,
2057 &resp, sizeof resp))
2064 if (is_ud && wr->wr.ud.ah)
2065 put_ah_read(wr->wr.ud.ah);
2074 return ret ? ret : in_len;
2077 static struct ib_recv_wr *ib_uverbs_unmarshall_recv(const char __user *buf,
2083 struct ib_uverbs_recv_wr *user_wr;
2084 struct ib_recv_wr *wr = NULL, *last, *next;
2089 if (in_len < wqe_size * wr_count +
2090 sge_count * sizeof (struct ib_uverbs_sge))
2091 return ERR_PTR(-EINVAL);
2093 if (wqe_size < sizeof (struct ib_uverbs_recv_wr))
2094 return ERR_PTR(-EINVAL);
2096 user_wr = kmalloc(wqe_size, GFP_KERNEL);
2098 return ERR_PTR(-ENOMEM);
2102 for (i = 0; i < wr_count; ++i) {
2103 if (copy_from_user(user_wr, buf + i * wqe_size,
2109 if (user_wr->num_sge + sg_ind > sge_count) {
2114 next = kmalloc(ALIGN(sizeof *next, sizeof (struct ib_sge)) +
2115 user_wr->num_sge * sizeof (struct ib_sge),
2129 next->wr_id = user_wr->wr_id;
2130 next->num_sge = user_wr->num_sge;
2132 if (next->num_sge) {
2133 next->sg_list = (void *) next +
2134 ALIGN(sizeof *next, sizeof (struct ib_sge));
2135 if (copy_from_user(next->sg_list,
2136 buf + wr_count * wqe_size +
2137 sg_ind * sizeof (struct ib_sge),
2138 next->num_sge * sizeof (struct ib_sge))) {
2142 sg_ind += next->num_sge;
2144 next->sg_list = NULL;
2159 return ERR_PTR(ret);
2162 ssize_t ib_uverbs_post_recv(struct ib_uverbs_file *file,
2163 const char __user *buf, int in_len,
2166 struct ib_uverbs_post_recv cmd;
2167 struct ib_uverbs_post_recv_resp resp;
2168 struct ib_recv_wr *wr, *next, *bad_wr;
2170 ssize_t ret = -EINVAL;
2172 if (copy_from_user(&cmd, buf, sizeof cmd))
2175 wr = ib_uverbs_unmarshall_recv(buf + sizeof cmd,
2176 in_len - sizeof cmd, cmd.wr_count,
2177 cmd.sge_count, cmd.wqe_size);
2181 qp = idr_read_qp(cmd.qp_handle, file->ucontext);
2186 ret = qp->device->post_recv(qp->real_qp, wr, &bad_wr);
2191 for (next = wr; next; next = next->next) {
2197 if (copy_to_user((void __user *) (unsigned long) cmd.response,
2198 &resp, sizeof resp))
2208 return ret ? ret : in_len;
2211 ssize_t ib_uverbs_post_srq_recv(struct ib_uverbs_file *file,
2212 const char __user *buf, int in_len,
2215 struct ib_uverbs_post_srq_recv cmd;
2216 struct ib_uverbs_post_srq_recv_resp resp;
2217 struct ib_recv_wr *wr, *next, *bad_wr;
2219 ssize_t ret = -EINVAL;
2221 if (copy_from_user(&cmd, buf, sizeof cmd))
2224 wr = ib_uverbs_unmarshall_recv(buf + sizeof cmd,
2225 in_len - sizeof cmd, cmd.wr_count,
2226 cmd.sge_count, cmd.wqe_size);
2230 srq = idr_read_srq(cmd.srq_handle, file->ucontext);
2235 ret = srq->device->post_srq_recv(srq, wr, &bad_wr);
2240 for (next = wr; next; next = next->next) {
2246 if (copy_to_user((void __user *) (unsigned long) cmd.response,
2247 &resp, sizeof resp))
2257 return ret ? ret : in_len;
2260 ssize_t ib_uverbs_create_ah(struct ib_uverbs_file *file,
2261 const char __user *buf, int in_len,
2264 struct ib_uverbs_create_ah cmd;
2265 struct ib_uverbs_create_ah_resp resp;
2266 struct ib_uobject *uobj;
2269 struct ib_ah_attr attr;
2272 if (out_len < sizeof resp)
2275 if (copy_from_user(&cmd, buf, sizeof cmd))
2278 uobj = kmalloc(sizeof *uobj, GFP_KERNEL);
2282 init_uobj(uobj, cmd.user_handle, file->ucontext, &ah_lock_class);
2283 down_write(&uobj->mutex);
2285 pd = idr_read_pd(cmd.pd_handle, file->ucontext);
2291 attr.dlid = cmd.attr.dlid;
2292 attr.sl = cmd.attr.sl;
2293 attr.src_path_bits = cmd.attr.src_path_bits;
2294 attr.static_rate = cmd.attr.static_rate;
2295 attr.ah_flags = cmd.attr.is_global ? IB_AH_GRH : 0;
2296 attr.port_num = cmd.attr.port_num;
2297 attr.grh.flow_label = cmd.attr.grh.flow_label;
2298 attr.grh.sgid_index = cmd.attr.grh.sgid_index;
2299 attr.grh.hop_limit = cmd.attr.grh.hop_limit;
2300 attr.grh.traffic_class = cmd.attr.grh.traffic_class;
2301 memcpy(attr.grh.dgid.raw, cmd.attr.grh.dgid, 16);
2303 ah = ib_create_ah(pd, &attr);
2312 ret = idr_add_uobj(&ib_uverbs_ah_idr, uobj);
2316 resp.ah_handle = uobj->id;
2318 if (copy_to_user((void __user *) (unsigned long) cmd.response,
2319 &resp, sizeof resp)) {
2326 mutex_lock(&file->mutex);
2327 list_add_tail(&uobj->list, &file->ucontext->ah_list);
2328 mutex_unlock(&file->mutex);
2332 up_write(&uobj->mutex);
2337 idr_remove_uobj(&ib_uverbs_ah_idr, uobj);
2346 put_uobj_write(uobj);
2350 ssize_t ib_uverbs_destroy_ah(struct ib_uverbs_file *file,
2351 const char __user *buf, int in_len, int out_len)
2353 struct ib_uverbs_destroy_ah cmd;
2355 struct ib_uobject *uobj;
2358 if (copy_from_user(&cmd, buf, sizeof cmd))
2361 uobj = idr_write_uobj(&ib_uverbs_ah_idr, cmd.ah_handle, file->ucontext);
2366 ret = ib_destroy_ah(ah);
2370 put_uobj_write(uobj);
2375 idr_remove_uobj(&ib_uverbs_ah_idr, uobj);
2377 mutex_lock(&file->mutex);
2378 list_del(&uobj->list);
2379 mutex_unlock(&file->mutex);
2386 ssize_t ib_uverbs_attach_mcast(struct ib_uverbs_file *file,
2387 const char __user *buf, int in_len,
2390 struct ib_uverbs_attach_mcast cmd;
2392 struct ib_uqp_object *obj;
2393 struct ib_uverbs_mcast_entry *mcast;
2396 if (copy_from_user(&cmd, buf, sizeof cmd))
2399 qp = idr_write_qp(cmd.qp_handle, file->ucontext);
2403 obj = container_of(qp->uobject, struct ib_uqp_object, uevent.uobject);
2405 list_for_each_entry(mcast, &obj->mcast_list, list)
2406 if (cmd.mlid == mcast->lid &&
2407 !memcmp(cmd.gid, mcast->gid.raw, sizeof mcast->gid.raw)) {
2412 mcast = kmalloc(sizeof *mcast, GFP_KERNEL);
2418 mcast->lid = cmd.mlid;
2419 memcpy(mcast->gid.raw, cmd.gid, sizeof mcast->gid.raw);
2421 ret = ib_attach_mcast(qp, &mcast->gid, cmd.mlid);
2423 list_add_tail(&mcast->list, &obj->mcast_list);
2430 return ret ? ret : in_len;
2433 ssize_t ib_uverbs_detach_mcast(struct ib_uverbs_file *file,
2434 const char __user *buf, int in_len,
2437 struct ib_uverbs_detach_mcast cmd;
2438 struct ib_uqp_object *obj;
2440 struct ib_uverbs_mcast_entry *mcast;
2443 if (copy_from_user(&cmd, buf, sizeof cmd))
2446 qp = idr_write_qp(cmd.qp_handle, file->ucontext);
2450 ret = ib_detach_mcast(qp, (union ib_gid *) cmd.gid, cmd.mlid);
2454 obj = container_of(qp->uobject, struct ib_uqp_object, uevent.uobject);
2456 list_for_each_entry(mcast, &obj->mcast_list, list)
2457 if (cmd.mlid == mcast->lid &&
2458 !memcmp(cmd.gid, mcast->gid.raw, sizeof mcast->gid.raw)) {
2459 list_del(&mcast->list);
2467 return ret ? ret : in_len;
2470 static int __uverbs_create_xsrq(struct ib_uverbs_file *file,
2471 struct ib_uverbs_create_xsrq *cmd,
2472 struct ib_udata *udata)
2474 struct ib_uverbs_create_srq_resp resp;
2475 struct ib_usrq_object *obj;
2478 struct ib_uobject *uninitialized_var(xrcd_uobj);
2479 struct ib_srq_init_attr attr;
2482 obj = kmalloc(sizeof *obj, GFP_KERNEL);
2486 init_uobj(&obj->uevent.uobject, cmd->user_handle, file->ucontext, &srq_lock_class);
2487 down_write(&obj->uevent.uobject.mutex);
2489 if (cmd->srq_type == IB_SRQT_XRC) {
2490 attr.ext.xrc.xrcd = idr_read_xrcd(cmd->xrcd_handle, file->ucontext, &xrcd_uobj);
2491 if (!attr.ext.xrc.xrcd) {
2496 obj->uxrcd = container_of(xrcd_uobj, struct ib_uxrcd_object, uobject);
2497 atomic_inc(&obj->uxrcd->refcnt);
2499 attr.ext.xrc.cq = idr_read_cq(cmd->cq_handle, file->ucontext, 0);
2500 if (!attr.ext.xrc.cq) {
2506 pd = idr_read_pd(cmd->pd_handle, file->ucontext);
2512 attr.event_handler = ib_uverbs_srq_event_handler;
2513 attr.srq_context = file;
2514 attr.srq_type = cmd->srq_type;
2515 attr.attr.max_wr = cmd->max_wr;
2516 attr.attr.max_sge = cmd->max_sge;
2517 attr.attr.srq_limit = cmd->srq_limit;
2519 obj->uevent.events_reported = 0;
2520 INIT_LIST_HEAD(&obj->uevent.event_list);
2522 srq = pd->device->create_srq(pd, &attr, udata);
2528 srq->device = pd->device;
2530 srq->srq_type = cmd->srq_type;
2531 srq->uobject = &obj->uevent.uobject;
2532 srq->event_handler = attr.event_handler;
2533 srq->srq_context = attr.srq_context;
2535 if (cmd->srq_type == IB_SRQT_XRC) {
2536 srq->ext.xrc.cq = attr.ext.xrc.cq;
2537 srq->ext.xrc.xrcd = attr.ext.xrc.xrcd;
2538 atomic_inc(&attr.ext.xrc.cq->usecnt);
2539 atomic_inc(&attr.ext.xrc.xrcd->usecnt);
2542 atomic_inc(&pd->usecnt);
2543 atomic_set(&srq->usecnt, 0);
2545 obj->uevent.uobject.object = srq;
2546 ret = idr_add_uobj(&ib_uverbs_srq_idr, &obj->uevent.uobject);
2550 memset(&resp, 0, sizeof resp);
2551 resp.srq_handle = obj->uevent.uobject.id;
2552 resp.max_wr = attr.attr.max_wr;
2553 resp.max_sge = attr.attr.max_sge;
2554 if (cmd->srq_type == IB_SRQT_XRC)
2555 resp.srqn = srq->ext.xrc.srq_num;
2557 if (copy_to_user((void __user *) (unsigned long) cmd->response,
2558 &resp, sizeof resp)) {
2563 if (cmd->srq_type == IB_SRQT_XRC) {
2564 put_uobj_read(xrcd_uobj);
2565 put_cq_read(attr.ext.xrc.cq);
2569 mutex_lock(&file->mutex);
2570 list_add_tail(&obj->uevent.uobject.list, &file->ucontext->srq_list);
2571 mutex_unlock(&file->mutex);
2573 obj->uevent.uobject.live = 1;
2575 up_write(&obj->uevent.uobject.mutex);
2580 idr_remove_uobj(&ib_uverbs_srq_idr, &obj->uevent.uobject);
2583 ib_destroy_srq(srq);
2589 if (cmd->srq_type == IB_SRQT_XRC)
2590 put_cq_read(attr.ext.xrc.cq);
2593 if (cmd->srq_type == IB_SRQT_XRC) {
2594 atomic_dec(&obj->uxrcd->refcnt);
2595 put_uobj_read(xrcd_uobj);
2599 put_uobj_write(&obj->uevent.uobject);
2603 ssize_t ib_uverbs_create_srq(struct ib_uverbs_file *file,
2604 const char __user *buf, int in_len,
2607 struct ib_uverbs_create_srq cmd;
2608 struct ib_uverbs_create_xsrq xcmd;
2609 struct ib_uverbs_create_srq_resp resp;
2610 struct ib_udata udata;
2613 if (out_len < sizeof resp)
2616 if (copy_from_user(&cmd, buf, sizeof cmd))
2619 xcmd.response = cmd.response;
2620 xcmd.user_handle = cmd.user_handle;
2621 xcmd.srq_type = IB_SRQT_BASIC;
2622 xcmd.pd_handle = cmd.pd_handle;
2623 xcmd.max_wr = cmd.max_wr;
2624 xcmd.max_sge = cmd.max_sge;
2625 xcmd.srq_limit = cmd.srq_limit;
2627 INIT_UDATA(&udata, buf + sizeof cmd,
2628 (unsigned long) cmd.response + sizeof resp,
2629 in_len - sizeof cmd, out_len - sizeof resp);
2631 ret = __uverbs_create_xsrq(file, &xcmd, &udata);
2638 ssize_t ib_uverbs_create_xsrq(struct ib_uverbs_file *file,
2639 const char __user *buf, int in_len, int out_len)
2641 struct ib_uverbs_create_xsrq cmd;
2642 struct ib_uverbs_create_srq_resp resp;
2643 struct ib_udata udata;
2646 if (out_len < sizeof resp)
2649 if (copy_from_user(&cmd, buf, sizeof cmd))
2652 INIT_UDATA(&udata, buf + sizeof cmd,
2653 (unsigned long) cmd.response + sizeof resp,
2654 in_len - sizeof cmd, out_len - sizeof resp);
2656 ret = __uverbs_create_xsrq(file, &cmd, &udata);
2663 ssize_t ib_uverbs_modify_srq(struct ib_uverbs_file *file,
2664 const char __user *buf, int in_len,
2667 struct ib_uverbs_modify_srq cmd;
2668 struct ib_udata udata;
2670 struct ib_srq_attr attr;
2673 if (copy_from_user(&cmd, buf, sizeof cmd))
2676 INIT_UDATA(&udata, buf + sizeof cmd, NULL, in_len - sizeof cmd,
2679 srq = idr_read_srq(cmd.srq_handle, file->ucontext);
2683 attr.max_wr = cmd.max_wr;
2684 attr.srq_limit = cmd.srq_limit;
2686 ret = srq->device->modify_srq(srq, &attr, cmd.attr_mask, &udata);
2690 return ret ? ret : in_len;
2693 ssize_t ib_uverbs_query_srq(struct ib_uverbs_file *file,
2694 const char __user *buf,
2695 int in_len, int out_len)
2697 struct ib_uverbs_query_srq cmd;
2698 struct ib_uverbs_query_srq_resp resp;
2699 struct ib_srq_attr attr;
2703 if (out_len < sizeof resp)
2706 if (copy_from_user(&cmd, buf, sizeof cmd))
2709 srq = idr_read_srq(cmd.srq_handle, file->ucontext);
2713 ret = ib_query_srq(srq, &attr);
2720 memset(&resp, 0, sizeof resp);
2722 resp.max_wr = attr.max_wr;
2723 resp.max_sge = attr.max_sge;
2724 resp.srq_limit = attr.srq_limit;
2726 if (copy_to_user((void __user *) (unsigned long) cmd.response,
2727 &resp, sizeof resp))
2733 ssize_t ib_uverbs_destroy_srq(struct ib_uverbs_file *file,
2734 const char __user *buf, int in_len,
2737 struct ib_uverbs_destroy_srq cmd;
2738 struct ib_uverbs_destroy_srq_resp resp;
2739 struct ib_uobject *uobj;
2741 struct ib_uevent_object *obj;
2744 if (copy_from_user(&cmd, buf, sizeof cmd))
2747 uobj = idr_write_uobj(&ib_uverbs_srq_idr, cmd.srq_handle, file->ucontext);
2751 obj = container_of(uobj, struct ib_uevent_object, uobject);
2753 ret = ib_destroy_srq(srq);
2757 put_uobj_write(uobj);
2762 idr_remove_uobj(&ib_uverbs_srq_idr, uobj);
2764 mutex_lock(&file->mutex);
2765 list_del(&uobj->list);
2766 mutex_unlock(&file->mutex);
2768 ib_uverbs_release_uevent(file, obj);
2770 memset(&resp, 0, sizeof resp);
2771 resp.events_reported = obj->events_reported;
2775 if (copy_to_user((void __user *) (unsigned long) cmd.response,
2776 &resp, sizeof resp))
2779 return ret ? ret : in_len;