Skip to content

Commit 5242711

Browse files
matanb10dledford
authored andcommitted
IB/core: Assign root to all drivers
In order to use the parsing tree, we need to assign the root to all drivers. Currently, we just assign the default parsing tree via ib_uverbs_add_one. The driver could override this by assigning a parsing tree prior to registering the device. Signed-off-by: Matan Barak <matanb@mellanox.com> Reviewed-by: Yishai Hadas <yishaih@mellanox.com> Signed-off-by: Doug Ledford <dledford@redhat.com>
1 parent 9ee79fc commit 5242711

4 files changed

Lines changed: 45 additions & 0 deletions

File tree

‎drivers/infiniband/core/uverbs.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ struct ib_uverbs_device {
100100
struct mutex lists_mutex; /* protect lists */
101101
struct list_head uverbs_file_list;
102102
struct list_head uverbs_events_file_list;
103+
struct uverbs_root_spec *specs_root;
103104
};
104105

105106
struct ib_uverbs_event_queue {

‎drivers/infiniband/core/uverbs_main.c‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include <linux/uaccess.h>
5050

5151
#include <rdma/ib.h>
52+
#include <rdma/uverbs_std_types.h>
5253

5354
#include "uverbs.h"
5455
#include "core_priv.h"
@@ -1097,6 +1098,18 @@ static void ib_uverbs_add_one(struct ib_device *device)
10971098
if (device_create_file(uverbs_dev->dev, &dev_attr_abi_version))
10981099
goto err_class;
10991100

1101+
if (!device->specs_root) {
1102+
const struct uverbs_object_tree_def *default_root[] = {
1103+
uverbs_default_get_objects()};
1104+
1105+
uverbs_dev->specs_root = uverbs_alloc_spec_tree(1,
1106+
default_root);
1107+
if (IS_ERR(uverbs_dev->specs_root))
1108+
goto err_class;
1109+
1110+
device->specs_root = uverbs_dev->specs_root;
1111+
}
1112+
11001113
ib_set_client_data(device, &uverbs_client, uverbs_dev);
11011114

11021115
return;
@@ -1228,6 +1241,11 @@ static void ib_uverbs_remove_one(struct ib_device *device, void *client_data)
12281241
ib_uverbs_comp_dev(uverbs_dev);
12291242
if (wait_clients)
12301243
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+
}
1248+
12311249
kobject_put(&uverbs_dev->kobj);
12321250
}
12331251

‎include/rdma/uverbs_ioctl.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,20 @@ static inline int _uverbs_copy_from(void *to, size_t to_size,
419419
* An object without any methods is considered invalid and will abort the
420420
* function with -ENOENT error.
421421
*/
422+
#if IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS)
422423
struct uverbs_root_spec *uverbs_alloc_spec_tree(unsigned int num_trees,
423424
const struct uverbs_object_tree_def **trees);
424425
void uverbs_free_spec_tree(struct uverbs_root_spec *root);
426+
#else
427+
static inline struct uverbs_root_spec *uverbs_alloc_spec_tree(unsigned int num_trees,
428+
const struct uverbs_object_tree_def **trees)
429+
{
430+
return NULL;
431+
}
432+
433+
static inline void uverbs_free_spec_tree(struct uverbs_root_spec *root)
434+
{
435+
}
436+
#endif
425437

426438
#endif

‎include/rdma/uverbs_std_types.h‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@
3434
#define _UVERBS_STD_TYPES__
3535

3636
#include <rdma/uverbs_types.h>
37+
#include <rdma/uverbs_ioctl.h>
3738
#include <rdma/ib_user_ioctl_verbs.h>
3839

40+
#if IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS)
3941
extern const struct uverbs_object_def uverbs_object_comp_channel;
4042
extern const struct uverbs_object_def uverbs_object_cq;
4143
extern const struct uverbs_object_def uverbs_object_qp;
@@ -50,6 +52,18 @@ extern const struct uverbs_object_def uverbs_object_pd;
5052
extern const struct uverbs_object_def uverbs_object_xrcd;
5153
extern const struct uverbs_object_def uverbs_object_device;
5254

55+
extern const struct uverbs_object_tree_def uverbs_default_objects;
56+
static inline const struct uverbs_object_tree_def *uverbs_default_get_objects(void)
57+
{
58+
return &uverbs_default_objects;
59+
}
60+
#else
61+
static inline const struct uverbs_object_tree_def *uverbs_default_get_objects(void)
62+
{
63+
return NULL;
64+
}
65+
#endif
66+
5367
static inline struct ib_uobject *__uobj_get(const struct uverbs_obj_type *type,
5468
bool write,
5569
struct ib_ucontext *ucontext,

0 commit comments

Comments
 (0)