2 * Copyright (c) 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005, 2006, 2007 Cisco Systems. All rights reserved.
4 * Copyright (c) 2005 PathScale, Inc. All rights reserved.
5 * Copyright (c) 2006 Mellanox Technologies. All rights reserved.
7 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU
9 * General Public License (GPL) Version 2, available from the file
10 * COPYING in the main directory of this source tree, or the
11 * OpenIB.org BSD license below:
13 * Redistribution and use in source and binary forms, with or
14 * without modification, are permitted provided that the following
17 * - Redistributions of source code must retain the above
18 * copyright notice, this list of conditions and the following
21 * - Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimer in the documentation and/or other materials
24 * provided with the distribution.
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
30 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36 #include <linux/file.h>
38 #include <linux/slab.h>
39 #include <linux/sched.h>
41 #include <linux/uaccess.h>
43 #include <rdma/uverbs_types.h>
44 #include <rdma/uverbs_std_types.h>
45 #include "rdma_core.h"
48 #include "core_priv.h"
51 * Copy a response to userspace. If the provided 'resp' is larger than the
52 * user buffer it is silently truncated. If the user provided a larger buffer
53 * then the trailing portion is zero filled.
55 * These semantics are intended to support future extension of the output
58 static int uverbs_response(struct uverbs_attr_bundle *attrs, const void *resp,
63 if (uverbs_attr_is_valid(attrs, UVERBS_ATTR_CORE_OUT))
64 return uverbs_copy_to_struct_or_zero(
65 attrs, UVERBS_ATTR_CORE_OUT, resp, resp_len);
67 if (copy_to_user(attrs->ucore.outbuf, resp,
68 min(attrs->ucore.outlen, resp_len)))
71 if (resp_len < attrs->ucore.outlen) {
73 * Zero fill any extra memory that user
74 * space might have provided.
76 ret = clear_user(attrs->ucore.outbuf + resp_len,
77 attrs->ucore.outlen - resp_len);
86 * Copy a request from userspace. If the provided 'req' is larger than the
87 * user buffer then the user buffer is zero extended into the 'req'. If 'req'
88 * is smaller than the user buffer then the uncopied bytes in the user buffer
91 static int uverbs_request(struct uverbs_attr_bundle *attrs, void *req,
94 if (copy_from_user(req, attrs->ucore.inbuf,
95 min(attrs->ucore.inlen, req_len)))
98 if (attrs->ucore.inlen < req_len) {
99 memset(req + attrs->ucore.inlen, 0,
100 req_len - attrs->ucore.inlen);
101 } else if (attrs->ucore.inlen > req_len) {
102 if (!ib_is_buffer_cleared(attrs->ucore.inbuf + req_len,
103 attrs->ucore.inlen - req_len))
110 * Generate the value for the 'response_length' protocol used by write_ex.
111 * This is the number of bytes the kernel actually wrote. Userspace can use
112 * this to detect what structure members in the response the kernel
115 static u32 uverbs_response_length(struct uverbs_attr_bundle *attrs,
118 return min_t(size_t, attrs->ucore.outlen, resp_len);
122 * The iterator version of the request interface is for handlers that need to
123 * step over a flex array at the end of a command header.
125 struct uverbs_req_iter {
126 const void __user *cur;
127 const void __user *end;
130 static int uverbs_request_start(struct uverbs_attr_bundle *attrs,
131 struct uverbs_req_iter *iter,
135 if (attrs->ucore.inlen < req_len)
138 if (copy_from_user(req, attrs->ucore.inbuf, req_len))
141 iter->cur = attrs->ucore.inbuf + req_len;
142 iter->end = attrs->ucore.inbuf + attrs->ucore.inlen;
146 static int uverbs_request_next(struct uverbs_req_iter *iter, void *val,
149 if (iter->cur + len > iter->end)
152 if (copy_from_user(val, iter->cur, len))
159 static const void __user *uverbs_request_next_ptr(struct uverbs_req_iter *iter,
162 const void __user *res = iter->cur;
164 if (iter->cur + len > iter->end)
165 return (void __force __user *)ERR_PTR(-ENOSPC);
170 static int uverbs_request_finish(struct uverbs_req_iter *iter)
172 if (!ib_is_buffer_cleared(iter->cur, iter->end - iter->cur))
178 * When calling a destroy function during an error unwind we need to pass in
179 * the udata that is sanitized of all user arguments. Ie from the driver
180 * perspective it looks like no udata was passed.
182 struct ib_udata *uverbs_get_cleared_udata(struct uverbs_attr_bundle *attrs)
184 attrs->driver_udata = (struct ib_udata){};
185 return &attrs->driver_udata;
188 static struct ib_uverbs_completion_event_file *
189 _ib_uverbs_lookup_comp_file(s32 fd, struct uverbs_attr_bundle *attrs)
191 struct ib_uobject *uobj = ufd_get_read(UVERBS_OBJECT_COMP_CHANNEL,
197 uverbs_uobject_get(uobj);
200 return container_of(uobj, struct ib_uverbs_completion_event_file,
203 #define ib_uverbs_lookup_comp_file(_fd, _ufile) \
204 _ib_uverbs_lookup_comp_file((_fd)*typecheck(s32, _fd), _ufile)
206 int ib_alloc_ucontext(struct uverbs_attr_bundle *attrs)
208 struct ib_uverbs_file *ufile = attrs->ufile;
209 struct ib_ucontext *ucontext;
210 struct ib_device *ib_dev;
212 ib_dev = srcu_dereference(ufile->device->ib_dev,
213 &ufile->device->disassociate_srcu);
217 ucontext = rdma_zalloc_drv_obj(ib_dev, ib_ucontext);
221 ucontext->device = ib_dev;
222 ucontext->ufile = ufile;
223 xa_init_flags(&ucontext->mmap_xa, XA_FLAGS_ALLOC);
225 rdma_restrack_new(&ucontext->res, RDMA_RESTRACK_CTX);
226 rdma_restrack_set_name(&ucontext->res, NULL);
227 attrs->context = ucontext;
231 int ib_init_ucontext(struct uverbs_attr_bundle *attrs)
233 struct ib_ucontext *ucontext = attrs->context;
234 struct ib_uverbs_file *file = attrs->ufile;
237 if (!down_read_trylock(&file->hw_destroy_rwsem))
239 mutex_lock(&file->ucontext_lock);
240 if (file->ucontext) {
245 ret = ib_rdmacg_try_charge(&ucontext->cg_obj, ucontext->device,
246 RDMACG_RESOURCE_HCA_HANDLE);
250 ret = ucontext->device->ops.alloc_ucontext(ucontext,
251 &attrs->driver_udata);
255 rdma_restrack_add(&ucontext->res);
258 * Make sure that ib_uverbs_get_ucontext() sees the pointer update
259 * only after all writes to setup the ucontext have completed
261 smp_store_release(&file->ucontext, ucontext);
263 mutex_unlock(&file->ucontext_lock);
264 up_read(&file->hw_destroy_rwsem);
268 ib_rdmacg_uncharge(&ucontext->cg_obj, ucontext->device,
269 RDMACG_RESOURCE_HCA_HANDLE);
271 mutex_unlock(&file->ucontext_lock);
272 up_read(&file->hw_destroy_rwsem);
276 static int ib_uverbs_get_context(struct uverbs_attr_bundle *attrs)
278 struct ib_uverbs_get_context_resp resp;
279 struct ib_uverbs_get_context cmd;
280 struct ib_device *ib_dev;
281 struct ib_uobject *uobj;
284 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
288 ret = ib_alloc_ucontext(attrs);
292 uobj = uobj_alloc(UVERBS_OBJECT_ASYNC_EVENT, attrs, &ib_dev);
298 resp = (struct ib_uverbs_get_context_resp){
299 .num_comp_vectors = attrs->ufile->device->num_comp_vectors,
300 .async_fd = uobj->id,
302 ret = uverbs_response(attrs, &resp, sizeof(resp));
306 ret = ib_init_ucontext(attrs);
310 ib_uverbs_init_async_event_file(
311 container_of(uobj, struct ib_uverbs_async_event_file, uobj));
312 rdma_alloc_commit_uobject(uobj, attrs);
316 rdma_alloc_abort_uobject(uobj, attrs, false);
318 rdma_restrack_put(&attrs->context->res);
319 kfree(attrs->context);
320 attrs->context = NULL;
324 static void copy_query_dev_fields(struct ib_ucontext *ucontext,
325 struct ib_uverbs_query_device_resp *resp,
326 struct ib_device_attr *attr)
328 struct ib_device *ib_dev = ucontext->device;
330 resp->fw_ver = attr->fw_ver;
331 resp->node_guid = ib_dev->node_guid;
332 resp->sys_image_guid = attr->sys_image_guid;
333 resp->max_mr_size = attr->max_mr_size;
334 resp->page_size_cap = attr->page_size_cap;
335 resp->vendor_id = attr->vendor_id;
336 resp->vendor_part_id = attr->vendor_part_id;
337 resp->hw_ver = attr->hw_ver;
338 resp->max_qp = attr->max_qp;
339 resp->max_qp_wr = attr->max_qp_wr;
340 resp->device_cap_flags = lower_32_bits(attr->device_cap_flags);
341 resp->max_sge = min(attr->max_send_sge, attr->max_recv_sge);
342 resp->max_sge_rd = attr->max_sge_rd;
343 resp->max_cq = attr->max_cq;
344 resp->max_cqe = attr->max_cqe;
345 resp->max_mr = attr->max_mr;
346 resp->max_pd = attr->max_pd;
347 resp->max_qp_rd_atom = attr->max_qp_rd_atom;
348 resp->max_ee_rd_atom = attr->max_ee_rd_atom;
349 resp->max_res_rd_atom = attr->max_res_rd_atom;
350 resp->max_qp_init_rd_atom = attr->max_qp_init_rd_atom;
351 resp->max_ee_init_rd_atom = attr->max_ee_init_rd_atom;
352 resp->atomic_cap = attr->atomic_cap;
353 resp->max_ee = attr->max_ee;
354 resp->max_rdd = attr->max_rdd;
355 resp->max_mw = attr->max_mw;
356 resp->max_raw_ipv6_qp = attr->max_raw_ipv6_qp;
357 resp->max_raw_ethy_qp = attr->max_raw_ethy_qp;
358 resp->max_mcast_grp = attr->max_mcast_grp;
359 resp->max_mcast_qp_attach = attr->max_mcast_qp_attach;
360 resp->max_total_mcast_qp_attach = attr->max_total_mcast_qp_attach;
361 resp->max_ah = attr->max_ah;
362 resp->max_srq = attr->max_srq;
363 resp->max_srq_wr = attr->max_srq_wr;
364 resp->max_srq_sge = attr->max_srq_sge;
365 resp->max_pkeys = attr->max_pkeys;
366 resp->local_ca_ack_delay = attr->local_ca_ack_delay;
367 resp->phys_port_cnt = 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;
578 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
582 mutex_lock(&ibudev->xrcd_tree_mutex);
585 /* search for file descriptor */
589 goto err_tree_mutex_unlock;
592 inode = file_inode(f.file);
593 xrcd = find_xrcd(ibudev, inode);
594 if (!xrcd && !(cmd.oflags & O_CREAT)) {
595 /* no file descriptor. Need CREATE flag */
597 goto err_tree_mutex_unlock;
600 if (xrcd && cmd.oflags & O_EXCL) {
602 goto err_tree_mutex_unlock;
606 obj = (struct ib_uxrcd_object *)uobj_alloc(UVERBS_OBJECT_XRCD, attrs,
610 goto err_tree_mutex_unlock;
614 xrcd = ib_alloc_xrcd_user(ib_dev, inode, &attrs->driver_udata);
622 atomic_set(&obj->refcnt, 0);
623 obj->uobject.object = xrcd;
627 /* create new inode/xrcd table entry */
628 ret = xrcd_table_insert(ibudev, inode, xrcd);
630 goto err_dealloc_xrcd;
632 atomic_inc(&xrcd->usecnt);
638 mutex_unlock(&ibudev->xrcd_tree_mutex);
639 uobj_finalize_uobj_create(&obj->uobject, attrs);
641 resp.xrcd_handle = obj->uobject.id;
642 return uverbs_response(attrs, &resp, sizeof(resp));
645 ib_dealloc_xrcd_user(xrcd, uverbs_get_cleared_udata(attrs));
648 uobj_alloc_abort(&obj->uobject, attrs);
650 err_tree_mutex_unlock:
654 mutex_unlock(&ibudev->xrcd_tree_mutex);
659 static int ib_uverbs_close_xrcd(struct uverbs_attr_bundle *attrs)
661 struct ib_uverbs_close_xrcd cmd;
664 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
668 return uobj_perform_destroy(UVERBS_OBJECT_XRCD, cmd.xrcd_handle, attrs);
671 int ib_uverbs_dealloc_xrcd(struct ib_uobject *uobject, struct ib_xrcd *xrcd,
672 enum rdma_remove_reason why,
673 struct uverbs_attr_bundle *attrs)
677 struct ib_uverbs_device *dev = attrs->ufile->device;
680 if (inode && !atomic_dec_and_test(&xrcd->usecnt))
683 ret = ib_dealloc_xrcd_user(xrcd, &attrs->driver_udata);
685 atomic_inc(&xrcd->usecnt);
690 xrcd_table_delete(dev, inode);
695 static int ib_uverbs_reg_mr(struct uverbs_attr_bundle *attrs)
697 struct ib_uverbs_reg_mr_resp resp = {};
698 struct ib_uverbs_reg_mr cmd;
699 struct ib_uobject *uobj;
703 struct ib_device *ib_dev;
705 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
709 if ((cmd.start & ~PAGE_MASK) != (cmd.hca_va & ~PAGE_MASK))
712 uobj = uobj_alloc(UVERBS_OBJECT_MR, attrs, &ib_dev);
714 return PTR_ERR(uobj);
716 ret = ib_check_mr_access(ib_dev, cmd.access_flags);
720 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, attrs);
726 mr = pd->device->ops.reg_user_mr(pd, cmd.start, cmd.length, cmd.hca_va,
728 &attrs->driver_udata);
734 mr->device = pd->device;
736 mr->type = IB_MR_TYPE_USER;
738 mr->sig_attrs = NULL;
740 atomic_inc(&pd->usecnt);
741 mr->iova = cmd.hca_va;
743 rdma_restrack_new(&mr->res, RDMA_RESTRACK_MR);
744 rdma_restrack_set_name(&mr->res, NULL);
745 rdma_restrack_add(&mr->res);
748 uobj_put_obj_read(pd);
749 uobj_finalize_uobj_create(uobj, attrs);
751 resp.lkey = mr->lkey;
752 resp.rkey = mr->rkey;
753 resp.mr_handle = uobj->id;
754 return uverbs_response(attrs, &resp, sizeof(resp));
757 uobj_put_obj_read(pd);
759 uobj_alloc_abort(uobj, attrs);
763 static int ib_uverbs_rereg_mr(struct uverbs_attr_bundle *attrs)
765 struct ib_uverbs_rereg_mr cmd;
766 struct ib_uverbs_rereg_mr_resp resp;
769 struct ib_uobject *uobj;
770 struct ib_uobject *new_uobj;
771 struct ib_device *ib_dev;
772 struct ib_pd *orig_pd;
773 struct ib_pd *new_pd;
774 struct ib_mr *new_mr;
776 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
783 if (cmd.flags & ~IB_MR_REREG_SUPPORTED)
786 if ((cmd.flags & IB_MR_REREG_TRANS) &&
787 (cmd.start & ~PAGE_MASK) != (cmd.hca_va & ~PAGE_MASK))
790 uobj = uobj_get_write(UVERBS_OBJECT_MR, cmd.mr_handle, attrs);
792 return PTR_ERR(uobj);
801 if (cmd.flags & IB_MR_REREG_ACCESS) {
802 ret = ib_check_mr_access(mr->device, cmd.access_flags);
808 if (cmd.flags & IB_MR_REREG_PD) {
809 new_pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle,
820 * The driver might create a new HW object as part of the rereg, we need
821 * to have a uobject ready to hold it.
823 new_uobj = uobj_alloc(UVERBS_OBJECT_MR, attrs, &ib_dev);
824 if (IS_ERR(new_uobj)) {
825 ret = PTR_ERR(new_uobj);
829 new_mr = ib_dev->ops.rereg_user_mr(mr, cmd.flags, cmd.start, cmd.length,
830 cmd.hca_va, cmd.access_flags, new_pd,
831 &attrs->driver_udata);
832 if (IS_ERR(new_mr)) {
833 ret = PTR_ERR(new_mr);
837 new_mr->device = new_pd->device;
839 new_mr->type = IB_MR_TYPE_USER;
841 new_mr->sig_attrs = NULL;
842 new_mr->uobject = uobj;
843 atomic_inc(&new_pd->usecnt);
844 new_mr->iova = cmd.hca_va;
845 new_uobj->object = new_mr;
847 rdma_restrack_new(&new_mr->res, RDMA_RESTRACK_MR);
848 rdma_restrack_set_name(&new_mr->res, NULL);
849 rdma_restrack_add(&new_mr->res);
852 * The new uobj for the new HW object is put into the same spot
853 * in the IDR and the old uobj & HW object is deleted.
855 rdma_assign_uobject(uobj, new_uobj, attrs);
856 rdma_alloc_commit_uobject(new_uobj, attrs);
857 uobj_put_destroy(uobj);
862 if (cmd.flags & IB_MR_REREG_PD) {
863 atomic_dec(&orig_pd->usecnt);
865 atomic_inc(&new_pd->usecnt);
867 if (cmd.flags & IB_MR_REREG_TRANS)
868 mr->iova = cmd.hca_va;
871 memset(&resp, 0, sizeof(resp));
872 resp.lkey = mr->lkey;
873 resp.rkey = mr->rkey;
875 ret = uverbs_response(attrs, &resp, sizeof(resp));
879 uobj_alloc_abort(new_uobj, attrs);
881 if (cmd.flags & IB_MR_REREG_PD)
882 uobj_put_obj_read(new_pd);
886 uobj_put_write(uobj);
891 static int ib_uverbs_dereg_mr(struct uverbs_attr_bundle *attrs)
893 struct ib_uverbs_dereg_mr cmd;
896 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
900 return uobj_perform_destroy(UVERBS_OBJECT_MR, cmd.mr_handle, attrs);
903 static int ib_uverbs_alloc_mw(struct uverbs_attr_bundle *attrs)
905 struct ib_uverbs_alloc_mw cmd;
906 struct ib_uverbs_alloc_mw_resp resp = {};
907 struct ib_uobject *uobj;
911 struct ib_device *ib_dev;
913 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
917 uobj = uobj_alloc(UVERBS_OBJECT_MW, attrs, &ib_dev);
919 return PTR_ERR(uobj);
921 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, attrs);
927 if (cmd.mw_type != IB_MW_TYPE_1 && cmd.mw_type != IB_MW_TYPE_2) {
932 mw = rdma_zalloc_drv_obj(ib_dev, ib_mw);
941 mw->type = cmd.mw_type;
943 ret = pd->device->ops.alloc_mw(mw, &attrs->driver_udata);
947 atomic_inc(&pd->usecnt);
950 uobj_put_obj_read(pd);
951 uobj_finalize_uobj_create(uobj, attrs);
953 resp.rkey = mw->rkey;
954 resp.mw_handle = uobj->id;
955 return uverbs_response(attrs, &resp, sizeof(resp));
960 uobj_put_obj_read(pd);
962 uobj_alloc_abort(uobj, attrs);
966 static int ib_uverbs_dealloc_mw(struct uverbs_attr_bundle *attrs)
968 struct ib_uverbs_dealloc_mw cmd;
971 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
975 return uobj_perform_destroy(UVERBS_OBJECT_MW, cmd.mw_handle, attrs);
978 static int ib_uverbs_create_comp_channel(struct uverbs_attr_bundle *attrs)
980 struct ib_uverbs_create_comp_channel cmd;
981 struct ib_uverbs_create_comp_channel_resp resp;
982 struct ib_uobject *uobj;
983 struct ib_uverbs_completion_event_file *ev_file;
984 struct ib_device *ib_dev;
987 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
991 uobj = uobj_alloc(UVERBS_OBJECT_COMP_CHANNEL, attrs, &ib_dev);
993 return PTR_ERR(uobj);
995 ev_file = container_of(uobj, struct ib_uverbs_completion_event_file,
997 ib_uverbs_init_event_queue(&ev_file->ev_queue);
998 uobj_finalize_uobj_create(uobj, attrs);
1001 return uverbs_response(attrs, &resp, sizeof(resp));
1004 static int create_cq(struct uverbs_attr_bundle *attrs,
1005 struct ib_uverbs_ex_create_cq *cmd)
1007 struct ib_ucq_object *obj;
1008 struct ib_uverbs_completion_event_file *ev_file = NULL;
1011 struct ib_uverbs_ex_create_cq_resp resp = {};
1012 struct ib_cq_init_attr attr = {};
1013 struct ib_device *ib_dev;
1015 if (cmd->comp_vector >= attrs->ufile->device->num_comp_vectors)
1018 obj = (struct ib_ucq_object *)uobj_alloc(UVERBS_OBJECT_CQ, attrs,
1021 return PTR_ERR(obj);
1023 if (cmd->comp_channel >= 0) {
1024 ev_file = ib_uverbs_lookup_comp_file(cmd->comp_channel, attrs);
1025 if (IS_ERR(ev_file)) {
1026 ret = PTR_ERR(ev_file);
1031 obj->uevent.uobject.user_handle = cmd->user_handle;
1032 INIT_LIST_HEAD(&obj->comp_list);
1033 INIT_LIST_HEAD(&obj->uevent.event_list);
1035 attr.cqe = cmd->cqe;
1036 attr.comp_vector = cmd->comp_vector;
1037 attr.flags = cmd->flags;
1039 cq = rdma_zalloc_drv_obj(ib_dev, ib_cq);
1044 cq->device = ib_dev;
1046 cq->comp_handler = ib_uverbs_comp_handler;
1047 cq->event_handler = ib_uverbs_cq_event_handler;
1048 cq->cq_context = ev_file ? &ev_file->ev_queue : NULL;
1049 atomic_set(&cq->usecnt, 0);
1051 rdma_restrack_new(&cq->res, RDMA_RESTRACK_CQ);
1052 rdma_restrack_set_name(&cq->res, NULL);
1054 ret = ib_dev->ops.create_cq(cq, &attr, &attrs->driver_udata);
1057 rdma_restrack_add(&cq->res);
1059 obj->uevent.uobject.object = cq;
1060 obj->uevent.event_file = READ_ONCE(attrs->ufile->default_async_file);
1061 if (obj->uevent.event_file)
1062 uverbs_uobject_get(&obj->uevent.event_file->uobj);
1063 uobj_finalize_uobj_create(&obj->uevent.uobject, attrs);
1065 resp.base.cq_handle = obj->uevent.uobject.id;
1066 resp.base.cqe = cq->cqe;
1067 resp.response_length = uverbs_response_length(attrs, sizeof(resp));
1068 return uverbs_response(attrs, &resp, sizeof(resp));
1071 rdma_restrack_put(&cq->res);
1075 ib_uverbs_release_ucq(ev_file, obj);
1077 uobj_alloc_abort(&obj->uevent.uobject, attrs);
1081 static int ib_uverbs_create_cq(struct uverbs_attr_bundle *attrs)
1083 struct ib_uverbs_create_cq cmd;
1084 struct ib_uverbs_ex_create_cq cmd_ex;
1087 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1091 memset(&cmd_ex, 0, sizeof(cmd_ex));
1092 cmd_ex.user_handle = cmd.user_handle;
1093 cmd_ex.cqe = cmd.cqe;
1094 cmd_ex.comp_vector = cmd.comp_vector;
1095 cmd_ex.comp_channel = cmd.comp_channel;
1097 return create_cq(attrs, &cmd_ex);
1100 static int ib_uverbs_ex_create_cq(struct uverbs_attr_bundle *attrs)
1102 struct ib_uverbs_ex_create_cq cmd;
1105 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1115 return create_cq(attrs, &cmd);
1118 static int ib_uverbs_resize_cq(struct uverbs_attr_bundle *attrs)
1120 struct ib_uverbs_resize_cq cmd;
1121 struct ib_uverbs_resize_cq_resp resp = {};
1125 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1129 cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs);
1133 ret = cq->device->ops.resize_cq(cq, cmd.cqe, &attrs->driver_udata);
1139 ret = uverbs_response(attrs, &resp, sizeof(resp));
1141 rdma_lookup_put_uobject(&cq->uobject->uevent.uobject,
1142 UVERBS_LOOKUP_READ);
1147 static int copy_wc_to_user(struct ib_device *ib_dev, void __user *dest,
1150 struct ib_uverbs_wc tmp;
1152 tmp.wr_id = wc->wr_id;
1153 tmp.status = wc->status;
1154 tmp.opcode = wc->opcode;
1155 tmp.vendor_err = wc->vendor_err;
1156 tmp.byte_len = wc->byte_len;
1157 tmp.ex.imm_data = wc->ex.imm_data;
1158 tmp.qp_num = wc->qp->qp_num;
1159 tmp.src_qp = wc->src_qp;
1160 tmp.wc_flags = wc->wc_flags;
1161 tmp.pkey_index = wc->pkey_index;
1162 if (rdma_cap_opa_ah(ib_dev, wc->port_num))
1163 tmp.slid = OPA_TO_IB_UCAST_LID(wc->slid);
1165 tmp.slid = ib_lid_cpu16(wc->slid);
1167 tmp.dlid_path_bits = wc->dlid_path_bits;
1168 tmp.port_num = wc->port_num;
1171 if (copy_to_user(dest, &tmp, sizeof tmp))
1177 static int ib_uverbs_poll_cq(struct uverbs_attr_bundle *attrs)
1179 struct ib_uverbs_poll_cq cmd;
1180 struct ib_uverbs_poll_cq_resp resp;
1181 u8 __user *header_ptr;
1182 u8 __user *data_ptr;
1187 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1191 cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs);
1195 /* we copy a struct ib_uverbs_poll_cq_resp to user space */
1196 header_ptr = attrs->ucore.outbuf;
1197 data_ptr = header_ptr + sizeof resp;
1199 memset(&resp, 0, sizeof resp);
1200 while (resp.count < cmd.ne) {
1201 ret = ib_poll_cq(cq, 1, &wc);
1207 ret = copy_wc_to_user(cq->device, data_ptr, &wc);
1211 data_ptr += sizeof(struct ib_uverbs_wc);
1215 if (copy_to_user(header_ptr, &resp, sizeof resp)) {
1221 if (uverbs_attr_is_valid(attrs, UVERBS_ATTR_CORE_OUT))
1222 ret = uverbs_output_written(attrs, UVERBS_ATTR_CORE_OUT);
1225 rdma_lookup_put_uobject(&cq->uobject->uevent.uobject,
1226 UVERBS_LOOKUP_READ);
1230 static int ib_uverbs_req_notify_cq(struct uverbs_attr_bundle *attrs)
1232 struct ib_uverbs_req_notify_cq cmd;
1236 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1240 cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs);
1244 ib_req_notify_cq(cq, cmd.solicited_only ?
1245 IB_CQ_SOLICITED : IB_CQ_NEXT_COMP);
1247 rdma_lookup_put_uobject(&cq->uobject->uevent.uobject,
1248 UVERBS_LOOKUP_READ);
1252 static int ib_uverbs_destroy_cq(struct uverbs_attr_bundle *attrs)
1254 struct ib_uverbs_destroy_cq cmd;
1255 struct ib_uverbs_destroy_cq_resp resp;
1256 struct ib_uobject *uobj;
1257 struct ib_ucq_object *obj;
1260 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1264 uobj = uobj_get_destroy(UVERBS_OBJECT_CQ, cmd.cq_handle, attrs);
1266 return PTR_ERR(uobj);
1268 obj = container_of(uobj, struct ib_ucq_object, uevent.uobject);
1269 memset(&resp, 0, sizeof(resp));
1270 resp.comp_events_reported = obj->comp_events_reported;
1271 resp.async_events_reported = obj->uevent.events_reported;
1273 uobj_put_destroy(uobj);
1275 return uverbs_response(attrs, &resp, sizeof(resp));
1278 static int create_qp(struct uverbs_attr_bundle *attrs,
1279 struct ib_uverbs_ex_create_qp *cmd)
1281 struct ib_uqp_object *obj;
1282 struct ib_device *device;
1283 struct ib_pd *pd = NULL;
1284 struct ib_xrcd *xrcd = NULL;
1285 struct ib_uobject *xrcd_uobj = ERR_PTR(-ENOENT);
1286 struct ib_cq *scq = NULL, *rcq = NULL;
1287 struct ib_srq *srq = NULL;
1289 struct ib_qp_init_attr attr = {};
1290 struct ib_uverbs_ex_create_qp_resp resp = {};
1292 struct ib_rwq_ind_table *ind_tbl = NULL;
1294 struct ib_device *ib_dev;
1296 switch (cmd->qp_type) {
1297 case IB_QPT_RAW_PACKET:
1298 if (!capable(CAP_NET_RAW))
1304 case IB_QPT_XRC_INI:
1305 case IB_QPT_XRC_TGT:
1312 obj = (struct ib_uqp_object *)uobj_alloc(UVERBS_OBJECT_QP, attrs,
1315 return PTR_ERR(obj);
1317 obj->uevent.uobject.user_handle = cmd->user_handle;
1318 mutex_init(&obj->mcast_lock);
1320 if (cmd->comp_mask & IB_UVERBS_CREATE_QP_MASK_IND_TABLE) {
1321 ind_tbl = uobj_get_obj_read(rwq_ind_table,
1322 UVERBS_OBJECT_RWQ_IND_TBL,
1323 cmd->rwq_ind_tbl_handle, attrs);
1329 attr.rwq_ind_tbl = ind_tbl;
1332 if (ind_tbl && (cmd->max_recv_wr || cmd->max_recv_sge || cmd->is_srq)) {
1337 if (ind_tbl && !cmd->max_send_wr)
1340 if (cmd->qp_type == IB_QPT_XRC_TGT) {
1341 xrcd_uobj = uobj_get_read(UVERBS_OBJECT_XRCD, cmd->pd_handle,
1344 if (IS_ERR(xrcd_uobj)) {
1349 xrcd = (struct ib_xrcd *)xrcd_uobj->object;
1354 device = xrcd->device;
1356 if (cmd->qp_type == IB_QPT_XRC_INI) {
1357 cmd->max_recv_wr = 0;
1358 cmd->max_recv_sge = 0;
1361 srq = uobj_get_obj_read(srq, UVERBS_OBJECT_SRQ,
1362 cmd->srq_handle, attrs);
1363 if (!srq || srq->srq_type == IB_SRQT_XRC) {
1370 if (cmd->recv_cq_handle != cmd->send_cq_handle) {
1371 rcq = uobj_get_obj_read(
1372 cq, UVERBS_OBJECT_CQ,
1373 cmd->recv_cq_handle, attrs);
1383 scq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ,
1384 cmd->send_cq_handle, attrs);
1385 if (!ind_tbl && cmd->qp_type != IB_QPT_XRC_INI)
1387 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd->pd_handle,
1389 if (!pd || (!scq && has_sq)) {
1394 device = pd->device;
1397 attr.event_handler = ib_uverbs_qp_event_handler;
1402 attr.sq_sig_type = cmd->sq_sig_all ? IB_SIGNAL_ALL_WR :
1404 attr.qp_type = cmd->qp_type;
1405 attr.create_flags = 0;
1407 attr.cap.max_send_wr = cmd->max_send_wr;
1408 attr.cap.max_recv_wr = cmd->max_recv_wr;
1409 attr.cap.max_send_sge = cmd->max_send_sge;
1410 attr.cap.max_recv_sge = cmd->max_recv_sge;
1411 attr.cap.max_inline_data = cmd->max_inline_data;
1413 INIT_LIST_HEAD(&obj->uevent.event_list);
1414 INIT_LIST_HEAD(&obj->mcast_list);
1416 attr.create_flags = cmd->create_flags;
1417 if (attr.create_flags & ~(IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK |
1418 IB_QP_CREATE_CROSS_CHANNEL |
1419 IB_QP_CREATE_MANAGED_SEND |
1420 IB_QP_CREATE_MANAGED_RECV |
1421 IB_QP_CREATE_SCATTER_FCS |
1422 IB_QP_CREATE_CVLAN_STRIPPING |
1423 IB_QP_CREATE_SOURCE_QPN |
1424 IB_QP_CREATE_PCI_WRITE_END_PADDING)) {
1429 if (attr.create_flags & IB_QP_CREATE_SOURCE_QPN) {
1430 if (!capable(CAP_NET_RAW)) {
1435 attr.source_qpn = cmd->source_qpn;
1438 if (cmd->qp_type == IB_QPT_XRC_TGT)
1439 qp = ib_create_qp(pd, &attr);
1441 qp = _ib_create_qp(device, pd, &attr, &attrs->driver_udata, obj,
1449 if (cmd->qp_type != IB_QPT_XRC_TGT) {
1450 ret = ib_create_qp_security(qp, device);
1454 atomic_inc(&pd->usecnt);
1456 atomic_inc(&attr.send_cq->usecnt);
1458 atomic_inc(&attr.recv_cq->usecnt);
1460 atomic_inc(&attr.srq->usecnt);
1462 atomic_inc(&ind_tbl->usecnt);
1464 /* It is done in _ib_create_qp for other QP types */
1468 obj->uevent.uobject.object = qp;
1469 obj->uevent.event_file = READ_ONCE(attrs->ufile->default_async_file);
1470 if (obj->uevent.event_file)
1471 uverbs_uobject_get(&obj->uevent.event_file->uobj);
1474 obj->uxrcd = container_of(xrcd_uobj, struct ib_uxrcd_object,
1476 atomic_inc(&obj->uxrcd->refcnt);
1477 uobj_put_read(xrcd_uobj);
1481 uobj_put_obj_read(pd);
1483 rdma_lookup_put_uobject(&scq->uobject->uevent.uobject,
1484 UVERBS_LOOKUP_READ);
1485 if (rcq && rcq != scq)
1486 rdma_lookup_put_uobject(&rcq->uobject->uevent.uobject,
1487 UVERBS_LOOKUP_READ);
1489 rdma_lookup_put_uobject(&srq->uobject->uevent.uobject,
1490 UVERBS_LOOKUP_READ);
1492 uobj_put_obj_read(ind_tbl);
1493 uobj_finalize_uobj_create(&obj->uevent.uobject, attrs);
1495 resp.base.qpn = qp->qp_num;
1496 resp.base.qp_handle = obj->uevent.uobject.id;
1497 resp.base.max_recv_sge = attr.cap.max_recv_sge;
1498 resp.base.max_send_sge = attr.cap.max_send_sge;
1499 resp.base.max_recv_wr = attr.cap.max_recv_wr;
1500 resp.base.max_send_wr = attr.cap.max_send_wr;
1501 resp.base.max_inline_data = attr.cap.max_inline_data;
1502 resp.response_length = uverbs_response_length(attrs, sizeof(resp));
1503 return uverbs_response(attrs, &resp, sizeof(resp));
1506 ib_destroy_qp_user(qp, uverbs_get_cleared_udata(attrs));
1509 if (!IS_ERR(xrcd_uobj))
1510 uobj_put_read(xrcd_uobj);
1512 uobj_put_obj_read(pd);
1514 rdma_lookup_put_uobject(&scq->uobject->uevent.uobject,
1515 UVERBS_LOOKUP_READ);
1516 if (rcq && rcq != scq)
1517 rdma_lookup_put_uobject(&rcq->uobject->uevent.uobject,
1518 UVERBS_LOOKUP_READ);
1520 rdma_lookup_put_uobject(&srq->uobject->uevent.uobject,
1521 UVERBS_LOOKUP_READ);
1523 uobj_put_obj_read(ind_tbl);
1525 uobj_alloc_abort(&obj->uevent.uobject, attrs);
1529 static int ib_uverbs_create_qp(struct uverbs_attr_bundle *attrs)
1531 struct ib_uverbs_create_qp cmd;
1532 struct ib_uverbs_ex_create_qp cmd_ex;
1535 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1539 memset(&cmd_ex, 0, sizeof(cmd_ex));
1540 cmd_ex.user_handle = cmd.user_handle;
1541 cmd_ex.pd_handle = cmd.pd_handle;
1542 cmd_ex.send_cq_handle = cmd.send_cq_handle;
1543 cmd_ex.recv_cq_handle = cmd.recv_cq_handle;
1544 cmd_ex.srq_handle = cmd.srq_handle;
1545 cmd_ex.max_send_wr = cmd.max_send_wr;
1546 cmd_ex.max_recv_wr = cmd.max_recv_wr;
1547 cmd_ex.max_send_sge = cmd.max_send_sge;
1548 cmd_ex.max_recv_sge = cmd.max_recv_sge;
1549 cmd_ex.max_inline_data = cmd.max_inline_data;
1550 cmd_ex.sq_sig_all = cmd.sq_sig_all;
1551 cmd_ex.qp_type = cmd.qp_type;
1552 cmd_ex.is_srq = cmd.is_srq;
1554 return create_qp(attrs, &cmd_ex);
1557 static int ib_uverbs_ex_create_qp(struct uverbs_attr_bundle *attrs)
1559 struct ib_uverbs_ex_create_qp cmd;
1562 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1566 if (cmd.comp_mask & ~IB_UVERBS_CREATE_QP_SUP_COMP_MASK)
1572 return create_qp(attrs, &cmd);
1575 static int ib_uverbs_open_qp(struct uverbs_attr_bundle *attrs)
1577 struct ib_uverbs_create_qp_resp resp = {};
1578 struct ib_uverbs_open_qp cmd;
1579 struct ib_uqp_object *obj;
1580 struct ib_xrcd *xrcd;
1582 struct ib_qp_open_attr attr = {};
1584 struct ib_uobject *xrcd_uobj;
1585 struct ib_device *ib_dev;
1587 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1591 obj = (struct ib_uqp_object *)uobj_alloc(UVERBS_OBJECT_QP, attrs,
1594 return PTR_ERR(obj);
1596 xrcd_uobj = uobj_get_read(UVERBS_OBJECT_XRCD, cmd.pd_handle, attrs);
1597 if (IS_ERR(xrcd_uobj)) {
1602 xrcd = (struct ib_xrcd *)xrcd_uobj->object;
1608 attr.event_handler = ib_uverbs_qp_event_handler;
1609 attr.qp_num = cmd.qpn;
1610 attr.qp_type = cmd.qp_type;
1612 INIT_LIST_HEAD(&obj->uevent.event_list);
1613 INIT_LIST_HEAD(&obj->mcast_list);
1615 qp = ib_open_qp(xrcd, &attr);
1621 obj->uevent.uobject.object = qp;
1622 obj->uevent.uobject.user_handle = cmd.user_handle;
1624 obj->uxrcd = container_of(xrcd_uobj, struct ib_uxrcd_object, uobject);
1625 atomic_inc(&obj->uxrcd->refcnt);
1627 uobj_put_read(xrcd_uobj);
1628 uobj_finalize_uobj_create(&obj->uevent.uobject, attrs);
1630 resp.qpn = qp->qp_num;
1631 resp.qp_handle = obj->uevent.uobject.id;
1632 return uverbs_response(attrs, &resp, sizeof(resp));
1635 uobj_put_read(xrcd_uobj);
1637 uobj_alloc_abort(&obj->uevent.uobject, attrs);
1641 static void copy_ah_attr_to_uverbs(struct ib_uverbs_qp_dest *uverb_attr,
1642 struct rdma_ah_attr *rdma_attr)
1644 const struct ib_global_route *grh;
1646 uverb_attr->dlid = rdma_ah_get_dlid(rdma_attr);
1647 uverb_attr->sl = rdma_ah_get_sl(rdma_attr);
1648 uverb_attr->src_path_bits = rdma_ah_get_path_bits(rdma_attr);
1649 uverb_attr->static_rate = rdma_ah_get_static_rate(rdma_attr);
1650 uverb_attr->is_global = !!(rdma_ah_get_ah_flags(rdma_attr) &
1652 if (uverb_attr->is_global) {
1653 grh = rdma_ah_read_grh(rdma_attr);
1654 memcpy(uverb_attr->dgid, grh->dgid.raw, 16);
1655 uverb_attr->flow_label = grh->flow_label;
1656 uverb_attr->sgid_index = grh->sgid_index;
1657 uverb_attr->hop_limit = grh->hop_limit;
1658 uverb_attr->traffic_class = grh->traffic_class;
1660 uverb_attr->port_num = rdma_ah_get_port_num(rdma_attr);
1663 static int ib_uverbs_query_qp(struct uverbs_attr_bundle *attrs)
1665 struct ib_uverbs_query_qp cmd;
1666 struct ib_uverbs_query_qp_resp resp;
1668 struct ib_qp_attr *attr;
1669 struct ib_qp_init_attr *init_attr;
1672 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1676 attr = kmalloc(sizeof *attr, GFP_KERNEL);
1677 init_attr = kmalloc(sizeof *init_attr, GFP_KERNEL);
1678 if (!attr || !init_attr) {
1683 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
1689 ret = ib_query_qp(qp, attr, cmd.attr_mask, init_attr);
1691 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
1692 UVERBS_LOOKUP_READ);
1697 memset(&resp, 0, sizeof resp);
1699 resp.qp_state = attr->qp_state;
1700 resp.cur_qp_state = attr->cur_qp_state;
1701 resp.path_mtu = attr->path_mtu;
1702 resp.path_mig_state = attr->path_mig_state;
1703 resp.qkey = attr->qkey;
1704 resp.rq_psn = attr->rq_psn;
1705 resp.sq_psn = attr->sq_psn;
1706 resp.dest_qp_num = attr->dest_qp_num;
1707 resp.qp_access_flags = attr->qp_access_flags;
1708 resp.pkey_index = attr->pkey_index;
1709 resp.alt_pkey_index = attr->alt_pkey_index;
1710 resp.sq_draining = attr->sq_draining;
1711 resp.max_rd_atomic = attr->max_rd_atomic;
1712 resp.max_dest_rd_atomic = attr->max_dest_rd_atomic;
1713 resp.min_rnr_timer = attr->min_rnr_timer;
1714 resp.port_num = attr->port_num;
1715 resp.timeout = attr->timeout;
1716 resp.retry_cnt = attr->retry_cnt;
1717 resp.rnr_retry = attr->rnr_retry;
1718 resp.alt_port_num = attr->alt_port_num;
1719 resp.alt_timeout = attr->alt_timeout;
1721 copy_ah_attr_to_uverbs(&resp.dest, &attr->ah_attr);
1722 copy_ah_attr_to_uverbs(&resp.alt_dest, &attr->alt_ah_attr);
1724 resp.max_send_wr = init_attr->cap.max_send_wr;
1725 resp.max_recv_wr = init_attr->cap.max_recv_wr;
1726 resp.max_send_sge = init_attr->cap.max_send_sge;
1727 resp.max_recv_sge = init_attr->cap.max_recv_sge;
1728 resp.max_inline_data = init_attr->cap.max_inline_data;
1729 resp.sq_sig_all = init_attr->sq_sig_type == IB_SIGNAL_ALL_WR;
1731 ret = uverbs_response(attrs, &resp, sizeof(resp));
1740 /* Remove ignored fields set in the attribute mask */
1741 static int modify_qp_mask(enum ib_qp_type qp_type, int mask)
1744 case IB_QPT_XRC_INI:
1745 return mask & ~(IB_QP_MAX_DEST_RD_ATOMIC | IB_QP_MIN_RNR_TIMER);
1746 case IB_QPT_XRC_TGT:
1747 return mask & ~(IB_QP_MAX_QP_RD_ATOMIC | IB_QP_RETRY_CNT |
1754 static void copy_ah_attr_from_uverbs(struct ib_device *dev,
1755 struct rdma_ah_attr *rdma_attr,
1756 struct ib_uverbs_qp_dest *uverb_attr)
1758 rdma_attr->type = rdma_ah_find_type(dev, uverb_attr->port_num);
1759 if (uverb_attr->is_global) {
1760 rdma_ah_set_grh(rdma_attr, NULL,
1761 uverb_attr->flow_label,
1762 uverb_attr->sgid_index,
1763 uverb_attr->hop_limit,
1764 uverb_attr->traffic_class);
1765 rdma_ah_set_dgid_raw(rdma_attr, uverb_attr->dgid);
1767 rdma_ah_set_ah_flags(rdma_attr, 0);
1769 rdma_ah_set_dlid(rdma_attr, uverb_attr->dlid);
1770 rdma_ah_set_sl(rdma_attr, uverb_attr->sl);
1771 rdma_ah_set_path_bits(rdma_attr, uverb_attr->src_path_bits);
1772 rdma_ah_set_static_rate(rdma_attr, uverb_attr->static_rate);
1773 rdma_ah_set_port_num(rdma_attr, uverb_attr->port_num);
1774 rdma_ah_set_make_grd(rdma_attr, false);
1777 static int modify_qp(struct uverbs_attr_bundle *attrs,
1778 struct ib_uverbs_ex_modify_qp *cmd)
1780 struct ib_qp_attr *attr;
1784 attr = kzalloc(sizeof(*attr), GFP_KERNEL);
1788 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd->base.qp_handle,
1795 if ((cmd->base.attr_mask & IB_QP_PORT) &&
1796 !rdma_is_port_valid(qp->device, cmd->base.port_num)) {
1801 if ((cmd->base.attr_mask & IB_QP_AV)) {
1802 if (!rdma_is_port_valid(qp->device, cmd->base.dest.port_num)) {
1807 if (cmd->base.attr_mask & IB_QP_STATE &&
1808 cmd->base.qp_state == IB_QPS_RTR) {
1809 /* We are in INIT->RTR TRANSITION (if we are not,
1810 * this transition will be rejected in subsequent checks).
1811 * In the INIT->RTR transition, we cannot have IB_QP_PORT set,
1812 * but the IB_QP_STATE flag is required.
1814 * Since kernel 3.14 (commit dbf727de7440), the uverbs driver,
1815 * when IB_QP_AV is set, has required inclusion of a valid
1816 * port number in the primary AV. (AVs are created and handled
1817 * differently for infiniband and ethernet (RoCE) ports).
1819 * Check the port number included in the primary AV against
1820 * the port number in the qp struct, which was set (and saved)
1821 * in the RST->INIT transition.
1823 if (cmd->base.dest.port_num != qp->real_qp->port) {
1828 /* We are in SQD->SQD. (If we are not, this transition will
1829 * be rejected later in the verbs layer checks).
1830 * Check for both IB_QP_PORT and IB_QP_AV, these can be set
1831 * together in the SQD->SQD transition.
1833 * If only IP_QP_AV was set, add in IB_QP_PORT as well (the
1834 * verbs layer driver does not track primary port changes
1835 * resulting from path migration. Thus, in SQD, if the primary
1836 * AV is modified, the primary port should also be modified).
1838 * Note that in this transition, the IB_QP_STATE flag
1841 if (((cmd->base.attr_mask & (IB_QP_AV | IB_QP_PORT))
1842 == (IB_QP_AV | IB_QP_PORT)) &&
1843 cmd->base.port_num != cmd->base.dest.port_num) {
1847 if ((cmd->base.attr_mask & (IB_QP_AV | IB_QP_PORT))
1849 cmd->base.attr_mask |= IB_QP_PORT;
1850 cmd->base.port_num = cmd->base.dest.port_num;
1855 if ((cmd->base.attr_mask & IB_QP_ALT_PATH) &&
1856 (!rdma_is_port_valid(qp->device, cmd->base.alt_port_num) ||
1857 !rdma_is_port_valid(qp->device, cmd->base.alt_dest.port_num) ||
1858 cmd->base.alt_port_num != cmd->base.alt_dest.port_num)) {
1863 if ((cmd->base.attr_mask & IB_QP_CUR_STATE &&
1864 cmd->base.cur_qp_state > IB_QPS_ERR) ||
1865 (cmd->base.attr_mask & IB_QP_STATE &&
1866 cmd->base.qp_state > IB_QPS_ERR)) {
1871 if (cmd->base.attr_mask & IB_QP_STATE)
1872 attr->qp_state = cmd->base.qp_state;
1873 if (cmd->base.attr_mask & IB_QP_CUR_STATE)
1874 attr->cur_qp_state = cmd->base.cur_qp_state;
1875 if (cmd->base.attr_mask & IB_QP_PATH_MTU)
1876 attr->path_mtu = cmd->base.path_mtu;
1877 if (cmd->base.attr_mask & IB_QP_PATH_MIG_STATE)
1878 attr->path_mig_state = cmd->base.path_mig_state;
1879 if (cmd->base.attr_mask & IB_QP_QKEY)
1880 attr->qkey = cmd->base.qkey;
1881 if (cmd->base.attr_mask & IB_QP_RQ_PSN)
1882 attr->rq_psn = cmd->base.rq_psn;
1883 if (cmd->base.attr_mask & IB_QP_SQ_PSN)
1884 attr->sq_psn = cmd->base.sq_psn;
1885 if (cmd->base.attr_mask & IB_QP_DEST_QPN)
1886 attr->dest_qp_num = cmd->base.dest_qp_num;
1887 if (cmd->base.attr_mask & IB_QP_ACCESS_FLAGS)
1888 attr->qp_access_flags = cmd->base.qp_access_flags;
1889 if (cmd->base.attr_mask & IB_QP_PKEY_INDEX)
1890 attr->pkey_index = cmd->base.pkey_index;
1891 if (cmd->base.attr_mask & IB_QP_EN_SQD_ASYNC_NOTIFY)
1892 attr->en_sqd_async_notify = cmd->base.en_sqd_async_notify;
1893 if (cmd->base.attr_mask & IB_QP_MAX_QP_RD_ATOMIC)
1894 attr->max_rd_atomic = cmd->base.max_rd_atomic;
1895 if (cmd->base.attr_mask & IB_QP_MAX_DEST_RD_ATOMIC)
1896 attr->max_dest_rd_atomic = cmd->base.max_dest_rd_atomic;
1897 if (cmd->base.attr_mask & IB_QP_MIN_RNR_TIMER)
1898 attr->min_rnr_timer = cmd->base.min_rnr_timer;
1899 if (cmd->base.attr_mask & IB_QP_PORT)
1900 attr->port_num = cmd->base.port_num;
1901 if (cmd->base.attr_mask & IB_QP_TIMEOUT)
1902 attr->timeout = cmd->base.timeout;
1903 if (cmd->base.attr_mask & IB_QP_RETRY_CNT)
1904 attr->retry_cnt = cmd->base.retry_cnt;
1905 if (cmd->base.attr_mask & IB_QP_RNR_RETRY)
1906 attr->rnr_retry = cmd->base.rnr_retry;
1907 if (cmd->base.attr_mask & IB_QP_ALT_PATH) {
1908 attr->alt_port_num = cmd->base.alt_port_num;
1909 attr->alt_timeout = cmd->base.alt_timeout;
1910 attr->alt_pkey_index = cmd->base.alt_pkey_index;
1912 if (cmd->base.attr_mask & IB_QP_RATE_LIMIT)
1913 attr->rate_limit = cmd->rate_limit;
1915 if (cmd->base.attr_mask & IB_QP_AV)
1916 copy_ah_attr_from_uverbs(qp->device, &attr->ah_attr,
1919 if (cmd->base.attr_mask & IB_QP_ALT_PATH)
1920 copy_ah_attr_from_uverbs(qp->device, &attr->alt_ah_attr,
1921 &cmd->base.alt_dest);
1923 ret = ib_modify_qp_with_udata(qp, attr,
1924 modify_qp_mask(qp->qp_type,
1925 cmd->base.attr_mask),
1926 &attrs->driver_udata);
1929 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
1930 UVERBS_LOOKUP_READ);
1937 static int ib_uverbs_modify_qp(struct uverbs_attr_bundle *attrs)
1939 struct ib_uverbs_ex_modify_qp cmd;
1942 ret = uverbs_request(attrs, &cmd.base, sizeof(cmd.base));
1946 if (cmd.base.attr_mask & ~IB_QP_ATTR_STANDARD_BITS)
1949 return modify_qp(attrs, &cmd);
1952 static int ib_uverbs_ex_modify_qp(struct uverbs_attr_bundle *attrs)
1954 struct ib_uverbs_ex_modify_qp cmd;
1955 struct ib_uverbs_ex_modify_qp_resp resp = {
1956 .response_length = uverbs_response_length(attrs, sizeof(resp))
1960 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1965 * Last bit is reserved for extending the attr_mask by
1966 * using another field.
1968 if (cmd.base.attr_mask & ~(IB_QP_ATTR_STANDARD_BITS | IB_QP_RATE_LIMIT))
1971 ret = modify_qp(attrs, &cmd);
1975 return uverbs_response(attrs, &resp, sizeof(resp));
1978 static int ib_uverbs_destroy_qp(struct uverbs_attr_bundle *attrs)
1980 struct ib_uverbs_destroy_qp cmd;
1981 struct ib_uverbs_destroy_qp_resp resp;
1982 struct ib_uobject *uobj;
1983 struct ib_uqp_object *obj;
1986 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
1990 uobj = uobj_get_destroy(UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
1992 return PTR_ERR(uobj);
1994 obj = container_of(uobj, struct ib_uqp_object, uevent.uobject);
1995 memset(&resp, 0, sizeof(resp));
1996 resp.events_reported = obj->uevent.events_reported;
1998 uobj_put_destroy(uobj);
2000 return uverbs_response(attrs, &resp, sizeof(resp));
2003 static void *alloc_wr(size_t wr_size, __u32 num_sge)
2005 if (num_sge >= (U32_MAX - ALIGN(wr_size, sizeof(struct ib_sge))) /
2006 sizeof(struct ib_sge))
2009 return kmalloc(ALIGN(wr_size, sizeof(struct ib_sge)) +
2010 num_sge * sizeof(struct ib_sge),
2014 static int ib_uverbs_post_send(struct uverbs_attr_bundle *attrs)
2016 struct ib_uverbs_post_send cmd;
2017 struct ib_uverbs_post_send_resp resp;
2018 struct ib_uverbs_send_wr *user_wr;
2019 struct ib_send_wr *wr = NULL, *last, *next;
2020 const struct ib_send_wr *bad_wr;
2026 const struct ib_sge __user *sgls;
2027 const void __user *wqes;
2028 struct uverbs_req_iter iter;
2030 ret = uverbs_request_start(attrs, &iter, &cmd, sizeof(cmd));
2033 wqes = uverbs_request_next_ptr(&iter, cmd.wqe_size * cmd.wr_count);
2035 return PTR_ERR(wqes);
2036 sgls = uverbs_request_next_ptr(
2037 &iter, cmd.sge_count * sizeof(struct ib_uverbs_sge));
2039 return PTR_ERR(sgls);
2040 ret = uverbs_request_finish(&iter);
2044 user_wr = kmalloc(cmd.wqe_size, GFP_KERNEL);
2048 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
2054 is_ud = qp->qp_type == IB_QPT_UD;
2057 for (i = 0; i < cmd.wr_count; ++i) {
2058 if (copy_from_user(user_wr, wqes + i * cmd.wqe_size,
2064 if (user_wr->num_sge + sg_ind > cmd.sge_count) {
2070 struct ib_ud_wr *ud;
2072 if (user_wr->opcode != IB_WR_SEND &&
2073 user_wr->opcode != IB_WR_SEND_WITH_IMM) {
2078 next_size = sizeof(*ud);
2079 ud = alloc_wr(next_size, user_wr->num_sge);
2085 ud->ah = uobj_get_obj_read(ah, UVERBS_OBJECT_AH,
2086 user_wr->wr.ud.ah, attrs);
2092 ud->remote_qpn = user_wr->wr.ud.remote_qpn;
2093 ud->remote_qkey = user_wr->wr.ud.remote_qkey;
2096 } else if (user_wr->opcode == IB_WR_RDMA_WRITE_WITH_IMM ||
2097 user_wr->opcode == IB_WR_RDMA_WRITE ||
2098 user_wr->opcode == IB_WR_RDMA_READ) {
2099 struct ib_rdma_wr *rdma;
2101 next_size = sizeof(*rdma);
2102 rdma = alloc_wr(next_size, user_wr->num_sge);
2108 rdma->remote_addr = user_wr->wr.rdma.remote_addr;
2109 rdma->rkey = user_wr->wr.rdma.rkey;
2112 } else if (user_wr->opcode == IB_WR_ATOMIC_CMP_AND_SWP ||
2113 user_wr->opcode == IB_WR_ATOMIC_FETCH_AND_ADD) {
2114 struct ib_atomic_wr *atomic;
2116 next_size = sizeof(*atomic);
2117 atomic = alloc_wr(next_size, user_wr->num_sge);
2123 atomic->remote_addr = user_wr->wr.atomic.remote_addr;
2124 atomic->compare_add = user_wr->wr.atomic.compare_add;
2125 atomic->swap = user_wr->wr.atomic.swap;
2126 atomic->rkey = user_wr->wr.atomic.rkey;
2129 } else if (user_wr->opcode == IB_WR_SEND ||
2130 user_wr->opcode == IB_WR_SEND_WITH_IMM ||
2131 user_wr->opcode == IB_WR_SEND_WITH_INV) {
2132 next_size = sizeof(*next);
2133 next = alloc_wr(next_size, user_wr->num_sge);
2143 if (user_wr->opcode == IB_WR_SEND_WITH_IMM ||
2144 user_wr->opcode == IB_WR_RDMA_WRITE_WITH_IMM) {
2146 (__be32 __force) user_wr->ex.imm_data;
2147 } else if (user_wr->opcode == IB_WR_SEND_WITH_INV) {
2148 next->ex.invalidate_rkey = user_wr->ex.invalidate_rkey;
2158 next->wr_id = user_wr->wr_id;
2159 next->num_sge = user_wr->num_sge;
2160 next->opcode = user_wr->opcode;
2161 next->send_flags = user_wr->send_flags;
2163 if (next->num_sge) {
2164 next->sg_list = (void *) next +
2165 ALIGN(next_size, sizeof(struct ib_sge));
2166 if (copy_from_user(next->sg_list, sgls + sg_ind,
2168 sizeof(struct ib_sge))) {
2172 sg_ind += next->num_sge;
2174 next->sg_list = NULL;
2178 ret = qp->device->ops.post_send(qp->real_qp, wr, &bad_wr);
2180 for (next = wr; next; next = next->next) {
2186 ret2 = uverbs_response(attrs, &resp, sizeof(resp));
2191 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
2192 UVERBS_LOOKUP_READ);
2195 if (is_ud && ud_wr(wr)->ah)
2196 uobj_put_obj_read(ud_wr(wr)->ah);
2208 static struct ib_recv_wr *
2209 ib_uverbs_unmarshall_recv(struct uverbs_req_iter *iter, u32 wr_count,
2210 u32 wqe_size, u32 sge_count)
2212 struct ib_uverbs_recv_wr *user_wr;
2213 struct ib_recv_wr *wr = NULL, *last, *next;
2217 const struct ib_sge __user *sgls;
2218 const void __user *wqes;
2220 if (wqe_size < sizeof(struct ib_uverbs_recv_wr))
2221 return ERR_PTR(-EINVAL);
2223 wqes = uverbs_request_next_ptr(iter, wqe_size * wr_count);
2225 return ERR_CAST(wqes);
2226 sgls = uverbs_request_next_ptr(
2227 iter, sge_count * sizeof(struct ib_uverbs_sge));
2229 return ERR_CAST(sgls);
2230 ret = uverbs_request_finish(iter);
2232 return ERR_PTR(ret);
2234 user_wr = kmalloc(wqe_size, GFP_KERNEL);
2236 return ERR_PTR(-ENOMEM);
2240 for (i = 0; i < wr_count; ++i) {
2241 if (copy_from_user(user_wr, wqes + i * wqe_size,
2247 if (user_wr->num_sge + sg_ind > sge_count) {
2252 if (user_wr->num_sge >=
2253 (U32_MAX - ALIGN(sizeof(*next), sizeof(struct ib_sge))) /
2254 sizeof(struct ib_sge)) {
2259 next = kmalloc(ALIGN(sizeof(*next), sizeof(struct ib_sge)) +
2260 user_wr->num_sge * sizeof(struct ib_sge),
2274 next->wr_id = user_wr->wr_id;
2275 next->num_sge = user_wr->num_sge;
2277 if (next->num_sge) {
2278 next->sg_list = (void *)next +
2279 ALIGN(sizeof(*next), sizeof(struct ib_sge));
2280 if (copy_from_user(next->sg_list, sgls + sg_ind,
2282 sizeof(struct ib_sge))) {
2286 sg_ind += next->num_sge;
2288 next->sg_list = NULL;
2303 return ERR_PTR(ret);
2306 static int ib_uverbs_post_recv(struct uverbs_attr_bundle *attrs)
2308 struct ib_uverbs_post_recv cmd;
2309 struct ib_uverbs_post_recv_resp resp;
2310 struct ib_recv_wr *wr, *next;
2311 const struct ib_recv_wr *bad_wr;
2314 struct uverbs_req_iter iter;
2316 ret = uverbs_request_start(attrs, &iter, &cmd, sizeof(cmd));
2320 wr = ib_uverbs_unmarshall_recv(&iter, cmd.wr_count, cmd.wqe_size,
2325 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
2332 ret = qp->device->ops.post_recv(qp->real_qp, wr, &bad_wr);
2334 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
2335 UVERBS_LOOKUP_READ);
2337 for (next = wr; next; next = next->next) {
2344 ret2 = uverbs_response(attrs, &resp, sizeof(resp));
2357 static int ib_uverbs_post_srq_recv(struct uverbs_attr_bundle *attrs)
2359 struct ib_uverbs_post_srq_recv cmd;
2360 struct ib_uverbs_post_srq_recv_resp resp;
2361 struct ib_recv_wr *wr, *next;
2362 const struct ib_recv_wr *bad_wr;
2365 struct uverbs_req_iter iter;
2367 ret = uverbs_request_start(attrs, &iter, &cmd, sizeof(cmd));
2371 wr = ib_uverbs_unmarshall_recv(&iter, cmd.wr_count, cmd.wqe_size,
2376 srq = uobj_get_obj_read(srq, UVERBS_OBJECT_SRQ, cmd.srq_handle, attrs);
2383 ret = srq->device->ops.post_srq_recv(srq, wr, &bad_wr);
2385 rdma_lookup_put_uobject(&srq->uobject->uevent.uobject,
2386 UVERBS_LOOKUP_READ);
2389 for (next = wr; next; next = next->next) {
2395 ret2 = uverbs_response(attrs, &resp, sizeof(resp));
2409 static int ib_uverbs_create_ah(struct uverbs_attr_bundle *attrs)
2411 struct ib_uverbs_create_ah cmd;
2412 struct ib_uverbs_create_ah_resp resp;
2413 struct ib_uobject *uobj;
2416 struct rdma_ah_attr attr = {};
2418 struct ib_device *ib_dev;
2420 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
2424 uobj = uobj_alloc(UVERBS_OBJECT_AH, attrs, &ib_dev);
2426 return PTR_ERR(uobj);
2428 if (!rdma_is_port_valid(ib_dev, cmd.attr.port_num)) {
2433 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, attrs);
2439 attr.type = rdma_ah_find_type(ib_dev, cmd.attr.port_num);
2440 rdma_ah_set_make_grd(&attr, false);
2441 rdma_ah_set_dlid(&attr, cmd.attr.dlid);
2442 rdma_ah_set_sl(&attr, cmd.attr.sl);
2443 rdma_ah_set_path_bits(&attr, cmd.attr.src_path_bits);
2444 rdma_ah_set_static_rate(&attr, cmd.attr.static_rate);
2445 rdma_ah_set_port_num(&attr, cmd.attr.port_num);
2447 if (cmd.attr.is_global) {
2448 rdma_ah_set_grh(&attr, NULL, cmd.attr.grh.flow_label,
2449 cmd.attr.grh.sgid_index,
2450 cmd.attr.grh.hop_limit,
2451 cmd.attr.grh.traffic_class);
2452 rdma_ah_set_dgid_raw(&attr, cmd.attr.grh.dgid);
2454 rdma_ah_set_ah_flags(&attr, 0);
2457 ah = rdma_create_user_ah(pd, &attr, &attrs->driver_udata);
2464 uobj->user_handle = cmd.user_handle;
2466 uobj_put_obj_read(pd);
2467 uobj_finalize_uobj_create(uobj, attrs);
2469 resp.ah_handle = uobj->id;
2470 return uverbs_response(attrs, &resp, sizeof(resp));
2473 uobj_put_obj_read(pd);
2475 uobj_alloc_abort(uobj, attrs);
2479 static int ib_uverbs_destroy_ah(struct uverbs_attr_bundle *attrs)
2481 struct ib_uverbs_destroy_ah cmd;
2484 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
2488 return uobj_perform_destroy(UVERBS_OBJECT_AH, cmd.ah_handle, attrs);
2491 static int ib_uverbs_attach_mcast(struct uverbs_attr_bundle *attrs)
2493 struct ib_uverbs_attach_mcast cmd;
2495 struct ib_uqp_object *obj;
2496 struct ib_uverbs_mcast_entry *mcast;
2499 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
2503 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
2509 mutex_lock(&obj->mcast_lock);
2510 list_for_each_entry(mcast, &obj->mcast_list, list)
2511 if (cmd.mlid == mcast->lid &&
2512 !memcmp(cmd.gid, mcast->gid.raw, sizeof mcast->gid.raw)) {
2517 mcast = kmalloc(sizeof *mcast, GFP_KERNEL);
2523 mcast->lid = cmd.mlid;
2524 memcpy(mcast->gid.raw, cmd.gid, sizeof mcast->gid.raw);
2526 ret = ib_attach_mcast(qp, &mcast->gid, cmd.mlid);
2528 list_add_tail(&mcast->list, &obj->mcast_list);
2533 mutex_unlock(&obj->mcast_lock);
2534 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
2535 UVERBS_LOOKUP_READ);
2540 static int ib_uverbs_detach_mcast(struct uverbs_attr_bundle *attrs)
2542 struct ib_uverbs_detach_mcast cmd;
2543 struct ib_uqp_object *obj;
2545 struct ib_uverbs_mcast_entry *mcast;
2549 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
2553 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
2558 mutex_lock(&obj->mcast_lock);
2560 list_for_each_entry(mcast, &obj->mcast_list, list)
2561 if (cmd.mlid == mcast->lid &&
2562 !memcmp(cmd.gid, mcast->gid.raw, sizeof mcast->gid.raw)) {
2563 list_del(&mcast->list);
2574 ret = ib_detach_mcast(qp, (union ib_gid *)cmd.gid, cmd.mlid);
2577 mutex_unlock(&obj->mcast_lock);
2578 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
2579 UVERBS_LOOKUP_READ);
2583 struct ib_uflow_resources *flow_resources_alloc(size_t num_specs)
2585 struct ib_uflow_resources *resources;
2587 resources = kzalloc(sizeof(*resources), GFP_KERNEL);
2595 resources->counters =
2596 kcalloc(num_specs, sizeof(*resources->counters), GFP_KERNEL);
2597 resources->collection =
2598 kcalloc(num_specs, sizeof(*resources->collection), GFP_KERNEL);
2600 if (!resources->counters || !resources->collection)
2604 resources->max = num_specs;
2608 kfree(resources->counters);
2613 EXPORT_SYMBOL(flow_resources_alloc);
2615 void ib_uverbs_flow_resources_free(struct ib_uflow_resources *uflow_res)
2622 for (i = 0; i < uflow_res->collection_num; i++)
2623 atomic_dec(&uflow_res->collection[i]->usecnt);
2625 for (i = 0; i < uflow_res->counters_num; i++)
2626 atomic_dec(&uflow_res->counters[i]->usecnt);
2628 kfree(uflow_res->collection);
2629 kfree(uflow_res->counters);
2632 EXPORT_SYMBOL(ib_uverbs_flow_resources_free);
2634 void flow_resources_add(struct ib_uflow_resources *uflow_res,
2635 enum ib_flow_spec_type type,
2638 WARN_ON(uflow_res->num >= uflow_res->max);
2641 case IB_FLOW_SPEC_ACTION_HANDLE:
2642 atomic_inc(&((struct ib_flow_action *)ibobj)->usecnt);
2643 uflow_res->collection[uflow_res->collection_num++] =
2644 (struct ib_flow_action *)ibobj;
2646 case IB_FLOW_SPEC_ACTION_COUNT:
2647 atomic_inc(&((struct ib_counters *)ibobj)->usecnt);
2648 uflow_res->counters[uflow_res->counters_num++] =
2649 (struct ib_counters *)ibobj;
2657 EXPORT_SYMBOL(flow_resources_add);
2659 static int kern_spec_to_ib_spec_action(struct uverbs_attr_bundle *attrs,
2660 struct ib_uverbs_flow_spec *kern_spec,
2661 union ib_flow_spec *ib_spec,
2662 struct ib_uflow_resources *uflow_res)
2664 ib_spec->type = kern_spec->type;
2665 switch (ib_spec->type) {
2666 case IB_FLOW_SPEC_ACTION_TAG:
2667 if (kern_spec->flow_tag.size !=
2668 sizeof(struct ib_uverbs_flow_spec_action_tag))
2671 ib_spec->flow_tag.size = sizeof(struct ib_flow_spec_action_tag);
2672 ib_spec->flow_tag.tag_id = kern_spec->flow_tag.tag_id;
2674 case IB_FLOW_SPEC_ACTION_DROP:
2675 if (kern_spec->drop.size !=
2676 sizeof(struct ib_uverbs_flow_spec_action_drop))
2679 ib_spec->drop.size = sizeof(struct ib_flow_spec_action_drop);
2681 case IB_FLOW_SPEC_ACTION_HANDLE:
2682 if (kern_spec->action.size !=
2683 sizeof(struct ib_uverbs_flow_spec_action_handle))
2685 ib_spec->action.act = uobj_get_obj_read(flow_action,
2686 UVERBS_OBJECT_FLOW_ACTION,
2687 kern_spec->action.handle,
2689 if (!ib_spec->action.act)
2691 ib_spec->action.size =
2692 sizeof(struct ib_flow_spec_action_handle);
2693 flow_resources_add(uflow_res,
2694 IB_FLOW_SPEC_ACTION_HANDLE,
2695 ib_spec->action.act);
2696 uobj_put_obj_read(ib_spec->action.act);
2698 case IB_FLOW_SPEC_ACTION_COUNT:
2699 if (kern_spec->flow_count.size !=
2700 sizeof(struct ib_uverbs_flow_spec_action_count))
2702 ib_spec->flow_count.counters =
2703 uobj_get_obj_read(counters,
2704 UVERBS_OBJECT_COUNTERS,
2705 kern_spec->flow_count.handle,
2707 if (!ib_spec->flow_count.counters)
2709 ib_spec->flow_count.size =
2710 sizeof(struct ib_flow_spec_action_count);
2711 flow_resources_add(uflow_res,
2712 IB_FLOW_SPEC_ACTION_COUNT,
2713 ib_spec->flow_count.counters);
2714 uobj_put_obj_read(ib_spec->flow_count.counters);
2722 static ssize_t spec_filter_size(const void *kern_spec_filter, u16 kern_filter_size,
2723 u16 ib_real_filter_sz)
2726 * User space filter structures must be 64 bit aligned, otherwise this
2727 * may pass, but we won't handle additional new attributes.
2730 if (kern_filter_size > ib_real_filter_sz) {
2731 if (memchr_inv(kern_spec_filter +
2732 ib_real_filter_sz, 0,
2733 kern_filter_size - ib_real_filter_sz))
2735 return ib_real_filter_sz;
2737 return kern_filter_size;
2740 int ib_uverbs_kern_spec_to_ib_spec_filter(enum ib_flow_spec_type type,
2741 const void *kern_spec_mask,
2742 const void *kern_spec_val,
2743 size_t kern_filter_sz,
2744 union ib_flow_spec *ib_spec)
2746 ssize_t actual_filter_sz;
2747 ssize_t ib_filter_sz;
2749 /* User flow spec size must be aligned to 4 bytes */
2750 if (kern_filter_sz != ALIGN(kern_filter_sz, 4))
2753 ib_spec->type = type;
2755 if (ib_spec->type == (IB_FLOW_SPEC_INNER | IB_FLOW_SPEC_VXLAN_TUNNEL))
2758 switch (ib_spec->type & ~IB_FLOW_SPEC_INNER) {
2759 case IB_FLOW_SPEC_ETH:
2760 ib_filter_sz = offsetof(struct ib_flow_eth_filter, real_sz);
2761 actual_filter_sz = spec_filter_size(kern_spec_mask,
2764 if (actual_filter_sz <= 0)
2766 ib_spec->size = sizeof(struct ib_flow_spec_eth);
2767 memcpy(&ib_spec->eth.val, kern_spec_val, actual_filter_sz);
2768 memcpy(&ib_spec->eth.mask, kern_spec_mask, actual_filter_sz);
2770 case IB_FLOW_SPEC_IPV4:
2771 ib_filter_sz = offsetof(struct ib_flow_ipv4_filter, real_sz);
2772 actual_filter_sz = spec_filter_size(kern_spec_mask,
2775 if (actual_filter_sz <= 0)
2777 ib_spec->size = sizeof(struct ib_flow_spec_ipv4);
2778 memcpy(&ib_spec->ipv4.val, kern_spec_val, actual_filter_sz);
2779 memcpy(&ib_spec->ipv4.mask, kern_spec_mask, actual_filter_sz);
2781 case IB_FLOW_SPEC_IPV6:
2782 ib_filter_sz = offsetof(struct ib_flow_ipv6_filter, real_sz);
2783 actual_filter_sz = spec_filter_size(kern_spec_mask,
2786 if (actual_filter_sz <= 0)
2788 ib_spec->size = sizeof(struct ib_flow_spec_ipv6);
2789 memcpy(&ib_spec->ipv6.val, kern_spec_val, actual_filter_sz);
2790 memcpy(&ib_spec->ipv6.mask, kern_spec_mask, actual_filter_sz);
2792 if ((ntohl(ib_spec->ipv6.mask.flow_label)) >= BIT(20) ||
2793 (ntohl(ib_spec->ipv6.val.flow_label)) >= BIT(20))
2796 case IB_FLOW_SPEC_TCP:
2797 case IB_FLOW_SPEC_UDP:
2798 ib_filter_sz = offsetof(struct ib_flow_tcp_udp_filter, real_sz);
2799 actual_filter_sz = spec_filter_size(kern_spec_mask,
2802 if (actual_filter_sz <= 0)
2804 ib_spec->size = sizeof(struct ib_flow_spec_tcp_udp);
2805 memcpy(&ib_spec->tcp_udp.val, kern_spec_val, actual_filter_sz);
2806 memcpy(&ib_spec->tcp_udp.mask, kern_spec_mask, actual_filter_sz);
2808 case IB_FLOW_SPEC_VXLAN_TUNNEL:
2809 ib_filter_sz = offsetof(struct ib_flow_tunnel_filter, real_sz);
2810 actual_filter_sz = spec_filter_size(kern_spec_mask,
2813 if (actual_filter_sz <= 0)
2815 ib_spec->tunnel.size = sizeof(struct ib_flow_spec_tunnel);
2816 memcpy(&ib_spec->tunnel.val, kern_spec_val, actual_filter_sz);
2817 memcpy(&ib_spec->tunnel.mask, kern_spec_mask, actual_filter_sz);
2819 if ((ntohl(ib_spec->tunnel.mask.tunnel_id)) >= BIT(24) ||
2820 (ntohl(ib_spec->tunnel.val.tunnel_id)) >= BIT(24))
2823 case IB_FLOW_SPEC_ESP:
2824 ib_filter_sz = offsetof(struct ib_flow_esp_filter, real_sz);
2825 actual_filter_sz = spec_filter_size(kern_spec_mask,
2828 if (actual_filter_sz <= 0)
2830 ib_spec->esp.size = sizeof(struct ib_flow_spec_esp);
2831 memcpy(&ib_spec->esp.val, kern_spec_val, actual_filter_sz);
2832 memcpy(&ib_spec->esp.mask, kern_spec_mask, actual_filter_sz);
2834 case IB_FLOW_SPEC_GRE:
2835 ib_filter_sz = offsetof(struct ib_flow_gre_filter, real_sz);
2836 actual_filter_sz = spec_filter_size(kern_spec_mask,
2839 if (actual_filter_sz <= 0)
2841 ib_spec->gre.size = sizeof(struct ib_flow_spec_gre);
2842 memcpy(&ib_spec->gre.val, kern_spec_val, actual_filter_sz);
2843 memcpy(&ib_spec->gre.mask, kern_spec_mask, actual_filter_sz);
2845 case IB_FLOW_SPEC_MPLS:
2846 ib_filter_sz = offsetof(struct ib_flow_mpls_filter, real_sz);
2847 actual_filter_sz = spec_filter_size(kern_spec_mask,
2850 if (actual_filter_sz <= 0)
2852 ib_spec->mpls.size = sizeof(struct ib_flow_spec_mpls);
2853 memcpy(&ib_spec->mpls.val, kern_spec_val, actual_filter_sz);
2854 memcpy(&ib_spec->mpls.mask, kern_spec_mask, actual_filter_sz);
2862 static int kern_spec_to_ib_spec_filter(struct ib_uverbs_flow_spec *kern_spec,
2863 union ib_flow_spec *ib_spec)
2865 size_t kern_filter_sz;
2866 void *kern_spec_mask;
2867 void *kern_spec_val;
2869 if (check_sub_overflow((size_t)kern_spec->hdr.size,
2870 sizeof(struct ib_uverbs_flow_spec_hdr),
2874 kern_filter_sz /= 2;
2876 kern_spec_val = (void *)kern_spec +
2877 sizeof(struct ib_uverbs_flow_spec_hdr);
2878 kern_spec_mask = kern_spec_val + kern_filter_sz;
2880 return ib_uverbs_kern_spec_to_ib_spec_filter(kern_spec->type,
2883 kern_filter_sz, ib_spec);
2886 static int kern_spec_to_ib_spec(struct uverbs_attr_bundle *attrs,
2887 struct ib_uverbs_flow_spec *kern_spec,
2888 union ib_flow_spec *ib_spec,
2889 struct ib_uflow_resources *uflow_res)
2891 if (kern_spec->reserved)
2894 if (kern_spec->type >= IB_FLOW_SPEC_ACTION_TAG)
2895 return kern_spec_to_ib_spec_action(attrs, kern_spec, ib_spec,
2898 return kern_spec_to_ib_spec_filter(kern_spec, ib_spec);
2901 static int ib_uverbs_ex_create_wq(struct uverbs_attr_bundle *attrs)
2903 struct ib_uverbs_ex_create_wq cmd;
2904 struct ib_uverbs_ex_create_wq_resp resp = {};
2905 struct ib_uwq_object *obj;
2910 struct ib_wq_init_attr wq_init_attr = {};
2911 struct ib_device *ib_dev;
2913 err = uverbs_request(attrs, &cmd, sizeof(cmd));
2920 obj = (struct ib_uwq_object *)uobj_alloc(UVERBS_OBJECT_WQ, attrs,
2923 return PTR_ERR(obj);
2925 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd.pd_handle, attrs);
2931 cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs);
2937 wq_init_attr.cq = cq;
2938 wq_init_attr.max_sge = cmd.max_sge;
2939 wq_init_attr.max_wr = cmd.max_wr;
2940 wq_init_attr.wq_type = cmd.wq_type;
2941 wq_init_attr.event_handler = ib_uverbs_wq_event_handler;
2942 wq_init_attr.create_flags = cmd.create_flags;
2943 INIT_LIST_HEAD(&obj->uevent.event_list);
2944 obj->uevent.uobject.user_handle = cmd.user_handle;
2946 wq = pd->device->ops.create_wq(pd, &wq_init_attr, &attrs->driver_udata);
2953 obj->uevent.uobject.object = wq;
2954 wq->wq_type = wq_init_attr.wq_type;
2957 wq->device = pd->device;
2958 atomic_set(&wq->usecnt, 0);
2959 atomic_inc(&pd->usecnt);
2960 atomic_inc(&cq->usecnt);
2961 obj->uevent.event_file = READ_ONCE(attrs->ufile->default_async_file);
2962 if (obj->uevent.event_file)
2963 uverbs_uobject_get(&obj->uevent.event_file->uobj);
2965 uobj_put_obj_read(pd);
2966 rdma_lookup_put_uobject(&cq->uobject->uevent.uobject,
2967 UVERBS_LOOKUP_READ);
2968 uobj_finalize_uobj_create(&obj->uevent.uobject, attrs);
2970 resp.wq_handle = obj->uevent.uobject.id;
2971 resp.max_sge = wq_init_attr.max_sge;
2972 resp.max_wr = wq_init_attr.max_wr;
2973 resp.wqn = wq->wq_num;
2974 resp.response_length = uverbs_response_length(attrs, sizeof(resp));
2975 return uverbs_response(attrs, &resp, sizeof(resp));
2978 rdma_lookup_put_uobject(&cq->uobject->uevent.uobject,
2979 UVERBS_LOOKUP_READ);
2981 uobj_put_obj_read(pd);
2983 uobj_alloc_abort(&obj->uevent.uobject, attrs);
2988 static int ib_uverbs_ex_destroy_wq(struct uverbs_attr_bundle *attrs)
2990 struct ib_uverbs_ex_destroy_wq cmd;
2991 struct ib_uverbs_ex_destroy_wq_resp resp = {};
2992 struct ib_uobject *uobj;
2993 struct ib_uwq_object *obj;
2996 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3003 resp.response_length = uverbs_response_length(attrs, sizeof(resp));
3004 uobj = uobj_get_destroy(UVERBS_OBJECT_WQ, cmd.wq_handle, attrs);
3006 return PTR_ERR(uobj);
3008 obj = container_of(uobj, struct ib_uwq_object, uevent.uobject);
3009 resp.events_reported = obj->uevent.events_reported;
3011 uobj_put_destroy(uobj);
3013 return uverbs_response(attrs, &resp, sizeof(resp));
3016 static int ib_uverbs_ex_modify_wq(struct uverbs_attr_bundle *attrs)
3018 struct ib_uverbs_ex_modify_wq cmd;
3020 struct ib_wq_attr wq_attr = {};
3023 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3030 if (cmd.attr_mask > (IB_WQ_STATE | IB_WQ_CUR_STATE | IB_WQ_FLAGS))
3033 wq = uobj_get_obj_read(wq, UVERBS_OBJECT_WQ, cmd.wq_handle, attrs);
3037 wq_attr.curr_wq_state = cmd.curr_wq_state;
3038 wq_attr.wq_state = cmd.wq_state;
3039 if (cmd.attr_mask & IB_WQ_FLAGS) {
3040 wq_attr.flags = cmd.flags;
3041 wq_attr.flags_mask = cmd.flags_mask;
3043 ret = wq->device->ops.modify_wq(wq, &wq_attr, cmd.attr_mask,
3044 &attrs->driver_udata);
3045 rdma_lookup_put_uobject(&wq->uobject->uevent.uobject,
3046 UVERBS_LOOKUP_READ);
3050 static int ib_uverbs_ex_create_rwq_ind_table(struct uverbs_attr_bundle *attrs)
3052 struct ib_uverbs_ex_create_rwq_ind_table cmd;
3053 struct ib_uverbs_ex_create_rwq_ind_table_resp resp = {};
3054 struct ib_uobject *uobj;
3056 struct ib_rwq_ind_table_init_attr init_attr = {};
3057 struct ib_rwq_ind_table *rwq_ind_tbl;
3058 struct ib_wq **wqs = NULL;
3059 u32 *wqs_handles = NULL;
3060 struct ib_wq *wq = NULL;
3061 int i, num_read_wqs;
3063 struct uverbs_req_iter iter;
3064 struct ib_device *ib_dev;
3066 err = uverbs_request_start(attrs, &iter, &cmd, sizeof(cmd));
3073 if (cmd.log_ind_tbl_size > IB_USER_VERBS_MAX_LOG_IND_TBL_SIZE)
3076 num_wq_handles = 1 << cmd.log_ind_tbl_size;
3077 wqs_handles = kcalloc(num_wq_handles, sizeof(*wqs_handles),
3082 err = uverbs_request_next(&iter, wqs_handles,
3083 num_wq_handles * sizeof(__u32));
3087 err = uverbs_request_finish(&iter);
3091 wqs = kcalloc(num_wq_handles, sizeof(*wqs), GFP_KERNEL);
3097 for (num_read_wqs = 0; num_read_wqs < num_wq_handles;
3099 wq = uobj_get_obj_read(wq, UVERBS_OBJECT_WQ,
3100 wqs_handles[num_read_wqs], attrs);
3106 wqs[num_read_wqs] = wq;
3107 atomic_inc(&wqs[num_read_wqs]->usecnt);
3110 uobj = uobj_alloc(UVERBS_OBJECT_RWQ_IND_TBL, attrs, &ib_dev);
3112 err = PTR_ERR(uobj);
3116 rwq_ind_tbl = rdma_zalloc_drv_obj(ib_dev, ib_rwq_ind_table);
3122 init_attr.log_ind_tbl_size = cmd.log_ind_tbl_size;
3123 init_attr.ind_tbl = wqs;
3125 rwq_ind_tbl->ind_tbl = wqs;
3126 rwq_ind_tbl->log_ind_tbl_size = init_attr.log_ind_tbl_size;
3127 rwq_ind_tbl->uobject = uobj;
3128 uobj->object = rwq_ind_tbl;
3129 rwq_ind_tbl->device = ib_dev;
3130 atomic_set(&rwq_ind_tbl->usecnt, 0);
3132 err = ib_dev->ops.create_rwq_ind_table(rwq_ind_tbl, &init_attr,
3133 &attrs->driver_udata);
3137 for (i = 0; i < num_wq_handles; i++)
3138 rdma_lookup_put_uobject(&wqs[i]->uobject->uevent.uobject,
3139 UVERBS_LOOKUP_READ);
3141 uobj_finalize_uobj_create(uobj, attrs);
3143 resp.ind_tbl_handle = uobj->id;
3144 resp.ind_tbl_num = rwq_ind_tbl->ind_tbl_num;
3145 resp.response_length = uverbs_response_length(attrs, sizeof(resp));
3146 return uverbs_response(attrs, &resp, sizeof(resp));
3151 uobj_alloc_abort(uobj, attrs);
3153 for (i = 0; i < num_read_wqs; i++) {
3154 rdma_lookup_put_uobject(&wqs[i]->uobject->uevent.uobject,
3155 UVERBS_LOOKUP_READ);
3156 atomic_dec(&wqs[i]->usecnt);
3164 static int ib_uverbs_ex_destroy_rwq_ind_table(struct uverbs_attr_bundle *attrs)
3166 struct ib_uverbs_ex_destroy_rwq_ind_table cmd;
3169 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3176 return uobj_perform_destroy(UVERBS_OBJECT_RWQ_IND_TBL,
3177 cmd.ind_tbl_handle, attrs);
3180 static int ib_uverbs_ex_create_flow(struct uverbs_attr_bundle *attrs)
3182 struct ib_uverbs_create_flow cmd;
3183 struct ib_uverbs_create_flow_resp resp = {};
3184 struct ib_uobject *uobj;
3185 struct ib_flow *flow_id;
3186 struct ib_uverbs_flow_attr *kern_flow_attr;
3187 struct ib_flow_attr *flow_attr;
3189 struct ib_uflow_resources *uflow_res;
3190 struct ib_uverbs_flow_spec_hdr *kern_spec;
3191 struct uverbs_req_iter iter;
3195 struct ib_device *ib_dev;
3197 err = uverbs_request_start(attrs, &iter, &cmd, sizeof(cmd));
3204 if (!capable(CAP_NET_RAW))
3207 if (cmd.flow_attr.flags >= IB_FLOW_ATTR_FLAGS_RESERVED)
3210 if ((cmd.flow_attr.flags & IB_FLOW_ATTR_FLAGS_DONT_TRAP) &&
3211 ((cmd.flow_attr.type == IB_FLOW_ATTR_ALL_DEFAULT) ||
3212 (cmd.flow_attr.type == IB_FLOW_ATTR_MC_DEFAULT)))
3215 if (cmd.flow_attr.num_of_specs > IB_FLOW_SPEC_SUPPORT_LAYERS)
3218 if (cmd.flow_attr.size >
3219 (cmd.flow_attr.num_of_specs * sizeof(struct ib_uverbs_flow_spec)))
3222 if (cmd.flow_attr.reserved[0] ||
3223 cmd.flow_attr.reserved[1])
3226 if (cmd.flow_attr.num_of_specs) {
3227 kern_flow_attr = kmalloc(sizeof(*kern_flow_attr) + cmd.flow_attr.size,
3229 if (!kern_flow_attr)
3232 *kern_flow_attr = cmd.flow_attr;
3233 err = uverbs_request_next(&iter, &kern_flow_attr->flow_specs,
3234 cmd.flow_attr.size);
3238 kern_flow_attr = &cmd.flow_attr;
3241 err = uverbs_request_finish(&iter);
3245 uobj = uobj_alloc(UVERBS_OBJECT_FLOW, attrs, &ib_dev);
3247 err = PTR_ERR(uobj);
3251 qp = uobj_get_obj_read(qp, UVERBS_OBJECT_QP, cmd.qp_handle, attrs);
3257 if (qp->qp_type != IB_QPT_UD && qp->qp_type != IB_QPT_RAW_PACKET) {
3262 flow_attr = kzalloc(struct_size(flow_attr, flows,
3263 cmd.flow_attr.num_of_specs), GFP_KERNEL);
3268 uflow_res = flow_resources_alloc(cmd.flow_attr.num_of_specs);
3271 goto err_free_flow_attr;
3274 flow_attr->type = kern_flow_attr->type;
3275 flow_attr->priority = kern_flow_attr->priority;
3276 flow_attr->num_of_specs = kern_flow_attr->num_of_specs;
3277 flow_attr->port = kern_flow_attr->port;
3278 flow_attr->flags = kern_flow_attr->flags;
3279 flow_attr->size = sizeof(*flow_attr);
3281 kern_spec = kern_flow_attr->flow_specs;
3282 ib_spec = flow_attr + 1;
3283 for (i = 0; i < flow_attr->num_of_specs &&
3284 cmd.flow_attr.size >= sizeof(*kern_spec) &&
3285 cmd.flow_attr.size >= kern_spec->size;
3287 err = kern_spec_to_ib_spec(
3288 attrs, (struct ib_uverbs_flow_spec *)kern_spec,
3289 ib_spec, uflow_res);
3294 ((union ib_flow_spec *) ib_spec)->size;
3295 cmd.flow_attr.size -= kern_spec->size;
3296 kern_spec = ((void *)kern_spec) + kern_spec->size;
3297 ib_spec += ((union ib_flow_spec *) ib_spec)->size;
3299 if (cmd.flow_attr.size || (i != flow_attr->num_of_specs)) {
3300 pr_warn("create flow failed, flow %d: %d bytes left from uverb cmd\n",
3301 i, cmd.flow_attr.size);
3306 flow_id = qp->device->ops.create_flow(qp, flow_attr,
3307 &attrs->driver_udata);
3309 if (IS_ERR(flow_id)) {
3310 err = PTR_ERR(flow_id);
3314 ib_set_flow(uobj, flow_id, qp, qp->device, uflow_res);
3316 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
3317 UVERBS_LOOKUP_READ);
3320 if (cmd.flow_attr.num_of_specs)
3321 kfree(kern_flow_attr);
3322 uobj_finalize_uobj_create(uobj, attrs);
3324 resp.flow_handle = uobj->id;
3325 return uverbs_response(attrs, &resp, sizeof(resp));
3328 ib_uverbs_flow_resources_free(uflow_res);
3332 rdma_lookup_put_uobject(&qp->uobject->uevent.uobject,
3333 UVERBS_LOOKUP_READ);
3335 uobj_alloc_abort(uobj, attrs);
3337 if (cmd.flow_attr.num_of_specs)
3338 kfree(kern_flow_attr);
3342 static int ib_uverbs_ex_destroy_flow(struct uverbs_attr_bundle *attrs)
3344 struct ib_uverbs_destroy_flow cmd;
3347 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3354 return uobj_perform_destroy(UVERBS_OBJECT_FLOW, cmd.flow_handle, attrs);
3357 static int __uverbs_create_xsrq(struct uverbs_attr_bundle *attrs,
3358 struct ib_uverbs_create_xsrq *cmd,
3359 struct ib_udata *udata)
3361 struct ib_uverbs_create_srq_resp resp = {};
3362 struct ib_usrq_object *obj;
3365 struct ib_srq_init_attr attr;
3367 struct ib_uobject *xrcd_uobj;
3368 struct ib_device *ib_dev;
3370 obj = (struct ib_usrq_object *)uobj_alloc(UVERBS_OBJECT_SRQ, attrs,
3373 return PTR_ERR(obj);
3375 if (cmd->srq_type == IB_SRQT_TM)
3376 attr.ext.tag_matching.max_num_tags = cmd->max_num_tags;
3378 if (cmd->srq_type == IB_SRQT_XRC) {
3379 xrcd_uobj = uobj_get_read(UVERBS_OBJECT_XRCD, cmd->xrcd_handle,
3381 if (IS_ERR(xrcd_uobj)) {
3386 attr.ext.xrc.xrcd = (struct ib_xrcd *)xrcd_uobj->object;
3387 if (!attr.ext.xrc.xrcd) {
3392 obj->uxrcd = container_of(xrcd_uobj, struct ib_uxrcd_object, uobject);
3393 atomic_inc(&obj->uxrcd->refcnt);
3396 if (ib_srq_has_cq(cmd->srq_type)) {
3397 attr.ext.cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ,
3398 cmd->cq_handle, attrs);
3405 pd = uobj_get_obj_read(pd, UVERBS_OBJECT_PD, cmd->pd_handle, attrs);
3411 attr.event_handler = ib_uverbs_srq_event_handler;
3412 attr.srq_type = cmd->srq_type;
3413 attr.attr.max_wr = cmd->max_wr;
3414 attr.attr.max_sge = cmd->max_sge;
3415 attr.attr.srq_limit = cmd->srq_limit;
3417 INIT_LIST_HEAD(&obj->uevent.event_list);
3418 obj->uevent.uobject.user_handle = cmd->user_handle;
3420 srq = ib_create_srq_user(pd, &attr, obj, udata);
3426 obj->uevent.uobject.object = srq;
3427 obj->uevent.uobject.user_handle = cmd->user_handle;
3428 obj->uevent.event_file = READ_ONCE(attrs->ufile->default_async_file);
3429 if (obj->uevent.event_file)
3430 uverbs_uobject_get(&obj->uevent.event_file->uobj);
3432 if (cmd->srq_type == IB_SRQT_XRC)
3433 resp.srqn = srq->ext.xrc.srq_num;
3435 if (cmd->srq_type == IB_SRQT_XRC)
3436 uobj_put_read(xrcd_uobj);
3438 if (ib_srq_has_cq(cmd->srq_type))
3439 rdma_lookup_put_uobject(&attr.ext.cq->uobject->uevent.uobject,
3440 UVERBS_LOOKUP_READ);
3442 uobj_put_obj_read(pd);
3443 uobj_finalize_uobj_create(&obj->uevent.uobject, attrs);
3445 resp.srq_handle = obj->uevent.uobject.id;
3446 resp.max_wr = attr.attr.max_wr;
3447 resp.max_sge = attr.attr.max_sge;
3448 return uverbs_response(attrs, &resp, sizeof(resp));
3451 uobj_put_obj_read(pd);
3453 if (ib_srq_has_cq(cmd->srq_type))
3454 rdma_lookup_put_uobject(&attr.ext.cq->uobject->uevent.uobject,
3455 UVERBS_LOOKUP_READ);
3458 if (cmd->srq_type == IB_SRQT_XRC) {
3459 atomic_dec(&obj->uxrcd->refcnt);
3460 uobj_put_read(xrcd_uobj);
3464 uobj_alloc_abort(&obj->uevent.uobject, attrs);
3468 static int ib_uverbs_create_srq(struct uverbs_attr_bundle *attrs)
3470 struct ib_uverbs_create_srq cmd;
3471 struct ib_uverbs_create_xsrq xcmd;
3474 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3478 memset(&xcmd, 0, sizeof(xcmd));
3479 xcmd.response = cmd.response;
3480 xcmd.user_handle = cmd.user_handle;
3481 xcmd.srq_type = IB_SRQT_BASIC;
3482 xcmd.pd_handle = cmd.pd_handle;
3483 xcmd.max_wr = cmd.max_wr;
3484 xcmd.max_sge = cmd.max_sge;
3485 xcmd.srq_limit = cmd.srq_limit;
3487 return __uverbs_create_xsrq(attrs, &xcmd, &attrs->driver_udata);
3490 static int ib_uverbs_create_xsrq(struct uverbs_attr_bundle *attrs)
3492 struct ib_uverbs_create_xsrq cmd;
3495 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3499 return __uverbs_create_xsrq(attrs, &cmd, &attrs->driver_udata);
3502 static int ib_uverbs_modify_srq(struct uverbs_attr_bundle *attrs)
3504 struct ib_uverbs_modify_srq cmd;
3506 struct ib_srq_attr attr;
3509 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3513 srq = uobj_get_obj_read(srq, UVERBS_OBJECT_SRQ, cmd.srq_handle, attrs);
3517 attr.max_wr = cmd.max_wr;
3518 attr.srq_limit = cmd.srq_limit;
3520 ret = srq->device->ops.modify_srq(srq, &attr, cmd.attr_mask,
3521 &attrs->driver_udata);
3523 rdma_lookup_put_uobject(&srq->uobject->uevent.uobject,
3524 UVERBS_LOOKUP_READ);
3529 static int ib_uverbs_query_srq(struct uverbs_attr_bundle *attrs)
3531 struct ib_uverbs_query_srq cmd;
3532 struct ib_uverbs_query_srq_resp resp;
3533 struct ib_srq_attr attr;
3537 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3541 srq = uobj_get_obj_read(srq, UVERBS_OBJECT_SRQ, cmd.srq_handle, attrs);
3545 ret = ib_query_srq(srq, &attr);
3547 rdma_lookup_put_uobject(&srq->uobject->uevent.uobject,
3548 UVERBS_LOOKUP_READ);
3553 memset(&resp, 0, sizeof resp);
3555 resp.max_wr = attr.max_wr;
3556 resp.max_sge = attr.max_sge;
3557 resp.srq_limit = attr.srq_limit;
3559 return uverbs_response(attrs, &resp, sizeof(resp));
3562 static int ib_uverbs_destroy_srq(struct uverbs_attr_bundle *attrs)
3564 struct ib_uverbs_destroy_srq cmd;
3565 struct ib_uverbs_destroy_srq_resp resp;
3566 struct ib_uobject *uobj;
3567 struct ib_uevent_object *obj;
3570 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3574 uobj = uobj_get_destroy(UVERBS_OBJECT_SRQ, cmd.srq_handle, attrs);
3576 return PTR_ERR(uobj);
3578 obj = container_of(uobj, struct ib_uevent_object, uobject);
3579 memset(&resp, 0, sizeof(resp));
3580 resp.events_reported = obj->events_reported;
3582 uobj_put_destroy(uobj);
3584 return uverbs_response(attrs, &resp, sizeof(resp));
3587 static int ib_uverbs_ex_query_device(struct uverbs_attr_bundle *attrs)
3589 struct ib_uverbs_ex_query_device_resp resp = {};
3590 struct ib_uverbs_ex_query_device cmd;
3591 struct ib_device_attr attr = {0};
3592 struct ib_ucontext *ucontext;
3593 struct ib_device *ib_dev;
3596 ucontext = ib_uverbs_get_ucontext(attrs);
3597 if (IS_ERR(ucontext))
3598 return PTR_ERR(ucontext);
3599 ib_dev = ucontext->device;
3601 err = uverbs_request(attrs, &cmd, sizeof(cmd));
3611 err = ib_dev->ops.query_device(ib_dev, &attr, &attrs->driver_udata);
3615 copy_query_dev_fields(ucontext, &resp.base, &attr);
3617 resp.odp_caps.general_caps = attr.odp_caps.general_caps;
3618 resp.odp_caps.per_transport_caps.rc_odp_caps =
3619 attr.odp_caps.per_transport_caps.rc_odp_caps;
3620 resp.odp_caps.per_transport_caps.uc_odp_caps =
3621 attr.odp_caps.per_transport_caps.uc_odp_caps;
3622 resp.odp_caps.per_transport_caps.ud_odp_caps =
3623 attr.odp_caps.per_transport_caps.ud_odp_caps;
3624 resp.xrc_odp_caps = attr.odp_caps.per_transport_caps.xrc_odp_caps;
3626 resp.timestamp_mask = attr.timestamp_mask;
3627 resp.hca_core_clock = attr.hca_core_clock;
3628 resp.device_cap_flags_ex = attr.device_cap_flags;
3629 resp.rss_caps.supported_qpts = attr.rss_caps.supported_qpts;
3630 resp.rss_caps.max_rwq_indirection_tables =
3631 attr.rss_caps.max_rwq_indirection_tables;
3632 resp.rss_caps.max_rwq_indirection_table_size =
3633 attr.rss_caps.max_rwq_indirection_table_size;
3634 resp.max_wq_type_rq = attr.max_wq_type_rq;
3635 resp.raw_packet_caps = attr.raw_packet_caps;
3636 resp.tm_caps.max_rndv_hdr_size = attr.tm_caps.max_rndv_hdr_size;
3637 resp.tm_caps.max_num_tags = attr.tm_caps.max_num_tags;
3638 resp.tm_caps.max_ops = attr.tm_caps.max_ops;
3639 resp.tm_caps.max_sge = attr.tm_caps.max_sge;
3640 resp.tm_caps.flags = attr.tm_caps.flags;
3641 resp.cq_moderation_caps.max_cq_moderation_count =
3642 attr.cq_caps.max_cq_moderation_count;
3643 resp.cq_moderation_caps.max_cq_moderation_period =
3644 attr.cq_caps.max_cq_moderation_period;
3645 resp.max_dm_size = attr.max_dm_size;
3646 resp.response_length = uverbs_response_length(attrs, sizeof(resp));
3648 return uverbs_response(attrs, &resp, sizeof(resp));
3651 static int ib_uverbs_ex_modify_cq(struct uverbs_attr_bundle *attrs)
3653 struct ib_uverbs_ex_modify_cq cmd;
3657 ret = uverbs_request(attrs, &cmd, sizeof(cmd));
3661 if (!cmd.attr_mask || cmd.reserved)
3664 if (cmd.attr_mask > IB_CQ_MODERATE)
3667 cq = uobj_get_obj_read(cq, UVERBS_OBJECT_CQ, cmd.cq_handle, attrs);
3671 ret = rdma_set_cq_moderation(cq, cmd.attr.cq_count, cmd.attr.cq_period);
3673 rdma_lookup_put_uobject(&cq->uobject->uevent.uobject,
3674 UVERBS_LOOKUP_READ);
3679 * Describe the input structs for write(). Some write methods have an input
3680 * only struct, most have an input and output. If the struct has an output then
3681 * the 'response' u64 must be the first field in the request structure.
3683 * If udata is present then both the request and response structs have a
3684 * trailing driver_data flex array. In this case the size of the base struct
3685 * cannot be changed.
3687 #define UAPI_DEF_WRITE_IO(req, resp) \
3688 .write.has_resp = 1 + \
3689 BUILD_BUG_ON_ZERO(offsetof(req, response) != 0) + \
3690 BUILD_BUG_ON_ZERO(sizeof_field(req, response) != \
3692 .write.req_size = sizeof(req), .write.resp_size = sizeof(resp)
3694 #define UAPI_DEF_WRITE_I(req) .write.req_size = sizeof(req)
3696 #define UAPI_DEF_WRITE_UDATA_IO(req, resp) \
3697 UAPI_DEF_WRITE_IO(req, resp), \
3698 .write.has_udata = \
3700 BUILD_BUG_ON_ZERO(offsetof(req, driver_data) != \
3702 BUILD_BUG_ON_ZERO(offsetof(resp, driver_data) != \
3705 #define UAPI_DEF_WRITE_UDATA_I(req) \
3706 UAPI_DEF_WRITE_I(req), \
3707 .write.has_udata = \
3708 1 + BUILD_BUG_ON_ZERO(offsetof(req, driver_data) != \
3712 * The _EX versions are for use with WRITE_EX and allow the last struct member
3713 * to be specified. Buffers that do not include that member will be rejected.
3715 #define UAPI_DEF_WRITE_IO_EX(req, req_last_member, resp, resp_last_member) \
3716 .write.has_resp = 1, \
3717 .write.req_size = offsetofend(req, req_last_member), \
3718 .write.resp_size = offsetofend(resp, resp_last_member)
3720 #define UAPI_DEF_WRITE_I_EX(req, req_last_member) \
3721 .write.req_size = offsetofend(req, req_last_member)
3723 const struct uapi_definition uverbs_def_write_intf[] = {
3724 DECLARE_UVERBS_OBJECT(
3726 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_CREATE_AH,
3727 ib_uverbs_create_ah,
3728 UAPI_DEF_WRITE_UDATA_IO(
3729 struct ib_uverbs_create_ah,
3730 struct ib_uverbs_create_ah_resp)),
3731 DECLARE_UVERBS_WRITE(
3732 IB_USER_VERBS_CMD_DESTROY_AH,
3733 ib_uverbs_destroy_ah,
3734 UAPI_DEF_WRITE_I(struct ib_uverbs_destroy_ah)),
3735 UAPI_DEF_OBJ_NEEDS_FN(create_user_ah),
3736 UAPI_DEF_OBJ_NEEDS_FN(destroy_ah)),
3738 DECLARE_UVERBS_OBJECT(
3739 UVERBS_OBJECT_COMP_CHANNEL,
3740 DECLARE_UVERBS_WRITE(
3741 IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL,
3742 ib_uverbs_create_comp_channel,
3744 struct ib_uverbs_create_comp_channel,
3745 struct ib_uverbs_create_comp_channel_resp))),
3747 DECLARE_UVERBS_OBJECT(
3749 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_CREATE_CQ,
3750 ib_uverbs_create_cq,
3751 UAPI_DEF_WRITE_UDATA_IO(
3752 struct ib_uverbs_create_cq,
3753 struct ib_uverbs_create_cq_resp),
3754 UAPI_DEF_METHOD_NEEDS_FN(create_cq)),
3755 DECLARE_UVERBS_WRITE(
3756 IB_USER_VERBS_CMD_DESTROY_CQ,
3757 ib_uverbs_destroy_cq,
3758 UAPI_DEF_WRITE_IO(struct ib_uverbs_destroy_cq,
3759 struct ib_uverbs_destroy_cq_resp),
3760 UAPI_DEF_METHOD_NEEDS_FN(destroy_cq)),
3761 DECLARE_UVERBS_WRITE(
3762 IB_USER_VERBS_CMD_POLL_CQ,
3764 UAPI_DEF_WRITE_IO(struct ib_uverbs_poll_cq,
3765 struct ib_uverbs_poll_cq_resp),
3766 UAPI_DEF_METHOD_NEEDS_FN(poll_cq)),
3767 DECLARE_UVERBS_WRITE(
3768 IB_USER_VERBS_CMD_REQ_NOTIFY_CQ,
3769 ib_uverbs_req_notify_cq,
3770 UAPI_DEF_WRITE_I(struct ib_uverbs_req_notify_cq),
3771 UAPI_DEF_METHOD_NEEDS_FN(req_notify_cq)),
3772 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_RESIZE_CQ,
3773 ib_uverbs_resize_cq,
3774 UAPI_DEF_WRITE_UDATA_IO(
3775 struct ib_uverbs_resize_cq,
3776 struct ib_uverbs_resize_cq_resp),
3777 UAPI_DEF_METHOD_NEEDS_FN(resize_cq)),
3778 DECLARE_UVERBS_WRITE_EX(
3779 IB_USER_VERBS_EX_CMD_CREATE_CQ,
3780 ib_uverbs_ex_create_cq,
3781 UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_ex_create_cq,
3783 struct ib_uverbs_ex_create_cq_resp,
3785 UAPI_DEF_METHOD_NEEDS_FN(create_cq)),
3786 DECLARE_UVERBS_WRITE_EX(
3787 IB_USER_VERBS_EX_CMD_MODIFY_CQ,
3788 ib_uverbs_ex_modify_cq,
3789 UAPI_DEF_WRITE_I(struct ib_uverbs_ex_modify_cq),
3790 UAPI_DEF_METHOD_NEEDS_FN(modify_cq))),
3792 DECLARE_UVERBS_OBJECT(
3793 UVERBS_OBJECT_DEVICE,
3794 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_GET_CONTEXT,
3795 ib_uverbs_get_context,
3796 UAPI_DEF_WRITE_UDATA_IO(
3797 struct ib_uverbs_get_context,
3798 struct ib_uverbs_get_context_resp)),
3799 DECLARE_UVERBS_WRITE(
3800 IB_USER_VERBS_CMD_QUERY_DEVICE,
3801 ib_uverbs_query_device,
3802 UAPI_DEF_WRITE_IO(struct ib_uverbs_query_device,
3803 struct ib_uverbs_query_device_resp)),
3804 DECLARE_UVERBS_WRITE(
3805 IB_USER_VERBS_CMD_QUERY_PORT,
3806 ib_uverbs_query_port,
3807 UAPI_DEF_WRITE_IO(struct ib_uverbs_query_port,
3808 struct ib_uverbs_query_port_resp),
3809 UAPI_DEF_METHOD_NEEDS_FN(query_port)),
3810 DECLARE_UVERBS_WRITE_EX(
3811 IB_USER_VERBS_EX_CMD_QUERY_DEVICE,
3812 ib_uverbs_ex_query_device,
3813 UAPI_DEF_WRITE_IO_EX(
3814 struct ib_uverbs_ex_query_device,
3816 struct ib_uverbs_ex_query_device_resp,
3818 UAPI_DEF_METHOD_NEEDS_FN(query_device)),
3819 UAPI_DEF_OBJ_NEEDS_FN(alloc_ucontext),
3820 UAPI_DEF_OBJ_NEEDS_FN(dealloc_ucontext)),
3822 DECLARE_UVERBS_OBJECT(
3824 DECLARE_UVERBS_WRITE_EX(
3825 IB_USER_VERBS_EX_CMD_CREATE_FLOW,
3826 ib_uverbs_ex_create_flow,
3827 UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_create_flow,
3829 struct ib_uverbs_create_flow_resp,
3831 UAPI_DEF_METHOD_NEEDS_FN(create_flow)),
3832 DECLARE_UVERBS_WRITE_EX(
3833 IB_USER_VERBS_EX_CMD_DESTROY_FLOW,
3834 ib_uverbs_ex_destroy_flow,
3835 UAPI_DEF_WRITE_I(struct ib_uverbs_destroy_flow),
3836 UAPI_DEF_METHOD_NEEDS_FN(destroy_flow))),
3838 DECLARE_UVERBS_OBJECT(
3840 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_DEREG_MR,
3842 UAPI_DEF_WRITE_I(struct ib_uverbs_dereg_mr),
3843 UAPI_DEF_METHOD_NEEDS_FN(dereg_mr)),
3844 DECLARE_UVERBS_WRITE(
3845 IB_USER_VERBS_CMD_REG_MR,
3847 UAPI_DEF_WRITE_UDATA_IO(struct ib_uverbs_reg_mr,
3848 struct ib_uverbs_reg_mr_resp),
3849 UAPI_DEF_METHOD_NEEDS_FN(reg_user_mr)),
3850 DECLARE_UVERBS_WRITE(
3851 IB_USER_VERBS_CMD_REREG_MR,
3853 UAPI_DEF_WRITE_UDATA_IO(struct ib_uverbs_rereg_mr,
3854 struct ib_uverbs_rereg_mr_resp),
3855 UAPI_DEF_METHOD_NEEDS_FN(rereg_user_mr))),
3857 DECLARE_UVERBS_OBJECT(
3859 DECLARE_UVERBS_WRITE(
3860 IB_USER_VERBS_CMD_ALLOC_MW,
3862 UAPI_DEF_WRITE_UDATA_IO(struct ib_uverbs_alloc_mw,
3863 struct ib_uverbs_alloc_mw_resp),
3864 UAPI_DEF_METHOD_NEEDS_FN(alloc_mw)),
3865 DECLARE_UVERBS_WRITE(
3866 IB_USER_VERBS_CMD_DEALLOC_MW,
3867 ib_uverbs_dealloc_mw,
3868 UAPI_DEF_WRITE_I(struct ib_uverbs_dealloc_mw),
3869 UAPI_DEF_METHOD_NEEDS_FN(dealloc_mw))),
3871 DECLARE_UVERBS_OBJECT(
3873 DECLARE_UVERBS_WRITE(
3874 IB_USER_VERBS_CMD_ALLOC_PD,
3876 UAPI_DEF_WRITE_UDATA_IO(struct ib_uverbs_alloc_pd,
3877 struct ib_uverbs_alloc_pd_resp),
3878 UAPI_DEF_METHOD_NEEDS_FN(alloc_pd)),
3879 DECLARE_UVERBS_WRITE(
3880 IB_USER_VERBS_CMD_DEALLOC_PD,
3881 ib_uverbs_dealloc_pd,
3882 UAPI_DEF_WRITE_I(struct ib_uverbs_dealloc_pd),
3883 UAPI_DEF_METHOD_NEEDS_FN(dealloc_pd))),
3885 DECLARE_UVERBS_OBJECT(
3887 DECLARE_UVERBS_WRITE(
3888 IB_USER_VERBS_CMD_ATTACH_MCAST,
3889 ib_uverbs_attach_mcast,
3890 UAPI_DEF_WRITE_I(struct ib_uverbs_attach_mcast),
3891 UAPI_DEF_METHOD_NEEDS_FN(attach_mcast),
3892 UAPI_DEF_METHOD_NEEDS_FN(detach_mcast)),
3893 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_CREATE_QP,
3894 ib_uverbs_create_qp,
3895 UAPI_DEF_WRITE_UDATA_IO(
3896 struct ib_uverbs_create_qp,
3897 struct ib_uverbs_create_qp_resp),
3898 UAPI_DEF_METHOD_NEEDS_FN(create_qp)),
3899 DECLARE_UVERBS_WRITE(
3900 IB_USER_VERBS_CMD_DESTROY_QP,
3901 ib_uverbs_destroy_qp,
3902 UAPI_DEF_WRITE_IO(struct ib_uverbs_destroy_qp,
3903 struct ib_uverbs_destroy_qp_resp),
3904 UAPI_DEF_METHOD_NEEDS_FN(destroy_qp)),
3905 DECLARE_UVERBS_WRITE(
3906 IB_USER_VERBS_CMD_DETACH_MCAST,
3907 ib_uverbs_detach_mcast,
3908 UAPI_DEF_WRITE_I(struct ib_uverbs_detach_mcast),
3909 UAPI_DEF_METHOD_NEEDS_FN(detach_mcast)),
3910 DECLARE_UVERBS_WRITE(
3911 IB_USER_VERBS_CMD_MODIFY_QP,
3912 ib_uverbs_modify_qp,
3913 UAPI_DEF_WRITE_I(struct ib_uverbs_modify_qp),
3914 UAPI_DEF_METHOD_NEEDS_FN(modify_qp)),
3915 DECLARE_UVERBS_WRITE(
3916 IB_USER_VERBS_CMD_POST_RECV,
3917 ib_uverbs_post_recv,
3918 UAPI_DEF_WRITE_IO(struct ib_uverbs_post_recv,
3919 struct ib_uverbs_post_recv_resp),
3920 UAPI_DEF_METHOD_NEEDS_FN(post_recv)),
3921 DECLARE_UVERBS_WRITE(
3922 IB_USER_VERBS_CMD_POST_SEND,
3923 ib_uverbs_post_send,
3924 UAPI_DEF_WRITE_IO(struct ib_uverbs_post_send,
3925 struct ib_uverbs_post_send_resp),
3926 UAPI_DEF_METHOD_NEEDS_FN(post_send)),
3927 DECLARE_UVERBS_WRITE(
3928 IB_USER_VERBS_CMD_QUERY_QP,
3930 UAPI_DEF_WRITE_IO(struct ib_uverbs_query_qp,
3931 struct ib_uverbs_query_qp_resp),
3932 UAPI_DEF_METHOD_NEEDS_FN(query_qp)),
3933 DECLARE_UVERBS_WRITE_EX(
3934 IB_USER_VERBS_EX_CMD_CREATE_QP,
3935 ib_uverbs_ex_create_qp,
3936 UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_ex_create_qp,
3938 struct ib_uverbs_ex_create_qp_resp,
3940 UAPI_DEF_METHOD_NEEDS_FN(create_qp)),
3941 DECLARE_UVERBS_WRITE_EX(
3942 IB_USER_VERBS_EX_CMD_MODIFY_QP,
3943 ib_uverbs_ex_modify_qp,
3944 UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_ex_modify_qp,
3946 struct ib_uverbs_ex_modify_qp_resp,
3948 UAPI_DEF_METHOD_NEEDS_FN(modify_qp))),
3950 DECLARE_UVERBS_OBJECT(
3951 UVERBS_OBJECT_RWQ_IND_TBL,
3952 DECLARE_UVERBS_WRITE_EX(
3953 IB_USER_VERBS_EX_CMD_CREATE_RWQ_IND_TBL,
3954 ib_uverbs_ex_create_rwq_ind_table,
3955 UAPI_DEF_WRITE_IO_EX(
3956 struct ib_uverbs_ex_create_rwq_ind_table,
3958 struct ib_uverbs_ex_create_rwq_ind_table_resp,
3960 UAPI_DEF_METHOD_NEEDS_FN(create_rwq_ind_table)),
3961 DECLARE_UVERBS_WRITE_EX(
3962 IB_USER_VERBS_EX_CMD_DESTROY_RWQ_IND_TBL,
3963 ib_uverbs_ex_destroy_rwq_ind_table,
3965 struct ib_uverbs_ex_destroy_rwq_ind_table),
3966 UAPI_DEF_METHOD_NEEDS_FN(destroy_rwq_ind_table))),
3968 DECLARE_UVERBS_OBJECT(
3970 DECLARE_UVERBS_WRITE_EX(
3971 IB_USER_VERBS_EX_CMD_CREATE_WQ,
3972 ib_uverbs_ex_create_wq,
3973 UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_ex_create_wq,
3975 struct ib_uverbs_ex_create_wq_resp,
3977 UAPI_DEF_METHOD_NEEDS_FN(create_wq)),
3978 DECLARE_UVERBS_WRITE_EX(
3979 IB_USER_VERBS_EX_CMD_DESTROY_WQ,
3980 ib_uverbs_ex_destroy_wq,
3981 UAPI_DEF_WRITE_IO_EX(struct ib_uverbs_ex_destroy_wq,
3983 struct ib_uverbs_ex_destroy_wq_resp,
3985 UAPI_DEF_METHOD_NEEDS_FN(destroy_wq)),
3986 DECLARE_UVERBS_WRITE_EX(
3987 IB_USER_VERBS_EX_CMD_MODIFY_WQ,
3988 ib_uverbs_ex_modify_wq,
3989 UAPI_DEF_WRITE_I_EX(struct ib_uverbs_ex_modify_wq,
3991 UAPI_DEF_METHOD_NEEDS_FN(modify_wq))),
3993 DECLARE_UVERBS_OBJECT(
3995 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_CREATE_SRQ,
3996 ib_uverbs_create_srq,
3997 UAPI_DEF_WRITE_UDATA_IO(
3998 struct ib_uverbs_create_srq,
3999 struct ib_uverbs_create_srq_resp),
4000 UAPI_DEF_METHOD_NEEDS_FN(create_srq)),
4001 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_CREATE_XSRQ,
4002 ib_uverbs_create_xsrq,
4003 UAPI_DEF_WRITE_UDATA_IO(
4004 struct ib_uverbs_create_xsrq,
4005 struct ib_uverbs_create_srq_resp),
4006 UAPI_DEF_METHOD_NEEDS_FN(create_srq)),
4007 DECLARE_UVERBS_WRITE(
4008 IB_USER_VERBS_CMD_DESTROY_SRQ,
4009 ib_uverbs_destroy_srq,
4010 UAPI_DEF_WRITE_IO(struct ib_uverbs_destroy_srq,
4011 struct ib_uverbs_destroy_srq_resp),
4012 UAPI_DEF_METHOD_NEEDS_FN(destroy_srq)),
4013 DECLARE_UVERBS_WRITE(
4014 IB_USER_VERBS_CMD_MODIFY_SRQ,
4015 ib_uverbs_modify_srq,
4016 UAPI_DEF_WRITE_UDATA_I(struct ib_uverbs_modify_srq),
4017 UAPI_DEF_METHOD_NEEDS_FN(modify_srq)),
4018 DECLARE_UVERBS_WRITE(
4019 IB_USER_VERBS_CMD_POST_SRQ_RECV,
4020 ib_uverbs_post_srq_recv,
4021 UAPI_DEF_WRITE_IO(struct ib_uverbs_post_srq_recv,
4022 struct ib_uverbs_post_srq_recv_resp),
4023 UAPI_DEF_METHOD_NEEDS_FN(post_srq_recv)),
4024 DECLARE_UVERBS_WRITE(
4025 IB_USER_VERBS_CMD_QUERY_SRQ,
4026 ib_uverbs_query_srq,
4027 UAPI_DEF_WRITE_IO(struct ib_uverbs_query_srq,
4028 struct ib_uverbs_query_srq_resp),
4029 UAPI_DEF_METHOD_NEEDS_FN(query_srq))),
4031 DECLARE_UVERBS_OBJECT(
4033 DECLARE_UVERBS_WRITE(
4034 IB_USER_VERBS_CMD_CLOSE_XRCD,
4035 ib_uverbs_close_xrcd,
4036 UAPI_DEF_WRITE_I(struct ib_uverbs_close_xrcd)),
4037 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_OPEN_QP,
4039 UAPI_DEF_WRITE_UDATA_IO(
4040 struct ib_uverbs_open_qp,
4041 struct ib_uverbs_create_qp_resp)),
4042 DECLARE_UVERBS_WRITE(IB_USER_VERBS_CMD_OPEN_XRCD,
4043 ib_uverbs_open_xrcd,
4044 UAPI_DEF_WRITE_UDATA_IO(
4045 struct ib_uverbs_open_xrcd,
4046 struct ib_uverbs_open_xrcd_resp)),
4047 UAPI_DEF_OBJ_NEEDS_FN(alloc_xrcd),
4048 UAPI_DEF_OBJ_NEEDS_FN(dealloc_xrcd)),