aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatan Barak <matanb@mellanox.com>2017-08-03 09:06:57 -0400
committerDoug Ledford <dledford@redhat.com>2017-08-31 08:35:09 -0400
commitfac9658cabb98afb68ef1630c558864e6f559c07 (patch)
treeef524d6e9cea6899ffebcdc31686e2131ef6863a
parent14d6c3a83fbcd9c3d19e24d8d5820a912f2615c9 (diff)
IB/core: Add new ioctl interface
In this ioctl interface, processing the command starts from properties of the command and fetching the appropriate user objects before calling the handler. Parsing and validation is done according to a specifier declared by the driver's code. In the driver, all supported objects are declared. These objects are separated to different object namepsaces. Dividing objects to namespaces is done at initialization by using the higher bits of the object ids. This initialization can mix objects declared in different places to one parsing tree using in this ioctl interface. For each object we list all supported methods. Similarly to objects, methods are separated to method namespaces too. Namespacing is done similarly to the objects case. This could be used in order to add methods to an existing object. Each method has a specific handler, which could be either a default handler or a driver specific handler. Along with the handler, a bunch of attributes are specified as well. Similarly to objects and method, attributes are namespaced and hashed by their ids at initialization too. All supported attributes are subject to automatic fetching and validation. These attributes include the command, response and the method's related objects' ids. When these entities (objects, methods and attributes) are used, the high bits of the entities ids are used in order to calculate the hash bucket index. Then, these high bits are masked out in order to have a zero based index. Since we use these high bits for both bucketing and namespacing, we get a compact representation and O(1) array access. This is mandatory for efficient dispatching. Each attribute has a type (PTR_IN, PTR_OUT, IDR and FD) and a length. Attributes could be validated through some attributes, like: (*) Minimum size / Exact size (*) Fops for FD (*) Object type for IDR If an IDR/fd attribute is specified, the kernel also states the object type and the required access (NEW, WRITE, READ or DESTROY). All uobject/fd management is done automatically by the infrastructure, meaning - the infrastructure will fail concurrent commands that at least one of them requires concurrent access (WRITE/DESTROY), synchronize actions with device removals (dissociate context events) and take care of reference counting (increase/decrease) for concurrent actions invocation. The reference counts on the actual kernel objects shall be handled by the handlers. objects +--------+ | | | | methods +--------+ | | ns method method_spec +-----+ |len | +--------+ +------+[d]+-------+ +----------------+[d]+------------+ |attr1+-> |type | | object +> |method+-> | spec +-> + attr_buckets +-> |default_chain+--> +-----+ |idr_type| +--------+ +------+ |handler| | | +------------+ |attr2| |access | | | | | +-------+ +----------------+ |driver chain| +-----+ +--------+ | | | | +------------+ | | +------+ | | | | | | | | | | | | | | | | | | | | +--------+ [d] = Hash ids to groups using the high order bits The right types table is also chosen by using the high bits from the ids. Currently we have either default or driver specific groups. Once validation and object fetching (or creation) completed, we call the handler: int (*handler)(struct ib_device *ib_dev, struct ib_uverbs_file *ufile, struct uverbs_attr_bundle *ctx); ctx bundles attributes of different namespaces. Each element there is an array of attributes which corresponds to one namespaces of attributes. For example, in the usually used case: ctx core +----------------------------+ +------------+ | core: +---> | valid | +----------------------------+ | cmd_attr | | driver: | +------------+ |----------------------------+--+ | valid | | | cmd_attr | | +------------+ | | valid | | | obj_attr | | +------------+ | | drivers | +------------+ +> | valid | | cmd_attr | +------------+ | valid | | cmd_attr | +------------+ | valid | | obj_attr | +------------+ Signed-off-by: Matan Barak <matanb@mellanox.com> Reviewed-by: Yishai Hadas <yishaih@mellanox.com> Signed-off-by: Doug Ledford <dledford@redhat.com>
-rw-r--r--drivers/infiniband/core/Makefile2
-rw-r--r--drivers/infiniband/core/rdma_core.c46
-rw-r--r--drivers/infiniband/core/rdma_core.h5
-rw-r--r--drivers/infiniband/core/uverbs_ioctl.c364
-rw-r--r--include/rdma/ib_verbs.h2
-rw-r--r--include/rdma/uverbs_ioctl.h101
-rw-r--r--include/uapi/rdma/rdma_user_ioctl.h33
7 files changed, 543 insertions, 10 deletions
diff --git a/drivers/infiniband/core/Makefile b/drivers/infiniband/core/Makefile
index 920609a0872e..746756dc9877 100644
--- a/drivers/infiniband/core/Makefile
+++ b/drivers/infiniband/core/Makefile
@@ -32,4 +32,4 @@ ib_umad-y := user_mad.o
32ib_ucm-y := ucm.o 32ib_ucm-y := ucm.o
33 33
34ib_uverbs-y := uverbs_main.o uverbs_cmd.o uverbs_marshall.o \ 34ib_uverbs-y := uverbs_main.o uverbs_cmd.o uverbs_marshall.o \
35 rdma_core.o uverbs_std_types.o 35 rdma_core.o uverbs_std_types.o uverbs_ioctl.o
diff --git a/drivers/infiniband/core/rdma_core.c b/drivers/infiniband/core/rdma_core.c
index 0fe8ef913387..2a2f002ac7cb 100644
--- a/drivers/infiniband/core/rdma_core.c
+++ b/drivers/infiniband/core/rdma_core.c
@@ -36,10 +36,56 @@
36#include <rdma/uverbs_types.h> 36#include <rdma/uverbs_types.h>
37#include <linux/rcupdate.h> 37#include <linux/rcupdate.h>
38#include <rdma/uverbs_ioctl.h> 38#include <rdma/uverbs_ioctl.h>
39#include <rdma/rdma_user_ioctl.h>
39#include "uverbs.h" 40#include "uverbs.h"
40#include "core_priv.h" 41#include "core_priv.h"
41#include "rdma_core.h" 42#include "rdma_core.h"
42 43
44int uverbs_ns_idx(u16 *id, unsigned int ns_count)
45{
46 int ret = (*id & UVERBS_ID_NS_MASK) >> UVERBS_ID_NS_SHIFT;
47
48 if (ret >= ns_count)
49 return -EINVAL;
50
51 *id &= ~UVERBS_ID_NS_MASK;
52 return ret;
53}
54
55const struct uverbs_object_spec *uverbs_get_object(const struct ib_device *ibdev,
56 uint16_t object)
57{
58 const struct uverbs_root_spec *object_hash = ibdev->specs_root;
59 const struct uverbs_object_spec_hash *objects;
60 int ret = uverbs_ns_idx(&object, object_hash->num_buckets);
61
62 if (ret < 0)
63 return NULL;
64
65 objects = object_hash->object_buckets[ret];
66
67 if (object >= objects->num_objects)
68 return NULL;
69
70 return objects->objects[object];
71}
72
73const struct uverbs_method_spec *uverbs_get_method(const struct uverbs_object_spec *object,
74 uint16_t method)
75{
76 const struct uverbs_method_spec_hash *methods;
77 int ret = uverbs_ns_idx(&method, object->num_buckets);
78
79 if (ret < 0)
80 return NULL;
81
82 methods = object->method_buckets[ret];
83 if (method >= methods->num_methods)
84 return NULL;
85
86 return methods->methods[method];
87}
88
43void uverbs_uobject_get(struct ib_uobject *uobject) 89void uverbs_uobject_get(struct ib_uobject *uobject)
44{ 90{
45 kref_get(&uobject->ref); 91 kref_get(&uobject->ref);
diff --git a/drivers/infiniband/core/rdma_core.h b/drivers/infiniband/core/rdma_core.h
index 9ed6ad0324c7..1efcf93238dd 100644
--- a/drivers/infiniband/core/rdma_core.h
+++ b/drivers/infiniband/core/rdma_core.h
@@ -43,6 +43,11 @@
43#include <rdma/ib_verbs.h> 43#include <rdma/ib_verbs.h>
44#include <linux/mutex.h> 44#include <linux/mutex.h>
45 45
46int uverbs_ns_idx(u16 *id, unsigned int ns_count);
47const struct uverbs_object_spec *uverbs_get_object(const struct ib_device *ibdev,
48 uint16_t object);
49const struct uverbs_method_spec *uverbs_get_method(const struct uverbs_object_spec *object,
50 uint16_t method);
46/* 51/*
47 * These functions initialize the context and cleanups its uobjects. 52 * These functions initialize the context and cleanups its uobjects.
48 * The context has a list of objects which is protected by a mutex 53 * The context has a list of objects which is protected by a mutex
diff --git a/drivers/infiniband/core/uverbs_ioctl.c b/drivers/infiniband/core/uverbs_ioctl.c
new file mode 100644
index 000000000000..5286ad57d903
--- /dev/null
+++ b/drivers/infiniband/core/uverbs_ioctl.c
@@ -0,0 +1,364 @@
1/*
2 * Copyright (c) 2017, Mellanox Technologies inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <rdma/rdma_user_ioctl.h>
34#include <rdma/uverbs_ioctl.h>
35#include "rdma_core.h"
36#include "uverbs.h"
37
38static int uverbs_process_attr(struct ib_device *ibdev,
39 struct ib_ucontext *ucontext,
40 const struct ib_uverbs_attr *uattr,
41 u16 attr_id,
42 const struct uverbs_attr_spec_hash *attr_spec_bucket,
43 struct uverbs_attr_bundle_hash *attr_bundle_h,
44 struct ib_uverbs_attr __user *uattr_ptr)
45{
46 const struct uverbs_attr_spec *spec;
47 struct uverbs_attr *e;
48 const struct uverbs_object_spec *object;
49 struct uverbs_obj_attr *o_attr;
50 struct uverbs_attr *elements = attr_bundle_h->attrs;
51
52 if (uattr->reserved)
53 return -EINVAL;
54
55 if (attr_id >= attr_spec_bucket->num_attrs) {
56 if (uattr->flags & UVERBS_ATTR_F_MANDATORY)
57 return -EINVAL;
58 else
59 return 0;
60 }
61
62 spec = &attr_spec_bucket->attrs[attr_id];
63 e = &elements[attr_id];
64 e->uattr = uattr_ptr;
65
66 switch (spec->type) {
67 case UVERBS_ATTR_TYPE_PTR_IN:
68 case UVERBS_ATTR_TYPE_PTR_OUT:
69 if (uattr->len < spec->len ||
70 (!(spec->flags & UVERBS_ATTR_SPEC_F_MIN_SZ) &&
71 uattr->len > spec->len))
72 return -EINVAL;
73
74 e->ptr_attr.data = uattr->data;
75 e->ptr_attr.len = uattr->len;
76 e->ptr_attr.flags = uattr->flags;
77 break;
78
79 case UVERBS_ATTR_TYPE_IDR:
80 if (uattr->data >> 32)
81 return -EINVAL;
82 /* fall through */
83 case UVERBS_ATTR_TYPE_FD:
84 if (uattr->len != 0 || !ucontext || uattr->data > INT_MAX)
85 return -EINVAL;
86
87 o_attr = &e->obj_attr;
88 object = uverbs_get_object(ibdev, spec->obj.obj_type);
89 if (!object)
90 return -EINVAL;
91 o_attr->type = object->type_attrs;
92
93 o_attr->id = (int)uattr->data;
94 o_attr->uobject = uverbs_get_uobject_from_context(
95 o_attr->type,
96 ucontext,
97 spec->obj.access,
98 o_attr->id);
99
100 if (IS_ERR(o_attr->uobject))
101 return PTR_ERR(o_attr->uobject);
102
103 if (spec->obj.access == UVERBS_ACCESS_NEW) {
104 u64 id = o_attr->uobject->id;
105
106 /* Copy the allocated id to the user-space */
107 if (put_user(id, &e->uattr->data)) {
108 uverbs_finalize_object(o_attr->uobject,
109 UVERBS_ACCESS_NEW,
110 false);
111 return -EFAULT;
112 }
113 }
114
115 break;
116 default:
117 return -EOPNOTSUPP;
118 }
119
120 set_bit(attr_id, attr_bundle_h->valid_bitmap);
121 return 0;
122}
123
124static int uverbs_uattrs_process(struct ib_device *ibdev,
125 struct ib_ucontext *ucontext,
126 const struct ib_uverbs_attr *uattrs,
127 size_t num_uattrs,
128 const struct uverbs_method_spec *method,
129 struct uverbs_attr_bundle *attr_bundle,
130 struct ib_uverbs_attr __user *uattr_ptr)
131{
132 size_t i;
133 int ret = 0;
134 int num_given_buckets = 0;
135
136 for (i = 0; i < num_uattrs; i++) {
137 const struct ib_uverbs_attr *uattr = &uattrs[i];
138 u16 attr_id = uattr->attr_id;
139 struct uverbs_attr_spec_hash *attr_spec_bucket;
140
141 ret = uverbs_ns_idx(&attr_id, method->num_buckets);
142 if (ret < 0) {
143 if (uattr->flags & UVERBS_ATTR_F_MANDATORY) {
144 uverbs_finalize_objects(attr_bundle,
145 method->attr_buckets,
146 num_given_buckets,
147 false);
148 return ret;
149 }
150 continue;
151 }
152
153 /*
154 * ret is the found ns, so increase num_given_buckets if
155 * necessary.
156 */
157 if (ret >= num_given_buckets)
158 num_given_buckets = ret + 1;
159
160 attr_spec_bucket = method->attr_buckets[ret];
161 ret = uverbs_process_attr(ibdev, ucontext, uattr, attr_id,
162 attr_spec_bucket, &attr_bundle->hash[ret],
163 uattr_ptr++);
164 if (ret) {
165 uverbs_finalize_objects(attr_bundle,
166 method->attr_buckets,
167 num_given_buckets,
168 false);
169 return ret;
170 }
171 }
172
173 return num_given_buckets;
174}
175
176static int uverbs_validate_kernel_mandatory(const struct uverbs_method_spec *method_spec,
177 struct uverbs_attr_bundle *attr_bundle)
178{
179 unsigned int i;
180
181 for (i = 0; i < attr_bundle->num_buckets; i++) {
182 struct uverbs_attr_spec_hash *attr_spec_bucket =
183 method_spec->attr_buckets[i];
184
185 if (!bitmap_subset(attr_spec_bucket->mandatory_attrs_bitmask,
186 attr_bundle->hash[i].valid_bitmap,
187 attr_spec_bucket->num_attrs))
188 return -EINVAL;
189 }
190
191 return 0;
192}
193
194static int uverbs_handle_method(struct ib_uverbs_attr __user *uattr_ptr,
195 const struct ib_uverbs_attr *uattrs,
196 size_t num_uattrs,
197 struct ib_device *ibdev,
198 struct ib_uverbs_file *ufile,
199 const struct uverbs_method_spec *method_spec,
200 struct uverbs_attr_bundle *attr_bundle)
201{
202 int ret;
203 int finalize_ret;
204 int num_given_buckets;
205
206 num_given_buckets = uverbs_uattrs_process(ibdev, ufile->ucontext, uattrs,
207 num_uattrs, method_spec,
208 attr_bundle, uattr_ptr);
209 if (num_given_buckets <= 0)
210 return -EINVAL;
211
212 attr_bundle->num_buckets = num_given_buckets;
213 ret = uverbs_validate_kernel_mandatory(method_spec, attr_bundle);
214 if (ret)
215 goto cleanup;
216
217 ret = method_spec->handler(ibdev, ufile, attr_bundle);
218cleanup:
219 finalize_ret = uverbs_finalize_objects(attr_bundle,
220 method_spec->attr_buckets,
221 attr_bundle->num_buckets,
222 !ret);
223
224 return ret ? ret : finalize_ret;
225}
226
227#define UVERBS_OPTIMIZE_USING_STACK_SZ 256
228static long ib_uverbs_cmd_verbs(struct ib_device *ib_dev,
229 struct ib_uverbs_file *file,
230 struct ib_uverbs_ioctl_hdr *hdr,
231 void __user *buf)
232{
233 const struct uverbs_object_spec *object_spec;
234 const struct uverbs_method_spec *method_spec;
235 long err = 0;
236 unsigned int i;
237 struct {
238 struct ib_uverbs_attr *uattrs;
239 struct uverbs_attr_bundle *uverbs_attr_bundle;
240 } *ctx = NULL;
241 struct uverbs_attr *curr_attr;
242 unsigned long *curr_bitmap;
243 size_t ctx_size;
244#ifdef UVERBS_OPTIMIZE_USING_STACK_SZ
245 uintptr_t data[UVERBS_OPTIMIZE_USING_STACK_SZ / sizeof(uintptr_t)];
246#endif
247
248 if (hdr->reserved)
249 return -EINVAL;
250
251 object_spec = uverbs_get_object(ib_dev, hdr->object_id);
252 if (!object_spec)
253 return -EOPNOTSUPP;
254
255 method_spec = uverbs_get_method(object_spec, hdr->method_id);
256 if (!method_spec)
257 return -EOPNOTSUPP;
258
259 if ((method_spec->flags & UVERBS_ACTION_FLAG_CREATE_ROOT) ^ !file->ucontext)
260 return -EINVAL;
261
262 ctx_size = sizeof(*ctx) +
263 sizeof(struct uverbs_attr_bundle) +
264 sizeof(struct uverbs_attr_bundle_hash) * method_spec->num_buckets +
265 sizeof(*ctx->uattrs) * hdr->num_attrs +
266 sizeof(*ctx->uverbs_attr_bundle->hash[0].attrs) *
267 method_spec->num_child_attrs +
268 sizeof(*ctx->uverbs_attr_bundle->hash[0].valid_bitmap) *
269 (method_spec->num_child_attrs / BITS_PER_LONG +
270 method_spec->num_buckets);
271
272#ifdef UVERBS_OPTIMIZE_USING_STACK_SZ
273 if (ctx_size <= UVERBS_OPTIMIZE_USING_STACK_SZ)
274 ctx = (void *)data;
275
276 if (!ctx)
277#endif
278 ctx = kmalloc(ctx_size, GFP_KERNEL);
279 if (!ctx)
280 return -ENOMEM;
281
282 ctx->uverbs_attr_bundle = (void *)ctx + sizeof(*ctx);
283 ctx->uattrs = (void *)(ctx->uverbs_attr_bundle + 1) +
284 (sizeof(ctx->uverbs_attr_bundle->hash[0]) *
285 method_spec->num_buckets);
286 curr_attr = (void *)(ctx->uattrs + hdr->num_attrs);
287 curr_bitmap = (void *)(curr_attr + method_spec->num_child_attrs);
288
289 /*
290 * We just fill the pointers and num_attrs here. The data itself will be
291 * filled at a later stage (uverbs_process_attr)
292 */
293 for (i = 0; i < method_spec->num_buckets; i++) {
294 unsigned int curr_num_attrs = method_spec->attr_buckets[i]->num_attrs;
295
296 ctx->uverbs_attr_bundle->hash[i].attrs = curr_attr;
297 curr_attr += curr_num_attrs;
298 ctx->uverbs_attr_bundle->hash[i].num_attrs = curr_num_attrs;
299 ctx->uverbs_attr_bundle->hash[i].valid_bitmap = curr_bitmap;
300 bitmap_zero(curr_bitmap, curr_num_attrs);
301 curr_bitmap += BITS_TO_LONGS(curr_num_attrs);
302 }
303
304 err = copy_from_user(ctx->uattrs, buf,
305 sizeof(*ctx->uattrs) * hdr->num_attrs);
306 if (err) {
307 err = -EFAULT;
308 goto out;
309 }
310
311 err = uverbs_handle_method(buf, ctx->uattrs, hdr->num_attrs, ib_dev,
312 file, method_spec, ctx->uverbs_attr_bundle);
313out:
314#ifdef UVERBS_OPTIMIZE_USING_STACK_SZ
315 if (ctx_size > UVERBS_OPTIMIZE_USING_STACK_SZ)
316#endif
317 kfree(ctx);
318 return err;
319}
320
321#define IB_UVERBS_MAX_CMD_SZ 4096
322
323long ib_uverbs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
324{
325 struct ib_uverbs_file *file = filp->private_data;
326 struct ib_uverbs_ioctl_hdr __user *user_hdr =
327 (struct ib_uverbs_ioctl_hdr __user *)arg;
328 struct ib_uverbs_ioctl_hdr hdr;
329 struct ib_device *ib_dev;
330 int srcu_key;
331 long err;
332
333 srcu_key = srcu_read_lock(&file->device->disassociate_srcu);
334 ib_dev = srcu_dereference(file->device->ib_dev,
335 &file->device->disassociate_srcu);
336 if (!ib_dev) {
337 err = -EIO;
338 goto out;
339 }
340
341 if (cmd == RDMA_VERBS_IOCTL) {
342 err = copy_from_user(&hdr, user_hdr, sizeof(hdr));
343
344 if (err || hdr.length > IB_UVERBS_MAX_CMD_SZ ||
345 hdr.length != sizeof(hdr) + hdr.num_attrs * sizeof(struct ib_uverbs_attr)) {
346 err = -EINVAL;
347 goto out;
348 }
349
350 if (hdr.reserved) {
351 err = -EOPNOTSUPP;
352 goto out;
353 }
354
355 err = ib_uverbs_cmd_verbs(ib_dev, file, &hdr,
356 (__user void *)arg + sizeof(hdr));
357 } else {
358 err = -ENOIOCTLCMD;
359 }
360out:
361 srcu_read_unlock(&file->device->disassociate_srcu, srcu_key);
362
363 return err;
364}
diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
index 1b4bb8743969..e6df68048517 100644
--- a/include/rdma/ib_verbs.h
+++ b/include/rdma/ib_verbs.h
@@ -2348,6 +2348,8 @@ struct ib_device {
2348 void (*get_dev_fw_str)(struct ib_device *, char *str); 2348 void (*get_dev_fw_str)(struct ib_device *, char *str);
2349 const struct cpumask *(*get_vector_affinity)(struct ib_device *ibdev, 2349 const struct cpumask *(*get_vector_affinity)(struct ib_device *ibdev,
2350 int comp_vector); 2350 int comp_vector);
2351
2352 struct uverbs_root_spec *specs_root;
2351}; 2353};
2352 2354
2353struct ib_client { 2355struct ib_client {
diff --git a/include/rdma/uverbs_ioctl.h b/include/rdma/uverbs_ioctl.h
index d3ec02b7d937..f83f56329761 100644
--- a/include/rdma/uverbs_ioctl.h
+++ b/include/rdma/uverbs_ioctl.h
@@ -43,6 +43,8 @@
43 43
44enum uverbs_attr_type { 44enum uverbs_attr_type {
45 UVERBS_ATTR_TYPE_NA, 45 UVERBS_ATTR_TYPE_NA,
46 UVERBS_ATTR_TYPE_PTR_IN,
47 UVERBS_ATTR_TYPE_PTR_OUT,
46 UVERBS_ATTR_TYPE_IDR, 48 UVERBS_ATTR_TYPE_IDR,
47 UVERBS_ATTR_TYPE_FD, 49 UVERBS_ATTR_TYPE_FD,
48}; 50};
@@ -54,29 +56,110 @@ enum uverbs_obj_access {
54 UVERBS_ACCESS_DESTROY 56 UVERBS_ACCESS_DESTROY
55}; 57};
56 58
59enum {
60 UVERBS_ATTR_SPEC_F_MANDATORY = 1U << 0,
61 /* Support extending attributes by length */
62 UVERBS_ATTR_SPEC_F_MIN_SZ = 1U << 1,
63};
64
57struct uverbs_attr_spec { 65struct uverbs_attr_spec {
58 enum uverbs_attr_type type; 66 enum uverbs_attr_type type;
59 struct { 67 union {
60 /* 68 u16 len;
61 * higher bits mean the namespace and lower bits mean 69 struct {
62 * the type id within the namespace. 70 /*
63 */ 71 * higher bits mean the namespace and lower bits mean
64 u16 obj_type; 72 * the type id within the namespace.
65 u8 access; 73 */
66 } obj; 74 u16 obj_type;
75 u8 access;
76 } obj;
77 };
78 /* Combination of bits from enum UVERBS_ATTR_SPEC_F_XXXX */
79 u8 flags;
67}; 80};
68 81
69struct uverbs_attr_spec_hash { 82struct uverbs_attr_spec_hash {
70 size_t num_attrs; 83 size_t num_attrs;
84 unsigned long *mandatory_attrs_bitmask;
71 struct uverbs_attr_spec attrs[0]; 85 struct uverbs_attr_spec attrs[0];
72}; 86};
73 87
88struct uverbs_attr_bundle;
89struct ib_uverbs_file;
90
91enum {
92 /*
93 * Action marked with this flag creates a context (or root for all
94 * objects).
95 */
96 UVERBS_ACTION_FLAG_CREATE_ROOT = 1U << 0,
97};
98
99struct uverbs_method_spec {
100 /* Combination of bits from enum UVERBS_ACTION_FLAG_XXXX */
101 u32 flags;
102 size_t num_buckets;
103 size_t num_child_attrs;
104 int (*handler)(struct ib_device *ib_dev, struct ib_uverbs_file *ufile,
105 struct uverbs_attr_bundle *ctx);
106 struct uverbs_attr_spec_hash *attr_buckets[0];
107};
108
109struct uverbs_method_spec_hash {
110 size_t num_methods;
111 struct uverbs_method_spec *methods[0];
112};
113
114struct uverbs_object_spec {
115 const struct uverbs_obj_type *type_attrs;
116 size_t num_buckets;
117 struct uverbs_method_spec_hash *method_buckets[0];
118};
119
120struct uverbs_object_spec_hash {
121 size_t num_objects;
122 struct uverbs_object_spec *objects[0];
123};
124
125struct uverbs_root_spec {
126 size_t num_buckets;
127 struct uverbs_object_spec_hash *object_buckets[0];
128};
129
130/* =================================================
131 * Parsing infrastructure
132 * =================================================
133 */
134
135struct uverbs_ptr_attr {
136 union {
137 u64 data;
138 void __user *ptr;
139 };
140 u16 len;
141 /* Combination of bits from enum UVERBS_ATTR_F_XXXX */
142 u16 flags;
143};
144
74struct uverbs_obj_attr { 145struct uverbs_obj_attr {
146 /* pointer to the kernel descriptor -> type, access, etc */
147 const struct uverbs_obj_type *type;
75 struct ib_uobject *uobject; 148 struct ib_uobject *uobject;
149 /* fd or id in idr of this object */
150 int id;
76}; 151};
77 152
78struct uverbs_attr { 153struct uverbs_attr {
79 struct uverbs_obj_attr obj_attr; 154 /*
155 * pointer to the user-space given attribute, in order to write the
156 * new uobject's id or update flags.
157 */
158 struct ib_uverbs_attr __user *uattr;
159 union {
160 struct uverbs_ptr_attr ptr_attr;
161 struct uverbs_obj_attr obj_attr;
162 };
80}; 163};
81 164
82struct uverbs_attr_bundle_hash { 165struct uverbs_attr_bundle_hash {
diff --git a/include/uapi/rdma/rdma_user_ioctl.h b/include/uapi/rdma/rdma_user_ioctl.h
index 9388125ad51b..165a27e969d5 100644
--- a/include/uapi/rdma/rdma_user_ioctl.h
+++ b/include/uapi/rdma/rdma_user_ioctl.h
@@ -43,6 +43,39 @@
43/* Legacy name, for user space application which already use it */ 43/* Legacy name, for user space application which already use it */
44#define IB_IOCTL_MAGIC RDMA_IOCTL_MAGIC 44#define IB_IOCTL_MAGIC RDMA_IOCTL_MAGIC
45 45
46#define RDMA_VERBS_IOCTL \
47 _IOWR(RDMA_IOCTL_MAGIC, 1, struct ib_uverbs_ioctl_hdr)
48
49#define UVERBS_ID_NS_MASK 0xF000
50#define UVERBS_ID_NS_SHIFT 12
51
52enum {
53 /* User input */
54 UVERBS_ATTR_F_MANDATORY = 1U << 0,
55 /*
56 * Valid output bit should be ignored and considered set in
57 * mandatory fields. This bit is kernel output.
58 */
59 UVERBS_ATTR_F_VALID_OUTPUT = 1U << 1,
60};
61
62struct ib_uverbs_attr {
63 __u16 attr_id; /* command specific type attribute */
64 __u16 len; /* only for pointers */
65 __u16 flags; /* combination of UVERBS_ATTR_F_XXXX */
66 __u16 reserved;
67 __u64 data; /* ptr to command, inline data or idr/fd */
68};
69
70struct ib_uverbs_ioctl_hdr {
71 __u16 length;
72 __u16 object_id;
73 __u16 method_id;
74 __u16 num_attrs;
75 __u64 reserved;
76 struct ib_uverbs_attr attrs[0];
77};
78
46/* 79/*
47 * General blocks assignments 80 * General blocks assignments
48 * It is closed on purpose do not expose it it user space 81 * It is closed on purpose do not expose it it user space