Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Matan Barak and committed by
Doug Ledford
52427112 9ee79fce

+45
+1
drivers/infiniband/core/uverbs.h
··· 100 100 struct mutex lists_mutex; /* protect lists */ 101 101 struct list_head uverbs_file_list; 102 102 struct list_head uverbs_events_file_list; 103 + struct uverbs_root_spec *specs_root; 103 104 }; 104 105 105 106 struct ib_uverbs_event_queue {
+18
drivers/infiniband/core/uverbs_main.c
··· 49 49 #include <linux/uaccess.h> 50 50 51 51 #include <rdma/ib.h> 52 + #include <rdma/uverbs_std_types.h> 52 53 53 54 #include "uverbs.h" 54 55 #include "core_priv.h" ··· 1098 1097 if (device_create_file(uverbs_dev->dev, &dev_attr_abi_version)) 1099 1098 goto err_class; 1100 1099 1100 + if (!device->specs_root) { 1101 + const struct uverbs_object_tree_def *default_root[] = { 1102 + uverbs_default_get_objects()}; 1103 + 1104 + uverbs_dev->specs_root = uverbs_alloc_spec_tree(1, 1105 + default_root); 1106 + if (IS_ERR(uverbs_dev->specs_root)) 1107 + goto err_class; 1108 + 1109 + device->specs_root = uverbs_dev->specs_root; 1110 + } 1111 + 1101 1112 ib_set_client_data(device, &uverbs_client, uverbs_dev); 1102 1113 1103 1114 return; ··· 1241 1228 ib_uverbs_comp_dev(uverbs_dev); 1242 1229 if (wait_clients) 1243 1230 wait_for_completion(&uverbs_dev->comp); 1231 + if (uverbs_dev->specs_root) { 1232 + uverbs_free_spec_tree(uverbs_dev->specs_root); 1233 + device->specs_root = NULL; 1234 + } 1235 + 1244 1236 kobject_put(&uverbs_dev->kobj); 1245 1237 } 1246 1238
+12
include/rdma/uverbs_ioctl.h
··· 419 419 * An object without any methods is considered invalid and will abort the 420 420 * function with -ENOENT error. 421 421 */ 422 + #if IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS) 422 423 struct uverbs_root_spec *uverbs_alloc_spec_tree(unsigned int num_trees, 423 424 const struct uverbs_object_tree_def **trees); 424 425 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 425 437 426 438 #endif
+14
include/rdma/uverbs_std_types.h
··· 34 34 #define _UVERBS_STD_TYPES__ 35 35 36 36 #include <rdma/uverbs_types.h> 37 + #include <rdma/uverbs_ioctl.h> 37 38 #include <rdma/ib_user_ioctl_verbs.h> 38 39 40 + #if IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS) 39 41 extern const struct uverbs_object_def uverbs_object_comp_channel; 40 42 extern const struct uverbs_object_def uverbs_object_cq; 41 43 extern const struct uverbs_object_def uverbs_object_qp; ··· 51 49 extern const struct uverbs_object_def uverbs_object_pd; 52 50 extern const struct uverbs_object_def uverbs_object_xrcd; 53 51 extern const struct uverbs_object_def uverbs_object_device; 52 + 53 + extern const struct uverbs_object_tree_def uverbs_default_objects; 54 + static inline const struct uverbs_object_tree_def *uverbs_default_get_objects(void) 55 + { 56 + return &uverbs_default_objects; 57 + } 58 + #else 59 + static inline const struct uverbs_object_tree_def *uverbs_default_get_objects(void) 60 + { 61 + return NULL; 62 + } 63 + #endif 54 64 55 65 static inline struct ib_uobject *__uobj_get(const struct uverbs_obj_type *type, 56 66 bool write,