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 (len > iter->end - iter->cur)
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 = min_t(u32, ib_dev->phys_port_cnt, U8_MAX);
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;
575 struct fd f = EMPTY_FD;
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(fd_file(f));
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);
637 mutex_unlock(&ibudev->xrcd_tree_mutex);
638 uobj_finalize_uobj_create(&obj->uobject, attrs);
640 resp.xrcd_handle = obj->uobject.id;
641 return uverbs_response(attrs, &resp, sizeof(resp));
644 ib_dealloc_xrcd_user(xrcd, uverbs_get_cleared_udata(attrs));
647 uobj_alloc_abort(&obj->uobject, attrs);
649 err_tree_mutex_unlock:
652 mutex_unlock(&ibudev->xrcd_tree_mutex);
657 static int ib_uverbs_close_xrcd(struct uverbs_attr_bundle *attrs)
659 struct ib_uverbs_close_xrcd cmd;
662 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
666 return uobj_perform_destroy(UVERBS_OBJECT_XRCD, cmd.xrcd_handle, attrs);
669 int ib_uverbs_dealloc_xrcd(struct ib_uobject *uobject, struct ib_xrcd *xrcd,
670 enum rdma_remove_reason why,
671 struct uverbs_attr_bundle *attrs)
675 struct ib_uverbs_device *dev = attrs->ufile->device;
678 if (inode && !atomic_dec_and_test(&xrcd->usecnt))
681 ret = ib_dealloc_xrcd_user(xrcd, &attrs->driver_udata);
683 atomic_inc(&xrcd->usecnt);
688 xrcd_table_delete(dev, inode);
693 static int ib_uverbs_reg_mr(struct uverbs_attr_bundle *attrs)
695 struct ib_uverbs_reg_mr_resp resp = {};
696 struct ib_uverbs_reg_mr cmd;
697 struct ib_uobject *uobj;
701 struct ib_device *ib_dev;
703 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
707 if ((cmd.start & ~PAGE_MASK) != (cmd.hca_va & ~PAGE_MASK))
710 uobj = uobj_alloc(UVERBS_OBJECT_MR, attrs, &ib_dev);
712 return PTR_ERR(uobj);
714 ret = ib_check_mr_access(ib_dev, cmd.access_flags);
718 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, attrs);
724 mr = pd->device->ops.reg_user_mr(pd, cmd.start, cmd.length, cmd.hca_va,
726 &attrs->driver_udata);
732 mr->device = pd->device;
734 mr->type = IB_MR_TYPE_USER;
736 mr->sig_attrs = NULL;
738 atomic_inc(&pd->usecnt);
739 mr->iova = cmd.hca_va;
740 mr->length = cmd.length;
742 rdma_restrack_new(&mr->res, RDMA_RESTRACK_MR);
743 rdma_restrack_set_name(&mr->res, NULL);
744 rdma_restrack_add(&mr->res);
747 uobj_put_obj_read(pd);
748 uobj_finalize_uobj_create(uobj, attrs);
750 resp.lkey = mr->lkey;
751 resp.rkey = mr->rkey;
752 resp.mr_handle = uobj->id;
753 return uverbs_response(attrs, &resp, sizeof(resp));
756 uobj_put_obj_read(pd);
758 uobj_alloc_abort(uobj, attrs);
762 static int ib_uverbs_rereg_mr(struct uverbs_attr_bundle *attrs)
764 struct ib_uverbs_rereg_mr cmd;
765 struct ib_uverbs_rereg_mr_resp resp;
768 struct ib_uobject *uobj;
769 struct ib_uobject *new_uobj;
770 struct ib_device *ib_dev;
771 struct ib_pd *orig_pd;
772 struct ib_pd *new_pd;
773 struct ib_mr *new_mr;
775 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
782 if (cmd.flags & ~IB_MR_REREG_SUPPORTED)
785 if ((cmd.flags & IB_MR_REREG_TRANS) &&
786 (cmd.start & ~PAGE_MASK) != (cmd.hca_va & ~PAGE_MASK))
789 uobj = uobj_get_write(UVERBS_OBJECT_MR, cmd.mr_handle, attrs);
791 return PTR_ERR(uobj);
800 if (cmd.flags & IB_MR_REREG_ACCESS) {
801 ret = ib_check_mr_access(mr->device, cmd.access_flags);
807 if (cmd.flags & IB_MR_REREG_PD) {
808 new_pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle,
819 * The driver might create a new HW object as part of the rereg, we need
820 * to have a uobject ready to hold it.
822 new_uobj = uobj_alloc(UVERBS_OBJECT_MR, attrs, &ib_dev);
823 if (IS_ERR(new_uobj)) {
824 ret = PTR_ERR(new_uobj);
828 new_mr = ib_dev->ops.rereg_user_mr(mr, cmd.flags, cmd.start, cmd.length,
829 cmd.hca_va, cmd.access_flags, new_pd,
830 &attrs->driver_udata);
831 if (IS_ERR(new_mr)) {
832 ret = PTR_ERR(new_mr);
836 new_mr->device = new_pd->device;
838 new_mr->type = IB_MR_TYPE_USER;
839 new_mr->uobject = uobj;
840 atomic_inc(&new_pd->usecnt);
841 new_uobj->object = new_mr;
843 rdma_restrack_new(&new_mr->res, RDMA_RESTRACK_MR);
844 rdma_restrack_set_name(&new_mr->res, NULL);
845 rdma_restrack_add(&new_mr->res);
848 * The new uobj for the new HW object is put into the same spot
849 * in the IDR and the old uobj & HW object is deleted.
851 rdma_assign_uobject(uobj, new_uobj, attrs);
852 rdma_alloc_commit_uobject(new_uobj, attrs);
853 uobj_put_destroy(uobj);
858 if (cmd.flags & IB_MR_REREG_PD) {
859 atomic_dec(&orig_pd->usecnt);
861 atomic_inc(&new_pd->usecnt);
863 if (cmd.flags & IB_MR_REREG_TRANS) {
864 mr->iova = cmd.hca_va;
865 mr->length = cmd.length;
869 memset(&resp, 0, sizeof(resp));
870 resp.lkey = mr->lkey;
871 resp.rkey = mr->rkey;
873 ret = uverbs_response(attrs, &resp, sizeof(resp));
877 uobj_alloc_abort(new_uobj, attrs);
879 if (cmd.flags & IB_MR_REREG_PD)
880 uobj_put_obj_read(new_pd);
884 uobj_put_write(uobj);
889 static int ib_uverbs_dereg_mr(struct uverbs_attr_bundle *attrs)
891 struct ib_uverbs_dereg_mr cmd;
894 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
898 return uobj_perform_destroy(UVERBS_OBJECT_MR, cmd.mr_handle, attrs);
901 static int ib_uverbs_alloc_mw(struct uverbs_attr_bundle *attrs)
903 struct ib_uverbs_alloc_mw cmd;
904 struct ib_uverbs_alloc_mw_resp resp = {};
905 struct ib_uobject *uobj;
909 struct ib_device *ib_dev;
911 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
915 uobj = uobj_alloc(UVERBS_OBJECT_MW, attrs, &ib_dev);
917 return PTR_ERR(uobj);
919 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, attrs);
925 if (cmd.mw_type != IB_MW_TYPE_1 && cmd.mw_type != IB_MW_TYPE_2) {
930 mw = rdma_zalloc_drv_obj(ib_dev, ib_mw);
939 mw->type = cmd.mw_type;
941 ret = pd->device->ops.alloc_mw(mw, &attrs->driver_udata);
945 atomic_inc(&pd->usecnt);
948 uobj_put_obj_read(pd);
949 uobj_finalize_uobj_create(uobj, attrs);
951 resp.rkey = mw->rkey;
952 resp.mw_handle = uobj->id;
953 return uverbs_response(attrs, &resp, sizeof(resp));
958 uobj_put_obj_read(pd);
960 uobj_alloc_abort(uobj, attrs);
964 static int ib_uverbs_dealloc_mw(struct uverbs_attr_bundle *attrs)
966 struct ib_uverbs_dealloc_mw cmd;
969 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
973 return uobj_perform_destroy(UVERBS_OBJECT_MW, cmd.mw_handle, attrs);
976 static int ib_uverbs_create_comp_channel(struct uverbs_attr_bundle *attrs)
978 struct ib_uverbs_create_comp_channel cmd;
979 struct ib_uverbs_create_comp_channel_resp resp;
980 struct ib_uobject *uobj;
981 struct ib_uverbs_completion_event_file *ev_file;
982 struct ib_device *ib_dev;
985 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
989 uobj = uobj_alloc(UVERBS_OBJECT_COMP_CHANNEL, attrs, &ib_dev);
991 return PTR_ERR(uobj);
993 ev_file = container_of(uobj, struct ib_uverbs_completion_event_file,
995 ib_uverbs_init_event_queue(&ev_file->ev_queue);
996 uobj_finalize_uobj_create(uobj, attrs);
999 return uverbs_response(attrs, &resp, sizeof(resp));
1002 static int create_cq(struct uverbs_attr_bundle *attrs,
1003 struct ib_uverbs_ex_create_cq *cmd)
1005 struct ib_ucq_object *obj;
1006 struct ib_uverbs_completion_event_file *ev_file = NULL;
1009 struct ib_uverbs_ex_create_cq_resp resp = {};
1010 struct ib_cq_init_attr attr = {};
1011 struct ib_device *ib_dev;
1013 if (cmd->comp_vector >= attrs->ufile->device->num_comp_vectors)
1016 obj = (struct ib_ucq_object *)uobj_alloc(UVERBS_OBJECT_CQ, attrs,
1019 return PTR_ERR(obj);
1021 if (cmd->comp_channel >= 0) {
1022 ev_file = ib_uverbs_lookup_comp_file(cmd->comp_channel, attrs);
1023 if (IS_ERR(ev_file)) {
1024 ret = PTR_ERR(ev_file);
1029 obj->uevent.uobject.user_handle = cmd->user_handle;
1030 INIT_LIST_HEAD(&obj->comp_list);
1031 INIT_LIST_HEAD(&obj->uevent.event_list);
1033 attr.cqe = cmd->cqe;
1034 attr.comp_vector = cmd->comp_vector;
1035 attr.flags = cmd->flags;
1037 cq = rdma_zalloc_drv_obj(ib_dev, ib_cq);
1042 cq->device = ib_dev;
1044 cq->comp_handler = ib_uverbs_comp_handler;
1045 cq->event_handler = ib_uverbs_cq_event_handler;
1046 cq->cq_context = ev_file ? &ev_file->ev_queue : NULL;
1047 atomic_set(&cq->usecnt, 0);
1049 rdma_restrack_new(&cq->res, RDMA_RESTRACK_CQ);
1050 rdma_restrack_set_name(&cq->res, NULL);
1052 ret = ib_dev->ops.create_cq(cq, &attr, attrs);
1055 rdma_restrack_add(&cq->res);
1057 obj->uevent.uobject.object = cq;
1058 obj->uevent.event_file = READ_ONCE(attrs->ufile->default_async_file);
1059 if (obj->uevent.event_file)
1060 uverbs_uobject_get(&obj->uevent.event_file->uobj);
1061 uobj_finalize_uobj_create(&obj->uevent.uobject, attrs);
1063 resp.base.cq_handle = obj->uevent.uobject.id;
1064 resp.base.cqe = cq->cqe;
1065 resp.response_length = uverbs_response_length(attrs, sizeof(resp));
1066 return uverbs_response(attrs, &resp, sizeof(resp));
1069 rdma_restrack_put(&cq->res);
1073 ib_uverbs_release_ucq(ev_file, obj);
1075 uobj_alloc_abort(&obj->uevent.uobject, attrs);
1079 static int ib_uverbs_create_cq(struct uverbs_attr_bundle *attrs)
1081 struct ib_uverbs_create_cq cmd;
1082 struct ib_uverbs_ex_create_cq cmd_ex;
1085 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1089 memset(&cmd_ex, 0, sizeof(cmd_ex));
1090 cmd_ex.user_handle = cmd.user_handle;
1091 cmd_ex.cqe = cmd.cqe;
1092 cmd_ex.comp_vector = cmd.comp_vector;
1093 cmd_ex.comp_channel = cmd.comp_channel;
1095 return create_cq(attrs, &cmd_ex);
1098 static int ib_uverbs_ex_create_cq(struct uverbs_attr_bundle *attrs)
1100 struct ib_uverbs_ex_create_cq cmd;
1103 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1113 return create_cq(attrs, &cmd);
1116 static int ib_uverbs_resize_cq(struct uverbs_attr_bundle *attrs)
1118 struct ib_uverbs_resize_cq cmd;
1119 struct ib_uverbs_resize_cq_resp resp = {};
1123 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1127 cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs);
1131 ret = cq->device->ops.resize_cq(cq, cmd.cqe, &attrs->driver_udata);
1137 ret = uverbs_response(attrs, &resp, sizeof(resp));
1139 rdma_lookup_put_uobject(&cq->uobject->uevent.uobject,
1140 UVERBS_LOOKUP_READ);
1145 static int copy_wc_to_user(struct ib_device *ib_dev, void __user *dest,
1148 struct ib_uverbs_wc tmp;
1150 tmp.wr_id = wc->wr_id;
1151 tmp.status = wc->status;
1152 tmp.opcode = wc->opcode;
1153 tmp.vendor_err = wc->vendor_err;
1154 tmp.byte_len = wc->byte_len;
1155 tmp.ex.imm_data = wc->ex.imm_data;
1156 tmp.qp_num = wc->qp->qp_num;
1157 tmp.src_qp = wc->src_qp;
1158 tmp.wc_flags = wc->wc_flags;
1159 tmp.pkey_index = wc->pkey_index;
1160 if (rdma_cap_opa_ah(ib_dev, wc->port_num))
1161 tmp.slid = OPA_TO_IB_UCAST_LID(wc->slid);
1163 tmp.slid = ib_lid_cpu16(wc->slid);
1165 tmp.dlid_path_bits = wc->dlid_path_bits;
1166 tmp.port_num = wc->port_num;
1169 if (copy_to_user(dest, &tmp, sizeof tmp))
1175 static int ib_uverbs_poll_cq(struct uverbs_attr_bundle *attrs)
1177 struct ib_uverbs_poll_cq cmd;
1178 struct ib_uverbs_poll_cq_resp resp;
1179 u8 __user *header_ptr;
1180 u8 __user *data_ptr;
1185 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1189 cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs);
1193 /* we copy a struct ib_uverbs_poll_cq_resp to user space */
1194 header_ptr = attrs->ucore.outbuf;
1195 data_ptr = header_ptr + sizeof resp;
1197 memset(&resp, 0, sizeof resp);
1198 while (resp.count < cmd.ne) {
1199 ret = ib_poll_cq(cq, 1, &wc);
1205 ret = copy_wc_to_user(cq->device, data_ptr, &wc);
1209 data_ptr += sizeof(struct ib_uverbs_wc);
1213 if (copy_to_user(header_ptr, &resp, sizeof resp)) {
1219 if (uverbs_attr_is_valid(attrs, UVERBS_ATTR_CORE_OUT))
1220 ret = uverbs_output_written(attrs, UVERBS_ATTR_CORE_OUT);
1223 rdma_lookup_put_uobject(&cq->uobject->uevent.uobject,
1224 UVERBS_LOOKUP_READ);
1228 static int ib_uverbs_req_notify_cq(struct uverbs_attr_bundle *attrs)
1230 struct ib_uverbs_req_notify_cq cmd;
1234 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1238 cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs);
1242 ib_req_notify_cq(cq, cmd.solicited_only ?
1243 IB_CQ_SOLICITED : IB_CQ_NEXT_COMP);
1245 rdma_lookup_put_uobject(&cq->uobject->uevent.uobject,
1246 UVERBS_LOOKUP_READ);
1250 static int ib_uverbs_destroy_cq(struct uverbs_attr_bundle *attrs)
1252 struct ib_uverbs_destroy_cq cmd;
1253 struct ib_uverbs_destroy_cq_resp resp;
1254 struct ib_uobject *uobj;
1255 struct ib_ucq_object *obj;
1258 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1262 uobj = uobj_get_destroy(UVERBS_OBJECT_CQ, cmd.cq_handle, attrs);
1264 return PTR_ERR(uobj);
1266 obj = container_of(uobj, struct ib_ucq_object, uevent.uobject);
1267 memset(&resp, 0, sizeof(resp));
1268 resp.comp_events_reported = obj->comp_events_reported;
1269 resp.async_events_reported = obj->uevent.events_reported;
1271 uobj_put_destroy(uobj);
1273 return uverbs_response(attrs, &resp, sizeof(resp));
1276 static int create_qp(struct uverbs_attr_bundle *attrs,
1277 struct ib_uverbs_ex_create_qp *cmd)
1279 struct ib_uqp_object *obj;
1280 struct ib_device *device;
1281 struct ib_pd *pd = NULL;
1282 struct ib_xrcd *xrcd = NULL;
1283 struct ib_uobject *xrcd_uobj = ERR_PTR(-ENOENT);
1284 struct ib_cq *scq = NULL, *rcq = NULL;
1285 struct ib_srq *srq = NULL;
1287 struct ib_qp_init_attr attr = {};
1288 struct ib_uverbs_ex_create_qp_resp resp = {};
1290 struct ib_rwq_ind_table *ind_tbl = NULL;
1292 struct ib_device *ib_dev;
1294 switch (cmd->qp_type) {
1295 case IB_QPT_RAW_PACKET:
1296 if (!capable(CAP_NET_RAW))
1302 case IB_QPT_XRC_INI:
1303 case IB_QPT_XRC_TGT:
1310 obj = (struct ib_uqp_object *)uobj_alloc(UVERBS_OBJECT_QP, attrs,
1313 return PTR_ERR(obj);
1315 obj->uevent.uobject.user_handle = cmd->user_handle;
1316 mutex_init(&obj->mcast_lock);
1318 if (cmd->comp_mask & IB_UVERBS_CREATE_QP_MASK_IND_TABLE) {
1319 ind_tbl = uobj_get_obj_read(rwq_ind_table,
1320 UVERBS_OBJECT_RWQ_IND_TBL,
1321 cmd->rwq_ind_tbl_handle, attrs);
1327 attr.rwq_ind_tbl = ind_tbl;
1330 if (ind_tbl && (cmd->max_recv_wr || cmd->max_recv_sge || cmd->is_srq)) {
1335 if (ind_tbl && !cmd->max_send_wr)
1338 if (cmd->qp_type == IB_QPT_XRC_TGT) {
1339 xrcd_uobj = uobj_get_read(UVERBS_OBJECT_XRCD, cmd->pd_handle,
1342 if (IS_ERR(xrcd_uobj)) {
1347 xrcd = (struct ib_xrcd *)xrcd_uobj->object;
1352 device = xrcd->device;
1354 if (cmd->qp_type == IB_QPT_XRC_INI) {
1355 cmd->max_recv_wr = 0;
1356 cmd->max_recv_sge = 0;
1359 srq = uobj_get_obj_read(srq, UVERBS_OBJECT_SRQ,
1360 cmd->srq_handle, attrs);
1361 if (!srq || srq->srq_type == IB_SRQT_XRC) {
1368 if (cmd->recv_cq_handle != cmd->send_cq_handle) {
1369 rcq = uobj_get_obj_read(
1370 cq, UVERBS_OBJECT_CQ,
1371 cmd->recv_cq_handle, attrs);
1381 scq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ,
1382 cmd->send_cq_handle, attrs);
1383 if (!ind_tbl && cmd->qp_type != IB_QPT_XRC_INI)
1385 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd->pd_handle,
1387 if (!pd || (!scq && has_sq)) {
1392 device = pd->device;
1395 attr.event_handler = ib_uverbs_qp_event_handler;
1400 attr.sq_sig_type = cmd->sq_sig_all ? IB_SIGNAL_ALL_WR :
1402 attr.qp_type = cmd->qp_type;
1404 attr.cap.max_send_wr = cmd->max_send_wr;
1405 attr.cap.max_recv_wr = cmd->max_recv_wr;
1406 attr.cap.max_send_sge = cmd->max_send_sge;
1407 attr.cap.max_recv_sge = cmd->max_recv_sge;
1408 attr.cap.max_inline_data = cmd->max_inline_data;
1410 INIT_LIST_HEAD(&obj->uevent.event_list);
1411 INIT_LIST_HEAD(&obj->mcast_list);
1413 attr.create_flags = cmd->create_flags;
1414 if (attr.create_flags & ~(IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK |
1415 IB_QP_CREATE_CROSS_CHANNEL |
1416 IB_QP_CREATE_MANAGED_SEND |
1417 IB_QP_CREATE_MANAGED_RECV |
1418 IB_QP_CREATE_SCATTER_FCS |
1419 IB_QP_CREATE_CVLAN_STRIPPING |
1420 IB_QP_CREATE_SOURCE_QPN |
1421 IB_QP_CREATE_PCI_WRITE_END_PADDING)) {
1426 if (attr.create_flags & IB_QP_CREATE_SOURCE_QPN) {
1427 if (!capable(CAP_NET_RAW)) {
1432 attr.source_qpn = cmd->source_qpn;
1435 qp = ib_create_qp_user(device, pd, &attr, &attrs->driver_udata, obj,
1441 ib_qp_usecnt_inc(qp);
1443 obj->uevent.uobject.object = qp;
1444 obj->uevent.event_file = READ_ONCE(attrs->ufile->default_async_file);
1445 if (obj->uevent.event_file)
1446 uverbs_uobject_get(&obj->uevent.event_file->uobj);
1449 obj->uxrcd = container_of(xrcd_uobj, struct ib_uxrcd_object,
1451 atomic_inc(&obj->uxrcd->refcnt);
1452 uobj_put_read(xrcd_uobj);
1456 uobj_put_obj_read(pd);
1458 rdma_lookup_put_uobject(&scq->uobject->uevent.uobject,
1459 UVERBS_LOOKUP_READ);
1460 if (rcq && rcq != scq)
1461 rdma_lookup_put_uobject(&rcq->uobject->uevent.uobject,
1462 UVERBS_LOOKUP_READ);
1464 rdma_lookup_put_uobject(&srq->uobject->uevent.uobject,
1465 UVERBS_LOOKUP_READ);
1467 uobj_put_obj_read(ind_tbl);
1468 uobj_finalize_uobj_create(&obj->uevent.uobject, attrs);
1470 resp.base.qpn = qp->qp_num;
1471 resp.base.qp_handle = obj->uevent.uobject.id;
1472 resp.base.max_recv_sge = attr.cap.max_recv_sge;
1473 resp.base.max_send_sge = attr.cap.max_send_sge;
1474 resp.base.max_recv_wr = attr.cap.max_recv_wr;
1475 resp.base.max_send_wr = attr.cap.max_send_wr;
1476 resp.base.max_inline_data = attr.cap.max_inline_data;
1477 resp.response_length = uverbs_response_length(attrs, sizeof(resp));
1478 return uverbs_response(attrs, &resp, sizeof(resp));
1481 if (!IS_ERR(xrcd_uobj))
1482 uobj_put_read(xrcd_uobj);
1484 uobj_put_obj_read(pd);
1486 rdma_lookup_put_uobject(&scq->uobject->uevent.uobject,
1487 UVERBS_LOOKUP_READ);
1488 if (rcq && rcq != scq)
1489 rdma_lookup_put_uobject(&rcq->uobject->uevent.uobject,
1490 UVERBS_LOOKUP_READ);
1492 rdma_lookup_put_uobject(&srq->uobject->uevent.uobject,
1493 UVERBS_LOOKUP_READ);
1495 uobj_put_obj_read(ind_tbl);
1497 uobj_alloc_abort(&obj->uevent.uobject, attrs);
1501 static int ib_uverbs_create_qp(struct uverbs_attr_bundle *attrs)
1503 struct ib_uverbs_create_qp cmd;
1504 struct ib_uverbs_ex_create_qp cmd_ex;
1507 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1511 memset(&cmd_ex, 0, sizeof(cmd_ex));
1512 cmd_ex.user_handle = cmd.user_handle;
1513 cmd_ex.pd_handle = cmd.pd_handle;
1514 cmd_ex.send_cq_handle = cmd.send_cq_handle;
1515 cmd_ex.recv_cq_handle = cmd.recv_cq_handle;
1516 cmd_ex.srq_handle = cmd.srq_handle;
1517 cmd_ex.max_send_wr = cmd.max_send_wr;
1518 cmd_ex.max_recv_wr = cmd.max_recv_wr;
1519 cmd_ex.max_send_sge = cmd.max_send_sge;
1520 cmd_ex.max_recv_sge = cmd.max_recv_sge;
1521 cmd_ex.max_inline_data = cmd.max_inline_data;
1522 cmd_ex.sq_sig_all = cmd.sq_sig_all;
1523 cmd_ex.qp_type = cmd.qp_type;
1524 cmd_ex.is_srq = cmd.is_srq;
1526 return create_qp(attrs, &cmd_ex);
1529 static int ib_uverbs_ex_create_qp(struct uverbs_attr_bundle *attrs)
1531 struct ib_uverbs_ex_create_qp cmd;
1534 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1538 if (cmd.comp_mask & ~IB_UVERBS_CREATE_QP_SUP_COMP_MASK)
1544 return create_qp(attrs, &cmd);
1547 static int ib_uverbs_open_qp(struct uverbs_attr_bundle *attrs)
1549 struct ib_uverbs_create_qp_resp resp = {};
1550 struct ib_uverbs_open_qp cmd;
1551 struct ib_uqp_object *obj;
1552 struct ib_xrcd *xrcd;
1554 struct ib_qp_open_attr attr = {};
1556 struct ib_uobject *xrcd_uobj;
1557 struct ib_device *ib_dev;
1559 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1563 obj = (struct ib_uqp_object *)uobj_alloc(UVERBS_OBJECT_QP, attrs,
1566 return PTR_ERR(obj);
1568 xrcd_uobj = uobj_get_read(UVERBS_OBJECT_XRCD, cmd.pd_handle, attrs);
1569 if (IS_ERR(xrcd_uobj)) {
1574 xrcd = (struct ib_xrcd *)xrcd_uobj->object;
1580 attr.event_handler = ib_uverbs_qp_event_handler;
1581 attr.qp_num = cmd.qpn;
1582 attr.qp_type = cmd.qp_type;
1584 INIT_LIST_HEAD(&obj->uevent.event_list);
1585 INIT_LIST_HEAD(&obj->mcast_list);
1587 qp = ib_open_qp(xrcd, &attr);
1593 obj->uevent.uobject.object = qp;
1594 obj->uevent.uobject.user_handle = cmd.user_handle;
1596 obj->uxrcd = container_of(xrcd_uobj, struct ib_uxrcd_object, uobject);
1597 atomic_inc(&obj->uxrcd->refcnt);
1599 uobj_put_read(xrcd_uobj);
1600 uobj_finalize_uobj_create(&obj->uevent.uobject, attrs);
1602 resp.qpn = qp->qp_num;
1603 resp.qp_handle = obj->uevent.uobject.id;
1604 return uverbs_response(attrs, &resp, sizeof(resp));
1607 uobj_put_read(xrcd_uobj);
1609 uobj_alloc_abort(&obj->uevent.uobject, attrs);
1613 static void copy_ah_attr_to_uverbs(struct ib_uverbs_qp_dest *uverb_attr,
1614 struct rdma_ah_attr *rdma_attr)
1616 const struct ib_global_route *grh;
1618 uverb_attr->dlid = rdma_ah_get_dlid(rdma_attr);
1619 uverb_attr->sl = rdma_ah_get_sl(rdma_attr);
1620 uverb_attr->src_path_bits = rdma_ah_get_path_bits(rdma_attr);
1621 uverb_attr->static_rate = rdma_ah_get_static_rate(rdma_attr);
1622 uverb_attr->is_global = !!(rdma_ah_get_ah_flags(rdma_attr) &
1624 if (uverb_attr->is_global) {
1625 grh = rdma_ah_read_grh(rdma_attr);
1626 memcpy(uverb_attr->dgid, grh->dgid.raw, 16);
1627 uverb_attr->flow_label = grh->flow_label;
1628 uverb_attr->sgid_index = grh->sgid_index;
1629 uverb_attr->hop_limit = grh->hop_limit;
1630 uverb_attr->traffic_class = grh->traffic_class;
1632 uverb_attr->port_num = rdma_ah_get_port_num(rdma_attr);
1635 static int ib_uverbs_query_qp(struct uverbs_attr_bundle *attrs)
1637 struct ib_uverbs_query_qp cmd;
1638 struct ib_uverbs_query_qp_resp resp;
1640 struct ib_qp_attr *attr;
1641 struct ib_qp_init_attr *init_attr;
1644 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1648 attr = kmalloc(sizeof *attr, GFP_KERNEL);
1649 init_attr = kmalloc(sizeof *init_attr, GFP_KERNEL);
1650 if (!attr || !init_attr) {
1655 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
1661 ret = ib_query_qp(qp, attr, cmd.attr_mask, init_attr);
1663 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
1664 UVERBS_LOOKUP_READ);
1669 memset(&resp, 0, sizeof resp);
1671 resp.qp_state = attr->qp_state;
1672 resp.cur_qp_state = attr->cur_qp_state;
1673 resp.path_mtu = attr->path_mtu;
1674 resp.path_mig_state = attr->path_mig_state;
1675 resp.qkey = attr->qkey;
1676 resp.rq_psn = attr->rq_psn;
1677 resp.sq_psn = attr->sq_psn;
1678 resp.dest_qp_num = attr->dest_qp_num;
1679 resp.qp_access_flags = attr->qp_access_flags;
1680 resp.pkey_index = attr->pkey_index;
1681 resp.alt_pkey_index = attr->alt_pkey_index;
1682 resp.sq_draining = attr->sq_draining;
1683 resp.max_rd_atomic = attr->max_rd_atomic;
1684 resp.max_dest_rd_atomic = attr->max_dest_rd_atomic;
1685 resp.min_rnr_timer = attr->min_rnr_timer;
1686 resp.port_num = attr->port_num;
1687 resp.timeout = attr->timeout;
1688 resp.retry_cnt = attr->retry_cnt;
1689 resp.rnr_retry = attr->rnr_retry;
1690 resp.alt_port_num = attr->alt_port_num;
1691 resp.alt_timeout = attr->alt_timeout;
1693 copy_ah_attr_to_uverbs(&resp.dest, &attr->ah_attr);
1694 copy_ah_attr_to_uverbs(&resp.alt_dest, &attr->alt_ah_attr);
1696 resp.max_send_wr = init_attr->cap.max_send_wr;
1697 resp.max_recv_wr = init_attr->cap.max_recv_wr;
1698 resp.max_send_sge = init_attr->cap.max_send_sge;
1699 resp.max_recv_sge = init_attr->cap.max_recv_sge;
1700 resp.max_inline_data = init_attr->cap.max_inline_data;
1701 resp.sq_sig_all = init_attr->sq_sig_type == IB_SIGNAL_ALL_WR;
1703 ret = uverbs_response(attrs, &resp, sizeof(resp));
1712 /* Remove ignored fields set in the attribute mask */
1713 static int modify_qp_mask(enum ib_qp_type qp_type, int mask)
1716 case IB_QPT_XRC_INI:
1717 return mask & ~(IB_QP_MAX_DEST_RD_ATOMIC | IB_QP_MIN_RNR_TIMER);
1718 case IB_QPT_XRC_TGT:
1719 return mask & ~(IB_QP_MAX_QP_RD_ATOMIC | IB_QP_RETRY_CNT |
1726 static void copy_ah_attr_from_uverbs(struct ib_device *dev,
1727 struct rdma_ah_attr *rdma_attr,
1728 struct ib_uverbs_qp_dest *uverb_attr)
1730 rdma_attr->type = rdma_ah_find_type(dev, uverb_attr->port_num);
1731 if (uverb_attr->is_global) {
1732 rdma_ah_set_grh(rdma_attr, NULL,
1733 uverb_attr->flow_label,
1734 uverb_attr->sgid_index,
1735 uverb_attr->hop_limit,
1736 uverb_attr->traffic_class);
1737 rdma_ah_set_dgid_raw(rdma_attr, uverb_attr->dgid);
1739 rdma_ah_set_ah_flags(rdma_attr, 0);
1741 rdma_ah_set_dlid(rdma_attr, uverb_attr->dlid);
1742 rdma_ah_set_sl(rdma_attr, uverb_attr->sl);
1743 rdma_ah_set_path_bits(rdma_attr, uverb_attr->src_path_bits);
1744 rdma_ah_set_static_rate(rdma_attr, uverb_attr->static_rate);
1745 rdma_ah_set_port_num(rdma_attr, uverb_attr->port_num);
1746 rdma_ah_set_make_grd(rdma_attr, false);
1749 static int modify_qp(struct uverbs_attr_bundle *attrs,
1750 struct ib_uverbs_ex_modify_qp *cmd)
1752 struct ib_qp_attr *attr;
1756 attr = kzalloc(sizeof(*attr), GFP_KERNEL);
1760 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd->base.qp_handle,
1767 if ((cmd->base.attr_mask & IB_QP_PORT) &&
1768 !rdma_is_port_valid(qp->device, cmd->base.port_num)) {
1773 if ((cmd->base.attr_mask & IB_QP_AV)) {
1774 if (!rdma_is_port_valid(qp->device, cmd->base.dest.port_num)) {
1779 if (cmd->base.attr_mask & IB_QP_STATE &&
1780 cmd->base.qp_state == IB_QPS_RTR) {
1781 /* We are in INIT->RTR TRANSITION (if we are not,
1782 * this transition will be rejected in subsequent checks).
1783 * In the INIT->RTR transition, we cannot have IB_QP_PORT set,
1784 * but the IB_QP_STATE flag is required.
1786 * Since kernel 3.14 (commit dbf727de7440), the uverbs driver,
1787 * when IB_QP_AV is set, has required inclusion of a valid
1788 * port number in the primary AV. (AVs are created and handled
1789 * differently for infiniband and ethernet (RoCE) ports).
1791 * Check the port number included in the primary AV against
1792 * the port number in the qp struct, which was set (and saved)
1793 * in the RST->INIT transition.
1795 if (cmd->base.dest.port_num != qp->real_qp->port) {
1800 /* We are in SQD->SQD. (If we are not, this transition will
1801 * be rejected later in the verbs layer checks).
1802 * Check for both IB_QP_PORT and IB_QP_AV, these can be set
1803 * together in the SQD->SQD transition.
1805 * If only IP_QP_AV was set, add in IB_QP_PORT as well (the
1806 * verbs layer driver does not track primary port changes
1807 * resulting from path migration. Thus, in SQD, if the primary
1808 * AV is modified, the primary port should also be modified).
1810 * Note that in this transition, the IB_QP_STATE flag
1813 if (((cmd->base.attr_mask & (IB_QP_AV | IB_QP_PORT))
1814 == (IB_QP_AV | IB_QP_PORT)) &&
1815 cmd->base.port_num != cmd->base.dest.port_num) {
1819 if ((cmd->base.attr_mask & (IB_QP_AV | IB_QP_PORT))
1821 cmd->base.attr_mask |= IB_QP_PORT;
1822 cmd->base.port_num = cmd->base.dest.port_num;
1827 if ((cmd->base.attr_mask & IB_QP_ALT_PATH) &&
1828 (!rdma_is_port_valid(qp->device, cmd->base.alt_port_num) ||
1829 !rdma_is_port_valid(qp->device, cmd->base.alt_dest.port_num) ||
1830 cmd->base.alt_port_num != cmd->base.alt_dest.port_num)) {
1835 if ((cmd->base.attr_mask & IB_QP_CUR_STATE &&
1836 cmd->base.cur_qp_state > IB_QPS_ERR) ||
1837 (cmd->base.attr_mask & IB_QP_STATE &&
1838 cmd->base.qp_state > IB_QPS_ERR)) {
1843 if (cmd->base.attr_mask & IB_QP_STATE)
1844 attr->qp_state = cmd->base.qp_state;
1845 if (cmd->base.attr_mask & IB_QP_CUR_STATE)
1846 attr->cur_qp_state = cmd->base.cur_qp_state;
1847 if (cmd->base.attr_mask & IB_QP_PATH_MTU)
1848 attr->path_mtu = cmd->base.path_mtu;
1849 if (cmd->base.attr_mask & IB_QP_PATH_MIG_STATE)
1850 attr->path_mig_state = cmd->base.path_mig_state;
1851 if (cmd->base.attr_mask & IB_QP_QKEY) {
1852 if (cmd->base.qkey & IB_QP_SET_QKEY &&
1853 !rdma_nl_get_privileged_qkey()) {
1857 attr->qkey = cmd->base.qkey;
1859 if (cmd->base.attr_mask & IB_QP_RQ_PSN)
1860 attr->rq_psn = cmd->base.rq_psn;
1861 if (cmd->base.attr_mask & IB_QP_SQ_PSN)
1862 attr->sq_psn = cmd->base.sq_psn;
1863 if (cmd->base.attr_mask & IB_QP_DEST_QPN)
1864 attr->dest_qp_num = cmd->base.dest_qp_num;
1865 if (cmd->base.attr_mask & IB_QP_ACCESS_FLAGS)
1866 attr->qp_access_flags = cmd->base.qp_access_flags;
1867 if (cmd->base.attr_mask & IB_QP_PKEY_INDEX)
1868 attr->pkey_index = cmd->base.pkey_index;
1869 if (cmd->base.attr_mask & IB_QP_EN_SQD_ASYNC_NOTIFY)
1870 attr->en_sqd_async_notify = cmd->base.en_sqd_async_notify;
1871 if (cmd->base.attr_mask & IB_QP_MAX_QP_RD_ATOMIC)
1872 attr->max_rd_atomic = cmd->base.max_rd_atomic;
1873 if (cmd->base.attr_mask & IB_QP_MAX_DEST_RD_ATOMIC)
1874 attr->max_dest_rd_atomic = cmd->base.max_dest_rd_atomic;
1875 if (cmd->base.attr_mask & IB_QP_MIN_RNR_TIMER)
1876 attr->min_rnr_timer = cmd->base.min_rnr_timer;
1877 if (cmd->base.attr_mask & IB_QP_PORT)
1878 attr->port_num = cmd->base.port_num;
1879 if (cmd->base.attr_mask & IB_QP_TIMEOUT)
1880 attr->timeout = cmd->base.timeout;
1881 if (cmd->base.attr_mask & IB_QP_RETRY_CNT)
1882 attr->retry_cnt = cmd->base.retry_cnt;
1883 if (cmd->base.attr_mask & IB_QP_RNR_RETRY)
1884 attr->rnr_retry = cmd->base.rnr_retry;
1885 if (cmd->base.attr_mask & IB_QP_ALT_PATH) {
1886 attr->alt_port_num = cmd->base.alt_port_num;
1887 attr->alt_timeout = cmd->base.alt_timeout;
1888 attr->alt_pkey_index = cmd->base.alt_pkey_index;
1890 if (cmd->base.attr_mask & IB_QP_RATE_LIMIT)
1891 attr->rate_limit = cmd->rate_limit;
1893 if (cmd->base.attr_mask & IB_QP_AV)
1894 copy_ah_attr_from_uverbs(qp->device, &attr->ah_attr,
1897 if (cmd->base.attr_mask & IB_QP_ALT_PATH)
1898 copy_ah_attr_from_uverbs(qp->device, &attr->alt_ah_attr,
1899 &cmd->base.alt_dest);
1901 ret = ib_modify_qp_with_udata(qp, attr,
1902 modify_qp_mask(qp->qp_type,
1903 cmd->base.attr_mask),
1904 &attrs->driver_udata);
1907 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
1908 UVERBS_LOOKUP_READ);
1915 static int ib_uverbs_modify_qp(struct uverbs_attr_bundle *attrs)
1917 struct ib_uverbs_ex_modify_qp cmd;
1920 ret = uverbs_request(attrs, &cmd.base, sizeof(cmd.base));
1924 if (cmd.base.attr_mask & ~IB_QP_ATTR_STANDARD_BITS)
1927 return modify_qp(attrs, &cmd);
1930 static int ib_uverbs_ex_modify_qp(struct uverbs_attr_bundle *attrs)
1932 struct ib_uverbs_ex_modify_qp cmd;
1933 struct ib_uverbs_ex_modify_qp_resp resp = {
1934 .response_length = uverbs_response_length(attrs, sizeof(resp))
1938 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1943 * Last bit is reserved for extending the attr_mask by
1944 * using another field.
1946 if (cmd.base.attr_mask & ~(IB_QP_ATTR_STANDARD_BITS | IB_QP_RATE_LIMIT))
1949 ret = modify_qp(attrs, &cmd);
1953 return uverbs_response(attrs, &resp, sizeof(resp));
1956 static int ib_uverbs_destroy_qp(struct uverbs_attr_bundle *attrs)
1958 struct ib_uverbs_destroy_qp cmd;
1959 struct ib_uverbs_destroy_qp_resp resp;
1960 struct ib_uobject *uobj;
1961 struct ib_uqp_object *obj;
1964 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1968 uobj = uobj_get_destroy(UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
1970 return PTR_ERR(uobj);
1972 obj = container_of(uobj, struct ib_uqp_object, uevent.uobject);
1973 memset(&resp, 0, sizeof(resp));
1974 resp.events_reported = obj->uevent.events_reported;
1976 uobj_put_destroy(uobj);
1978 return uverbs_response(attrs, &resp, sizeof(resp));
1981 static void *alloc_wr(size_t wr_size, __u32 num_sge)
1983 if (num_sge >= (U32_MAX - ALIGN(wr_size, sizeof(struct ib_sge))) /
1984 sizeof(struct ib_sge))
1987 return kmalloc(ALIGN(wr_size, sizeof(struct ib_sge)) +
1988 num_sge * sizeof(struct ib_sge),
1992 static int ib_uverbs_post_send(struct uverbs_attr_bundle *attrs)
1994 struct ib_uverbs_post_send cmd;
1995 struct ib_uverbs_post_send_resp resp;
1996 struct ib_uverbs_send_wr *user_wr;
1997 struct ib_send_wr *wr = NULL, *last, *next;
1998 const struct ib_send_wr *bad_wr;
2004 const struct ib_sge __user *sgls;
2005 const void __user *wqes;
2006 struct uverbs_req_iter iter;
2008 ret = uverbs_request_start(attrs, &iter, &cmd, sizeof(cmd));
2011 wqes = uverbs_request_next_ptr(&iter, size_mul(cmd.wqe_size,
2014 return PTR_ERR(wqes);
2015 sgls = uverbs_request_next_ptr(&iter,
2016 size_mul(cmd.sge_count,
2017 sizeof(struct ib_uverbs_sge)));
2019 return PTR_ERR(sgls);
2020 ret = uverbs_request_finish(&iter);
2024 user_wr = kmalloc(cmd.wqe_size, GFP_KERNEL);
2028 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
2034 is_ud = qp->qp_type == IB_QPT_UD;
2037 for (i = 0; i < cmd.wr_count; ++i) {
2038 if (copy_from_user(user_wr, wqes + i * cmd.wqe_size,
2044 if (user_wr->num_sge + sg_ind > cmd.sge_count) {
2050 struct ib_ud_wr *ud;
2052 if (user_wr->opcode != IB_WR_SEND &&
2053 user_wr->opcode != IB_WR_SEND_WITH_IMM) {
2058 next_size = sizeof(*ud);
2059 ud = alloc_wr(next_size, user_wr->num_sge);
2065 ud->ah = uobj_get_obj_read(ah, UVERBS_OBJECT_AH,
2066 user_wr->wr.ud.ah, attrs);
2072 ud->remote_qpn = user_wr->wr.ud.remote_qpn;
2073 ud->remote_qkey = user_wr->wr.ud.remote_qkey;
2076 } else if (user_wr->opcode == IB_WR_RDMA_WRITE_WITH_IMM ||
2077 user_wr->opcode == IB_WR_RDMA_WRITE ||
2078 user_wr->opcode == IB_WR_RDMA_READ) {
2079 struct ib_rdma_wr *rdma;
2081 next_size = sizeof(*rdma);
2082 rdma = alloc_wr(next_size, user_wr->num_sge);
2088 rdma->remote_addr = user_wr->wr.rdma.remote_addr;
2089 rdma->rkey = user_wr->wr.rdma.rkey;
2092 } else if (user_wr->opcode == IB_WR_ATOMIC_CMP_AND_SWP ||
2093 user_wr->opcode == IB_WR_ATOMIC_FETCH_AND_ADD) {
2094 struct ib_atomic_wr *atomic;
2096 next_size = sizeof(*atomic);
2097 atomic = alloc_wr(next_size, user_wr->num_sge);
2103 atomic->remote_addr = user_wr->wr.atomic.remote_addr;
2104 atomic->compare_add = user_wr->wr.atomic.compare_add;
2105 atomic->swap = user_wr->wr.atomic.swap;
2106 atomic->rkey = user_wr->wr.atomic.rkey;
2109 } else if (user_wr->opcode == IB_WR_SEND ||
2110 user_wr->opcode == IB_WR_SEND_WITH_IMM ||
2111 user_wr->opcode == IB_WR_SEND_WITH_INV) {
2112 next_size = sizeof(*next);
2113 next = alloc_wr(next_size, user_wr->num_sge);
2123 if (user_wr->opcode == IB_WR_SEND_WITH_IMM ||
2124 user_wr->opcode == IB_WR_RDMA_WRITE_WITH_IMM) {
2126 (__be32 __force) user_wr->ex.imm_data;
2127 } else if (user_wr->opcode == IB_WR_SEND_WITH_INV) {
2128 next->ex.invalidate_rkey = user_wr->ex.invalidate_rkey;
2138 next->wr_id = user_wr->wr_id;
2139 next->num_sge = user_wr->num_sge;
2140 next->opcode = user_wr->opcode;
2141 next->send_flags = user_wr->send_flags;
2143 if (next->num_sge) {
2144 next->sg_list = (void *) next +
2145 ALIGN(next_size, sizeof(struct ib_sge));
2146 if (copy_from_user(next->sg_list, sgls + sg_ind,
2148 sizeof(struct ib_sge))) {
2152 sg_ind += next->num_sge;
2154 next->sg_list = NULL;
2158 ret = qp->device->ops.post_send(qp->real_qp, wr, &bad_wr);
2160 for (next = wr; next; next = next->next) {
2166 ret2 = uverbs_response(attrs, &resp, sizeof(resp));
2171 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
2172 UVERBS_LOOKUP_READ);
2175 if (is_ud && ud_wr(wr)->ah)
2176 uobj_put_obj_read(ud_wr(wr)->ah);
2188 static struct ib_recv_wr *
2189 ib_uverbs_unmarshall_recv(struct uverbs_req_iter *iter, u32 wr_count,
2190 u32 wqe_size, u32 sge_count)
2192 struct ib_uverbs_recv_wr *user_wr;
2193 struct ib_recv_wr *wr = NULL, *last, *next;
2197 const struct ib_sge __user *sgls;
2198 const void __user *wqes;
2200 if (wqe_size < sizeof(struct ib_uverbs_recv_wr))
2201 return ERR_PTR(-EINVAL);
2203 wqes = uverbs_request_next_ptr(iter, size_mul(wqe_size, wr_count));
2205 return ERR_CAST(wqes);
2206 sgls = uverbs_request_next_ptr(iter, size_mul(sge_count,
2207 sizeof(struct ib_uverbs_sge)));
2209 return ERR_CAST(sgls);
2210 ret = uverbs_request_finish(iter);
2212 return ERR_PTR(ret);
2214 user_wr = kmalloc(wqe_size, GFP_KERNEL);
2216 return ERR_PTR(-ENOMEM);
2220 for (i = 0; i < wr_count; ++i) {
2221 if (copy_from_user(user_wr, wqes + i * wqe_size,
2227 if (user_wr->num_sge + sg_ind > sge_count) {
2232 if (user_wr->num_sge >=
2233 (U32_MAX - ALIGN(sizeof(*next), sizeof(struct ib_sge))) /
2234 sizeof(struct ib_sge)) {
2239 next = kmalloc(ALIGN(sizeof(*next), sizeof(struct ib_sge)) +
2240 user_wr->num_sge * sizeof(struct ib_sge),
2254 next->wr_id = user_wr->wr_id;
2255 next->num_sge = user_wr->num_sge;
2257 if (next->num_sge) {
2258 next->sg_list = (void *)next +
2259 ALIGN(sizeof(*next), sizeof(struct ib_sge));
2260 if (copy_from_user(next->sg_list, sgls + sg_ind,
2262 sizeof(struct ib_sge))) {
2266 sg_ind += next->num_sge;
2268 next->sg_list = NULL;
2283 return ERR_PTR(ret);
2286 static int ib_uverbs_post_recv(struct uverbs_attr_bundle *attrs)
2288 struct ib_uverbs_post_recv cmd;
2289 struct ib_uverbs_post_recv_resp resp;
2290 struct ib_recv_wr *wr, *next;
2291 const struct ib_recv_wr *bad_wr;
2294 struct uverbs_req_iter iter;
2296 ret = uverbs_request_start(attrs, &iter, &cmd, sizeof(cmd));
2300 wr = ib_uverbs_unmarshall_recv(&iter, cmd.wr_count, cmd.wqe_size,
2305 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
2312 ret = qp->device->ops.post_recv(qp->real_qp, wr, &bad_wr);
2314 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
2315 UVERBS_LOOKUP_READ);
2317 for (next = wr; next; next = next->next) {
2324 ret2 = uverbs_response(attrs, &resp, sizeof(resp));
2337 static int ib_uverbs_post_srq_recv(struct uverbs_attr_bundle *attrs)
2339 struct ib_uverbs_post_srq_recv cmd;
2340 struct ib_uverbs_post_srq_recv_resp resp;
2341 struct ib_recv_wr *wr, *next;
2342 const struct ib_recv_wr *bad_wr;
2345 struct uverbs_req_iter iter;
2347 ret = uverbs_request_start(attrs, &iter, &cmd, sizeof(cmd));
2351 wr = ib_uverbs_unmarshall_recv(&iter, cmd.wr_count, cmd.wqe_size,
2356 srq = uobj_get_obj_read(srq, UVERBS_OBJECT_SRQ, cmd.srq_handle, attrs);
2363 ret = srq->device->ops.post_srq_recv(srq, wr, &bad_wr);
2365 rdma_lookup_put_uobject(&srq->uobject->uevent.uobject,
2366 UVERBS_LOOKUP_READ);
2369 for (next = wr; next; next = next->next) {
2375 ret2 = uverbs_response(attrs, &resp, sizeof(resp));
2389 static int ib_uverbs_create_ah(struct uverbs_attr_bundle *attrs)
2391 struct ib_uverbs_create_ah cmd;
2392 struct ib_uverbs_create_ah_resp resp;
2393 struct ib_uobject *uobj;
2396 struct rdma_ah_attr attr = {};
2398 struct ib_device *ib_dev;
2400 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
2404 uobj = uobj_alloc(UVERBS_OBJECT_AH, attrs, &ib_dev);
2406 return PTR_ERR(uobj);
2408 if (!rdma_is_port_valid(ib_dev, cmd.attr.port_num)) {
2413 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, attrs);
2419 attr.type = rdma_ah_find_type(ib_dev, cmd.attr.port_num);
2420 rdma_ah_set_make_grd(&attr, false);
2421 rdma_ah_set_dlid(&attr, cmd.attr.dlid);
2422 rdma_ah_set_sl(&attr, cmd.attr.sl);
2423 rdma_ah_set_path_bits(&attr, cmd.attr.src_path_bits);
2424 rdma_ah_set_static_rate(&attr, cmd.attr.static_rate);
2425 rdma_ah_set_port_num(&attr, cmd.attr.port_num);
2427 if (cmd.attr.is_global) {
2428 rdma_ah_set_grh(&attr, NULL, cmd.attr.grh.flow_label,
2429 cmd.attr.grh.sgid_index,
2430 cmd.attr.grh.hop_limit,
2431 cmd.attr.grh.traffic_class);
2432 rdma_ah_set_dgid_raw(&attr, cmd.attr.grh.dgid);
2434 rdma_ah_set_ah_flags(&attr, 0);
2437 ah = rdma_create_user_ah(pd, &attr, &attrs->driver_udata);
2444 uobj->user_handle = cmd.user_handle;
2446 uobj_put_obj_read(pd);
2447 uobj_finalize_uobj_create(uobj, attrs);
2449 resp.ah_handle = uobj->id;
2450 return uverbs_response(attrs, &resp, sizeof(resp));
2453 uobj_put_obj_read(pd);
2455 uobj_alloc_abort(uobj, attrs);
2459 static int ib_uverbs_destroy_ah(struct uverbs_attr_bundle *attrs)
2461 struct ib_uverbs_destroy_ah cmd;
2464 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
2468 return uobj_perform_destroy(UVERBS_OBJECT_AH, cmd.ah_handle, attrs);
2471 static int ib_uverbs_attach_mcast(struct uverbs_attr_bundle *attrs)
2473 struct ib_uverbs_attach_mcast cmd;
2475 struct ib_uqp_object *obj;
2476 struct ib_uverbs_mcast_entry *mcast;
2479 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
2483 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
2489 mutex_lock(&obj->mcast_lock);
2490 list_for_each_entry(mcast, &obj->mcast_list, list)
2491 if (cmd.mlid == mcast->lid &&
2492 !memcmp(cmd.gid, mcast->gid.raw, sizeof mcast->gid.raw)) {
2497 mcast = kmalloc(sizeof *mcast, GFP_KERNEL);
2503 mcast->lid = cmd.mlid;
2504 memcpy(mcast->gid.raw, cmd.gid, sizeof mcast->gid.raw);
2506 ret = ib_attach_mcast(qp, &mcast->gid, cmd.mlid);
2508 list_add_tail(&mcast->list, &obj->mcast_list);
2513 mutex_unlock(&obj->mcast_lock);
2514 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
2515 UVERBS_LOOKUP_READ);
2520 static int ib_uverbs_detach_mcast(struct uverbs_attr_bundle *attrs)
2522 struct ib_uverbs_detach_mcast cmd;
2523 struct ib_uqp_object *obj;
2525 struct ib_uverbs_mcast_entry *mcast;
2529 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
2533 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
2538 mutex_lock(&obj->mcast_lock);
2540 list_for_each_entry(mcast, &obj->mcast_list, list)
2541 if (cmd.mlid == mcast->lid &&
2542 !memcmp(cmd.gid, mcast->gid.raw, sizeof mcast->gid.raw)) {
2543 list_del(&mcast->list);
2554 ret = ib_detach_mcast(qp, (union ib_gid *)cmd.gid, cmd.mlid);
2557 mutex_unlock(&obj->mcast_lock);
2558 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
2559 UVERBS_LOOKUP_READ);
2563 struct ib_uflow_resources *flow_resources_alloc(size_t num_specs)
2565 struct ib_uflow_resources *resources;
2567 resources = kzalloc(sizeof(*resources), GFP_KERNEL);
2575 resources->counters =
2576 kcalloc(num_specs, sizeof(*resources->counters), GFP_KERNEL);
2577 resources->collection =
2578 kcalloc(num_specs, sizeof(*resources->collection), GFP_KERNEL);
2580 if (!resources->counters || !resources->collection)
2584 resources->max = num_specs;
2588 kfree(resources->counters);
2593 EXPORT_SYMBOL(flow_resources_alloc);
2595 void ib_uverbs_flow_resources_free(struct ib_uflow_resources *uflow_res)
2602 for (i = 0; i < uflow_res->collection_num; i++)
2603 atomic_dec(&uflow_res->collection[i]->usecnt);
2605 for (i = 0; i < uflow_res->counters_num; i++)
2606 atomic_dec(&uflow_res->counters[i]->usecnt);
2608 kfree(uflow_res->collection);
2609 kfree(uflow_res->counters);
2612 EXPORT_SYMBOL(ib_uverbs_flow_resources_free);
2614 void flow_resources_add(struct ib_uflow_resources *uflow_res,
2615 enum ib_flow_spec_type type,
2618 WARN_ON(uflow_res->num >= uflow_res->max);
2621 case IB_FLOW_SPEC_ACTION_HANDLE:
2622 atomic_inc(&((struct ib_flow_action *)ibobj)->usecnt);
2623 uflow_res->collection[uflow_res->collection_num++] =
2624 (struct ib_flow_action *)ibobj;
2626 case IB_FLOW_SPEC_ACTION_COUNT:
2627 atomic_inc(&((struct ib_counters *)ibobj)->usecnt);
2628 uflow_res->counters[uflow_res->counters_num++] =
2629 (struct ib_counters *)ibobj;
2637 EXPORT_SYMBOL(flow_resources_add);
2639 static int kern_spec_to_ib_spec_action(struct uverbs_attr_bundle *attrs,
2640 struct ib_uverbs_flow_spec *kern_spec,
2641 union ib_flow_spec *ib_spec,
2642 struct ib_uflow_resources *uflow_res)
2644 ib_spec->type = kern_spec->type;
2645 switch (ib_spec->type) {
2646 case IB_FLOW_SPEC_ACTION_TAG:
2647 if (kern_spec->flow_tag.size !=
2648 sizeof(struct ib_uverbs_flow_spec_action_tag))
2651 ib_spec->flow_tag.size = sizeof(struct ib_flow_spec_action_tag);
2652 ib_spec->flow_tag.tag_id = kern_spec->flow_tag.tag_id;
2654 case IB_FLOW_SPEC_ACTION_DROP:
2655 if (kern_spec->drop.size !=
2656 sizeof(struct ib_uverbs_flow_spec_action_drop))
2659 ib_spec->drop.size = sizeof(struct ib_flow_spec_action_drop);
2661 case IB_FLOW_SPEC_ACTION_HANDLE:
2662 if (kern_spec->action.size !=
2663 sizeof(struct ib_uverbs_flow_spec_action_handle))
2665 ib_spec->action.act = uobj_get_obj_read(flow_action,
2666 UVERBS_OBJECT_FLOW_ACTION,
2667 kern_spec->action.handle,
2669 if (!ib_spec->action.act)
2671 ib_spec->action.size =
2672 sizeof(struct ib_flow_spec_action_handle);
2673 flow_resources_add(uflow_res,
2674 IB_FLOW_SPEC_ACTION_HANDLE,
2675 ib_spec->action.act);
2676 uobj_put_obj_read(ib_spec->action.act);
2678 case IB_FLOW_SPEC_ACTION_COUNT:
2679 if (kern_spec->flow_count.size !=
2680 sizeof(struct ib_uverbs_flow_spec_action_count))
2682 ib_spec->flow_count.counters =
2683 uobj_get_obj_read(counters,
2684 UVERBS_OBJECT_COUNTERS,
2685 kern_spec->flow_count.handle,
2687 if (!ib_spec->flow_count.counters)
2689 ib_spec->flow_count.size =
2690 sizeof(struct ib_flow_spec_action_count);
2691 flow_resources_add(uflow_res,
2692 IB_FLOW_SPEC_ACTION_COUNT,
2693 ib_spec->flow_count.counters);
2694 uobj_put_obj_read(ib_spec->flow_count.counters);
2702 static ssize_t spec_filter_size(const void *kern_spec_filter, u16 kern_filter_size,
2703 u16 ib_real_filter_sz)
2706 * User space filter structures must be 64 bit aligned, otherwise this
2707 * may pass, but we won't handle additional new attributes.
2710 if (kern_filter_size > ib_real_filter_sz) {
2711 if (memchr_inv(kern_spec_filter +
2712 ib_real_filter_sz, 0,
2713 kern_filter_size - ib_real_filter_sz))
2715 return ib_real_filter_sz;
2717 return kern_filter_size;
2720 int ib_uverbs_kern_spec_to_ib_spec_filter(enum ib_flow_spec_type type,
2721 const void *kern_spec_mask,
2722 const void *kern_spec_val,
2723 size_t kern_filter_sz,
2724 union ib_flow_spec *ib_spec)
2726 ssize_t actual_filter_sz;
2727 ssize_t ib_filter_sz;
2729 /* User flow spec size must be aligned to 4 bytes */
2730 if (kern_filter_sz != ALIGN(kern_filter_sz, 4))
2733 ib_spec->type = type;
2735 if (ib_spec->type == (IB_FLOW_SPEC_INNER | IB_FLOW_SPEC_VXLAN_TUNNEL))
2738 switch (ib_spec->type & ~IB_FLOW_SPEC_INNER) {
2739 case IB_FLOW_SPEC_ETH:
2740 ib_filter_sz = sizeof(struct ib_flow_eth_filter);
2741 actual_filter_sz = spec_filter_size(kern_spec_mask,
2744 if (actual_filter_sz <= 0)
2746 ib_spec->size = sizeof(struct ib_flow_spec_eth);
2747 memcpy(&ib_spec->eth.val, kern_spec_val, actual_filter_sz);
2748 memcpy(&ib_spec->eth.mask, kern_spec_mask, actual_filter_sz);
2750 case IB_FLOW_SPEC_IPV4:
2751 ib_filter_sz = sizeof(struct ib_flow_ipv4_filter);
2752 actual_filter_sz = spec_filter_size(kern_spec_mask,
2755 if (actual_filter_sz <= 0)
2757 ib_spec->size = sizeof(struct ib_flow_spec_ipv4);
2758 memcpy(&ib_spec->ipv4.val, kern_spec_val, actual_filter_sz);
2759 memcpy(&ib_spec->ipv4.mask, kern_spec_mask, actual_filter_sz);
2761 case IB_FLOW_SPEC_IPV6:
2762 ib_filter_sz = sizeof(struct ib_flow_ipv6_filter);
2763 actual_filter_sz = spec_filter_size(kern_spec_mask,
2766 if (actual_filter_sz <= 0)
2768 ib_spec->size = sizeof(struct ib_flow_spec_ipv6);
2769 memcpy(&ib_spec->ipv6.val, kern_spec_val, actual_filter_sz);
2770 memcpy(&ib_spec->ipv6.mask, kern_spec_mask, actual_filter_sz);
2772 if ((ntohl(ib_spec->ipv6.mask.flow_label)) >= BIT(20) ||
2773 (ntohl(ib_spec->ipv6.val.flow_label)) >= BIT(20))
2776 case IB_FLOW_SPEC_TCP:
2777 case IB_FLOW_SPEC_UDP:
2778 ib_filter_sz = sizeof(struct ib_flow_tcp_udp_filter);
2779 actual_filter_sz = spec_filter_size(kern_spec_mask,
2782 if (actual_filter_sz <= 0)
2784 ib_spec->size = sizeof(struct ib_flow_spec_tcp_udp);
2785 memcpy(&ib_spec->tcp_udp.val, kern_spec_val, actual_filter_sz);
2786 memcpy(&ib_spec->tcp_udp.mask, kern_spec_mask, actual_filter_sz);
2788 case IB_FLOW_SPEC_VXLAN_TUNNEL:
2789 ib_filter_sz = sizeof(struct ib_flow_tunnel_filter);
2790 actual_filter_sz = spec_filter_size(kern_spec_mask,
2793 if (actual_filter_sz <= 0)
2795 ib_spec->tunnel.size = sizeof(struct ib_flow_spec_tunnel);
2796 memcpy(&ib_spec->tunnel.val, kern_spec_val, actual_filter_sz);
2797 memcpy(&ib_spec->tunnel.mask, kern_spec_mask, actual_filter_sz);
2799 if ((ntohl(ib_spec->tunnel.mask.tunnel_id)) >= BIT(24) ||
2800 (ntohl(ib_spec->tunnel.val.tunnel_id)) >= BIT(24))
2803 case IB_FLOW_SPEC_ESP:
2804 ib_filter_sz = sizeof(struct ib_flow_esp_filter);
2805 actual_filter_sz = spec_filter_size(kern_spec_mask,
2808 if (actual_filter_sz <= 0)
2810 ib_spec->esp.size = sizeof(struct ib_flow_spec_esp);
2811 memcpy(&ib_spec->esp.val, kern_spec_val, actual_filter_sz);
2812 memcpy(&ib_spec->esp.mask, kern_spec_mask, actual_filter_sz);
2814 case IB_FLOW_SPEC_GRE:
2815 ib_filter_sz = sizeof(struct ib_flow_gre_filter);
2816 actual_filter_sz = spec_filter_size(kern_spec_mask,
2819 if (actual_filter_sz <= 0)
2821 ib_spec->gre.size = sizeof(struct ib_flow_spec_gre);
2822 memcpy(&ib_spec->gre.val, kern_spec_val, actual_filter_sz);
2823 memcpy(&ib_spec->gre.mask, kern_spec_mask, actual_filter_sz);
2825 case IB_FLOW_SPEC_MPLS:
2826 ib_filter_sz = sizeof(struct ib_flow_mpls_filter);
2827 actual_filter_sz = spec_filter_size(kern_spec_mask,
2830 if (actual_filter_sz <= 0)
2832 ib_spec->mpls.size = sizeof(struct ib_flow_spec_mpls);
2833 memcpy(&ib_spec->mpls.val, kern_spec_val, actual_filter_sz);
2834 memcpy(&ib_spec->mpls.mask, kern_spec_mask, actual_filter_sz);
2842 static int kern_spec_to_ib_spec_filter(struct ib_uverbs_flow_spec *kern_spec,
2843 union ib_flow_spec *ib_spec)
2845 size_t kern_filter_sz;
2846 void *kern_spec_mask;
2847 void *kern_spec_val;
2849 if (check_sub_overflow((size_t)kern_spec->hdr.size,
2850 sizeof(struct ib_uverbs_flow_spec_hdr),
2854 kern_filter_sz /= 2;
2856 kern_spec_val = (void *)kern_spec +
2857 sizeof(struct ib_uverbs_flow_spec_hdr);
2858 kern_spec_mask = kern_spec_val + kern_filter_sz;
2860 return ib_uverbs_kern_spec_to_ib_spec_filter(kern_spec->type,
2863 kern_filter_sz, ib_spec);
2866 static int kern_spec_to_ib_spec(struct uverbs_attr_bundle *attrs,
2867 struct ib_uverbs_flow_spec *kern_spec,
2868 union ib_flow_spec *ib_spec,
2869 struct ib_uflow_resources *uflow_res)
2871 if (kern_spec->reserved)
2874 if (kern_spec->type >= IB_FLOW_SPEC_ACTION_TAG)
2875 return kern_spec_to_ib_spec_action(attrs, kern_spec, ib_spec,
2878 return kern_spec_to_ib_spec_filter(kern_spec, ib_spec);
2881 static int ib_uverbs_ex_create_wq(struct uverbs_attr_bundle *attrs)
2883 struct ib_uverbs_ex_create_wq cmd;
2884 struct ib_uverbs_ex_create_wq_resp resp = {};
2885 struct ib_uwq_object *obj;
2890 struct ib_wq_init_attr wq_init_attr = {};
2891 struct ib_device *ib_dev;
2893 err = uverbs_request(attrs, &cmd, sizeof(cmd));
2900 obj = (struct ib_uwq_object *)uobj_alloc(UVERBS_OBJECT_WQ, attrs,
2903 return PTR_ERR(obj);
2905 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, attrs);
2911 cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs);
2917 wq_init_attr.cq = cq;
2918 wq_init_attr.max_sge = cmd.max_sge;
2919 wq_init_attr.max_wr = cmd.max_wr;
2920 wq_init_attr.wq_type = cmd.wq_type;
2921 wq_init_attr.event_handler = ib_uverbs_wq_event_handler;
2922 wq_init_attr.create_flags = cmd.create_flags;
2923 INIT_LIST_HEAD(&obj->uevent.event_list);
2924 obj->uevent.uobject.user_handle = cmd.user_handle;
2926 wq = pd->device->ops.create_wq(pd, &wq_init_attr, &attrs->driver_udata);
2933 obj->uevent.uobject.object = wq;
2934 wq->wq_type = wq_init_attr.wq_type;
2937 wq->device = pd->device;
2938 atomic_set(&wq->usecnt, 0);
2939 atomic_inc(&pd->usecnt);
2940 atomic_inc(&cq->usecnt);
2941 obj->uevent.event_file = READ_ONCE(attrs->ufile->default_async_file);
2942 if (obj->uevent.event_file)
2943 uverbs_uobject_get(&obj->uevent.event_file->uobj);
2945 uobj_put_obj_read(pd);
2946 rdma_lookup_put_uobject(&cq->uobject->uevent.uobject,
2947 UVERBS_LOOKUP_READ);
2948 uobj_finalize_uobj_create(&obj->uevent.uobject, attrs);
2950 resp.wq_handle = obj->uevent.uobject.id;
2951 resp.max_sge = wq_init_attr.max_sge;
2952 resp.max_wr = wq_init_attr.max_wr;
2953 resp.wqn = wq->wq_num;
2954 resp.response_length = uverbs_response_length(attrs, sizeof(resp));
2955 return uverbs_response(attrs, &resp, sizeof(resp));
2958 rdma_lookup_put_uobject(&cq->uobject->uevent.uobject,
2959 UVERBS_LOOKUP_READ);
2961 uobj_put_obj_read(pd);
2963 uobj_alloc_abort(&obj->uevent.uobject, attrs);
2968 static int ib_uverbs_ex_destroy_wq(struct uverbs_attr_bundle *attrs)
2970 struct ib_uverbs_ex_destroy_wq cmd;
2971 struct ib_uverbs_ex_destroy_wq_resp resp = {};
2972 struct ib_uobject *uobj;
2973 struct ib_uwq_object *obj;
2976 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
2983 resp.response_length = uverbs_response_length(attrs, sizeof(resp));
2984 uobj = uobj_get_destroy(UVERBS_OBJECT_WQ, cmd.wq_handle, attrs);
2986 return PTR_ERR(uobj);
2988 obj = container_of(uobj, struct ib_uwq_object, uevent.uobject);
2989 resp.events_reported = obj->uevent.events_reported;
2991 uobj_put_destroy(uobj);
2993 return uverbs_response(attrs, &resp, sizeof(resp));
2996 static int ib_uverbs_ex_modify_wq(struct uverbs_attr_bundle *attrs)
2998 struct ib_uverbs_ex_modify_wq cmd;
3000 struct ib_wq_attr wq_attr = {};
3003 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3010 if (cmd.attr_mask > (IB_WQ_STATE | IB_WQ_CUR_STATE | IB_WQ_FLAGS))
3013 wq = uobj_get_obj_read(wq, UVERBS_OBJECT_WQ, cmd.wq_handle, attrs);
3017 if (cmd.attr_mask & IB_WQ_FLAGS) {
3018 wq_attr.flags = cmd.flags;
3019 wq_attr.flags_mask = cmd.flags_mask;
3022 if (cmd.attr_mask & IB_WQ_CUR_STATE) {
3023 if (cmd.curr_wq_state > IB_WQS_ERR)
3026 wq_attr.curr_wq_state = cmd.curr_wq_state;
3028 wq_attr.curr_wq_state = wq->state;
3031 if (cmd.attr_mask & IB_WQ_STATE) {
3032 if (cmd.wq_state > IB_WQS_ERR)
3035 wq_attr.wq_state = cmd.wq_state;
3037 wq_attr.wq_state = wq_attr.curr_wq_state;
3040 ret = wq->device->ops.modify_wq(wq, &wq_attr, cmd.attr_mask,
3041 &attrs->driver_udata);
3042 rdma_lookup_put_uobject(&wq->uobject->uevent.uobject,
3043 UVERBS_LOOKUP_READ);
3047 static int ib_uverbs_ex_create_rwq_ind_table(struct uverbs_attr_bundle *attrs)
3049 struct ib_uverbs_ex_create_rwq_ind_table cmd;
3050 struct ib_uverbs_ex_create_rwq_ind_table_resp resp = {};
3051 struct ib_uobject *uobj;
3053 struct ib_rwq_ind_table_init_attr init_attr = {};
3054 struct ib_rwq_ind_table *rwq_ind_tbl;
3055 struct ib_wq **wqs = NULL;
3056 u32 *wqs_handles = NULL;
3057 struct ib_wq *wq = NULL;
3058 int i, num_read_wqs;
3060 struct uverbs_req_iter iter;
3061 struct ib_device *ib_dev;
3063 err = uverbs_request_start(attrs, &iter, &cmd, sizeof(cmd));
3070 if (cmd.log_ind_tbl_size > IB_USER_VERBS_MAX_LOG_IND_TBL_SIZE)
3073 num_wq_handles = 1 << cmd.log_ind_tbl_size;
3074 wqs_handles = kcalloc(num_wq_handles, sizeof(*wqs_handles),
3079 err = uverbs_request_next(&iter, wqs_handles,
3080 num_wq_handles * sizeof(__u32));
3084 err = uverbs_request_finish(&iter);
3088 wqs = kcalloc(num_wq_handles, sizeof(*wqs), GFP_KERNEL);
3094 for (num_read_wqs = 0; num_read_wqs < num_wq_handles;
3096 wq = uobj_get_obj_read(wq, UVERBS_OBJECT_WQ,
3097 wqs_handles[num_read_wqs], attrs);
3103 wqs[num_read_wqs] = wq;
3104 atomic_inc(&wqs[num_read_wqs]->usecnt);
3107 uobj = uobj_alloc(UVERBS_OBJECT_RWQ_IND_TBL, attrs, &ib_dev);
3109 err = PTR_ERR(uobj);
3113 rwq_ind_tbl = rdma_zalloc_drv_obj(ib_dev, ib_rwq_ind_table);
3119 init_attr.log_ind_tbl_size = cmd.log_ind_tbl_size;
3120 init_attr.ind_tbl = wqs;
3122 rwq_ind_tbl->ind_tbl = wqs;
3123 rwq_ind_tbl->log_ind_tbl_size = init_attr.log_ind_tbl_size;
3124 rwq_ind_tbl->uobject = uobj;
3125 uobj->object = rwq_ind_tbl;
3126 rwq_ind_tbl->device = ib_dev;
3127 atomic_set(&rwq_ind_tbl->usecnt, 0);
3129 err = ib_dev->ops.create_rwq_ind_table(rwq_ind_tbl, &init_attr,
3130 &attrs->driver_udata);
3134 for (i = 0; i < num_wq_handles; i++)
3135 rdma_lookup_put_uobject(&wqs[i]->uobject->uevent.uobject,
3136 UVERBS_LOOKUP_READ);
3138 uobj_finalize_uobj_create(uobj, attrs);
3140 resp.ind_tbl_handle = uobj->id;
3141 resp.ind_tbl_num = rwq_ind_tbl->ind_tbl_num;
3142 resp.response_length = uverbs_response_length(attrs, sizeof(resp));
3143 return uverbs_response(attrs, &resp, sizeof(resp));
3148 uobj_alloc_abort(uobj, attrs);
3150 for (i = 0; i < num_read_wqs; i++) {
3151 rdma_lookup_put_uobject(&wqs[i]->uobject->uevent.uobject,
3152 UVERBS_LOOKUP_READ);
3153 atomic_dec(&wqs[i]->usecnt);
3161 static int ib_uverbs_ex_destroy_rwq_ind_table(struct uverbs_attr_bundle *attrs)
3163 struct ib_uverbs_ex_destroy_rwq_ind_table cmd;
3166 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3173 return uobj_perform_destroy(UVERBS_OBJECT_RWQ_IND_TBL,
3174 cmd.ind_tbl_handle, attrs);
3177 static int ib_uverbs_ex_create_flow(struct uverbs_attr_bundle *attrs)
3179 struct ib_uverbs_create_flow cmd;
3180 struct ib_uverbs_create_flow_resp resp = {};
3181 struct ib_uobject *uobj;
3182 struct ib_flow *flow_id;
3183 struct ib_uverbs_flow_attr *kern_flow_attr;
3184 struct ib_flow_attr *flow_attr;
3186 struct ib_uflow_resources *uflow_res;
3187 struct ib_uverbs_flow_spec_hdr *kern_spec;
3188 struct uverbs_req_iter iter;
3192 struct ib_device *ib_dev;
3194 err = uverbs_request_start(attrs, &iter, &cmd, sizeof(cmd));
3201 if (!capable(CAP_NET_RAW))
3204 if (cmd.flow_attr.flags >= IB_FLOW_ATTR_FLAGS_RESERVED)
3207 if ((cmd.flow_attr.flags & IB_FLOW_ATTR_FLAGS_DONT_TRAP) &&
3208 ((cmd.flow_attr.type == IB_FLOW_ATTR_ALL_DEFAULT) ||
3209 (cmd.flow_attr.type == IB_FLOW_ATTR_MC_DEFAULT)))
3212 if (cmd.flow_attr.num_of_specs > IB_FLOW_SPEC_SUPPORT_LAYERS)
3215 if (cmd.flow_attr.size >
3216 (cmd.flow_attr.num_of_specs * sizeof(struct ib_uverbs_flow_spec)))
3219 if (cmd.flow_attr.reserved[0] ||
3220 cmd.flow_attr.reserved[1])
3223 if (cmd.flow_attr.num_of_specs) {
3224 kern_flow_attr = kmalloc(sizeof(*kern_flow_attr) + cmd.flow_attr.size,
3226 if (!kern_flow_attr)
3229 *kern_flow_attr = cmd.flow_attr;
3230 err = uverbs_request_next(&iter, &kern_flow_attr->flow_specs,
3231 cmd.flow_attr.size);
3235 kern_flow_attr = &cmd.flow_attr;
3238 err = uverbs_request_finish(&iter);
3242 uobj = uobj_alloc(UVERBS_OBJECT_FLOW, attrs, &ib_dev);
3244 err = PTR_ERR(uobj);
3248 if (!rdma_is_port_valid(uobj->context->device, cmd.flow_attr.port)) {
3253 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
3259 if (qp->qp_type != IB_QPT_UD && qp->qp_type != IB_QPT_RAW_PACKET) {
3264 flow_attr = kzalloc(struct_size(flow_attr, flows,
3265 cmd.flow_attr.num_of_specs), GFP_KERNEL);
3270 uflow_res = flow_resources_alloc(cmd.flow_attr.num_of_specs);
3273 goto err_free_flow_attr;
3276 flow_attr->type = kern_flow_attr->type;
3277 flow_attr->priority = kern_flow_attr->priority;
3278 flow_attr->num_of_specs = kern_flow_attr->num_of_specs;
3279 flow_attr->port = kern_flow_attr->port;
3280 flow_attr->flags = kern_flow_attr->flags;
3281 flow_attr->size = sizeof(*flow_attr);
3283 kern_spec = kern_flow_attr->flow_specs;
3284 ib_spec = flow_attr + 1;
3285 for (i = 0; i < flow_attr->num_of_specs &&
3286 cmd.flow_attr.size >= sizeof(*kern_spec) &&
3287 cmd.flow_attr.size >= kern_spec->size;
3289 err = kern_spec_to_ib_spec(
3290 attrs, (struct ib_uverbs_flow_spec *)kern_spec,
3291 ib_spec, uflow_res);
3296 ((union ib_flow_spec *) ib_spec)->size;
3297 cmd.flow_attr.size -= kern_spec->size;
3298 kern_spec = ((void *)kern_spec) + kern_spec->size;
3299 ib_spec += ((union ib_flow_spec *) ib_spec)->size;
3301 if (cmd.flow_attr.size || (i != flow_attr->num_of_specs)) {
3302 pr_warn("create flow failed, flow %d: %u bytes left from uverb cmd\n",
3303 i, cmd.flow_attr.size);
3308 flow_id = qp->device->ops.create_flow(qp, flow_attr,
3309 &attrs->driver_udata);
3311 if (IS_ERR(flow_id)) {
3312 err = PTR_ERR(flow_id);
3316 ib_set_flow(uobj, flow_id, qp, qp->device, uflow_res);
3318 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
3319 UVERBS_LOOKUP_READ);
3322 if (cmd.flow_attr.num_of_specs)
3323 kfree(kern_flow_attr);
3324 uobj_finalize_uobj_create(uobj, attrs);
3326 resp.flow_handle = uobj->id;
3327 return uverbs_response(attrs, &resp, sizeof(resp));
3330 ib_uverbs_flow_resources_free(uflow_res);
3334 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
3335 UVERBS_LOOKUP_READ);
3337 uobj_alloc_abort(uobj, attrs);
3339 if (cmd.flow_attr.num_of_specs)
3340 kfree(kern_flow_attr);
3344 static int ib_uverbs_ex_destroy_flow(struct uverbs_attr_bundle *attrs)
3346 struct ib_uverbs_destroy_flow cmd;
3349 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3356 return uobj_perform_destroy(UVERBS_OBJECT_FLOW, cmd.flow_handle, attrs);
3359 static int __uverbs_create_xsrq(struct uverbs_attr_bundle *attrs,
3360 struct ib_uverbs_create_xsrq *cmd,
3361 struct ib_udata *udata)
3363 struct ib_uverbs_create_srq_resp resp = {};
3364 struct ib_usrq_object *obj;
3367 struct ib_srq_init_attr attr;
3369 struct ib_uobject *xrcd_uobj;
3370 struct ib_device *ib_dev;
3372 obj = (struct ib_usrq_object *)uobj_alloc(UVERBS_OBJECT_SRQ, attrs,
3375 return PTR_ERR(obj);
3377 if (cmd->srq_type == IB_SRQT_TM)
3378 attr.ext.tag_matching.max_num_tags = cmd->max_num_tags;
3380 if (cmd->srq_type == IB_SRQT_XRC) {
3381 xrcd_uobj = uobj_get_read(UVERBS_OBJECT_XRCD, cmd->xrcd_handle,
3383 if (IS_ERR(xrcd_uobj)) {
3388 attr.ext.xrc.xrcd = (struct ib_xrcd *)xrcd_uobj->object;
3389 if (!attr.ext.xrc.xrcd) {
3394 obj->uxrcd = container_of(xrcd_uobj, struct ib_uxrcd_object, uobject);
3395 atomic_inc(&obj->uxrcd->refcnt);
3398 if (ib_srq_has_cq(cmd->srq_type)) {
3399 attr.ext.cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ,
3400 cmd->cq_handle, attrs);
3407 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd->pd_handle, attrs);
3413 attr.event_handler = ib_uverbs_srq_event_handler;
3414 attr.srq_type = cmd->srq_type;
3415 attr.attr.max_wr = cmd->max_wr;
3416 attr.attr.max_sge = cmd->max_sge;
3417 attr.attr.srq_limit = cmd->srq_limit;
3419 INIT_LIST_HEAD(&obj->uevent.event_list);
3420 obj->uevent.uobject.user_handle = cmd->user_handle;
3422 srq = ib_create_srq_user(pd, &attr, obj, udata);
3428 obj->uevent.uobject.object = srq;
3429 obj->uevent.uobject.user_handle = cmd->user_handle;
3430 obj->uevent.event_file = READ_ONCE(attrs->ufile->default_async_file);
3431 if (obj->uevent.event_file)
3432 uverbs_uobject_get(&obj->uevent.event_file->uobj);
3434 if (cmd->srq_type == IB_SRQT_XRC)
3435 resp.srqn = srq->ext.xrc.srq_num;
3437 if (cmd->srq_type == IB_SRQT_XRC)
3438 uobj_put_read(xrcd_uobj);
3440 if (ib_srq_has_cq(cmd->srq_type))
3441 rdma_lookup_put_uobject(&attr.ext.cq->uobject->uevent.uobject,
3442 UVERBS_LOOKUP_READ);
3444 uobj_put_obj_read(pd);
3445 uobj_finalize_uobj_create(&obj->uevent.uobject, attrs);
3447 resp.srq_handle = obj->uevent.uobject.id;
3448 resp.max_wr = attr.attr.max_wr;
3449 resp.max_sge = attr.attr.max_sge;
3450 return uverbs_response(attrs, &resp, sizeof(resp));
3453 uobj_put_obj_read(pd);
3455 if (ib_srq_has_cq(cmd->srq_type))
3456 rdma_lookup_put_uobject(&attr.ext.cq->uobject->uevent.uobject,
3457 UVERBS_LOOKUP_READ);
3460 if (cmd->srq_type == IB_SRQT_XRC) {
3461 atomic_dec(&obj->uxrcd->refcnt);
3462 uobj_put_read(xrcd_uobj);
3466 uobj_alloc_abort(&obj->uevent.uobject, attrs);
3470 static int ib_uverbs_create_srq(struct uverbs_attr_bundle *attrs)
3472 struct ib_uverbs_create_srq cmd;
3473 struct ib_uverbs_create_xsrq xcmd;
3476 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3480 memset(&xcmd, 0, sizeof(xcmd));
3481 xcmd.response = cmd.response;
3482 xcmd.user_handle = cmd.user_handle;
3483 xcmd.srq_type = IB_SRQT_BASIC;
3484 xcmd.pd_handle = cmd.pd_handle;
3485 xcmd.max_wr = cmd.max_wr;
3486 xcmd.max_sge = cmd.max_sge;
3487 xcmd.srq_limit = cmd.srq_limit;
3489 return __uverbs_create_xsrq(attrs, &xcmd, &attrs->driver_udata);
3492 static int ib_uverbs_create_xsrq(struct uverbs_attr_bundle *attrs)
3494 struct ib_uverbs_create_xsrq cmd;
3497 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3501 return __uverbs_create_xsrq(attrs, &cmd, &attrs->driver_udata);
3504 static int ib_uverbs_modify_srq(struct uverbs_attr_bundle *attrs)
3506 struct ib_uverbs_modify_srq cmd;
3508 struct ib_srq_attr attr;
3511 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3515 srq = uobj_get_obj_read(srq, UVERBS_OBJECT_SRQ, cmd.srq_handle, attrs);
3519 attr.max_wr = cmd.max_wr;
3520 attr.srq_limit = cmd.srq_limit;
3522 ret = srq->device->ops.modify_srq(srq, &attr, cmd.attr_mask,
3523 &attrs->driver_udata);
3525 rdma_lookup_put_uobject(&srq->uobject->uevent.uobject,
3526 UVERBS_LOOKUP_READ);
3531 static int ib_uverbs_query_srq(struct uverbs_attr_bundle *attrs)
3533 struct ib_uverbs_query_srq cmd;
3534 struct ib_uverbs_query_srq_resp resp;
3535 struct ib_srq_attr attr;
3539 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3543 srq = uobj_get_obj_read(srq, UVERBS_OBJECT_SRQ, cmd.srq_handle, attrs);
3547 ret = ib_query_srq(srq, &attr);
3549 rdma_lookup_put_uobject(&srq->uobject->uevent.uobject,
3550 UVERBS_LOOKUP_READ);
3555 memset(&resp, 0, sizeof resp);
3557 resp.max_wr = attr.max_wr;
3558 resp.max_sge = attr.max_sge;
3559 resp.srq_limit = attr.srq_limit;
3561 return uverbs_response(attrs, &resp, sizeof(resp));
3564 static int ib_uverbs_destroy_srq(struct uverbs_attr_bundle *attrs)
3566 struct ib_uverbs_destroy_srq cmd;
3567 struct ib_uverbs_destroy_srq_resp resp;
3568 struct ib_uobject *uobj;
3569 struct ib_uevent_object *obj;
3572 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3576 uobj = uobj_get_destroy(UVERBS_OBJECT_SRQ, cmd.srq_handle, attrs);
3578 return PTR_ERR(uobj);
3580 obj = container_of(uobj, struct ib_uevent_object, uobject);
3581 memset(&resp, 0, sizeof(resp));
3582 resp.events_reported = obj->events_reported;
3584 uobj_put_destroy(uobj);
3586 return uverbs_response(attrs, &resp, sizeof(resp));
3589 static int ib_uverbs_ex_query_device(struct uverbs_attr_bundle *attrs)
3591 struct ib_uverbs_ex_query_device_resp resp = {};
3592 struct ib_uverbs_ex_query_device cmd;
3593 struct ib_device_attr attr = {0};
3594 struct ib_ucontext *ucontext;
3595 struct ib_device *ib_dev;
3598 ucontext = ib_uverbs_get_ucontext(attrs);
3599 if (IS_ERR(ucontext))
3600 return PTR_ERR(ucontext);
3601 ib_dev = ucontext->device;
3603 err = uverbs_request(attrs, &cmd, sizeof(cmd));
3613 err = ib_dev->ops.query_device(ib_dev, &attr, &attrs->driver_udata);
3617 copy_query_dev_fields(ucontext, &resp.base, &attr);
3619 resp.odp_caps.general_caps = attr.odp_caps.general_caps;
3620 resp.odp_caps.per_transport_caps.rc_odp_caps =
3621 attr.odp_caps.per_transport_caps.rc_odp_caps;
3622 resp.odp_caps.per_transport_caps.uc_odp_caps =
3623 attr.odp_caps.per_transport_caps.uc_odp_caps;
3624 resp.odp_caps.per_transport_caps.ud_odp_caps =
3625 attr.odp_caps.per_transport_caps.ud_odp_caps;
3626 resp.xrc_odp_caps = attr.odp_caps.per_transport_caps.xrc_odp_caps;
3628 resp.timestamp_mask = attr.timestamp_mask;
3629 resp.hca_core_clock = attr.hca_core_clock;
3630 resp.device_cap_flags_ex = attr.device_cap_flags;
3631 resp.rss_caps.supported_qpts = attr.rss_caps.supported_qpts;
3632 resp.rss_caps.max_rwq_indirection_tables =
3633 attr.rss_caps.max_rwq_indirection_tables;
3634 resp.rss_caps.max_rwq_indirection_table_size =
3635 attr.rss_caps.max_rwq_indirection_table_size;
3636 resp.max_wq_type_rq = attr.max_wq_type_rq;
3637 resp.raw_packet_caps = attr.raw_packet_caps;
3638 resp.tm_caps.max_rndv_hdr_size = attr.tm_caps.max_rndv_hdr_size;
3639 resp.tm_caps.max_num_tags = attr.tm_caps.max_num_tags;
3640 resp.tm_caps.max_ops = attr.tm_caps.max_ops;
3641 resp.tm_caps.max_sge = attr.tm_caps.max_sge;
3642 resp.tm_caps.flags = attr.tm_caps.flags;
3643 resp.cq_moderation_caps.max_cq_moderation_count =
3644 attr.cq_caps.max_cq_moderation_count;
3645 resp.cq_moderation_caps.max_cq_moderation_period =
3646 attr.cq_caps.max_cq_moderation_period;
3647 resp.max_dm_size = attr.max_dm_size;
3648 resp.response_length = uverbs_response_length(attrs, sizeof(resp));
3650 return uverbs_response(attrs, &resp, sizeof(resp));
3653 static int ib_uverbs_ex_modify_cq(struct uverbs_attr_bundle *attrs)
3655 struct ib_uverbs_ex_modify_cq cmd;
3659 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3663 if (!cmd.attr_mask || cmd.reserved)
3666 if (cmd.attr_mask > IB_CQ_MODERATE)
3669 cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs);
3673 ret = rdma_set_cq_moderation(cq, cmd.attr.cq_count, cmd.attr.cq_period);
3675 rdma_lookup_put_uobject(&cq->uobject->uevent.uobject,
3676 UVERBS_LOOKUP_READ);
3681 * Describe the input structs for write(). Some write methods have an input
3682 * only struct, most have an input and output. If the struct has an output then
3683 * the 'response' u64 must be the first field in the request structure.
3685 * If udata is present then both the request and response structs have a
3686 * trailing driver_data flex array. In this case the size of the base struct
3687 * cannot be changed.
3689 #define UAPI_DEF_WRITE_IO(req, resp) \
3690 .write.has_resp = 1 + \
3691 BUILD_BUG_ON_ZERO(offsetof(req, response) != 0) + \
3692 BUILD_BUG_ON_ZERO(sizeof_field(req, response) != \
3694 .write.req_size = sizeof(req), .write.resp_size = sizeof(resp)
3696 #define UAPI_DEF_WRITE_I(req) .write.req_size = sizeof(req)
3698 #define UAPI_DEF_WRITE_UDATA_IO(req, resp) \
3699 UAPI_DEF_WRITE_IO(req, resp), \
3700 .write.has_udata = \
3702 BUILD_BUG_ON_ZERO(offsetof(req, driver_data) != \
3704 BUILD_BUG_ON_ZERO(offsetof(resp, driver_data) != \
3707 #define UAPI_DEF_WRITE_UDATA_I(req) \
3708 UAPI_DEF_WRITE_I(req), \
3709 .write.has_udata = \
3710 1 + BUILD_BUG_ON_ZERO(offsetof(req, driver_data) != \
3714 * The _EX versions are for use with WRITE_EX and allow the last struct member
3715 * to be specified. Buffers that do not include that member will be rejected.
3717 #define UAPI_DEF_WRITE_IO_EX(req, req_last_member, resp, resp_last_member) \
3718 .write.has_resp = 1, \
3719 .write.req_size = offsetofend(req, req_last_member), \
3720 .write.resp_size = offsetofend(resp, resp_last_member)
3722 #define UAPI_DEF_WRITE_I_EX(req, req_last_member) \
3723 .write.req_size = offsetofend(req, req_last_member)
3725 const struct uapi_definition uverbs_def_write_intf[] = {
3726 DECLARE_UVERBS_OBJECT(
3728 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_CREATE_AH,
3729 ib_uverbs_create_ah,
3730 UAPI_DEF_WRITE_UDATA_IO(
3731 struct ib_uverbs_create_ah,
3732 struct ib_uverbs_create_ah_resp)),
3733 DECLARE_UVERBS_WRITE(
3734 IB_USER_VERBS_CMD_DESTROY_AH,
3735 ib_uverbs_destroy_ah,
3736 UAPI_DEF_WRITE_I(struct ib_uverbs_destroy_ah)),
3737 UAPI_DEF_OBJ_NEEDS_FN(create_user_ah),
3738 UAPI_DEF_OBJ_NEEDS_FN(destroy_ah)),
3740 DECLARE_UVERBS_OBJECT(
3741 UVERBS_OBJECT_COMP_CHANNEL,
3742 DECLARE_UVERBS_WRITE(
3743 IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL,
3744 ib_uverbs_create_comp_channel,
3746 struct ib_uverbs_create_comp_channel,
3747 struct ib_uverbs_create_comp_channel_resp))),
3749 DECLARE_UVERBS_OBJECT(
3751 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_CREATE_CQ,
3752 ib_uverbs_create_cq,
3753 UAPI_DEF_WRITE_UDATA_IO(
3754 struct ib_uverbs_create_cq,
3755 struct ib_uverbs_create_cq_resp),
3756 UAPI_DEF_METHOD_NEEDS_FN(create_cq)),
3757 DECLARE_UVERBS_WRITE(
3758 IB_USER_VERBS_CMD_DESTROY_CQ,
3759 ib_uverbs_destroy_cq,
3760 UAPI_DEF_WRITE_IO(struct ib_uverbs_destroy_cq,
3761 struct ib_uverbs_destroy_cq_resp),
3762 UAPI_DEF_METHOD_NEEDS_FN(destroy_cq)),
3763 DECLARE_UVERBS_WRITE(
3764 IB_USER_VERBS_CMD_POLL_CQ,
3766 UAPI_DEF_WRITE_IO(struct ib_uverbs_poll_cq,
3767 struct ib_uverbs_poll_cq_resp),
3768 UAPI_DEF_METHOD_NEEDS_FN(poll_cq)),
3769 DECLARE_UVERBS_WRITE(
3770 IB_USER_VERBS_CMD_REQ_NOTIFY_CQ,
3771 ib_uverbs_req_notify_cq,
3772 UAPI_DEF_WRITE_I(struct ib_uverbs_req_notify_cq),
3773 UAPI_DEF_METHOD_NEEDS_FN(req_notify_cq)),
3774 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_RESIZE_CQ,
3775 ib_uverbs_resize_cq,
3776 UAPI_DEF_WRITE_UDATA_IO(
3777 struct ib_uverbs_resize_cq,
3778 struct ib_uverbs_resize_cq_resp),
3779 UAPI_DEF_METHOD_NEEDS_FN(resize_cq)),
3780 DECLARE_UVERBS_WRITE_EX(
3781 IB_USER_VERBS_EX_CMD_CREATE_CQ,
3782 ib_uverbs_ex_create_cq,
3783 UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_ex_create_cq,
3785 struct ib_uverbs_ex_create_cq_resp,
3787 UAPI_DEF_METHOD_NEEDS_FN(create_cq)),
3788 DECLARE_UVERBS_WRITE_EX(
3789 IB_USER_VERBS_EX_CMD_MODIFY_CQ,
3790 ib_uverbs_ex_modify_cq,
3791 UAPI_DEF_WRITE_I(struct ib_uverbs_ex_modify_cq),
3792 UAPI_DEF_METHOD_NEEDS_FN(modify_cq))),
3794 DECLARE_UVERBS_OBJECT(
3795 UVERBS_OBJECT_DEVICE,
3796 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_GET_CONTEXT,
3797 ib_uverbs_get_context,
3798 UAPI_DEF_WRITE_UDATA_IO(
3799 struct ib_uverbs_get_context,
3800 struct ib_uverbs_get_context_resp)),
3801 DECLARE_UVERBS_WRITE(
3802 IB_USER_VERBS_CMD_QUERY_DEVICE,
3803 ib_uverbs_query_device,
3804 UAPI_DEF_WRITE_IO(struct ib_uverbs_query_device,
3805 struct ib_uverbs_query_device_resp)),
3806 DECLARE_UVERBS_WRITE(
3807 IB_USER_VERBS_CMD_QUERY_PORT,
3808 ib_uverbs_query_port,
3809 UAPI_DEF_WRITE_IO(struct ib_uverbs_query_port,
3810 struct ib_uverbs_query_port_resp),
3811 UAPI_DEF_METHOD_NEEDS_FN(query_port)),
3812 DECLARE_UVERBS_WRITE_EX(
3813 IB_USER_VERBS_EX_CMD_QUERY_DEVICE,
3814 ib_uverbs_ex_query_device,
3815 UAPI_DEF_WRITE_IO_EX(
3816 struct ib_uverbs_ex_query_device,
3818 struct ib_uverbs_ex_query_device_resp,
3820 UAPI_DEF_METHOD_NEEDS_FN(query_device)),
3821 UAPI_DEF_OBJ_NEEDS_FN(alloc_ucontext),
3822 UAPI_DEF_OBJ_NEEDS_FN(dealloc_ucontext)),
3824 DECLARE_UVERBS_OBJECT(
3826 DECLARE_UVERBS_WRITE_EX(
3827 IB_USER_VERBS_EX_CMD_CREATE_FLOW,
3828 ib_uverbs_ex_create_flow,
3829 UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_create_flow,
3831 struct ib_uverbs_create_flow_resp,
3833 UAPI_DEF_METHOD_NEEDS_FN(create_flow)),
3834 DECLARE_UVERBS_WRITE_EX(
3835 IB_USER_VERBS_EX_CMD_DESTROY_FLOW,
3836 ib_uverbs_ex_destroy_flow,
3837 UAPI_DEF_WRITE_I(struct ib_uverbs_destroy_flow),
3838 UAPI_DEF_METHOD_NEEDS_FN(destroy_flow))),
3840 DECLARE_UVERBS_OBJECT(
3842 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_DEREG_MR,
3844 UAPI_DEF_WRITE_I(struct ib_uverbs_dereg_mr),
3845 UAPI_DEF_METHOD_NEEDS_FN(dereg_mr)),
3846 DECLARE_UVERBS_WRITE(
3847 IB_USER_VERBS_CMD_REG_MR,
3849 UAPI_DEF_WRITE_UDATA_IO(struct ib_uverbs_reg_mr,
3850 struct ib_uverbs_reg_mr_resp),
3851 UAPI_DEF_METHOD_NEEDS_FN(reg_user_mr)),
3852 DECLARE_UVERBS_WRITE(
3853 IB_USER_VERBS_CMD_REREG_MR,
3855 UAPI_DEF_WRITE_UDATA_IO(struct ib_uverbs_rereg_mr,
3856 struct ib_uverbs_rereg_mr_resp),
3857 UAPI_DEF_METHOD_NEEDS_FN(rereg_user_mr))),
3859 DECLARE_UVERBS_OBJECT(
3861 DECLARE_UVERBS_WRITE(
3862 IB_USER_VERBS_CMD_ALLOC_MW,
3864 UAPI_DEF_WRITE_UDATA_IO(struct ib_uverbs_alloc_mw,
3865 struct ib_uverbs_alloc_mw_resp),
3866 UAPI_DEF_METHOD_NEEDS_FN(alloc_mw)),
3867 DECLARE_UVERBS_WRITE(
3868 IB_USER_VERBS_CMD_DEALLOC_MW,
3869 ib_uverbs_dealloc_mw,
3870 UAPI_DEF_WRITE_I(struct ib_uverbs_dealloc_mw),
3871 UAPI_DEF_METHOD_NEEDS_FN(dealloc_mw))),
3873 DECLARE_UVERBS_OBJECT(
3875 DECLARE_UVERBS_WRITE(
3876 IB_USER_VERBS_CMD_ALLOC_PD,
3878 UAPI_DEF_WRITE_UDATA_IO(struct ib_uverbs_alloc_pd,
3879 struct ib_uverbs_alloc_pd_resp),
3880 UAPI_DEF_METHOD_NEEDS_FN(alloc_pd)),
3881 DECLARE_UVERBS_WRITE(
3882 IB_USER_VERBS_CMD_DEALLOC_PD,
3883 ib_uverbs_dealloc_pd,
3884 UAPI_DEF_WRITE_I(struct ib_uverbs_dealloc_pd),
3885 UAPI_DEF_METHOD_NEEDS_FN(dealloc_pd))),
3887 DECLARE_UVERBS_OBJECT(
3889 DECLARE_UVERBS_WRITE(
3890 IB_USER_VERBS_CMD_ATTACH_MCAST,
3891 ib_uverbs_attach_mcast,
3892 UAPI_DEF_WRITE_I(struct ib_uverbs_attach_mcast),
3893 UAPI_DEF_METHOD_NEEDS_FN(attach_mcast),
3894 UAPI_DEF_METHOD_NEEDS_FN(detach_mcast)),
3895 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_CREATE_QP,
3896 ib_uverbs_create_qp,
3897 UAPI_DEF_WRITE_UDATA_IO(
3898 struct ib_uverbs_create_qp,
3899 struct ib_uverbs_create_qp_resp),
3900 UAPI_DEF_METHOD_NEEDS_FN(create_qp)),
3901 DECLARE_UVERBS_WRITE(
3902 IB_USER_VERBS_CMD_DESTROY_QP,
3903 ib_uverbs_destroy_qp,
3904 UAPI_DEF_WRITE_IO(struct ib_uverbs_destroy_qp,
3905 struct ib_uverbs_destroy_qp_resp),
3906 UAPI_DEF_METHOD_NEEDS_FN(destroy_qp)),
3907 DECLARE_UVERBS_WRITE(
3908 IB_USER_VERBS_CMD_DETACH_MCAST,
3909 ib_uverbs_detach_mcast,
3910 UAPI_DEF_WRITE_I(struct ib_uverbs_detach_mcast),
3911 UAPI_DEF_METHOD_NEEDS_FN(detach_mcast)),
3912 DECLARE_UVERBS_WRITE(
3913 IB_USER_VERBS_CMD_MODIFY_QP,
3914 ib_uverbs_modify_qp,
3915 UAPI_DEF_WRITE_I(struct ib_uverbs_modify_qp),
3916 UAPI_DEF_METHOD_NEEDS_FN(modify_qp)),
3917 DECLARE_UVERBS_WRITE(
3918 IB_USER_VERBS_CMD_POST_RECV,
3919 ib_uverbs_post_recv,
3920 UAPI_DEF_WRITE_IO(struct ib_uverbs_post_recv,
3921 struct ib_uverbs_post_recv_resp),
3922 UAPI_DEF_METHOD_NEEDS_FN(post_recv)),
3923 DECLARE_UVERBS_WRITE(
3924 IB_USER_VERBS_CMD_POST_SEND,
3925 ib_uverbs_post_send,
3926 UAPI_DEF_WRITE_IO(struct ib_uverbs_post_send,
3927 struct ib_uverbs_post_send_resp),
3928 UAPI_DEF_METHOD_NEEDS_FN(post_send)),
3929 DECLARE_UVERBS_WRITE(
3930 IB_USER_VERBS_CMD_QUERY_QP,
3932 UAPI_DEF_WRITE_IO(struct ib_uverbs_query_qp,
3933 struct ib_uverbs_query_qp_resp),
3934 UAPI_DEF_METHOD_NEEDS_FN(query_qp)),
3935 DECLARE_UVERBS_WRITE_EX(
3936 IB_USER_VERBS_EX_CMD_CREATE_QP,
3937 ib_uverbs_ex_create_qp,
3938 UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_ex_create_qp,
3940 struct ib_uverbs_ex_create_qp_resp,
3942 UAPI_DEF_METHOD_NEEDS_FN(create_qp)),
3943 DECLARE_UVERBS_WRITE_EX(
3944 IB_USER_VERBS_EX_CMD_MODIFY_QP,
3945 ib_uverbs_ex_modify_qp,
3946 UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_ex_modify_qp,
3948 struct ib_uverbs_ex_modify_qp_resp,
3950 UAPI_DEF_METHOD_NEEDS_FN(modify_qp))),
3952 DECLARE_UVERBS_OBJECT(
3953 UVERBS_OBJECT_RWQ_IND_TBL,
3954 DECLARE_UVERBS_WRITE_EX(
3955 IB_USER_VERBS_EX_CMD_CREATE_RWQ_IND_TBL,
3956 ib_uverbs_ex_create_rwq_ind_table,
3957 UAPI_DEF_WRITE_IO_EX(
3958 struct ib_uverbs_ex_create_rwq_ind_table,
3960 struct ib_uverbs_ex_create_rwq_ind_table_resp,
3962 UAPI_DEF_METHOD_NEEDS_FN(create_rwq_ind_table)),
3963 DECLARE_UVERBS_WRITE_EX(
3964 IB_USER_VERBS_EX_CMD_DESTROY_RWQ_IND_TBL,
3965 ib_uverbs_ex_destroy_rwq_ind_table,
3967 struct ib_uverbs_ex_destroy_rwq_ind_table),
3968 UAPI_DEF_METHOD_NEEDS_FN(destroy_rwq_ind_table))),
3970 DECLARE_UVERBS_OBJECT(
3972 DECLARE_UVERBS_WRITE_EX(
3973 IB_USER_VERBS_EX_CMD_CREATE_WQ,
3974 ib_uverbs_ex_create_wq,
3975 UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_ex_create_wq,
3977 struct ib_uverbs_ex_create_wq_resp,
3979 UAPI_DEF_METHOD_NEEDS_FN(create_wq)),
3980 DECLARE_UVERBS_WRITE_EX(
3981 IB_USER_VERBS_EX_CMD_DESTROY_WQ,
3982 ib_uverbs_ex_destroy_wq,
3983 UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_ex_destroy_wq,
3985 struct ib_uverbs_ex_destroy_wq_resp,
3987 UAPI_DEF_METHOD_NEEDS_FN(destroy_wq)),
3988 DECLARE_UVERBS_WRITE_EX(
3989 IB_USER_VERBS_EX_CMD_MODIFY_WQ,
3990 ib_uverbs_ex_modify_wq,
3991 UAPI_DEF_WRITE_I_EX(struct ib_uverbs_ex_modify_wq,
3993 UAPI_DEF_METHOD_NEEDS_FN(modify_wq))),
3995 DECLARE_UVERBS_OBJECT(
3997 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_CREATE_SRQ,
3998 ib_uverbs_create_srq,
3999 UAPI_DEF_WRITE_UDATA_IO(
4000 struct ib_uverbs_create_srq,
4001 struct ib_uverbs_create_srq_resp),
4002 UAPI_DEF_METHOD_NEEDS_FN(create_srq)),
4003 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_CREATE_XSRQ,
4004 ib_uverbs_create_xsrq,
4005 UAPI_DEF_WRITE_UDATA_IO(
4006 struct ib_uverbs_create_xsrq,
4007 struct ib_uverbs_create_srq_resp),
4008 UAPI_DEF_METHOD_NEEDS_FN(create_srq)),
4009 DECLARE_UVERBS_WRITE(
4010 IB_USER_VERBS_CMD_DESTROY_SRQ,
4011 ib_uverbs_destroy_srq,
4012 UAPI_DEF_WRITE_IO(struct ib_uverbs_destroy_srq,
4013 struct ib_uverbs_destroy_srq_resp),
4014 UAPI_DEF_METHOD_NEEDS_FN(destroy_srq)),
4015 DECLARE_UVERBS_WRITE(
4016 IB_USER_VERBS_CMD_MODIFY_SRQ,
4017 ib_uverbs_modify_srq,
4018 UAPI_DEF_WRITE_UDATA_I(struct ib_uverbs_modify_srq),
4019 UAPI_DEF_METHOD_NEEDS_FN(modify_srq)),
4020 DECLARE_UVERBS_WRITE(
4021 IB_USER_VERBS_CMD_POST_SRQ_RECV,
4022 ib_uverbs_post_srq_recv,
4023 UAPI_DEF_WRITE_IO(struct ib_uverbs_post_srq_recv,
4024 struct ib_uverbs_post_srq_recv_resp),
4025 UAPI_DEF_METHOD_NEEDS_FN(post_srq_recv)),
4026 DECLARE_UVERBS_WRITE(
4027 IB_USER_VERBS_CMD_QUERY_SRQ,
4028 ib_uverbs_query_srq,
4029 UAPI_DEF_WRITE_IO(struct ib_uverbs_query_srq,
4030 struct ib_uverbs_query_srq_resp),
4031 UAPI_DEF_METHOD_NEEDS_FN(query_srq))),
4033 DECLARE_UVERBS_OBJECT(
4035 DECLARE_UVERBS_WRITE(
4036 IB_USER_VERBS_CMD_CLOSE_XRCD,
4037 ib_uverbs_close_xrcd,
4038 UAPI_DEF_WRITE_I(struct ib_uverbs_close_xrcd)),
4039 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_OPEN_QP,
4041 UAPI_DEF_WRITE_UDATA_IO(
4042 struct ib_uverbs_open_qp,
4043 struct ib_uverbs_create_qp_resp)),
4044 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_OPEN_XRCD,
4045 ib_uverbs_open_xrcd,
4046 UAPI_DEF_WRITE_UDATA_IO(
4047 struct ib_uverbs_open_xrcd,
4048 struct ib_uverbs_open_xrcd_resp)),
4049 UAPI_DEF_OBJ_NEEDS_FN(alloc_xrcd),
4050 UAPI_DEF_OBJ_NEEDS_FN(dealloc_xrcd)),