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>
39 #include <linux/sched.h>
41 #include <linux/uaccess.h>
43 #include <rdma/uverbs_types.h>
44 #include <rdma/uverbs_std_types.h>
45 #include "rdma_core.h"
48 #include "core_priv.h"
51 * Copy a response to userspace. If the provided 'resp' is larger than the
52 * user buffer it is silently truncated. If the user provided a larger buffer
53 * then the trailing portion is zero filled.
55 * These semantics are intended to support future extension of the output
58 static int uverbs_response(struct uverbs_attr_bundle *attrs, const void *resp,
63 if (uverbs_attr_is_valid(attrs, UVERBS_ATTR_CORE_OUT))
64 return uverbs_copy_to_struct_or_zero(
65 attrs, UVERBS_ATTR_CORE_OUT, resp, resp_len);
67 if (copy_to_user(attrs->ucore.outbuf, resp,
68 min(attrs->ucore.outlen, resp_len)))
71 if (resp_len < attrs->ucore.outlen) {
73 * Zero fill any extra memory that user
74 * space might have provided.
76 ret = clear_user(attrs->ucore.outbuf + resp_len,
77 attrs->ucore.outlen - resp_len);
86 * Copy a request from userspace. If the provided 'req' is larger than the
87 * user buffer then the user buffer is zero extended into the 'req'. If 'req'
88 * is smaller than the user buffer then the uncopied bytes in the user buffer
91 static int uverbs_request(struct uverbs_attr_bundle *attrs, void *req,
94 if (copy_from_user(req, attrs->ucore.inbuf,
95 min(attrs->ucore.inlen, req_len)))
98 if (attrs->ucore.inlen < req_len) {
99 memset(req + attrs->ucore.inlen, 0,
100 req_len - attrs->ucore.inlen);
101 } else if (attrs->ucore.inlen > req_len) {
102 if (!ib_is_buffer_cleared(attrs->ucore.inbuf + req_len,
103 attrs->ucore.inlen - req_len))
110 * Generate the value for the 'response_length' protocol used by write_ex.
111 * This is the number of bytes the kernel actually wrote. Userspace can use
112 * this to detect what structure members in the response the kernel
115 static u32 uverbs_response_length(struct uverbs_attr_bundle *attrs,
118 return min_t(size_t, attrs->ucore.outlen, resp_len);
122 * The iterator version of the request interface is for handlers that need to
123 * step over a flex array at the end of a command header.
125 struct uverbs_req_iter {
126 const void __user *cur;
127 const void __user *end;
130 static int uverbs_request_start(struct uverbs_attr_bundle *attrs,
131 struct uverbs_req_iter *iter,
135 if (attrs->ucore.inlen < req_len)
138 if (copy_from_user(req, attrs->ucore.inbuf, req_len))
141 iter->cur = attrs->ucore.inbuf + req_len;
142 iter->end = attrs->ucore.inbuf + attrs->ucore.inlen;
146 static int uverbs_request_next(struct uverbs_req_iter *iter, void *val,
149 if (iter->cur + len > iter->end)
152 if (copy_from_user(val, iter->cur, len))
159 static const void __user *uverbs_request_next_ptr(struct uverbs_req_iter *iter,
162 const void __user *res = iter->cur;
164 if (iter->cur + len > iter->end)
165 return (void __force __user *)ERR_PTR(-ENOSPC);
170 static int uverbs_request_finish(struct uverbs_req_iter *iter)
172 if (!ib_is_buffer_cleared(iter->cur, iter->end - iter->cur))
178 * When calling a destroy function during an error unwind we need to pass in
179 * the udata that is sanitized of all user arguments. Ie from the driver
180 * perspective it looks like no udata was passed.
182 struct ib_udata *uverbs_get_cleared_udata(struct uverbs_attr_bundle *attrs)
184 attrs->driver_udata = (struct ib_udata){};
185 return &attrs->driver_udata;
188 static struct ib_uverbs_completion_event_file *
189 _ib_uverbs_lookup_comp_file(s32 fd, struct uverbs_attr_bundle *attrs)
191 struct ib_uobject *uobj = ufd_get_read(UVERBS_OBJECT_COMP_CHANNEL,
197 uverbs_uobject_get(uobj);
200 return container_of(uobj, struct ib_uverbs_completion_event_file,
203 #define ib_uverbs_lookup_comp_file(_fd, _ufile) \
204 _ib_uverbs_lookup_comp_file((_fd)*typecheck(s32, _fd), _ufile)
206 int ib_alloc_ucontext(struct uverbs_attr_bundle *attrs)
208 struct ib_uverbs_file *ufile = attrs->ufile;
209 struct ib_ucontext *ucontext;
210 struct ib_device *ib_dev;
212 ib_dev = srcu_dereference(ufile->device->ib_dev,
213 &ufile->device->disassociate_srcu);
217 ucontext = rdma_zalloc_drv_obj(ib_dev, ib_ucontext);
221 ucontext->device = ib_dev;
222 ucontext->ufile = ufile;
223 xa_init_flags(&ucontext->mmap_xa, XA_FLAGS_ALLOC);
225 rdma_restrack_new(&ucontext->res, RDMA_RESTRACK_CTX);
226 rdma_restrack_set_name(&ucontext->res, NULL);
227 attrs->context = ucontext;
231 int ib_init_ucontext(struct uverbs_attr_bundle *attrs)
233 struct ib_ucontext *ucontext = attrs->context;
234 struct ib_uverbs_file *file = attrs->ufile;
237 if (!down_read_trylock(&file->hw_destroy_rwsem))
239 mutex_lock(&file->ucontext_lock);
240 if (file->ucontext) {
245 ret = ib_rdmacg_try_charge(&ucontext->cg_obj, ucontext->device,
246 RDMACG_RESOURCE_HCA_HANDLE);
250 ret = ucontext->device->ops.alloc_ucontext(ucontext,
251 &attrs->driver_udata);
255 rdma_restrack_add(&ucontext->res);
258 * Make sure that ib_uverbs_get_ucontext() sees the pointer update
259 * only after all writes to setup the ucontext have completed
261 smp_store_release(&file->ucontext, ucontext);
263 mutex_unlock(&file->ucontext_lock);
264 up_read(&file->hw_destroy_rwsem);
268 ib_rdmacg_uncharge(&ucontext->cg_obj, ucontext->device,
269 RDMACG_RESOURCE_HCA_HANDLE);
271 mutex_unlock(&file->ucontext_lock);
272 up_read(&file->hw_destroy_rwsem);
276 static int ib_uverbs_get_context(struct uverbs_attr_bundle *attrs)
278 struct ib_uverbs_get_context_resp resp;
279 struct ib_uverbs_get_context cmd;
280 struct ib_device *ib_dev;
281 struct ib_uobject *uobj;
284 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
288 ret = ib_alloc_ucontext(attrs);
292 uobj = uobj_alloc(UVERBS_OBJECT_ASYNC_EVENT, attrs, &ib_dev);
298 resp = (struct ib_uverbs_get_context_resp){
299 .num_comp_vectors = attrs->ufile->device->num_comp_vectors,
300 .async_fd = uobj->id,
302 ret = uverbs_response(attrs, &resp, sizeof(resp));
306 ret = ib_init_ucontext(attrs);
310 ib_uverbs_init_async_event_file(
311 container_of(uobj, struct ib_uverbs_async_event_file, uobj));
312 rdma_alloc_commit_uobject(uobj, attrs);
316 rdma_alloc_abort_uobject(uobj, attrs, false);
318 rdma_restrack_put(&attrs->context->res);
319 kfree(attrs->context);
320 attrs->context = NULL;
324 static void copy_query_dev_fields(struct ib_ucontext *ucontext,
325 struct ib_uverbs_query_device_resp *resp,
326 struct ib_device_attr *attr)
328 struct ib_device *ib_dev = ucontext->device;
330 resp->fw_ver = attr->fw_ver;
331 resp->node_guid = ib_dev->node_guid;
332 resp->sys_image_guid = attr->sys_image_guid;
333 resp->max_mr_size = attr->max_mr_size;
334 resp->page_size_cap = attr->page_size_cap;
335 resp->vendor_id = attr->vendor_id;
336 resp->vendor_part_id = attr->vendor_part_id;
337 resp->hw_ver = attr->hw_ver;
338 resp->max_qp = attr->max_qp;
339 resp->max_qp_wr = attr->max_qp_wr;
340 resp->device_cap_flags = lower_32_bits(attr->device_cap_flags);
341 resp->max_sge = min(attr->max_send_sge, attr->max_recv_sge);
342 resp->max_sge_rd = attr->max_sge_rd;
343 resp->max_cq = attr->max_cq;
344 resp->max_cqe = attr->max_cqe;
345 resp->max_mr = attr->max_mr;
346 resp->max_pd = attr->max_pd;
347 resp->max_qp_rd_atom = attr->max_qp_rd_atom;
348 resp->max_ee_rd_atom = attr->max_ee_rd_atom;
349 resp->max_res_rd_atom = attr->max_res_rd_atom;
350 resp->max_qp_init_rd_atom = attr->max_qp_init_rd_atom;
351 resp->max_ee_init_rd_atom = attr->max_ee_init_rd_atom;
352 resp->atomic_cap = attr->atomic_cap;
353 resp->max_ee = attr->max_ee;
354 resp->max_rdd = attr->max_rdd;
355 resp->max_mw = attr->max_mw;
356 resp->max_raw_ipv6_qp = attr->max_raw_ipv6_qp;
357 resp->max_raw_ethy_qp = attr->max_raw_ethy_qp;
358 resp->max_mcast_grp = attr->max_mcast_grp;
359 resp->max_mcast_qp_attach = attr->max_mcast_qp_attach;
360 resp->max_total_mcast_qp_attach = attr->max_total_mcast_qp_attach;
361 resp->max_ah = attr->max_ah;
362 resp->max_srq = attr->max_srq;
363 resp->max_srq_wr = attr->max_srq_wr;
364 resp->max_srq_sge = attr->max_srq_sge;
365 resp->max_pkeys = attr->max_pkeys;
366 resp->local_ca_ack_delay = attr->local_ca_ack_delay;
367 resp->phys_port_cnt = ib_dev->phys_port_cnt;
370 static int ib_uverbs_query_device(struct uverbs_attr_bundle *attrs)
372 struct ib_uverbs_query_device cmd;
373 struct ib_uverbs_query_device_resp resp;
374 struct ib_ucontext *ucontext;
377 ucontext = ib_uverbs_get_ucontext(attrs);
378 if (IS_ERR(ucontext))
379 return PTR_ERR(ucontext);
381 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
385 memset(&resp, 0, sizeof resp);
386 copy_query_dev_fields(ucontext, &resp, &ucontext->device->attrs);
388 return uverbs_response(attrs, &resp, sizeof(resp));
391 static int ib_uverbs_query_port(struct uverbs_attr_bundle *attrs)
393 struct ib_uverbs_query_port cmd;
394 struct ib_uverbs_query_port_resp resp;
395 struct ib_port_attr attr;
397 struct ib_ucontext *ucontext;
398 struct ib_device *ib_dev;
400 ucontext = ib_uverbs_get_ucontext(attrs);
401 if (IS_ERR(ucontext))
402 return PTR_ERR(ucontext);
403 ib_dev = ucontext->device;
405 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
409 ret = ib_query_port(ib_dev, cmd.port_num, &attr);
413 memset(&resp, 0, sizeof resp);
414 copy_port_attr_to_resp(&attr, &resp, ib_dev, cmd.port_num);
416 return uverbs_response(attrs, &resp, sizeof(resp));
419 static int ib_uverbs_alloc_pd(struct uverbs_attr_bundle *attrs)
421 struct ib_uverbs_alloc_pd_resp resp = {};
422 struct ib_uverbs_alloc_pd cmd;
423 struct ib_uobject *uobj;
426 struct ib_device *ib_dev;
428 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
432 uobj = uobj_alloc(UVERBS_OBJECT_PD, attrs, &ib_dev);
434 return PTR_ERR(uobj);
436 pd = rdma_zalloc_drv_obj(ib_dev, ib_pd);
444 atomic_set(&pd->usecnt, 0);
446 rdma_restrack_new(&pd->res, RDMA_RESTRACK_PD);
447 rdma_restrack_set_name(&pd->res, NULL);
449 ret = ib_dev->ops.alloc_pd(pd, &attrs->driver_udata);
452 rdma_restrack_add(&pd->res);
455 uobj_finalize_uobj_create(uobj, attrs);
457 resp.pd_handle = uobj->id;
458 return uverbs_response(attrs, &resp, sizeof(resp));
461 rdma_restrack_put(&pd->res);
464 uobj_alloc_abort(uobj, attrs);
468 static int ib_uverbs_dealloc_pd(struct uverbs_attr_bundle *attrs)
470 struct ib_uverbs_dealloc_pd cmd;
473 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
477 return uobj_perform_destroy(UVERBS_OBJECT_PD, cmd.pd_handle, attrs);
480 struct xrcd_table_entry {
482 struct ib_xrcd *xrcd;
486 static int xrcd_table_insert(struct ib_uverbs_device *dev,
488 struct ib_xrcd *xrcd)
490 struct xrcd_table_entry *entry, *scan;
491 struct rb_node **p = &dev->xrcd_tree.rb_node;
492 struct rb_node *parent = NULL;
494 entry = kmalloc(sizeof *entry, GFP_KERNEL);
499 entry->inode = inode;
503 scan = rb_entry(parent, struct xrcd_table_entry, node);
505 if (inode < scan->inode) {
507 } else if (inode > scan->inode) {
515 rb_link_node(&entry->node, parent, p);
516 rb_insert_color(&entry->node, &dev->xrcd_tree);
521 static struct xrcd_table_entry *xrcd_table_search(struct ib_uverbs_device *dev,
524 struct xrcd_table_entry *entry;
525 struct rb_node *p = dev->xrcd_tree.rb_node;
528 entry = rb_entry(p, struct xrcd_table_entry, node);
530 if (inode < entry->inode)
532 else if (inode > entry->inode)
541 static struct ib_xrcd *find_xrcd(struct ib_uverbs_device *dev, struct inode *inode)
543 struct xrcd_table_entry *entry;
545 entry = xrcd_table_search(dev, inode);
552 static void xrcd_table_delete(struct ib_uverbs_device *dev,
555 struct xrcd_table_entry *entry;
557 entry = xrcd_table_search(dev, inode);
560 rb_erase(&entry->node, &dev->xrcd_tree);
565 static int ib_uverbs_open_xrcd(struct uverbs_attr_bundle *attrs)
567 struct ib_uverbs_device *ibudev = attrs->ufile->device;
568 struct ib_uverbs_open_xrcd_resp resp = {};
569 struct ib_uverbs_open_xrcd cmd;
570 struct ib_uxrcd_object *obj;
571 struct ib_xrcd *xrcd = NULL;
572 struct inode *inode = NULL;
574 struct ib_device *ib_dev;
578 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
582 mutex_lock(&ibudev->xrcd_tree_mutex);
585 /* search for file descriptor */
589 goto err_tree_mutex_unlock;
592 inode = file_inode(f.file);
593 xrcd = find_xrcd(ibudev, inode);
594 if (!xrcd && !(cmd.oflags & O_CREAT)) {
595 /* no file descriptor. Need CREATE flag */
597 goto err_tree_mutex_unlock;
600 if (xrcd && cmd.oflags & O_EXCL) {
602 goto err_tree_mutex_unlock;
606 obj = (struct ib_uxrcd_object *)uobj_alloc(UVERBS_OBJECT_XRCD, attrs,
610 goto err_tree_mutex_unlock;
614 xrcd = ib_alloc_xrcd_user(ib_dev, inode, &attrs->driver_udata);
622 atomic_set(&obj->refcnt, 0);
623 obj->uobject.object = xrcd;
627 /* create new inode/xrcd table entry */
628 ret = xrcd_table_insert(ibudev, inode, xrcd);
630 goto err_dealloc_xrcd;
632 atomic_inc(&xrcd->usecnt);
638 mutex_unlock(&ibudev->xrcd_tree_mutex);
639 uobj_finalize_uobj_create(&obj->uobject, attrs);
641 resp.xrcd_handle = obj->uobject.id;
642 return uverbs_response(attrs, &resp, sizeof(resp));
645 ib_dealloc_xrcd_user(xrcd, uverbs_get_cleared_udata(attrs));
648 uobj_alloc_abort(&obj->uobject, attrs);
650 err_tree_mutex_unlock:
654 mutex_unlock(&ibudev->xrcd_tree_mutex);
659 static int ib_uverbs_close_xrcd(struct uverbs_attr_bundle *attrs)
661 struct ib_uverbs_close_xrcd cmd;
664 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
668 return uobj_perform_destroy(UVERBS_OBJECT_XRCD, cmd.xrcd_handle, attrs);
671 int ib_uverbs_dealloc_xrcd(struct ib_uobject *uobject, struct ib_xrcd *xrcd,
672 enum rdma_remove_reason why,
673 struct uverbs_attr_bundle *attrs)
677 struct ib_uverbs_device *dev = attrs->ufile->device;
680 if (inode && !atomic_dec_and_test(&xrcd->usecnt))
683 ret = ib_dealloc_xrcd_user(xrcd, &attrs->driver_udata);
685 atomic_inc(&xrcd->usecnt);
690 xrcd_table_delete(dev, inode);
695 static int ib_uverbs_reg_mr(struct uverbs_attr_bundle *attrs)
697 struct ib_uverbs_reg_mr_resp resp = {};
698 struct ib_uverbs_reg_mr cmd;
699 struct ib_uobject *uobj;
703 struct ib_device *ib_dev;
705 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
709 if ((cmd.start & ~PAGE_MASK) != (cmd.hca_va & ~PAGE_MASK))
712 uobj = uobj_alloc(UVERBS_OBJECT_MR, attrs, &ib_dev);
714 return PTR_ERR(uobj);
716 ret = ib_check_mr_access(ib_dev, cmd.access_flags);
720 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, attrs);
726 mr = pd->device->ops.reg_user_mr(pd, cmd.start, cmd.length, cmd.hca_va,
728 &attrs->driver_udata);
734 mr->device = pd->device;
736 mr->type = IB_MR_TYPE_USER;
738 mr->sig_attrs = NULL;
740 atomic_inc(&pd->usecnt);
741 mr->iova = cmd.hca_va;
743 rdma_restrack_new(&mr->res, RDMA_RESTRACK_MR);
744 rdma_restrack_set_name(&mr->res, NULL);
745 rdma_restrack_add(&mr->res);
748 uobj_put_obj_read(pd);
749 uobj_finalize_uobj_create(uobj, attrs);
751 resp.lkey = mr->lkey;
752 resp.rkey = mr->rkey;
753 resp.mr_handle = uobj->id;
754 return uverbs_response(attrs, &resp, sizeof(resp));
757 uobj_put_obj_read(pd);
759 uobj_alloc_abort(uobj, attrs);
763 static int ib_uverbs_rereg_mr(struct uverbs_attr_bundle *attrs)
765 struct ib_uverbs_rereg_mr cmd;
766 struct ib_uverbs_rereg_mr_resp resp;
767 struct ib_pd *pd = NULL;
769 struct ib_pd *old_pd;
771 struct ib_uobject *uobj;
773 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
780 if (cmd.flags & ~IB_MR_REREG_SUPPORTED)
783 if ((cmd.flags & IB_MR_REREG_TRANS) &&
784 (cmd.start & ~PAGE_MASK) != (cmd.hca_va & ~PAGE_MASK))
787 uobj = uobj_get_write(UVERBS_OBJECT_MR, cmd.mr_handle, attrs);
789 return PTR_ERR(uobj);
798 if (cmd.flags & IB_MR_REREG_ACCESS) {
799 ret = ib_check_mr_access(mr->device, cmd.access_flags);
804 if (cmd.flags & IB_MR_REREG_PD) {
805 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle,
814 ret = mr->device->ops.rereg_user_mr(mr, cmd.flags, cmd.start,
815 cmd.length, cmd.hca_va,
816 cmd.access_flags, pd,
817 &attrs->driver_udata);
821 if (cmd.flags & IB_MR_REREG_PD) {
822 atomic_inc(&pd->usecnt);
824 atomic_dec(&old_pd->usecnt);
827 if (cmd.flags & IB_MR_REREG_TRANS)
828 mr->iova = cmd.hca_va;
830 memset(&resp, 0, sizeof(resp));
831 resp.lkey = mr->lkey;
832 resp.rkey = mr->rkey;
834 ret = uverbs_response(attrs, &resp, sizeof(resp));
837 if (cmd.flags & IB_MR_REREG_PD)
838 uobj_put_obj_read(pd);
841 uobj_put_write(uobj);
846 static int ib_uverbs_dereg_mr(struct uverbs_attr_bundle *attrs)
848 struct ib_uverbs_dereg_mr cmd;
851 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
855 return uobj_perform_destroy(UVERBS_OBJECT_MR, cmd.mr_handle, attrs);
858 static int ib_uverbs_alloc_mw(struct uverbs_attr_bundle *attrs)
860 struct ib_uverbs_alloc_mw cmd;
861 struct ib_uverbs_alloc_mw_resp resp = {};
862 struct ib_uobject *uobj;
866 struct ib_device *ib_dev;
868 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
872 uobj = uobj_alloc(UVERBS_OBJECT_MW, attrs, &ib_dev);
874 return PTR_ERR(uobj);
876 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, attrs);
882 if (cmd.mw_type != IB_MW_TYPE_1 && cmd.mw_type != IB_MW_TYPE_2) {
887 mw = rdma_zalloc_drv_obj(ib_dev, ib_mw);
896 mw->type = cmd.mw_type;
898 ret = pd->device->ops.alloc_mw(mw, &attrs->driver_udata);
902 atomic_inc(&pd->usecnt);
905 uobj_put_obj_read(pd);
906 uobj_finalize_uobj_create(uobj, attrs);
908 resp.rkey = mw->rkey;
909 resp.mw_handle = uobj->id;
910 return uverbs_response(attrs, &resp, sizeof(resp));
915 uobj_put_obj_read(pd);
917 uobj_alloc_abort(uobj, attrs);
921 static int ib_uverbs_dealloc_mw(struct uverbs_attr_bundle *attrs)
923 struct ib_uverbs_dealloc_mw cmd;
926 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
930 return uobj_perform_destroy(UVERBS_OBJECT_MW, cmd.mw_handle, attrs);
933 static int ib_uverbs_create_comp_channel(struct uverbs_attr_bundle *attrs)
935 struct ib_uverbs_create_comp_channel cmd;
936 struct ib_uverbs_create_comp_channel_resp resp;
937 struct ib_uobject *uobj;
938 struct ib_uverbs_completion_event_file *ev_file;
939 struct ib_device *ib_dev;
942 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
946 uobj = uobj_alloc(UVERBS_OBJECT_COMP_CHANNEL, attrs, &ib_dev);
948 return PTR_ERR(uobj);
950 ev_file = container_of(uobj, struct ib_uverbs_completion_event_file,
952 ib_uverbs_init_event_queue(&ev_file->ev_queue);
953 uobj_finalize_uobj_create(uobj, attrs);
956 return uverbs_response(attrs, &resp, sizeof(resp));
959 static int create_cq(struct uverbs_attr_bundle *attrs,
960 struct ib_uverbs_ex_create_cq *cmd)
962 struct ib_ucq_object *obj;
963 struct ib_uverbs_completion_event_file *ev_file = NULL;
966 struct ib_uverbs_ex_create_cq_resp resp = {};
967 struct ib_cq_init_attr attr = {};
968 struct ib_device *ib_dev;
970 if (cmd->comp_vector >= attrs->ufile->device->num_comp_vectors)
973 obj = (struct ib_ucq_object *)uobj_alloc(UVERBS_OBJECT_CQ, attrs,
978 if (cmd->comp_channel >= 0) {
979 ev_file = ib_uverbs_lookup_comp_file(cmd->comp_channel, attrs);
980 if (IS_ERR(ev_file)) {
981 ret = PTR_ERR(ev_file);
986 obj->uevent.uobject.user_handle = cmd->user_handle;
987 INIT_LIST_HEAD(&obj->comp_list);
988 INIT_LIST_HEAD(&obj->uevent.event_list);
991 attr.comp_vector = cmd->comp_vector;
992 attr.flags = cmd->flags;
994 cq = rdma_zalloc_drv_obj(ib_dev, ib_cq);
1001 cq->comp_handler = ib_uverbs_comp_handler;
1002 cq->event_handler = ib_uverbs_cq_event_handler;
1003 cq->cq_context = ev_file ? &ev_file->ev_queue : NULL;
1004 atomic_set(&cq->usecnt, 0);
1006 rdma_restrack_new(&cq->res, RDMA_RESTRACK_CQ);
1007 rdma_restrack_set_name(&cq->res, NULL);
1009 ret = ib_dev->ops.create_cq(cq, &attr, &attrs->driver_udata);
1012 rdma_restrack_add(&cq->res);
1014 obj->uevent.uobject.object = cq;
1015 obj->uevent.event_file = READ_ONCE(attrs->ufile->default_async_file);
1016 if (obj->uevent.event_file)
1017 uverbs_uobject_get(&obj->uevent.event_file->uobj);
1018 uobj_finalize_uobj_create(&obj->uevent.uobject, attrs);
1020 resp.base.cq_handle = obj->uevent.uobject.id;
1021 resp.base.cqe = cq->cqe;
1022 resp.response_length = uverbs_response_length(attrs, sizeof(resp));
1023 return uverbs_response(attrs, &resp, sizeof(resp));
1026 rdma_restrack_put(&cq->res);
1030 ib_uverbs_release_ucq(ev_file, obj);
1032 uobj_alloc_abort(&obj->uevent.uobject, attrs);
1036 static int ib_uverbs_create_cq(struct uverbs_attr_bundle *attrs)
1038 struct ib_uverbs_create_cq cmd;
1039 struct ib_uverbs_ex_create_cq cmd_ex;
1042 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1046 memset(&cmd_ex, 0, sizeof(cmd_ex));
1047 cmd_ex.user_handle = cmd.user_handle;
1048 cmd_ex.cqe = cmd.cqe;
1049 cmd_ex.comp_vector = cmd.comp_vector;
1050 cmd_ex.comp_channel = cmd.comp_channel;
1052 return create_cq(attrs, &cmd_ex);
1055 static int ib_uverbs_ex_create_cq(struct uverbs_attr_bundle *attrs)
1057 struct ib_uverbs_ex_create_cq cmd;
1060 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1070 return create_cq(attrs, &cmd);
1073 static int ib_uverbs_resize_cq(struct uverbs_attr_bundle *attrs)
1075 struct ib_uverbs_resize_cq cmd;
1076 struct ib_uverbs_resize_cq_resp resp = {};
1080 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1084 cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs);
1088 ret = cq->device->ops.resize_cq(cq, cmd.cqe, &attrs->driver_udata);
1094 ret = uverbs_response(attrs, &resp, sizeof(resp));
1096 rdma_lookup_put_uobject(&cq->uobject->uevent.uobject,
1097 UVERBS_LOOKUP_READ);
1102 static int copy_wc_to_user(struct ib_device *ib_dev, void __user *dest,
1105 struct ib_uverbs_wc tmp;
1107 tmp.wr_id = wc->wr_id;
1108 tmp.status = wc->status;
1109 tmp.opcode = wc->opcode;
1110 tmp.vendor_err = wc->vendor_err;
1111 tmp.byte_len = wc->byte_len;
1112 tmp.ex.imm_data = wc->ex.imm_data;
1113 tmp.qp_num = wc->qp->qp_num;
1114 tmp.src_qp = wc->src_qp;
1115 tmp.wc_flags = wc->wc_flags;
1116 tmp.pkey_index = wc->pkey_index;
1117 if (rdma_cap_opa_ah(ib_dev, wc->port_num))
1118 tmp.slid = OPA_TO_IB_UCAST_LID(wc->slid);
1120 tmp.slid = ib_lid_cpu16(wc->slid);
1122 tmp.dlid_path_bits = wc->dlid_path_bits;
1123 tmp.port_num = wc->port_num;
1126 if (copy_to_user(dest, &tmp, sizeof tmp))
1132 static int ib_uverbs_poll_cq(struct uverbs_attr_bundle *attrs)
1134 struct ib_uverbs_poll_cq cmd;
1135 struct ib_uverbs_poll_cq_resp resp;
1136 u8 __user *header_ptr;
1137 u8 __user *data_ptr;
1142 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1146 cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs);
1150 /* we copy a struct ib_uverbs_poll_cq_resp to user space */
1151 header_ptr = attrs->ucore.outbuf;
1152 data_ptr = header_ptr + sizeof resp;
1154 memset(&resp, 0, sizeof resp);
1155 while (resp.count < cmd.ne) {
1156 ret = ib_poll_cq(cq, 1, &wc);
1162 ret = copy_wc_to_user(cq->device, data_ptr, &wc);
1166 data_ptr += sizeof(struct ib_uverbs_wc);
1170 if (copy_to_user(header_ptr, &resp, sizeof resp)) {
1176 if (uverbs_attr_is_valid(attrs, UVERBS_ATTR_CORE_OUT))
1177 ret = uverbs_output_written(attrs, UVERBS_ATTR_CORE_OUT);
1180 rdma_lookup_put_uobject(&cq->uobject->uevent.uobject,
1181 UVERBS_LOOKUP_READ);
1185 static int ib_uverbs_req_notify_cq(struct uverbs_attr_bundle *attrs)
1187 struct ib_uverbs_req_notify_cq cmd;
1191 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1195 cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs);
1199 ib_req_notify_cq(cq, cmd.solicited_only ?
1200 IB_CQ_SOLICITED : IB_CQ_NEXT_COMP);
1202 rdma_lookup_put_uobject(&cq->uobject->uevent.uobject,
1203 UVERBS_LOOKUP_READ);
1207 static int ib_uverbs_destroy_cq(struct uverbs_attr_bundle *attrs)
1209 struct ib_uverbs_destroy_cq cmd;
1210 struct ib_uverbs_destroy_cq_resp resp;
1211 struct ib_uobject *uobj;
1212 struct ib_ucq_object *obj;
1215 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1219 uobj = uobj_get_destroy(UVERBS_OBJECT_CQ, cmd.cq_handle, attrs);
1221 return PTR_ERR(uobj);
1223 obj = container_of(uobj, struct ib_ucq_object, uevent.uobject);
1224 memset(&resp, 0, sizeof(resp));
1225 resp.comp_events_reported = obj->comp_events_reported;
1226 resp.async_events_reported = obj->uevent.events_reported;
1228 uobj_put_destroy(uobj);
1230 return uverbs_response(attrs, &resp, sizeof(resp));
1233 static int create_qp(struct uverbs_attr_bundle *attrs,
1234 struct ib_uverbs_ex_create_qp *cmd)
1236 struct ib_uqp_object *obj;
1237 struct ib_device *device;
1238 struct ib_pd *pd = NULL;
1239 struct ib_xrcd *xrcd = NULL;
1240 struct ib_uobject *xrcd_uobj = ERR_PTR(-ENOENT);
1241 struct ib_cq *scq = NULL, *rcq = NULL;
1242 struct ib_srq *srq = NULL;
1244 struct ib_qp_init_attr attr = {};
1245 struct ib_uverbs_ex_create_qp_resp resp = {};
1247 struct ib_rwq_ind_table *ind_tbl = NULL;
1249 struct ib_device *ib_dev;
1251 switch (cmd->qp_type) {
1252 case IB_QPT_RAW_PACKET:
1253 if (!capable(CAP_NET_RAW))
1259 case IB_QPT_XRC_INI:
1260 case IB_QPT_XRC_TGT:
1267 obj = (struct ib_uqp_object *)uobj_alloc(UVERBS_OBJECT_QP, attrs,
1270 return PTR_ERR(obj);
1272 obj->uevent.uobject.user_handle = cmd->user_handle;
1273 mutex_init(&obj->mcast_lock);
1275 if (cmd->comp_mask & IB_UVERBS_CREATE_QP_MASK_IND_TABLE) {
1276 ind_tbl = uobj_get_obj_read(rwq_ind_table,
1277 UVERBS_OBJECT_RWQ_IND_TBL,
1278 cmd->rwq_ind_tbl_handle, attrs);
1284 attr.rwq_ind_tbl = ind_tbl;
1287 if (ind_tbl && (cmd->max_recv_wr || cmd->max_recv_sge || cmd->is_srq)) {
1292 if (ind_tbl && !cmd->max_send_wr)
1295 if (cmd->qp_type == IB_QPT_XRC_TGT) {
1296 xrcd_uobj = uobj_get_read(UVERBS_OBJECT_XRCD, cmd->pd_handle,
1299 if (IS_ERR(xrcd_uobj)) {
1304 xrcd = (struct ib_xrcd *)xrcd_uobj->object;
1309 device = xrcd->device;
1311 if (cmd->qp_type == IB_QPT_XRC_INI) {
1312 cmd->max_recv_wr = 0;
1313 cmd->max_recv_sge = 0;
1316 srq = uobj_get_obj_read(srq, UVERBS_OBJECT_SRQ,
1317 cmd->srq_handle, attrs);
1318 if (!srq || srq->srq_type == IB_SRQT_XRC) {
1325 if (cmd->recv_cq_handle != cmd->send_cq_handle) {
1326 rcq = uobj_get_obj_read(
1327 cq, UVERBS_OBJECT_CQ,
1328 cmd->recv_cq_handle, attrs);
1338 scq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ,
1339 cmd->send_cq_handle, attrs);
1342 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd->pd_handle,
1344 if (!pd || (!scq && has_sq)) {
1349 device = pd->device;
1352 attr.event_handler = ib_uverbs_qp_event_handler;
1357 attr.sq_sig_type = cmd->sq_sig_all ? IB_SIGNAL_ALL_WR :
1359 attr.qp_type = cmd->qp_type;
1360 attr.create_flags = 0;
1362 attr.cap.max_send_wr = cmd->max_send_wr;
1363 attr.cap.max_recv_wr = cmd->max_recv_wr;
1364 attr.cap.max_send_sge = cmd->max_send_sge;
1365 attr.cap.max_recv_sge = cmd->max_recv_sge;
1366 attr.cap.max_inline_data = cmd->max_inline_data;
1368 INIT_LIST_HEAD(&obj->uevent.event_list);
1369 INIT_LIST_HEAD(&obj->mcast_list);
1371 attr.create_flags = cmd->create_flags;
1372 if (attr.create_flags & ~(IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK |
1373 IB_QP_CREATE_CROSS_CHANNEL |
1374 IB_QP_CREATE_MANAGED_SEND |
1375 IB_QP_CREATE_MANAGED_RECV |
1376 IB_QP_CREATE_SCATTER_FCS |
1377 IB_QP_CREATE_CVLAN_STRIPPING |
1378 IB_QP_CREATE_SOURCE_QPN |
1379 IB_QP_CREATE_PCI_WRITE_END_PADDING)) {
1384 if (attr.create_flags & IB_QP_CREATE_SOURCE_QPN) {
1385 if (!capable(CAP_NET_RAW)) {
1390 attr.source_qpn = cmd->source_qpn;
1393 if (cmd->qp_type == IB_QPT_XRC_TGT)
1394 qp = ib_create_qp(pd, &attr);
1396 qp = _ib_create_qp(device, pd, &attr, &attrs->driver_udata, obj,
1404 if (cmd->qp_type != IB_QPT_XRC_TGT) {
1405 ret = ib_create_qp_security(qp, device);
1409 atomic_inc(&pd->usecnt);
1411 atomic_inc(&attr.send_cq->usecnt);
1413 atomic_inc(&attr.recv_cq->usecnt);
1415 atomic_inc(&attr.srq->usecnt);
1417 atomic_inc(&ind_tbl->usecnt);
1419 /* It is done in _ib_create_qp for other QP types */
1423 obj->uevent.uobject.object = qp;
1424 obj->uevent.event_file = READ_ONCE(attrs->ufile->default_async_file);
1425 if (obj->uevent.event_file)
1426 uverbs_uobject_get(&obj->uevent.event_file->uobj);
1429 obj->uxrcd = container_of(xrcd_uobj, struct ib_uxrcd_object,
1431 atomic_inc(&obj->uxrcd->refcnt);
1432 uobj_put_read(xrcd_uobj);
1436 uobj_put_obj_read(pd);
1438 rdma_lookup_put_uobject(&scq->uobject->uevent.uobject,
1439 UVERBS_LOOKUP_READ);
1440 if (rcq && rcq != scq)
1441 rdma_lookup_put_uobject(&rcq->uobject->uevent.uobject,
1442 UVERBS_LOOKUP_READ);
1444 rdma_lookup_put_uobject(&srq->uobject->uevent.uobject,
1445 UVERBS_LOOKUP_READ);
1447 uobj_put_obj_read(ind_tbl);
1448 uobj_finalize_uobj_create(&obj->uevent.uobject, attrs);
1450 resp.base.qpn = qp->qp_num;
1451 resp.base.qp_handle = obj->uevent.uobject.id;
1452 resp.base.max_recv_sge = attr.cap.max_recv_sge;
1453 resp.base.max_send_sge = attr.cap.max_send_sge;
1454 resp.base.max_recv_wr = attr.cap.max_recv_wr;
1455 resp.base.max_send_wr = attr.cap.max_send_wr;
1456 resp.base.max_inline_data = attr.cap.max_inline_data;
1457 resp.response_length = uverbs_response_length(attrs, sizeof(resp));
1458 return uverbs_response(attrs, &resp, sizeof(resp));
1461 ib_destroy_qp_user(qp, uverbs_get_cleared_udata(attrs));
1464 if (!IS_ERR(xrcd_uobj))
1465 uobj_put_read(xrcd_uobj);
1467 uobj_put_obj_read(pd);
1469 rdma_lookup_put_uobject(&scq->uobject->uevent.uobject,
1470 UVERBS_LOOKUP_READ);
1471 if (rcq && rcq != scq)
1472 rdma_lookup_put_uobject(&rcq->uobject->uevent.uobject,
1473 UVERBS_LOOKUP_READ);
1475 rdma_lookup_put_uobject(&srq->uobject->uevent.uobject,
1476 UVERBS_LOOKUP_READ);
1478 uobj_put_obj_read(ind_tbl);
1480 uobj_alloc_abort(&obj->uevent.uobject, attrs);
1484 static int ib_uverbs_create_qp(struct uverbs_attr_bundle *attrs)
1486 struct ib_uverbs_create_qp cmd;
1487 struct ib_uverbs_ex_create_qp cmd_ex;
1490 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1494 memset(&cmd_ex, 0, sizeof(cmd_ex));
1495 cmd_ex.user_handle = cmd.user_handle;
1496 cmd_ex.pd_handle = cmd.pd_handle;
1497 cmd_ex.send_cq_handle = cmd.send_cq_handle;
1498 cmd_ex.recv_cq_handle = cmd.recv_cq_handle;
1499 cmd_ex.srq_handle = cmd.srq_handle;
1500 cmd_ex.max_send_wr = cmd.max_send_wr;
1501 cmd_ex.max_recv_wr = cmd.max_recv_wr;
1502 cmd_ex.max_send_sge = cmd.max_send_sge;
1503 cmd_ex.max_recv_sge = cmd.max_recv_sge;
1504 cmd_ex.max_inline_data = cmd.max_inline_data;
1505 cmd_ex.sq_sig_all = cmd.sq_sig_all;
1506 cmd_ex.qp_type = cmd.qp_type;
1507 cmd_ex.is_srq = cmd.is_srq;
1509 return create_qp(attrs, &cmd_ex);
1512 static int ib_uverbs_ex_create_qp(struct uverbs_attr_bundle *attrs)
1514 struct ib_uverbs_ex_create_qp cmd;
1517 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1521 if (cmd.comp_mask & ~IB_UVERBS_CREATE_QP_SUP_COMP_MASK)
1527 return create_qp(attrs, &cmd);
1530 static int ib_uverbs_open_qp(struct uverbs_attr_bundle *attrs)
1532 struct ib_uverbs_create_qp_resp resp = {};
1533 struct ib_uverbs_open_qp cmd;
1534 struct ib_uqp_object *obj;
1535 struct ib_xrcd *xrcd;
1537 struct ib_qp_open_attr attr = {};
1539 struct ib_uobject *xrcd_uobj;
1540 struct ib_device *ib_dev;
1542 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1546 obj = (struct ib_uqp_object *)uobj_alloc(UVERBS_OBJECT_QP, attrs,
1549 return PTR_ERR(obj);
1551 xrcd_uobj = uobj_get_read(UVERBS_OBJECT_XRCD, cmd.pd_handle, attrs);
1552 if (IS_ERR(xrcd_uobj)) {
1557 xrcd = (struct ib_xrcd *)xrcd_uobj->object;
1563 attr.event_handler = ib_uverbs_qp_event_handler;
1564 attr.qp_num = cmd.qpn;
1565 attr.qp_type = cmd.qp_type;
1567 INIT_LIST_HEAD(&obj->uevent.event_list);
1568 INIT_LIST_HEAD(&obj->mcast_list);
1570 qp = ib_open_qp(xrcd, &attr);
1576 obj->uevent.uobject.object = qp;
1577 obj->uevent.uobject.user_handle = cmd.user_handle;
1579 obj->uxrcd = container_of(xrcd_uobj, struct ib_uxrcd_object, uobject);
1580 atomic_inc(&obj->uxrcd->refcnt);
1582 uobj_put_read(xrcd_uobj);
1583 uobj_finalize_uobj_create(&obj->uevent.uobject, attrs);
1585 resp.qpn = qp->qp_num;
1586 resp.qp_handle = obj->uevent.uobject.id;
1587 return uverbs_response(attrs, &resp, sizeof(resp));
1590 uobj_put_read(xrcd_uobj);
1592 uobj_alloc_abort(&obj->uevent.uobject, attrs);
1596 static void copy_ah_attr_to_uverbs(struct ib_uverbs_qp_dest *uverb_attr,
1597 struct rdma_ah_attr *rdma_attr)
1599 const struct ib_global_route *grh;
1601 uverb_attr->dlid = rdma_ah_get_dlid(rdma_attr);
1602 uverb_attr->sl = rdma_ah_get_sl(rdma_attr);
1603 uverb_attr->src_path_bits = rdma_ah_get_path_bits(rdma_attr);
1604 uverb_attr->static_rate = rdma_ah_get_static_rate(rdma_attr);
1605 uverb_attr->is_global = !!(rdma_ah_get_ah_flags(rdma_attr) &
1607 if (uverb_attr->is_global) {
1608 grh = rdma_ah_read_grh(rdma_attr);
1609 memcpy(uverb_attr->dgid, grh->dgid.raw, 16);
1610 uverb_attr->flow_label = grh->flow_label;
1611 uverb_attr->sgid_index = grh->sgid_index;
1612 uverb_attr->hop_limit = grh->hop_limit;
1613 uverb_attr->traffic_class = grh->traffic_class;
1615 uverb_attr->port_num = rdma_ah_get_port_num(rdma_attr);
1618 static int ib_uverbs_query_qp(struct uverbs_attr_bundle *attrs)
1620 struct ib_uverbs_query_qp cmd;
1621 struct ib_uverbs_query_qp_resp resp;
1623 struct ib_qp_attr *attr;
1624 struct ib_qp_init_attr *init_attr;
1627 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1631 attr = kmalloc(sizeof *attr, GFP_KERNEL);
1632 init_attr = kmalloc(sizeof *init_attr, GFP_KERNEL);
1633 if (!attr || !init_attr) {
1638 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
1644 ret = ib_query_qp(qp, attr, cmd.attr_mask, init_attr);
1646 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
1647 UVERBS_LOOKUP_READ);
1652 memset(&resp, 0, sizeof resp);
1654 resp.qp_state = attr->qp_state;
1655 resp.cur_qp_state = attr->cur_qp_state;
1656 resp.path_mtu = attr->path_mtu;
1657 resp.path_mig_state = attr->path_mig_state;
1658 resp.qkey = attr->qkey;
1659 resp.rq_psn = attr->rq_psn;
1660 resp.sq_psn = attr->sq_psn;
1661 resp.dest_qp_num = attr->dest_qp_num;
1662 resp.qp_access_flags = attr->qp_access_flags;
1663 resp.pkey_index = attr->pkey_index;
1664 resp.alt_pkey_index = attr->alt_pkey_index;
1665 resp.sq_draining = attr->sq_draining;
1666 resp.max_rd_atomic = attr->max_rd_atomic;
1667 resp.max_dest_rd_atomic = attr->max_dest_rd_atomic;
1668 resp.min_rnr_timer = attr->min_rnr_timer;
1669 resp.port_num = attr->port_num;
1670 resp.timeout = attr->timeout;
1671 resp.retry_cnt = attr->retry_cnt;
1672 resp.rnr_retry = attr->rnr_retry;
1673 resp.alt_port_num = attr->alt_port_num;
1674 resp.alt_timeout = attr->alt_timeout;
1676 copy_ah_attr_to_uverbs(&resp.dest, &attr->ah_attr);
1677 copy_ah_attr_to_uverbs(&resp.alt_dest, &attr->alt_ah_attr);
1679 resp.max_send_wr = init_attr->cap.max_send_wr;
1680 resp.max_recv_wr = init_attr->cap.max_recv_wr;
1681 resp.max_send_sge = init_attr->cap.max_send_sge;
1682 resp.max_recv_sge = init_attr->cap.max_recv_sge;
1683 resp.max_inline_data = init_attr->cap.max_inline_data;
1684 resp.sq_sig_all = init_attr->sq_sig_type == IB_SIGNAL_ALL_WR;
1686 ret = uverbs_response(attrs, &resp, sizeof(resp));
1695 /* Remove ignored fields set in the attribute mask */
1696 static int modify_qp_mask(enum ib_qp_type qp_type, int mask)
1699 case IB_QPT_XRC_INI:
1700 return mask & ~(IB_QP_MAX_DEST_RD_ATOMIC | IB_QP_MIN_RNR_TIMER);
1701 case IB_QPT_XRC_TGT:
1702 return mask & ~(IB_QP_MAX_QP_RD_ATOMIC | IB_QP_RETRY_CNT |
1709 static void copy_ah_attr_from_uverbs(struct ib_device *dev,
1710 struct rdma_ah_attr *rdma_attr,
1711 struct ib_uverbs_qp_dest *uverb_attr)
1713 rdma_attr->type = rdma_ah_find_type(dev, uverb_attr->port_num);
1714 if (uverb_attr->is_global) {
1715 rdma_ah_set_grh(rdma_attr, NULL,
1716 uverb_attr->flow_label,
1717 uverb_attr->sgid_index,
1718 uverb_attr->hop_limit,
1719 uverb_attr->traffic_class);
1720 rdma_ah_set_dgid_raw(rdma_attr, uverb_attr->dgid);
1722 rdma_ah_set_ah_flags(rdma_attr, 0);
1724 rdma_ah_set_dlid(rdma_attr, uverb_attr->dlid);
1725 rdma_ah_set_sl(rdma_attr, uverb_attr->sl);
1726 rdma_ah_set_path_bits(rdma_attr, uverb_attr->src_path_bits);
1727 rdma_ah_set_static_rate(rdma_attr, uverb_attr->static_rate);
1728 rdma_ah_set_port_num(rdma_attr, uverb_attr->port_num);
1729 rdma_ah_set_make_grd(rdma_attr, false);
1732 static int modify_qp(struct uverbs_attr_bundle *attrs,
1733 struct ib_uverbs_ex_modify_qp *cmd)
1735 struct ib_qp_attr *attr;
1739 attr = kzalloc(sizeof(*attr), GFP_KERNEL);
1743 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd->base.qp_handle,
1750 if ((cmd->base.attr_mask & IB_QP_PORT) &&
1751 !rdma_is_port_valid(qp->device, cmd->base.port_num)) {
1756 if ((cmd->base.attr_mask & IB_QP_AV)) {
1757 if (!rdma_is_port_valid(qp->device, cmd->base.dest.port_num)) {
1762 if (cmd->base.attr_mask & IB_QP_STATE &&
1763 cmd->base.qp_state == IB_QPS_RTR) {
1764 /* We are in INIT->RTR TRANSITION (if we are not,
1765 * this transition will be rejected in subsequent checks).
1766 * In the INIT->RTR transition, we cannot have IB_QP_PORT set,
1767 * but the IB_QP_STATE flag is required.
1769 * Since kernel 3.14 (commit dbf727de7440), the uverbs driver,
1770 * when IB_QP_AV is set, has required inclusion of a valid
1771 * port number in the primary AV. (AVs are created and handled
1772 * differently for infiniband and ethernet (RoCE) ports).
1774 * Check the port number included in the primary AV against
1775 * the port number in the qp struct, which was set (and saved)
1776 * in the RST->INIT transition.
1778 if (cmd->base.dest.port_num != qp->real_qp->port) {
1783 /* We are in SQD->SQD. (If we are not, this transition will
1784 * be rejected later in the verbs layer checks).
1785 * Check for both IB_QP_PORT and IB_QP_AV, these can be set
1786 * together in the SQD->SQD transition.
1788 * If only IP_QP_AV was set, add in IB_QP_PORT as well (the
1789 * verbs layer driver does not track primary port changes
1790 * resulting from path migration. Thus, in SQD, if the primary
1791 * AV is modified, the primary port should also be modified).
1793 * Note that in this transition, the IB_QP_STATE flag
1796 if (((cmd->base.attr_mask & (IB_QP_AV | IB_QP_PORT))
1797 == (IB_QP_AV | IB_QP_PORT)) &&
1798 cmd->base.port_num != cmd->base.dest.port_num) {
1802 if ((cmd->base.attr_mask & (IB_QP_AV | IB_QP_PORT))
1804 cmd->base.attr_mask |= IB_QP_PORT;
1805 cmd->base.port_num = cmd->base.dest.port_num;
1810 if ((cmd->base.attr_mask & IB_QP_ALT_PATH) &&
1811 (!rdma_is_port_valid(qp->device, cmd->base.alt_port_num) ||
1812 !rdma_is_port_valid(qp->device, cmd->base.alt_dest.port_num) ||
1813 cmd->base.alt_port_num != cmd->base.alt_dest.port_num)) {
1818 if ((cmd->base.attr_mask & IB_QP_CUR_STATE &&
1819 cmd->base.cur_qp_state > IB_QPS_ERR) ||
1820 (cmd->base.attr_mask & IB_QP_STATE &&
1821 cmd->base.qp_state > IB_QPS_ERR)) {
1826 if (cmd->base.attr_mask & IB_QP_STATE)
1827 attr->qp_state = cmd->base.qp_state;
1828 if (cmd->base.attr_mask & IB_QP_CUR_STATE)
1829 attr->cur_qp_state = cmd->base.cur_qp_state;
1830 if (cmd->base.attr_mask & IB_QP_PATH_MTU)
1831 attr->path_mtu = cmd->base.path_mtu;
1832 if (cmd->base.attr_mask & IB_QP_PATH_MIG_STATE)
1833 attr->path_mig_state = cmd->base.path_mig_state;
1834 if (cmd->base.attr_mask & IB_QP_QKEY)
1835 attr->qkey = cmd->base.qkey;
1836 if (cmd->base.attr_mask & IB_QP_RQ_PSN)
1837 attr->rq_psn = cmd->base.rq_psn;
1838 if (cmd->base.attr_mask & IB_QP_SQ_PSN)
1839 attr->sq_psn = cmd->base.sq_psn;
1840 if (cmd->base.attr_mask & IB_QP_DEST_QPN)
1841 attr->dest_qp_num = cmd->base.dest_qp_num;
1842 if (cmd->base.attr_mask & IB_QP_ACCESS_FLAGS)
1843 attr->qp_access_flags = cmd->base.qp_access_flags;
1844 if (cmd->base.attr_mask & IB_QP_PKEY_INDEX)
1845 attr->pkey_index = cmd->base.pkey_index;
1846 if (cmd->base.attr_mask & IB_QP_EN_SQD_ASYNC_NOTIFY)
1847 attr->en_sqd_async_notify = cmd->base.en_sqd_async_notify;
1848 if (cmd->base.attr_mask & IB_QP_MAX_QP_RD_ATOMIC)
1849 attr->max_rd_atomic = cmd->base.max_rd_atomic;
1850 if (cmd->base.attr_mask & IB_QP_MAX_DEST_RD_ATOMIC)
1851 attr->max_dest_rd_atomic = cmd->base.max_dest_rd_atomic;
1852 if (cmd->base.attr_mask & IB_QP_MIN_RNR_TIMER)
1853 attr->min_rnr_timer = cmd->base.min_rnr_timer;
1854 if (cmd->base.attr_mask & IB_QP_PORT)
1855 attr->port_num = cmd->base.port_num;
1856 if (cmd->base.attr_mask & IB_QP_TIMEOUT)
1857 attr->timeout = cmd->base.timeout;
1858 if (cmd->base.attr_mask & IB_QP_RETRY_CNT)
1859 attr->retry_cnt = cmd->base.retry_cnt;
1860 if (cmd->base.attr_mask & IB_QP_RNR_RETRY)
1861 attr->rnr_retry = cmd->base.rnr_retry;
1862 if (cmd->base.attr_mask & IB_QP_ALT_PATH) {
1863 attr->alt_port_num = cmd->base.alt_port_num;
1864 attr->alt_timeout = cmd->base.alt_timeout;
1865 attr->alt_pkey_index = cmd->base.alt_pkey_index;
1867 if (cmd->base.attr_mask & IB_QP_RATE_LIMIT)
1868 attr->rate_limit = cmd->rate_limit;
1870 if (cmd->base.attr_mask & IB_QP_AV)
1871 copy_ah_attr_from_uverbs(qp->device, &attr->ah_attr,
1874 if (cmd->base.attr_mask & IB_QP_ALT_PATH)
1875 copy_ah_attr_from_uverbs(qp->device, &attr->alt_ah_attr,
1876 &cmd->base.alt_dest);
1878 ret = ib_modify_qp_with_udata(qp, attr,
1879 modify_qp_mask(qp->qp_type,
1880 cmd->base.attr_mask),
1881 &attrs->driver_udata);
1884 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
1885 UVERBS_LOOKUP_READ);
1892 static int ib_uverbs_modify_qp(struct uverbs_attr_bundle *attrs)
1894 struct ib_uverbs_ex_modify_qp cmd;
1897 ret = uverbs_request(attrs, &cmd.base, sizeof(cmd.base));
1901 if (cmd.base.attr_mask & ~IB_QP_ATTR_STANDARD_BITS)
1904 return modify_qp(attrs, &cmd);
1907 static int ib_uverbs_ex_modify_qp(struct uverbs_attr_bundle *attrs)
1909 struct ib_uverbs_ex_modify_qp cmd;
1910 struct ib_uverbs_ex_modify_qp_resp resp = {
1911 .response_length = uverbs_response_length(attrs, sizeof(resp))
1915 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1920 * Last bit is reserved for extending the attr_mask by
1921 * using another field.
1923 if (cmd.base.attr_mask & ~(IB_QP_ATTR_STANDARD_BITS | IB_QP_RATE_LIMIT))
1926 ret = modify_qp(attrs, &cmd);
1930 return uverbs_response(attrs, &resp, sizeof(resp));
1933 static int ib_uverbs_destroy_qp(struct uverbs_attr_bundle *attrs)
1935 struct ib_uverbs_destroy_qp cmd;
1936 struct ib_uverbs_destroy_qp_resp resp;
1937 struct ib_uobject *uobj;
1938 struct ib_uqp_object *obj;
1941 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1945 uobj = uobj_get_destroy(UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
1947 return PTR_ERR(uobj);
1949 obj = container_of(uobj, struct ib_uqp_object, uevent.uobject);
1950 memset(&resp, 0, sizeof(resp));
1951 resp.events_reported = obj->uevent.events_reported;
1953 uobj_put_destroy(uobj);
1955 return uverbs_response(attrs, &resp, sizeof(resp));
1958 static void *alloc_wr(size_t wr_size, __u32 num_sge)
1960 if (num_sge >= (U32_MAX - ALIGN(wr_size, sizeof (struct ib_sge))) /
1961 sizeof (struct ib_sge))
1964 return kmalloc(ALIGN(wr_size, sizeof (struct ib_sge)) +
1965 num_sge * sizeof (struct ib_sge), GFP_KERNEL);
1968 static int ib_uverbs_post_send(struct uverbs_attr_bundle *attrs)
1970 struct ib_uverbs_post_send cmd;
1971 struct ib_uverbs_post_send_resp resp;
1972 struct ib_uverbs_send_wr *user_wr;
1973 struct ib_send_wr *wr = NULL, *last, *next;
1974 const struct ib_send_wr *bad_wr;
1980 const struct ib_sge __user *sgls;
1981 const void __user *wqes;
1982 struct uverbs_req_iter iter;
1984 ret = uverbs_request_start(attrs, &iter, &cmd, sizeof(cmd));
1987 wqes = uverbs_request_next_ptr(&iter, cmd.wqe_size * cmd.wr_count);
1989 return PTR_ERR(wqes);
1990 sgls = uverbs_request_next_ptr(
1991 &iter, cmd.sge_count * sizeof(struct ib_uverbs_sge));
1993 return PTR_ERR(sgls);
1994 ret = uverbs_request_finish(&iter);
1998 user_wr = kmalloc(cmd.wqe_size, GFP_KERNEL);
2002 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
2008 is_ud = qp->qp_type == IB_QPT_UD;
2011 for (i = 0; i < cmd.wr_count; ++i) {
2012 if (copy_from_user(user_wr, wqes + i * cmd.wqe_size,
2018 if (user_wr->num_sge + sg_ind > cmd.sge_count) {
2024 struct ib_ud_wr *ud;
2026 if (user_wr->opcode != IB_WR_SEND &&
2027 user_wr->opcode != IB_WR_SEND_WITH_IMM) {
2032 next_size = sizeof(*ud);
2033 ud = alloc_wr(next_size, user_wr->num_sge);
2039 ud->ah = uobj_get_obj_read(ah, UVERBS_OBJECT_AH,
2040 user_wr->wr.ud.ah, attrs);
2046 ud->remote_qpn = user_wr->wr.ud.remote_qpn;
2047 ud->remote_qkey = user_wr->wr.ud.remote_qkey;
2050 } else if (user_wr->opcode == IB_WR_RDMA_WRITE_WITH_IMM ||
2051 user_wr->opcode == IB_WR_RDMA_WRITE ||
2052 user_wr->opcode == IB_WR_RDMA_READ) {
2053 struct ib_rdma_wr *rdma;
2055 next_size = sizeof(*rdma);
2056 rdma = alloc_wr(next_size, user_wr->num_sge);
2062 rdma->remote_addr = user_wr->wr.rdma.remote_addr;
2063 rdma->rkey = user_wr->wr.rdma.rkey;
2066 } else if (user_wr->opcode == IB_WR_ATOMIC_CMP_AND_SWP ||
2067 user_wr->opcode == IB_WR_ATOMIC_FETCH_AND_ADD) {
2068 struct ib_atomic_wr *atomic;
2070 next_size = sizeof(*atomic);
2071 atomic = alloc_wr(next_size, user_wr->num_sge);
2077 atomic->remote_addr = user_wr->wr.atomic.remote_addr;
2078 atomic->compare_add = user_wr->wr.atomic.compare_add;
2079 atomic->swap = user_wr->wr.atomic.swap;
2080 atomic->rkey = user_wr->wr.atomic.rkey;
2083 } else if (user_wr->opcode == IB_WR_SEND ||
2084 user_wr->opcode == IB_WR_SEND_WITH_IMM ||
2085 user_wr->opcode == IB_WR_SEND_WITH_INV) {
2086 next_size = sizeof(*next);
2087 next = alloc_wr(next_size, user_wr->num_sge);
2097 if (user_wr->opcode == IB_WR_SEND_WITH_IMM ||
2098 user_wr->opcode == IB_WR_RDMA_WRITE_WITH_IMM) {
2100 (__be32 __force) user_wr->ex.imm_data;
2101 } else if (user_wr->opcode == IB_WR_SEND_WITH_INV) {
2102 next->ex.invalidate_rkey = user_wr->ex.invalidate_rkey;
2112 next->wr_id = user_wr->wr_id;
2113 next->num_sge = user_wr->num_sge;
2114 next->opcode = user_wr->opcode;
2115 next->send_flags = user_wr->send_flags;
2117 if (next->num_sge) {
2118 next->sg_list = (void *) next +
2119 ALIGN(next_size, sizeof(struct ib_sge));
2120 if (copy_from_user(next->sg_list, sgls + sg_ind,
2122 sizeof(struct ib_sge))) {
2126 sg_ind += next->num_sge;
2128 next->sg_list = NULL;
2132 ret = qp->device->ops.post_send(qp->real_qp, wr, &bad_wr);
2134 for (next = wr; next; next = next->next) {
2140 ret2 = uverbs_response(attrs, &resp, sizeof(resp));
2145 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
2146 UVERBS_LOOKUP_READ);
2149 if (is_ud && ud_wr(wr)->ah)
2150 uobj_put_obj_read(ud_wr(wr)->ah);
2162 static struct ib_recv_wr *
2163 ib_uverbs_unmarshall_recv(struct uverbs_req_iter *iter, u32 wr_count,
2164 u32 wqe_size, u32 sge_count)
2166 struct ib_uverbs_recv_wr *user_wr;
2167 struct ib_recv_wr *wr = NULL, *last, *next;
2171 const struct ib_sge __user *sgls;
2172 const void __user *wqes;
2174 if (wqe_size < sizeof (struct ib_uverbs_recv_wr))
2175 return ERR_PTR(-EINVAL);
2177 wqes = uverbs_request_next_ptr(iter, wqe_size * wr_count);
2179 return ERR_CAST(wqes);
2180 sgls = uverbs_request_next_ptr(
2181 iter, sge_count * sizeof(struct ib_uverbs_sge));
2183 return ERR_CAST(sgls);
2184 ret = uverbs_request_finish(iter);
2186 return ERR_PTR(ret);
2188 user_wr = kmalloc(wqe_size, GFP_KERNEL);
2190 return ERR_PTR(-ENOMEM);
2194 for (i = 0; i < wr_count; ++i) {
2195 if (copy_from_user(user_wr, wqes + i * wqe_size,
2201 if (user_wr->num_sge + sg_ind > sge_count) {
2206 if (user_wr->num_sge >=
2207 (U32_MAX - ALIGN(sizeof *next, sizeof (struct ib_sge))) /
2208 sizeof (struct ib_sge)) {
2213 next = kmalloc(ALIGN(sizeof *next, sizeof (struct ib_sge)) +
2214 user_wr->num_sge * sizeof (struct ib_sge),
2228 next->wr_id = user_wr->wr_id;
2229 next->num_sge = user_wr->num_sge;
2231 if (next->num_sge) {
2232 next->sg_list = (void *) next +
2233 ALIGN(sizeof *next, sizeof (struct ib_sge));
2234 if (copy_from_user(next->sg_list, sgls + sg_ind,
2236 sizeof(struct ib_sge))) {
2240 sg_ind += next->num_sge;
2242 next->sg_list = NULL;
2257 return ERR_PTR(ret);
2260 static int ib_uverbs_post_recv(struct uverbs_attr_bundle *attrs)
2262 struct ib_uverbs_post_recv cmd;
2263 struct ib_uverbs_post_recv_resp resp;
2264 struct ib_recv_wr *wr, *next;
2265 const struct ib_recv_wr *bad_wr;
2268 struct uverbs_req_iter iter;
2270 ret = uverbs_request_start(attrs, &iter, &cmd, sizeof(cmd));
2274 wr = ib_uverbs_unmarshall_recv(&iter, cmd.wr_count, cmd.wqe_size,
2279 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
2286 ret = qp->device->ops.post_recv(qp->real_qp, wr, &bad_wr);
2288 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
2289 UVERBS_LOOKUP_READ);
2291 for (next = wr; next; next = next->next) {
2298 ret2 = uverbs_response(attrs, &resp, sizeof(resp));
2311 static int ib_uverbs_post_srq_recv(struct uverbs_attr_bundle *attrs)
2313 struct ib_uverbs_post_srq_recv cmd;
2314 struct ib_uverbs_post_srq_recv_resp resp;
2315 struct ib_recv_wr *wr, *next;
2316 const struct ib_recv_wr *bad_wr;
2319 struct uverbs_req_iter iter;
2321 ret = uverbs_request_start(attrs, &iter, &cmd, sizeof(cmd));
2325 wr = ib_uverbs_unmarshall_recv(&iter, cmd.wr_count, cmd.wqe_size,
2330 srq = uobj_get_obj_read(srq, UVERBS_OBJECT_SRQ, cmd.srq_handle, attrs);
2337 ret = srq->device->ops.post_srq_recv(srq, wr, &bad_wr);
2339 rdma_lookup_put_uobject(&srq->uobject->uevent.uobject,
2340 UVERBS_LOOKUP_READ);
2343 for (next = wr; next; next = next->next) {
2349 ret2 = uverbs_response(attrs, &resp, sizeof(resp));
2363 static int ib_uverbs_create_ah(struct uverbs_attr_bundle *attrs)
2365 struct ib_uverbs_create_ah cmd;
2366 struct ib_uverbs_create_ah_resp resp;
2367 struct ib_uobject *uobj;
2370 struct rdma_ah_attr attr = {};
2372 struct ib_device *ib_dev;
2374 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
2378 uobj = uobj_alloc(UVERBS_OBJECT_AH, attrs, &ib_dev);
2380 return PTR_ERR(uobj);
2382 if (!rdma_is_port_valid(ib_dev, cmd.attr.port_num)) {
2387 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, attrs);
2393 attr.type = rdma_ah_find_type(ib_dev, cmd.attr.port_num);
2394 rdma_ah_set_make_grd(&attr, false);
2395 rdma_ah_set_dlid(&attr, cmd.attr.dlid);
2396 rdma_ah_set_sl(&attr, cmd.attr.sl);
2397 rdma_ah_set_path_bits(&attr, cmd.attr.src_path_bits);
2398 rdma_ah_set_static_rate(&attr, cmd.attr.static_rate);
2399 rdma_ah_set_port_num(&attr, cmd.attr.port_num);
2401 if (cmd.attr.is_global) {
2402 rdma_ah_set_grh(&attr, NULL, cmd.attr.grh.flow_label,
2403 cmd.attr.grh.sgid_index,
2404 cmd.attr.grh.hop_limit,
2405 cmd.attr.grh.traffic_class);
2406 rdma_ah_set_dgid_raw(&attr, cmd.attr.grh.dgid);
2408 rdma_ah_set_ah_flags(&attr, 0);
2411 ah = rdma_create_user_ah(pd, &attr, &attrs->driver_udata);
2418 uobj->user_handle = cmd.user_handle;
2420 uobj_put_obj_read(pd);
2421 uobj_finalize_uobj_create(uobj, attrs);
2423 resp.ah_handle = uobj->id;
2424 return uverbs_response(attrs, &resp, sizeof(resp));
2427 uobj_put_obj_read(pd);
2429 uobj_alloc_abort(uobj, attrs);
2433 static int ib_uverbs_destroy_ah(struct uverbs_attr_bundle *attrs)
2435 struct ib_uverbs_destroy_ah cmd;
2438 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
2442 return uobj_perform_destroy(UVERBS_OBJECT_AH, cmd.ah_handle, attrs);
2445 static int ib_uverbs_attach_mcast(struct uverbs_attr_bundle *attrs)
2447 struct ib_uverbs_attach_mcast cmd;
2449 struct ib_uqp_object *obj;
2450 struct ib_uverbs_mcast_entry *mcast;
2453 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
2457 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
2463 mutex_lock(&obj->mcast_lock);
2464 list_for_each_entry(mcast, &obj->mcast_list, list)
2465 if (cmd.mlid == mcast->lid &&
2466 !memcmp(cmd.gid, mcast->gid.raw, sizeof mcast->gid.raw)) {
2471 mcast = kmalloc(sizeof *mcast, GFP_KERNEL);
2477 mcast->lid = cmd.mlid;
2478 memcpy(mcast->gid.raw, cmd.gid, sizeof mcast->gid.raw);
2480 ret = ib_attach_mcast(qp, &mcast->gid, cmd.mlid);
2482 list_add_tail(&mcast->list, &obj->mcast_list);
2487 mutex_unlock(&obj->mcast_lock);
2488 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
2489 UVERBS_LOOKUP_READ);
2494 static int ib_uverbs_detach_mcast(struct uverbs_attr_bundle *attrs)
2496 struct ib_uverbs_detach_mcast cmd;
2497 struct ib_uqp_object *obj;
2499 struct ib_uverbs_mcast_entry *mcast;
2503 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
2507 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
2512 mutex_lock(&obj->mcast_lock);
2514 list_for_each_entry(mcast, &obj->mcast_list, list)
2515 if (cmd.mlid == mcast->lid &&
2516 !memcmp(cmd.gid, mcast->gid.raw, sizeof mcast->gid.raw)) {
2517 list_del(&mcast->list);
2528 ret = ib_detach_mcast(qp, (union ib_gid *)cmd.gid, cmd.mlid);
2531 mutex_unlock(&obj->mcast_lock);
2532 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
2533 UVERBS_LOOKUP_READ);
2537 struct ib_uflow_resources *flow_resources_alloc(size_t num_specs)
2539 struct ib_uflow_resources *resources;
2541 resources = kzalloc(sizeof(*resources), GFP_KERNEL);
2549 resources->counters =
2550 kcalloc(num_specs, sizeof(*resources->counters), GFP_KERNEL);
2551 resources->collection =
2552 kcalloc(num_specs, sizeof(*resources->collection), GFP_KERNEL);
2554 if (!resources->counters || !resources->collection)
2558 resources->max = num_specs;
2562 kfree(resources->counters);
2567 EXPORT_SYMBOL(flow_resources_alloc);
2569 void ib_uverbs_flow_resources_free(struct ib_uflow_resources *uflow_res)
2576 for (i = 0; i < uflow_res->collection_num; i++)
2577 atomic_dec(&uflow_res->collection[i]->usecnt);
2579 for (i = 0; i < uflow_res->counters_num; i++)
2580 atomic_dec(&uflow_res->counters[i]->usecnt);
2582 kfree(uflow_res->collection);
2583 kfree(uflow_res->counters);
2586 EXPORT_SYMBOL(ib_uverbs_flow_resources_free);
2588 void flow_resources_add(struct ib_uflow_resources *uflow_res,
2589 enum ib_flow_spec_type type,
2592 WARN_ON(uflow_res->num >= uflow_res->max);
2595 case IB_FLOW_SPEC_ACTION_HANDLE:
2596 atomic_inc(&((struct ib_flow_action *)ibobj)->usecnt);
2597 uflow_res->collection[uflow_res->collection_num++] =
2598 (struct ib_flow_action *)ibobj;
2600 case IB_FLOW_SPEC_ACTION_COUNT:
2601 atomic_inc(&((struct ib_counters *)ibobj)->usecnt);
2602 uflow_res->counters[uflow_res->counters_num++] =
2603 (struct ib_counters *)ibobj;
2611 EXPORT_SYMBOL(flow_resources_add);
2613 static int kern_spec_to_ib_spec_action(struct uverbs_attr_bundle *attrs,
2614 struct ib_uverbs_flow_spec *kern_spec,
2615 union ib_flow_spec *ib_spec,
2616 struct ib_uflow_resources *uflow_res)
2618 ib_spec->type = kern_spec->type;
2619 switch (ib_spec->type) {
2620 case IB_FLOW_SPEC_ACTION_TAG:
2621 if (kern_spec->flow_tag.size !=
2622 sizeof(struct ib_uverbs_flow_spec_action_tag))
2625 ib_spec->flow_tag.size = sizeof(struct ib_flow_spec_action_tag);
2626 ib_spec->flow_tag.tag_id = kern_spec->flow_tag.tag_id;
2628 case IB_FLOW_SPEC_ACTION_DROP:
2629 if (kern_spec->drop.size !=
2630 sizeof(struct ib_uverbs_flow_spec_action_drop))
2633 ib_spec->drop.size = sizeof(struct ib_flow_spec_action_drop);
2635 case IB_FLOW_SPEC_ACTION_HANDLE:
2636 if (kern_spec->action.size !=
2637 sizeof(struct ib_uverbs_flow_spec_action_handle))
2639 ib_spec->action.act = uobj_get_obj_read(flow_action,
2640 UVERBS_OBJECT_FLOW_ACTION,
2641 kern_spec->action.handle,
2643 if (!ib_spec->action.act)
2645 ib_spec->action.size =
2646 sizeof(struct ib_flow_spec_action_handle);
2647 flow_resources_add(uflow_res,
2648 IB_FLOW_SPEC_ACTION_HANDLE,
2649 ib_spec->action.act);
2650 uobj_put_obj_read(ib_spec->action.act);
2652 case IB_FLOW_SPEC_ACTION_COUNT:
2653 if (kern_spec->flow_count.size !=
2654 sizeof(struct ib_uverbs_flow_spec_action_count))
2656 ib_spec->flow_count.counters =
2657 uobj_get_obj_read(counters,
2658 UVERBS_OBJECT_COUNTERS,
2659 kern_spec->flow_count.handle,
2661 if (!ib_spec->flow_count.counters)
2663 ib_spec->flow_count.size =
2664 sizeof(struct ib_flow_spec_action_count);
2665 flow_resources_add(uflow_res,
2666 IB_FLOW_SPEC_ACTION_COUNT,
2667 ib_spec->flow_count.counters);
2668 uobj_put_obj_read(ib_spec->flow_count.counters);
2676 static ssize_t spec_filter_size(const void *kern_spec_filter, u16 kern_filter_size,
2677 u16 ib_real_filter_sz)
2680 * User space filter structures must be 64 bit aligned, otherwise this
2681 * may pass, but we won't handle additional new attributes.
2684 if (kern_filter_size > ib_real_filter_sz) {
2685 if (memchr_inv(kern_spec_filter +
2686 ib_real_filter_sz, 0,
2687 kern_filter_size - ib_real_filter_sz))
2689 return ib_real_filter_sz;
2691 return kern_filter_size;
2694 int ib_uverbs_kern_spec_to_ib_spec_filter(enum ib_flow_spec_type type,
2695 const void *kern_spec_mask,
2696 const void *kern_spec_val,
2697 size_t kern_filter_sz,
2698 union ib_flow_spec *ib_spec)
2700 ssize_t actual_filter_sz;
2701 ssize_t ib_filter_sz;
2703 /* User flow spec size must be aligned to 4 bytes */
2704 if (kern_filter_sz != ALIGN(kern_filter_sz, 4))
2707 ib_spec->type = type;
2709 if (ib_spec->type == (IB_FLOW_SPEC_INNER | IB_FLOW_SPEC_VXLAN_TUNNEL))
2712 switch (ib_spec->type & ~IB_FLOW_SPEC_INNER) {
2713 case IB_FLOW_SPEC_ETH:
2714 ib_filter_sz = offsetof(struct ib_flow_eth_filter, real_sz);
2715 actual_filter_sz = spec_filter_size(kern_spec_mask,
2718 if (actual_filter_sz <= 0)
2720 ib_spec->size = sizeof(struct ib_flow_spec_eth);
2721 memcpy(&ib_spec->eth.val, kern_spec_val, actual_filter_sz);
2722 memcpy(&ib_spec->eth.mask, kern_spec_mask, actual_filter_sz);
2724 case IB_FLOW_SPEC_IPV4:
2725 ib_filter_sz = offsetof(struct ib_flow_ipv4_filter, real_sz);
2726 actual_filter_sz = spec_filter_size(kern_spec_mask,
2729 if (actual_filter_sz <= 0)
2731 ib_spec->size = sizeof(struct ib_flow_spec_ipv4);
2732 memcpy(&ib_spec->ipv4.val, kern_spec_val, actual_filter_sz);
2733 memcpy(&ib_spec->ipv4.mask, kern_spec_mask, actual_filter_sz);
2735 case IB_FLOW_SPEC_IPV6:
2736 ib_filter_sz = offsetof(struct ib_flow_ipv6_filter, real_sz);
2737 actual_filter_sz = spec_filter_size(kern_spec_mask,
2740 if (actual_filter_sz <= 0)
2742 ib_spec->size = sizeof(struct ib_flow_spec_ipv6);
2743 memcpy(&ib_spec->ipv6.val, kern_spec_val, actual_filter_sz);
2744 memcpy(&ib_spec->ipv6.mask, kern_spec_mask, actual_filter_sz);
2746 if ((ntohl(ib_spec->ipv6.mask.flow_label)) >= BIT(20) ||
2747 (ntohl(ib_spec->ipv6.val.flow_label)) >= BIT(20))
2750 case IB_FLOW_SPEC_TCP:
2751 case IB_FLOW_SPEC_UDP:
2752 ib_filter_sz = offsetof(struct ib_flow_tcp_udp_filter, real_sz);
2753 actual_filter_sz = spec_filter_size(kern_spec_mask,
2756 if (actual_filter_sz <= 0)
2758 ib_spec->size = sizeof(struct ib_flow_spec_tcp_udp);
2759 memcpy(&ib_spec->tcp_udp.val, kern_spec_val, actual_filter_sz);
2760 memcpy(&ib_spec->tcp_udp.mask, kern_spec_mask, actual_filter_sz);
2762 case IB_FLOW_SPEC_VXLAN_TUNNEL:
2763 ib_filter_sz = offsetof(struct ib_flow_tunnel_filter, real_sz);
2764 actual_filter_sz = spec_filter_size(kern_spec_mask,
2767 if (actual_filter_sz <= 0)
2769 ib_spec->tunnel.size = sizeof(struct ib_flow_spec_tunnel);
2770 memcpy(&ib_spec->tunnel.val, kern_spec_val, actual_filter_sz);
2771 memcpy(&ib_spec->tunnel.mask, kern_spec_mask, actual_filter_sz);
2773 if ((ntohl(ib_spec->tunnel.mask.tunnel_id)) >= BIT(24) ||
2774 (ntohl(ib_spec->tunnel.val.tunnel_id)) >= BIT(24))
2777 case IB_FLOW_SPEC_ESP:
2778 ib_filter_sz = offsetof(struct ib_flow_esp_filter, real_sz);
2779 actual_filter_sz = spec_filter_size(kern_spec_mask,
2782 if (actual_filter_sz <= 0)
2784 ib_spec->esp.size = sizeof(struct ib_flow_spec_esp);
2785 memcpy(&ib_spec->esp.val, kern_spec_val, actual_filter_sz);
2786 memcpy(&ib_spec->esp.mask, kern_spec_mask, actual_filter_sz);
2788 case IB_FLOW_SPEC_GRE:
2789 ib_filter_sz = offsetof(struct ib_flow_gre_filter, real_sz);
2790 actual_filter_sz = spec_filter_size(kern_spec_mask,
2793 if (actual_filter_sz <= 0)
2795 ib_spec->gre.size = sizeof(struct ib_flow_spec_gre);
2796 memcpy(&ib_spec->gre.val, kern_spec_val, actual_filter_sz);
2797 memcpy(&ib_spec->gre.mask, kern_spec_mask, actual_filter_sz);
2799 case IB_FLOW_SPEC_MPLS:
2800 ib_filter_sz = offsetof(struct ib_flow_mpls_filter, real_sz);
2801 actual_filter_sz = spec_filter_size(kern_spec_mask,
2804 if (actual_filter_sz <= 0)
2806 ib_spec->mpls.size = sizeof(struct ib_flow_spec_mpls);
2807 memcpy(&ib_spec->mpls.val, kern_spec_val, actual_filter_sz);
2808 memcpy(&ib_spec->mpls.mask, kern_spec_mask, actual_filter_sz);
2816 static int kern_spec_to_ib_spec_filter(struct ib_uverbs_flow_spec *kern_spec,
2817 union ib_flow_spec *ib_spec)
2819 size_t kern_filter_sz;
2820 void *kern_spec_mask;
2821 void *kern_spec_val;
2823 if (check_sub_overflow((size_t)kern_spec->hdr.size,
2824 sizeof(struct ib_uverbs_flow_spec_hdr),
2828 kern_filter_sz /= 2;
2830 kern_spec_val = (void *)kern_spec +
2831 sizeof(struct ib_uverbs_flow_spec_hdr);
2832 kern_spec_mask = kern_spec_val + kern_filter_sz;
2834 return ib_uverbs_kern_spec_to_ib_spec_filter(kern_spec->type,
2837 kern_filter_sz, ib_spec);
2840 static int kern_spec_to_ib_spec(struct uverbs_attr_bundle *attrs,
2841 struct ib_uverbs_flow_spec *kern_spec,
2842 union ib_flow_spec *ib_spec,
2843 struct ib_uflow_resources *uflow_res)
2845 if (kern_spec->reserved)
2848 if (kern_spec->type >= IB_FLOW_SPEC_ACTION_TAG)
2849 return kern_spec_to_ib_spec_action(attrs, kern_spec, ib_spec,
2852 return kern_spec_to_ib_spec_filter(kern_spec, ib_spec);
2855 static int ib_uverbs_ex_create_wq(struct uverbs_attr_bundle *attrs)
2857 struct ib_uverbs_ex_create_wq cmd;
2858 struct ib_uverbs_ex_create_wq_resp resp = {};
2859 struct ib_uwq_object *obj;
2864 struct ib_wq_init_attr wq_init_attr = {};
2865 struct ib_device *ib_dev;
2867 err = uverbs_request(attrs, &cmd, sizeof(cmd));
2874 obj = (struct ib_uwq_object *)uobj_alloc(UVERBS_OBJECT_WQ, attrs,
2877 return PTR_ERR(obj);
2879 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, attrs);
2885 cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs);
2891 wq_init_attr.cq = cq;
2892 wq_init_attr.max_sge = cmd.max_sge;
2893 wq_init_attr.max_wr = cmd.max_wr;
2894 wq_init_attr.wq_type = cmd.wq_type;
2895 wq_init_attr.event_handler = ib_uverbs_wq_event_handler;
2896 wq_init_attr.create_flags = cmd.create_flags;
2897 INIT_LIST_HEAD(&obj->uevent.event_list);
2898 obj->uevent.uobject.user_handle = cmd.user_handle;
2900 wq = pd->device->ops.create_wq(pd, &wq_init_attr, &attrs->driver_udata);
2907 obj->uevent.uobject.object = wq;
2908 wq->wq_type = wq_init_attr.wq_type;
2911 wq->device = pd->device;
2912 atomic_set(&wq->usecnt, 0);
2913 atomic_inc(&pd->usecnt);
2914 atomic_inc(&cq->usecnt);
2915 obj->uevent.event_file = READ_ONCE(attrs->ufile->default_async_file);
2916 if (obj->uevent.event_file)
2917 uverbs_uobject_get(&obj->uevent.event_file->uobj);
2919 uobj_put_obj_read(pd);
2920 rdma_lookup_put_uobject(&cq->uobject->uevent.uobject,
2921 UVERBS_LOOKUP_READ);
2922 uobj_finalize_uobj_create(&obj->uevent.uobject, attrs);
2924 resp.wq_handle = obj->uevent.uobject.id;
2925 resp.max_sge = wq_init_attr.max_sge;
2926 resp.max_wr = wq_init_attr.max_wr;
2927 resp.wqn = wq->wq_num;
2928 resp.response_length = uverbs_response_length(attrs, sizeof(resp));
2929 return uverbs_response(attrs, &resp, sizeof(resp));
2932 rdma_lookup_put_uobject(&cq->uobject->uevent.uobject,
2933 UVERBS_LOOKUP_READ);
2935 uobj_put_obj_read(pd);
2937 uobj_alloc_abort(&obj->uevent.uobject, attrs);
2942 static int ib_uverbs_ex_destroy_wq(struct uverbs_attr_bundle *attrs)
2944 struct ib_uverbs_ex_destroy_wq cmd;
2945 struct ib_uverbs_ex_destroy_wq_resp resp = {};
2946 struct ib_uobject *uobj;
2947 struct ib_uwq_object *obj;
2950 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
2957 resp.response_length = uverbs_response_length(attrs, sizeof(resp));
2958 uobj = uobj_get_destroy(UVERBS_OBJECT_WQ, cmd.wq_handle, attrs);
2960 return PTR_ERR(uobj);
2962 obj = container_of(uobj, struct ib_uwq_object, uevent.uobject);
2963 resp.events_reported = obj->uevent.events_reported;
2965 uobj_put_destroy(uobj);
2967 return uverbs_response(attrs, &resp, sizeof(resp));
2970 static int ib_uverbs_ex_modify_wq(struct uverbs_attr_bundle *attrs)
2972 struct ib_uverbs_ex_modify_wq cmd;
2974 struct ib_wq_attr wq_attr = {};
2977 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
2984 if (cmd.attr_mask > (IB_WQ_STATE | IB_WQ_CUR_STATE | IB_WQ_FLAGS))
2987 wq = uobj_get_obj_read(wq, UVERBS_OBJECT_WQ, cmd.wq_handle, attrs);
2991 wq_attr.curr_wq_state = cmd.curr_wq_state;
2992 wq_attr.wq_state = cmd.wq_state;
2993 if (cmd.attr_mask & IB_WQ_FLAGS) {
2994 wq_attr.flags = cmd.flags;
2995 wq_attr.flags_mask = cmd.flags_mask;
2997 ret = wq->device->ops.modify_wq(wq, &wq_attr, cmd.attr_mask,
2998 &attrs->driver_udata);
2999 rdma_lookup_put_uobject(&wq->uobject->uevent.uobject,
3000 UVERBS_LOOKUP_READ);
3004 static int ib_uverbs_ex_create_rwq_ind_table(struct uverbs_attr_bundle *attrs)
3006 struct ib_uverbs_ex_create_rwq_ind_table cmd;
3007 struct ib_uverbs_ex_create_rwq_ind_table_resp resp = {};
3008 struct ib_uobject *uobj;
3010 struct ib_rwq_ind_table_init_attr init_attr = {};
3011 struct ib_rwq_ind_table *rwq_ind_tbl;
3012 struct ib_wq **wqs = NULL;
3013 u32 *wqs_handles = NULL;
3014 struct ib_wq *wq = NULL;
3015 int i, num_read_wqs;
3017 struct uverbs_req_iter iter;
3018 struct ib_device *ib_dev;
3020 err = uverbs_request_start(attrs, &iter, &cmd, sizeof(cmd));
3027 if (cmd.log_ind_tbl_size > IB_USER_VERBS_MAX_LOG_IND_TBL_SIZE)
3030 num_wq_handles = 1 << cmd.log_ind_tbl_size;
3031 wqs_handles = kcalloc(num_wq_handles, sizeof(*wqs_handles),
3036 err = uverbs_request_next(&iter, wqs_handles,
3037 num_wq_handles * sizeof(__u32));
3041 err = uverbs_request_finish(&iter);
3045 wqs = kcalloc(num_wq_handles, sizeof(*wqs), GFP_KERNEL);
3051 for (num_read_wqs = 0; num_read_wqs < num_wq_handles;
3053 wq = uobj_get_obj_read(wq, UVERBS_OBJECT_WQ,
3054 wqs_handles[num_read_wqs], attrs);
3060 wqs[num_read_wqs] = wq;
3061 atomic_inc(&wqs[num_read_wqs]->usecnt);
3064 uobj = uobj_alloc(UVERBS_OBJECT_RWQ_IND_TBL, attrs, &ib_dev);
3066 err = PTR_ERR(uobj);
3070 rwq_ind_tbl = rdma_zalloc_drv_obj(ib_dev, ib_rwq_ind_table);
3076 init_attr.log_ind_tbl_size = cmd.log_ind_tbl_size;
3077 init_attr.ind_tbl = wqs;
3079 rwq_ind_tbl->ind_tbl = wqs;
3080 rwq_ind_tbl->log_ind_tbl_size = init_attr.log_ind_tbl_size;
3081 rwq_ind_tbl->uobject = uobj;
3082 uobj->object = rwq_ind_tbl;
3083 rwq_ind_tbl->device = ib_dev;
3084 atomic_set(&rwq_ind_tbl->usecnt, 0);
3086 err = ib_dev->ops.create_rwq_ind_table(rwq_ind_tbl, &init_attr,
3087 &attrs->driver_udata);
3091 for (i = 0; i < num_wq_handles; i++)
3092 rdma_lookup_put_uobject(&wqs[i]->uobject->uevent.uobject,
3093 UVERBS_LOOKUP_READ);
3095 uobj_finalize_uobj_create(uobj, attrs);
3097 resp.ind_tbl_handle = uobj->id;
3098 resp.ind_tbl_num = rwq_ind_tbl->ind_tbl_num;
3099 resp.response_length = uverbs_response_length(attrs, sizeof(resp));
3100 return uverbs_response(attrs, &resp, sizeof(resp));
3105 uobj_alloc_abort(uobj, attrs);
3107 for (i = 0; i < num_read_wqs; i++) {
3108 rdma_lookup_put_uobject(&wqs[i]->uobject->uevent.uobject,
3109 UVERBS_LOOKUP_READ);
3110 atomic_dec(&wqs[i]->usecnt);
3118 static int ib_uverbs_ex_destroy_rwq_ind_table(struct uverbs_attr_bundle *attrs)
3120 struct ib_uverbs_ex_destroy_rwq_ind_table cmd;
3123 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3130 return uobj_perform_destroy(UVERBS_OBJECT_RWQ_IND_TBL,
3131 cmd.ind_tbl_handle, attrs);
3134 static int ib_uverbs_ex_create_flow(struct uverbs_attr_bundle *attrs)
3136 struct ib_uverbs_create_flow cmd;
3137 struct ib_uverbs_create_flow_resp resp = {};
3138 struct ib_uobject *uobj;
3139 struct ib_flow *flow_id;
3140 struct ib_uverbs_flow_attr *kern_flow_attr;
3141 struct ib_flow_attr *flow_attr;
3143 struct ib_uflow_resources *uflow_res;
3144 struct ib_uverbs_flow_spec_hdr *kern_spec;
3145 struct uverbs_req_iter iter;
3149 struct ib_device *ib_dev;
3151 err = uverbs_request_start(attrs, &iter, &cmd, sizeof(cmd));
3158 if (!capable(CAP_NET_RAW))
3161 if (cmd.flow_attr.flags >= IB_FLOW_ATTR_FLAGS_RESERVED)
3164 if ((cmd.flow_attr.flags & IB_FLOW_ATTR_FLAGS_DONT_TRAP) &&
3165 ((cmd.flow_attr.type == IB_FLOW_ATTR_ALL_DEFAULT) ||
3166 (cmd.flow_attr.type == IB_FLOW_ATTR_MC_DEFAULT)))
3169 if (cmd.flow_attr.num_of_specs > IB_FLOW_SPEC_SUPPORT_LAYERS)
3172 if (cmd.flow_attr.size >
3173 (cmd.flow_attr.num_of_specs * sizeof(struct ib_uverbs_flow_spec)))
3176 if (cmd.flow_attr.reserved[0] ||
3177 cmd.flow_attr.reserved[1])
3180 if (cmd.flow_attr.num_of_specs) {
3181 kern_flow_attr = kmalloc(sizeof(*kern_flow_attr) + cmd.flow_attr.size,
3183 if (!kern_flow_attr)
3186 *kern_flow_attr = cmd.flow_attr;
3187 err = uverbs_request_next(&iter, &kern_flow_attr->flow_specs,
3188 cmd.flow_attr.size);
3192 kern_flow_attr = &cmd.flow_attr;
3195 err = uverbs_request_finish(&iter);
3199 uobj = uobj_alloc(UVERBS_OBJECT_FLOW, attrs, &ib_dev);
3201 err = PTR_ERR(uobj);
3205 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
3211 if (qp->qp_type != IB_QPT_UD && qp->qp_type != IB_QPT_RAW_PACKET) {
3216 flow_attr = kzalloc(struct_size(flow_attr, flows,
3217 cmd.flow_attr.num_of_specs), GFP_KERNEL);
3222 uflow_res = flow_resources_alloc(cmd.flow_attr.num_of_specs);
3225 goto err_free_flow_attr;
3228 flow_attr->type = kern_flow_attr->type;
3229 flow_attr->priority = kern_flow_attr->priority;
3230 flow_attr->num_of_specs = kern_flow_attr->num_of_specs;
3231 flow_attr->port = kern_flow_attr->port;
3232 flow_attr->flags = kern_flow_attr->flags;
3233 flow_attr->size = sizeof(*flow_attr);
3235 kern_spec = kern_flow_attr->flow_specs;
3236 ib_spec = flow_attr + 1;
3237 for (i = 0; i < flow_attr->num_of_specs &&
3238 cmd.flow_attr.size >= sizeof(*kern_spec) &&
3239 cmd.flow_attr.size >= kern_spec->size;
3241 err = kern_spec_to_ib_spec(
3242 attrs, (struct ib_uverbs_flow_spec *)kern_spec,
3243 ib_spec, uflow_res);
3248 ((union ib_flow_spec *) ib_spec)->size;
3249 cmd.flow_attr.size -= kern_spec->size;
3250 kern_spec = ((void *)kern_spec) + kern_spec->size;
3251 ib_spec += ((union ib_flow_spec *) ib_spec)->size;
3253 if (cmd.flow_attr.size || (i != flow_attr->num_of_specs)) {
3254 pr_warn("create flow failed, flow %d: %d bytes left from uverb cmd\n",
3255 i, cmd.flow_attr.size);
3260 flow_id = qp->device->ops.create_flow(qp, flow_attr,
3261 &attrs->driver_udata);
3263 if (IS_ERR(flow_id)) {
3264 err = PTR_ERR(flow_id);
3268 ib_set_flow(uobj, flow_id, qp, qp->device, uflow_res);
3270 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
3271 UVERBS_LOOKUP_READ);
3274 if (cmd.flow_attr.num_of_specs)
3275 kfree(kern_flow_attr);
3276 uobj_finalize_uobj_create(uobj, attrs);
3278 resp.flow_handle = uobj->id;
3279 return uverbs_response(attrs, &resp, sizeof(resp));
3282 ib_uverbs_flow_resources_free(uflow_res);
3286 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
3287 UVERBS_LOOKUP_READ);
3289 uobj_alloc_abort(uobj, attrs);
3291 if (cmd.flow_attr.num_of_specs)
3292 kfree(kern_flow_attr);
3296 static int ib_uverbs_ex_destroy_flow(struct uverbs_attr_bundle *attrs)
3298 struct ib_uverbs_destroy_flow cmd;
3301 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3308 return uobj_perform_destroy(UVERBS_OBJECT_FLOW, cmd.flow_handle, attrs);
3311 static int __uverbs_create_xsrq(struct uverbs_attr_bundle *attrs,
3312 struct ib_uverbs_create_xsrq *cmd,
3313 struct ib_udata *udata)
3315 struct ib_uverbs_create_srq_resp resp = {};
3316 struct ib_usrq_object *obj;
3319 struct ib_srq_init_attr attr;
3321 struct ib_uobject *xrcd_uobj;
3322 struct ib_device *ib_dev;
3324 obj = (struct ib_usrq_object *)uobj_alloc(UVERBS_OBJECT_SRQ, attrs,
3327 return PTR_ERR(obj);
3329 if (cmd->srq_type == IB_SRQT_TM)
3330 attr.ext.tag_matching.max_num_tags = cmd->max_num_tags;
3332 if (cmd->srq_type == IB_SRQT_XRC) {
3333 xrcd_uobj = uobj_get_read(UVERBS_OBJECT_XRCD, cmd->xrcd_handle,
3335 if (IS_ERR(xrcd_uobj)) {
3340 attr.ext.xrc.xrcd = (struct ib_xrcd *)xrcd_uobj->object;
3341 if (!attr.ext.xrc.xrcd) {
3346 obj->uxrcd = container_of(xrcd_uobj, struct ib_uxrcd_object, uobject);
3347 atomic_inc(&obj->uxrcd->refcnt);
3350 if (ib_srq_has_cq(cmd->srq_type)) {
3351 attr.ext.cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ,
3352 cmd->cq_handle, attrs);
3359 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd->pd_handle, attrs);
3365 attr.event_handler = ib_uverbs_srq_event_handler;
3366 attr.srq_type = cmd->srq_type;
3367 attr.attr.max_wr = cmd->max_wr;
3368 attr.attr.max_sge = cmd->max_sge;
3369 attr.attr.srq_limit = cmd->srq_limit;
3371 INIT_LIST_HEAD(&obj->uevent.event_list);
3372 obj->uevent.uobject.user_handle = cmd->user_handle;
3374 srq = ib_create_srq_user(pd, &attr, obj, udata);
3380 obj->uevent.uobject.object = srq;
3381 obj->uevent.uobject.user_handle = cmd->user_handle;
3382 obj->uevent.event_file = READ_ONCE(attrs->ufile->default_async_file);
3383 if (obj->uevent.event_file)
3384 uverbs_uobject_get(&obj->uevent.event_file->uobj);
3386 if (cmd->srq_type == IB_SRQT_XRC)
3387 resp.srqn = srq->ext.xrc.srq_num;
3389 if (cmd->srq_type == IB_SRQT_XRC)
3390 uobj_put_read(xrcd_uobj);
3392 if (ib_srq_has_cq(cmd->srq_type))
3393 rdma_lookup_put_uobject(&attr.ext.cq->uobject->uevent.uobject,
3394 UVERBS_LOOKUP_READ);
3396 uobj_put_obj_read(pd);
3397 uobj_finalize_uobj_create(&obj->uevent.uobject, attrs);
3399 resp.srq_handle = obj->uevent.uobject.id;
3400 resp.max_wr = attr.attr.max_wr;
3401 resp.max_sge = attr.attr.max_sge;
3402 return uverbs_response(attrs, &resp, sizeof(resp));
3405 uobj_put_obj_read(pd);
3407 if (ib_srq_has_cq(cmd->srq_type))
3408 rdma_lookup_put_uobject(&attr.ext.cq->uobject->uevent.uobject,
3409 UVERBS_LOOKUP_READ);
3412 if (cmd->srq_type == IB_SRQT_XRC) {
3413 atomic_dec(&obj->uxrcd->refcnt);
3414 uobj_put_read(xrcd_uobj);
3418 uobj_alloc_abort(&obj->uevent.uobject, attrs);
3422 static int ib_uverbs_create_srq(struct uverbs_attr_bundle *attrs)
3424 struct ib_uverbs_create_srq cmd;
3425 struct ib_uverbs_create_xsrq xcmd;
3428 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3432 memset(&xcmd, 0, sizeof(xcmd));
3433 xcmd.response = cmd.response;
3434 xcmd.user_handle = cmd.user_handle;
3435 xcmd.srq_type = IB_SRQT_BASIC;
3436 xcmd.pd_handle = cmd.pd_handle;
3437 xcmd.max_wr = cmd.max_wr;
3438 xcmd.max_sge = cmd.max_sge;
3439 xcmd.srq_limit = cmd.srq_limit;
3441 return __uverbs_create_xsrq(attrs, &xcmd, &attrs->driver_udata);
3444 static int ib_uverbs_create_xsrq(struct uverbs_attr_bundle *attrs)
3446 struct ib_uverbs_create_xsrq cmd;
3449 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3453 return __uverbs_create_xsrq(attrs, &cmd, &attrs->driver_udata);
3456 static int ib_uverbs_modify_srq(struct uverbs_attr_bundle *attrs)
3458 struct ib_uverbs_modify_srq cmd;
3460 struct ib_srq_attr attr;
3463 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3467 srq = uobj_get_obj_read(srq, UVERBS_OBJECT_SRQ, cmd.srq_handle, attrs);
3471 attr.max_wr = cmd.max_wr;
3472 attr.srq_limit = cmd.srq_limit;
3474 ret = srq->device->ops.modify_srq(srq, &attr, cmd.attr_mask,
3475 &attrs->driver_udata);
3477 rdma_lookup_put_uobject(&srq->uobject->uevent.uobject,
3478 UVERBS_LOOKUP_READ);
3483 static int ib_uverbs_query_srq(struct uverbs_attr_bundle *attrs)
3485 struct ib_uverbs_query_srq cmd;
3486 struct ib_uverbs_query_srq_resp resp;
3487 struct ib_srq_attr attr;
3491 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3495 srq = uobj_get_obj_read(srq, UVERBS_OBJECT_SRQ, cmd.srq_handle, attrs);
3499 ret = ib_query_srq(srq, &attr);
3501 rdma_lookup_put_uobject(&srq->uobject->uevent.uobject,
3502 UVERBS_LOOKUP_READ);
3507 memset(&resp, 0, sizeof resp);
3509 resp.max_wr = attr.max_wr;
3510 resp.max_sge = attr.max_sge;
3511 resp.srq_limit = attr.srq_limit;
3513 return uverbs_response(attrs, &resp, sizeof(resp));
3516 static int ib_uverbs_destroy_srq(struct uverbs_attr_bundle *attrs)
3518 struct ib_uverbs_destroy_srq cmd;
3519 struct ib_uverbs_destroy_srq_resp resp;
3520 struct ib_uobject *uobj;
3521 struct ib_uevent_object *obj;
3524 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3528 uobj = uobj_get_destroy(UVERBS_OBJECT_SRQ, cmd.srq_handle, attrs);
3530 return PTR_ERR(uobj);
3532 obj = container_of(uobj, struct ib_uevent_object, uobject);
3533 memset(&resp, 0, sizeof(resp));
3534 resp.events_reported = obj->events_reported;
3536 uobj_put_destroy(uobj);
3538 return uverbs_response(attrs, &resp, sizeof(resp));
3541 static int ib_uverbs_ex_query_device(struct uverbs_attr_bundle *attrs)
3543 struct ib_uverbs_ex_query_device_resp resp = {};
3544 struct ib_uverbs_ex_query_device cmd;
3545 struct ib_device_attr attr = {0};
3546 struct ib_ucontext *ucontext;
3547 struct ib_device *ib_dev;
3550 ucontext = ib_uverbs_get_ucontext(attrs);
3551 if (IS_ERR(ucontext))
3552 return PTR_ERR(ucontext);
3553 ib_dev = ucontext->device;
3555 err = uverbs_request(attrs, &cmd, sizeof(cmd));
3565 err = ib_dev->ops.query_device(ib_dev, &attr, &attrs->driver_udata);
3569 copy_query_dev_fields(ucontext, &resp.base, &attr);
3571 resp.odp_caps.general_caps = attr.odp_caps.general_caps;
3572 resp.odp_caps.per_transport_caps.rc_odp_caps =
3573 attr.odp_caps.per_transport_caps.rc_odp_caps;
3574 resp.odp_caps.per_transport_caps.uc_odp_caps =
3575 attr.odp_caps.per_transport_caps.uc_odp_caps;
3576 resp.odp_caps.per_transport_caps.ud_odp_caps =
3577 attr.odp_caps.per_transport_caps.ud_odp_caps;
3578 resp.xrc_odp_caps = attr.odp_caps.per_transport_caps.xrc_odp_caps;
3580 resp.timestamp_mask = attr.timestamp_mask;
3581 resp.hca_core_clock = attr.hca_core_clock;
3582 resp.device_cap_flags_ex = attr.device_cap_flags;
3583 resp.rss_caps.supported_qpts = attr.rss_caps.supported_qpts;
3584 resp.rss_caps.max_rwq_indirection_tables =
3585 attr.rss_caps.max_rwq_indirection_tables;
3586 resp.rss_caps.max_rwq_indirection_table_size =
3587 attr.rss_caps.max_rwq_indirection_table_size;
3588 resp.max_wq_type_rq = attr.max_wq_type_rq;
3589 resp.raw_packet_caps = attr.raw_packet_caps;
3590 resp.tm_caps.max_rndv_hdr_size = attr.tm_caps.max_rndv_hdr_size;
3591 resp.tm_caps.max_num_tags = attr.tm_caps.max_num_tags;
3592 resp.tm_caps.max_ops = attr.tm_caps.max_ops;
3593 resp.tm_caps.max_sge = attr.tm_caps.max_sge;
3594 resp.tm_caps.flags = attr.tm_caps.flags;
3595 resp.cq_moderation_caps.max_cq_moderation_count =
3596 attr.cq_caps.max_cq_moderation_count;
3597 resp.cq_moderation_caps.max_cq_moderation_period =
3598 attr.cq_caps.max_cq_moderation_period;
3599 resp.max_dm_size = attr.max_dm_size;
3600 resp.response_length = uverbs_response_length(attrs, sizeof(resp));
3602 return uverbs_response(attrs, &resp, sizeof(resp));
3605 static int ib_uverbs_ex_modify_cq(struct uverbs_attr_bundle *attrs)
3607 struct ib_uverbs_ex_modify_cq cmd;
3611 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3615 if (!cmd.attr_mask || cmd.reserved)
3618 if (cmd.attr_mask > IB_CQ_MODERATE)
3621 cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs);
3625 ret = rdma_set_cq_moderation(cq, cmd.attr.cq_count, cmd.attr.cq_period);
3627 rdma_lookup_put_uobject(&cq->uobject->uevent.uobject,
3628 UVERBS_LOOKUP_READ);
3633 * Describe the input structs for write(). Some write methods have an input
3634 * only struct, most have an input and output. If the struct has an output then
3635 * the 'response' u64 must be the first field in the request structure.
3637 * If udata is present then both the request and response structs have a
3638 * trailing driver_data flex array. In this case the size of the base struct
3639 * cannot be changed.
3641 #define UAPI_DEF_WRITE_IO(req, resp) \
3642 .write.has_resp = 1 + \
3643 BUILD_BUG_ON_ZERO(offsetof(req, response) != 0) + \
3644 BUILD_BUG_ON_ZERO(sizeof_field(req, response) != \
3646 .write.req_size = sizeof(req), .write.resp_size = sizeof(resp)
3648 #define UAPI_DEF_WRITE_I(req) .write.req_size = sizeof(req)
3650 #define UAPI_DEF_WRITE_UDATA_IO(req, resp) \
3651 UAPI_DEF_WRITE_IO(req, resp), \
3652 .write.has_udata = \
3654 BUILD_BUG_ON_ZERO(offsetof(req, driver_data) != \
3656 BUILD_BUG_ON_ZERO(offsetof(resp, driver_data) != \
3659 #define UAPI_DEF_WRITE_UDATA_I(req) \
3660 UAPI_DEF_WRITE_I(req), \
3661 .write.has_udata = \
3662 1 + BUILD_BUG_ON_ZERO(offsetof(req, driver_data) != \
3666 * The _EX versions are for use with WRITE_EX and allow the last struct member
3667 * to be specified. Buffers that do not include that member will be rejected.
3669 #define UAPI_DEF_WRITE_IO_EX(req, req_last_member, resp, resp_last_member) \
3670 .write.has_resp = 1, \
3671 .write.req_size = offsetofend(req, req_last_member), \
3672 .write.resp_size = offsetofend(resp, resp_last_member)
3674 #define UAPI_DEF_WRITE_I_EX(req, req_last_member) \
3675 .write.req_size = offsetofend(req, req_last_member)
3677 const struct uapi_definition uverbs_def_write_intf[] = {
3678 DECLARE_UVERBS_OBJECT(
3680 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_CREATE_AH,
3681 ib_uverbs_create_ah,
3682 UAPI_DEF_WRITE_UDATA_IO(
3683 struct ib_uverbs_create_ah,
3684 struct ib_uverbs_create_ah_resp)),
3685 DECLARE_UVERBS_WRITE(
3686 IB_USER_VERBS_CMD_DESTROY_AH,
3687 ib_uverbs_destroy_ah,
3688 UAPI_DEF_WRITE_I(struct ib_uverbs_destroy_ah)),
3689 UAPI_DEF_OBJ_NEEDS_FN(create_user_ah),
3690 UAPI_DEF_OBJ_NEEDS_FN(destroy_ah)),
3692 DECLARE_UVERBS_OBJECT(
3693 UVERBS_OBJECT_COMP_CHANNEL,
3694 DECLARE_UVERBS_WRITE(
3695 IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL,
3696 ib_uverbs_create_comp_channel,
3698 struct ib_uverbs_create_comp_channel,
3699 struct ib_uverbs_create_comp_channel_resp))),
3701 DECLARE_UVERBS_OBJECT(
3703 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_CREATE_CQ,
3704 ib_uverbs_create_cq,
3705 UAPI_DEF_WRITE_UDATA_IO(
3706 struct ib_uverbs_create_cq,
3707 struct ib_uverbs_create_cq_resp),
3708 UAPI_DEF_METHOD_NEEDS_FN(create_cq)),
3709 DECLARE_UVERBS_WRITE(
3710 IB_USER_VERBS_CMD_DESTROY_CQ,
3711 ib_uverbs_destroy_cq,
3712 UAPI_DEF_WRITE_IO(struct ib_uverbs_destroy_cq,
3713 struct ib_uverbs_destroy_cq_resp),
3714 UAPI_DEF_METHOD_NEEDS_FN(destroy_cq)),
3715 DECLARE_UVERBS_WRITE(
3716 IB_USER_VERBS_CMD_POLL_CQ,
3718 UAPI_DEF_WRITE_IO(struct ib_uverbs_poll_cq,
3719 struct ib_uverbs_poll_cq_resp),
3720 UAPI_DEF_METHOD_NEEDS_FN(poll_cq)),
3721 DECLARE_UVERBS_WRITE(
3722 IB_USER_VERBS_CMD_REQ_NOTIFY_CQ,
3723 ib_uverbs_req_notify_cq,
3724 UAPI_DEF_WRITE_I(struct ib_uverbs_req_notify_cq),
3725 UAPI_DEF_METHOD_NEEDS_FN(req_notify_cq)),
3726 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_RESIZE_CQ,
3727 ib_uverbs_resize_cq,
3728 UAPI_DEF_WRITE_UDATA_IO(
3729 struct ib_uverbs_resize_cq,
3730 struct ib_uverbs_resize_cq_resp),
3731 UAPI_DEF_METHOD_NEEDS_FN(resize_cq)),
3732 DECLARE_UVERBS_WRITE_EX(
3733 IB_USER_VERBS_EX_CMD_CREATE_CQ,
3734 ib_uverbs_ex_create_cq,
3735 UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_ex_create_cq,
3737 struct ib_uverbs_ex_create_cq_resp,
3739 UAPI_DEF_METHOD_NEEDS_FN(create_cq)),
3740 DECLARE_UVERBS_WRITE_EX(
3741 IB_USER_VERBS_EX_CMD_MODIFY_CQ,
3742 ib_uverbs_ex_modify_cq,
3743 UAPI_DEF_WRITE_I(struct ib_uverbs_ex_modify_cq),
3744 UAPI_DEF_METHOD_NEEDS_FN(modify_cq))),
3746 DECLARE_UVERBS_OBJECT(
3747 UVERBS_OBJECT_DEVICE,
3748 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_GET_CONTEXT,
3749 ib_uverbs_get_context,
3750 UAPI_DEF_WRITE_UDATA_IO(
3751 struct ib_uverbs_get_context,
3752 struct ib_uverbs_get_context_resp)),
3753 DECLARE_UVERBS_WRITE(
3754 IB_USER_VERBS_CMD_QUERY_DEVICE,
3755 ib_uverbs_query_device,
3756 UAPI_DEF_WRITE_IO(struct ib_uverbs_query_device,
3757 struct ib_uverbs_query_device_resp)),
3758 DECLARE_UVERBS_WRITE(
3759 IB_USER_VERBS_CMD_QUERY_PORT,
3760 ib_uverbs_query_port,
3761 UAPI_DEF_WRITE_IO(struct ib_uverbs_query_port,
3762 struct ib_uverbs_query_port_resp),
3763 UAPI_DEF_METHOD_NEEDS_FN(query_port)),
3764 DECLARE_UVERBS_WRITE_EX(
3765 IB_USER_VERBS_EX_CMD_QUERY_DEVICE,
3766 ib_uverbs_ex_query_device,
3767 UAPI_DEF_WRITE_IO_EX(
3768 struct ib_uverbs_ex_query_device,
3770 struct ib_uverbs_ex_query_device_resp,
3772 UAPI_DEF_METHOD_NEEDS_FN(query_device)),
3773 UAPI_DEF_OBJ_NEEDS_FN(alloc_ucontext),
3774 UAPI_DEF_OBJ_NEEDS_FN(dealloc_ucontext)),
3776 DECLARE_UVERBS_OBJECT(
3778 DECLARE_UVERBS_WRITE_EX(
3779 IB_USER_VERBS_EX_CMD_CREATE_FLOW,
3780 ib_uverbs_ex_create_flow,
3781 UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_create_flow,
3783 struct ib_uverbs_create_flow_resp,
3785 UAPI_DEF_METHOD_NEEDS_FN(create_flow)),
3786 DECLARE_UVERBS_WRITE_EX(
3787 IB_USER_VERBS_EX_CMD_DESTROY_FLOW,
3788 ib_uverbs_ex_destroy_flow,
3789 UAPI_DEF_WRITE_I(struct ib_uverbs_destroy_flow),
3790 UAPI_DEF_METHOD_NEEDS_FN(destroy_flow))),
3792 DECLARE_UVERBS_OBJECT(
3794 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_DEREG_MR,
3796 UAPI_DEF_WRITE_I(struct ib_uverbs_dereg_mr),
3797 UAPI_DEF_METHOD_NEEDS_FN(dereg_mr)),
3798 DECLARE_UVERBS_WRITE(
3799 IB_USER_VERBS_CMD_REG_MR,
3801 UAPI_DEF_WRITE_UDATA_IO(struct ib_uverbs_reg_mr,
3802 struct ib_uverbs_reg_mr_resp),
3803 UAPI_DEF_METHOD_NEEDS_FN(reg_user_mr)),
3804 DECLARE_UVERBS_WRITE(
3805 IB_USER_VERBS_CMD_REREG_MR,
3807 UAPI_DEF_WRITE_UDATA_IO(struct ib_uverbs_rereg_mr,
3808 struct ib_uverbs_rereg_mr_resp),
3809 UAPI_DEF_METHOD_NEEDS_FN(rereg_user_mr))),
3811 DECLARE_UVERBS_OBJECT(
3813 DECLARE_UVERBS_WRITE(
3814 IB_USER_VERBS_CMD_ALLOC_MW,
3816 UAPI_DEF_WRITE_UDATA_IO(struct ib_uverbs_alloc_mw,
3817 struct ib_uverbs_alloc_mw_resp),
3818 UAPI_DEF_METHOD_NEEDS_FN(alloc_mw)),
3819 DECLARE_UVERBS_WRITE(
3820 IB_USER_VERBS_CMD_DEALLOC_MW,
3821 ib_uverbs_dealloc_mw,
3822 UAPI_DEF_WRITE_I(struct ib_uverbs_dealloc_mw),
3823 UAPI_DEF_METHOD_NEEDS_FN(dealloc_mw))),
3825 DECLARE_UVERBS_OBJECT(
3827 DECLARE_UVERBS_WRITE(
3828 IB_USER_VERBS_CMD_ALLOC_PD,
3830 UAPI_DEF_WRITE_UDATA_IO(struct ib_uverbs_alloc_pd,
3831 struct ib_uverbs_alloc_pd_resp),
3832 UAPI_DEF_METHOD_NEEDS_FN(alloc_pd)),
3833 DECLARE_UVERBS_WRITE(
3834 IB_USER_VERBS_CMD_DEALLOC_PD,
3835 ib_uverbs_dealloc_pd,
3836 UAPI_DEF_WRITE_I(struct ib_uverbs_dealloc_pd),
3837 UAPI_DEF_METHOD_NEEDS_FN(dealloc_pd))),
3839 DECLARE_UVERBS_OBJECT(
3841 DECLARE_UVERBS_WRITE(
3842 IB_USER_VERBS_CMD_ATTACH_MCAST,
3843 ib_uverbs_attach_mcast,
3844 UAPI_DEF_WRITE_I(struct ib_uverbs_attach_mcast),
3845 UAPI_DEF_METHOD_NEEDS_FN(attach_mcast),
3846 UAPI_DEF_METHOD_NEEDS_FN(detach_mcast)),
3847 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_CREATE_QP,
3848 ib_uverbs_create_qp,
3849 UAPI_DEF_WRITE_UDATA_IO(
3850 struct ib_uverbs_create_qp,
3851 struct ib_uverbs_create_qp_resp),
3852 UAPI_DEF_METHOD_NEEDS_FN(create_qp)),
3853 DECLARE_UVERBS_WRITE(
3854 IB_USER_VERBS_CMD_DESTROY_QP,
3855 ib_uverbs_destroy_qp,
3856 UAPI_DEF_WRITE_IO(struct ib_uverbs_destroy_qp,
3857 struct ib_uverbs_destroy_qp_resp),
3858 UAPI_DEF_METHOD_NEEDS_FN(destroy_qp)),
3859 DECLARE_UVERBS_WRITE(
3860 IB_USER_VERBS_CMD_DETACH_MCAST,
3861 ib_uverbs_detach_mcast,
3862 UAPI_DEF_WRITE_I(struct ib_uverbs_detach_mcast),
3863 UAPI_DEF_METHOD_NEEDS_FN(detach_mcast)),
3864 DECLARE_UVERBS_WRITE(
3865 IB_USER_VERBS_CMD_MODIFY_QP,
3866 ib_uverbs_modify_qp,
3867 UAPI_DEF_WRITE_I(struct ib_uverbs_modify_qp),
3868 UAPI_DEF_METHOD_NEEDS_FN(modify_qp)),
3869 DECLARE_UVERBS_WRITE(
3870 IB_USER_VERBS_CMD_POST_RECV,
3871 ib_uverbs_post_recv,
3872 UAPI_DEF_WRITE_IO(struct ib_uverbs_post_recv,
3873 struct ib_uverbs_post_recv_resp),
3874 UAPI_DEF_METHOD_NEEDS_FN(post_recv)),
3875 DECLARE_UVERBS_WRITE(
3876 IB_USER_VERBS_CMD_POST_SEND,
3877 ib_uverbs_post_send,
3878 UAPI_DEF_WRITE_IO(struct ib_uverbs_post_send,
3879 struct ib_uverbs_post_send_resp),
3880 UAPI_DEF_METHOD_NEEDS_FN(post_send)),
3881 DECLARE_UVERBS_WRITE(
3882 IB_USER_VERBS_CMD_QUERY_QP,
3884 UAPI_DEF_WRITE_IO(struct ib_uverbs_query_qp,
3885 struct ib_uverbs_query_qp_resp),
3886 UAPI_DEF_METHOD_NEEDS_FN(query_qp)),
3887 DECLARE_UVERBS_WRITE_EX(
3888 IB_USER_VERBS_EX_CMD_CREATE_QP,
3889 ib_uverbs_ex_create_qp,
3890 UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_ex_create_qp,
3892 struct ib_uverbs_ex_create_qp_resp,
3894 UAPI_DEF_METHOD_NEEDS_FN(create_qp)),
3895 DECLARE_UVERBS_WRITE_EX(
3896 IB_USER_VERBS_EX_CMD_MODIFY_QP,
3897 ib_uverbs_ex_modify_qp,
3898 UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_ex_modify_qp,
3900 struct ib_uverbs_ex_modify_qp_resp,
3902 UAPI_DEF_METHOD_NEEDS_FN(modify_qp))),
3904 DECLARE_UVERBS_OBJECT(
3905 UVERBS_OBJECT_RWQ_IND_TBL,
3906 DECLARE_UVERBS_WRITE_EX(
3907 IB_USER_VERBS_EX_CMD_CREATE_RWQ_IND_TBL,
3908 ib_uverbs_ex_create_rwq_ind_table,
3909 UAPI_DEF_WRITE_IO_EX(
3910 struct ib_uverbs_ex_create_rwq_ind_table,
3912 struct ib_uverbs_ex_create_rwq_ind_table_resp,
3914 UAPI_DEF_METHOD_NEEDS_FN(create_rwq_ind_table)),
3915 DECLARE_UVERBS_WRITE_EX(
3916 IB_USER_VERBS_EX_CMD_DESTROY_RWQ_IND_TBL,
3917 ib_uverbs_ex_destroy_rwq_ind_table,
3919 struct ib_uverbs_ex_destroy_rwq_ind_table),
3920 UAPI_DEF_METHOD_NEEDS_FN(destroy_rwq_ind_table))),
3922 DECLARE_UVERBS_OBJECT(
3924 DECLARE_UVERBS_WRITE_EX(
3925 IB_USER_VERBS_EX_CMD_CREATE_WQ,
3926 ib_uverbs_ex_create_wq,
3927 UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_ex_create_wq,
3929 struct ib_uverbs_ex_create_wq_resp,
3931 UAPI_DEF_METHOD_NEEDS_FN(create_wq)),
3932 DECLARE_UVERBS_WRITE_EX(
3933 IB_USER_VERBS_EX_CMD_DESTROY_WQ,
3934 ib_uverbs_ex_destroy_wq,
3935 UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_ex_destroy_wq,
3937 struct ib_uverbs_ex_destroy_wq_resp,
3939 UAPI_DEF_METHOD_NEEDS_FN(destroy_wq)),
3940 DECLARE_UVERBS_WRITE_EX(
3941 IB_USER_VERBS_EX_CMD_MODIFY_WQ,
3942 ib_uverbs_ex_modify_wq,
3943 UAPI_DEF_WRITE_I_EX(struct ib_uverbs_ex_modify_wq,
3945 UAPI_DEF_METHOD_NEEDS_FN(modify_wq))),
3947 DECLARE_UVERBS_OBJECT(
3949 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_CREATE_SRQ,
3950 ib_uverbs_create_srq,
3951 UAPI_DEF_WRITE_UDATA_IO(
3952 struct ib_uverbs_create_srq,
3953 struct ib_uverbs_create_srq_resp),
3954 UAPI_DEF_METHOD_NEEDS_FN(create_srq)),
3955 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_CREATE_XSRQ,
3956 ib_uverbs_create_xsrq,
3957 UAPI_DEF_WRITE_UDATA_IO(
3958 struct ib_uverbs_create_xsrq,
3959 struct ib_uverbs_create_srq_resp),
3960 UAPI_DEF_METHOD_NEEDS_FN(create_srq)),
3961 DECLARE_UVERBS_WRITE(
3962 IB_USER_VERBS_CMD_DESTROY_SRQ,
3963 ib_uverbs_destroy_srq,
3964 UAPI_DEF_WRITE_IO(struct ib_uverbs_destroy_srq,
3965 struct ib_uverbs_destroy_srq_resp),
3966 UAPI_DEF_METHOD_NEEDS_FN(destroy_srq)),
3967 DECLARE_UVERBS_WRITE(
3968 IB_USER_VERBS_CMD_MODIFY_SRQ,
3969 ib_uverbs_modify_srq,
3970 UAPI_DEF_WRITE_UDATA_I(struct ib_uverbs_modify_srq),
3971 UAPI_DEF_METHOD_NEEDS_FN(modify_srq)),
3972 DECLARE_UVERBS_WRITE(
3973 IB_USER_VERBS_CMD_POST_SRQ_RECV,
3974 ib_uverbs_post_srq_recv,
3975 UAPI_DEF_WRITE_IO(struct ib_uverbs_post_srq_recv,
3976 struct ib_uverbs_post_srq_recv_resp),
3977 UAPI_DEF_METHOD_NEEDS_FN(post_srq_recv)),
3978 DECLARE_UVERBS_WRITE(
3979 IB_USER_VERBS_CMD_QUERY_SRQ,
3980 ib_uverbs_query_srq,
3981 UAPI_DEF_WRITE_IO(struct ib_uverbs_query_srq,
3982 struct ib_uverbs_query_srq_resp),
3983 UAPI_DEF_METHOD_NEEDS_FN(query_srq))),
3985 DECLARE_UVERBS_OBJECT(
3987 DECLARE_UVERBS_WRITE(
3988 IB_USER_VERBS_CMD_CLOSE_XRCD,
3989 ib_uverbs_close_xrcd,
3990 UAPI_DEF_WRITE_I(struct ib_uverbs_close_xrcd)),
3991 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_OPEN_QP,
3993 UAPI_DEF_WRITE_UDATA_IO(
3994 struct ib_uverbs_open_qp,
3995 struct ib_uverbs_create_qp_resp)),
3996 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_OPEN_XRCD,
3997 ib_uverbs_open_xrcd,
3998 UAPI_DEF_WRITE_UDATA_IO(
3999 struct ib_uverbs_open_xrcd,
4000 struct ib_uverbs_open_xrcd_resp)),
4001 UAPI_DEF_OBJ_NEEDS_FN(alloc_xrcd),
4002 UAPI_DEF_OBJ_NEEDS_FN(dealloc_xrcd)),