History

RDMA/uverbs: Store the specs_root in the struct ib_uverbs_device

The specs are required to operate the uverbs file, so they belong inside the ib_uverbs_device, not inside the ib_device. The spec passed in the ib_device is just a communication from the driver and should not be used during runtime. This also changes the lifetime of the spec memory to match the ib_uverbs_device, however at this time the spec_root can still contain driver pointers after disassociation, so it cannot be used if ib_dev is NULL. This is preparation for another series.

Jason Gunthorpe committed 8 years ago

Commit 87fc2a61 parent 8193abb6 files · +28 −28Browse files

Unified · Split

6 files
  1. drivers/infiniband/core/rdma_core.c +2 −2
  2. drivers/infiniband/core/rdma_core.h +1 −1
  3. drivers/infiniband/core/uverbs_ioctl.c +12 −14
  4. drivers/infiniband/core/uverbs_main.c +9 −7
  5. drivers/infiniband/hw/mlx5/main.c +3 −3
  6. include/rdma/ib_verbs.h +1 −1
drivers/infiniband/core/rdma_core.c+2−2
@@ -52,10 +52,10 @@ int uverbs_ns_idx(u16 *id, unsigned int ns_count) · 51 unmodified lines
5252 return ret;
5353 }
5454
55−const struct uverbs_object_spec *uverbs_get_object(const struct ib_device *ibdev,
55+const struct uverbs_object_spec *uverbs_get_object(struct ib_uverbs_file *ufile,
5656 uint16_t object)
5757 {
58− const struct uverbs_root_spec *object_hash = ibdev->specs_root;
58+ const struct uverbs_root_spec *object_hash = ufile->device->specs_root;
5959 const struct uverbs_object_spec_hash *objects;
6060 int ret = uverbs_ns_idx(&object, object_hash->num_buckets);
6161
drivers/infiniband/core/rdma_core.h+1−1
@@ -44,7 +44,7 @@ · 43 unmodified lines
4444 #include <linux/mutex.h>
4545
4646 int uverbs_ns_idx(u16 *id, unsigned int ns_count);
47−const struct uverbs_object_spec *uverbs_get_object(const struct ib_device *ibdev,
47+const struct uverbs_object_spec *uverbs_get_object(struct ib_uverbs_file *ufile,
4848 uint16_t object);
4949 const struct uverbs_method_spec *uverbs_get_method(const struct uverbs_object_spec *object,
5050 uint16_t method);
drivers/infiniband/core/uverbs_ioctl.c+12−14
@@ -46,8 +46,7 @@ static bool uverbs_is_attr_cleared(const struct ib_uverbs_attr *uattr, · 45 unmodified lines
4646 0, uattr->len - len);
4747 }
4848
49−static int uverbs_process_attr(struct ib_device *ibdev,
50− struct ib_ucontext *ucontext,
49+static int uverbs_process_attr(struct ib_uverbs_file *ufile,
5150 const struct ib_uverbs_attr *uattr,
5251 u16 attr_id,
5352 const struct uverbs_attr_spec_hash *attr_spec_bucket,
@@ -145,17 +144,18 @@ static int uverbs_process_attr(struct ib_device *ibdev, · 91 unmodified lines
145144 if (uattr->attr_data.reserved)
146145 return -EINVAL;
147146
148− if (uattr->len != 0 || !ucontext || uattr->data > INT_MAX)
147+ if (uattr->len != 0 || !ufile->ucontext ||
148+ uattr->data > INT_MAX)
149149 return -EINVAL;
150150
151151 o_attr = &e->obj_attr;
152− object = uverbs_get_object(ibdev, spec->obj.obj_type);
152+ object = uverbs_get_object(ufile, spec->obj.obj_type);
153153 if (!object)
154154 return -EINVAL;
155155
156156 o_attr->uobject = uverbs_get_uobject_from_context(
157157 object->type_attrs,
158− ucontext,
158+ ufile->ucontext,
159159 spec->obj.access,
160160 (int)uattr->data);
161161
@@ -230,8 +230,7 @@ static int uverbs_finalize_attrs(struct uverbs_attr_bundle *attrs_bundle, · 68 unmodified lines
230230 return ret;
231231 }
232232
233−static int uverbs_uattrs_process(struct ib_device *ibdev,
234− struct ib_ucontext *ucontext,
233+static int uverbs_uattrs_process(struct ib_uverbs_file *ufile,
235234 const struct ib_uverbs_attr *uattrs,
236235 size_t num_uattrs,
237236 const struct uverbs_method_spec *method,
@@ -267,9 +266,9 @@ static int uverbs_uattrs_process(struct ib_device *ibdev, · 29 unmodified lines
267266 num_given_buckets = ret + 1;
268267
269268 attr_spec_bucket = method->attr_buckets[ret];
270− ret = uverbs_process_attr(ibdev, ucontext, uattr, attr_id,
271− attr_spec_bucket, &attr_bundle->hash[ret],
272− uattr_ptr++);
269+ ret = uverbs_process_attr(ufile, uattr, attr_id,
270+ attr_spec_bucket,
271+ &attr_bundle->hash[ret], uattr_ptr++);
273272 if (ret) {
274273 uverbs_finalize_attrs(attr_bundle,
275274 method->attr_buckets,
@@ -324,9 +323,8 @@ static int uverbs_handle_method(struct ib_uverbs_attr __user *uattr_ptr, · 48 unmodified lines
324323 int finalize_ret;
325324 int num_given_buckets;
326325
327− num_given_buckets = uverbs_uattrs_process(ibdev, ufile->ucontext, uattrs,
328− num_uattrs, method_spec,
329− attr_bundle, uattr_ptr);
326+ num_given_buckets = uverbs_uattrs_process(
327+ ufile, uattrs, num_uattrs, method_spec, attr_bundle, uattr_ptr);
330328 if (num_given_buckets <= 0)
331329 return -EINVAL;
332330
@@ -367,7 +365,7 @@ static long ib_uverbs_cmd_verbs(struct ib_device *ib_dev, · 34 unmodified lines
367365 if (hdr->driver_id != ib_dev->driver_id)
368366 return -EINVAL;
369367
370− object_spec = uverbs_get_object(ib_dev, hdr->object_id);
368+ object_spec = uverbs_get_object(file, hdr->object_id);
371369 if (!object_spec)
372370 return -EPROTONOSUPPORT;
373371
drivers/infiniband/core/uverbs_main.c+9−7
@@ -161,6 +161,7 @@ static void ib_uverbs_release_dev(struct kobject *kobj) · 160 unmodified lines
161161 container_of(kobj, struct ib_uverbs_device, kobj);
162162
163163 cleanup_srcu_struct(&dev->disassociate_srcu);
164+ uverbs_free_spec_tree(dev->specs_root);
164165 kfree(dev);
165166 }
166167
@@ -1067,7 +1068,7 @@ static void ib_uverbs_add_one(struct ib_device *device) · 900 unmodified lines
10671068 if (device_create_file(uverbs_dev->dev, &dev_attr_abi_version))
10681069 goto err_class;
10691070
1070− if (!device->specs_root) {
1071+ if (!device->driver_specs_root) {
10711072 const struct uverbs_object_tree_def *default_root[] = {
10721073 uverbs_default_get_objects()};
10731074
@@ -1075,8 +1076,13 @@ static void ib_uverbs_add_one(struct ib_device *device) · 1 unmodified line
10751076 default_root);
10761077 if (IS_ERR(uverbs_dev->specs_root))
10771078 goto err_class;
1078−
1079− device->specs_root = uverbs_dev->specs_root;
1079+ } else {
1080+ uverbs_dev->specs_root = device->driver_specs_root;
1081+ /*
1082+ * Take responsibility to free the specs allocated by the
1083+ * driver.
1084+ */
1085+ device->driver_specs_root = NULL;
10801086 }
10811087
10821088 ib_set_client_data(device, &uverbs_client, uverbs_dev);
@@ -1241,10 +1247,6 @@ static void ib_uverbs_remove_one(struct ib_device *device, void *client_data) · 158 unmodified lines
12411247 ib_uverbs_comp_dev(uverbs_dev);
12421248 if (wait_clients)
12431249 wait_for_completion(&uverbs_dev->comp);
1244− if (uverbs_dev->specs_root) {
1245− uverbs_free_spec_tree(uverbs_dev->specs_root);
1246− device->specs_root = NULL;
1247− }
12481250
12491251 kobject_put(&uverbs_dev->kobj);
12501252 }
drivers/infiniband/hw/mlx5/main.c+3−3
@@ -5350,15 +5350,15 @@ static int populate_specs_root(struct mlx5_ib_dev *dev) · 5349 unmodified lines
53505350 !WARN_ON(num_trees >= ARRAY_SIZE(default_root)))
53515351 default_root[num_trees++] = mlx5_ib_get_devx_tree();
53525352
5353− dev->ib_dev.specs_root =
5353+ dev->ib_dev.driver_specs_root =
53545354 uverbs_alloc_spec_tree(num_trees, default_root);
53555355
5356− return PTR_ERR_OR_ZERO(dev->ib_dev.specs_root);
5356+ return PTR_ERR_OR_ZERO(dev->ib_dev.driver_specs_root);
53575357 }
53585358
53595359 static void depopulate_specs_root(struct mlx5_ib_dev *dev)
53605360 {
5361− uverbs_free_spec_tree(dev->ib_dev.specs_root);
5361+ uverbs_free_spec_tree(dev->ib_dev.driver_specs_root);
53625362 }
53635363
53645364 static int mlx5_ib_read_counters(struct ib_counters *counters,
include/rdma/ib_verbs.h+1−1
@@ -2602,7 +2602,7 @@ struct ib_device { · 2601 unmodified lines
26022602 const struct cpumask *(*get_vector_affinity)(struct ib_device *ibdev,
26032603 int comp_vector);
26042604
2605− struct uverbs_root_spec *specs_root;
2605+ struct uverbs_root_spec *driver_specs_root;
26062606 enum rdma_driver_id driver_id;
26072607 };
26082608

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t