RDMA/uverbs: Require all objects to have a driver destroy function
authorJason Gunthorpe <jgg@mellanox.com>
Mon, 12 Nov 2018 20:59:54 +0000 (22:59 +0200)
committerJason Gunthorpe <jgg@mellanox.com>
Thu, 22 Nov 2018 18:57:32 +0000 (11:57 -0700)
If we can't destroy the object then we certainly shouldn't allow it be
created or used. Remove it from the uverbs_uapi in this case.

This also disables methods of other objects that have mandatory object
handle inputs - ie REG_DM_MR is now automatically removed if DM objects
cannot be created.

Typically drivers not supporting an interface will mark all of the
supporting functions as NULL, including destroy.

This is intended to automatically eliminate entire corner cases in the API
that are difficult to test.

Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
drivers/infiniband/core/rdma_core.h
drivers/infiniband/core/uverbs_std_types.c
drivers/infiniband/core/uverbs_std_types_counters.c
drivers/infiniband/core/uverbs_std_types_cq.c
drivers/infiniband/core/uverbs_std_types_dm.c
drivers/infiniband/core/uverbs_std_types_flow_action.c
drivers/infiniband/core/uverbs_std_types_mr.c
drivers/infiniband/core/uverbs_uapi.c

index ce042e5..93da02c 100644 (file)
@@ -161,6 +161,11 @@ void uapi_compute_bundle_size(struct uverbs_api_ioctl_method *method_elm,
                              unsigned int num_attrs);
 void uverbs_user_mmap_disassociate(struct ib_uverbs_file *ufile);
 
+extern const struct uapi_definition uverbs_def_obj_counters[];
+extern const struct uapi_definition uverbs_def_obj_cq[];
+extern const struct uapi_definition uverbs_def_obj_dm[];
+extern const struct uapi_definition uverbs_def_obj_flow_action[];
 extern const struct uapi_definition uverbs_def_obj_intf[];
+extern const struct uapi_definition uverbs_def_obj_mr[];
 
 #endif /* RDMA_CORE_H */
index 2db188e..9e1abea 100644 (file)
@@ -264,20 +264,26 @@ DECLARE_UVERBS_GLOBAL_METHODS(UVERBS_OBJECT_DEVICE);
 
 const struct uapi_definition uverbs_def_obj_intf[] = {
        UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_DEVICE),
-       UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_PD),
-       UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_MR),
-       UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_COMP_CHANNEL),
-       UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_CQ),
-       UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_QP),
-       UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_AH),
-       UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_MW),
-       UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_SRQ),
-       UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_FLOW),
-       UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_WQ),
-       UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_RWQ_IND_TBL),
-       UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_XRCD),
-       UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_FLOW_ACTION),
-       UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_DM),
-       UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_COUNTERS),
+       UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_PD,
+                                     UAPI_DEF_OBJ_NEEDS_FN(dealloc_pd)),
+       UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_COMP_CHANNEL,
+                                     UAPI_DEF_OBJ_NEEDS_FN(dealloc_pd)),
+       UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_QP,
+                                     UAPI_DEF_OBJ_NEEDS_FN(destroy_qp)),
+       UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_AH,
+                                     UAPI_DEF_OBJ_NEEDS_FN(destroy_ah)),
+       UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_MW,
+                                     UAPI_DEF_OBJ_NEEDS_FN(dealloc_mw)),
+       UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_SRQ,
+                                     UAPI_DEF_OBJ_NEEDS_FN(destroy_srq)),
+       UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_FLOW,
+                                     UAPI_DEF_OBJ_NEEDS_FN(destroy_flow)),
+       UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_WQ,
+                                     UAPI_DEF_OBJ_NEEDS_FN(destroy_wq)),
+       UAPI_DEF_CHAIN_OBJ_TREE_NAMED(
+               UVERBS_OBJECT_RWQ_IND_TBL,
+               UAPI_DEF_OBJ_NEEDS_FN(destroy_rwq_ind_table)),
+       UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_XRCD,
+                                     UAPI_DEF_OBJ_NEEDS_FN(dealloc_xrcd)),
        {}
 };
index a0ffdcf..c4a78ab 100644 (file)
@@ -149,3 +149,9 @@ DECLARE_UVERBS_NAMED_OBJECT(UVERBS_OBJECT_COUNTERS,
                            &UVERBS_METHOD(UVERBS_METHOD_COUNTERS_CREATE),
                            &UVERBS_METHOD(UVERBS_METHOD_COUNTERS_DESTROY),
                            &UVERBS_METHOD(UVERBS_METHOD_COUNTERS_READ));
+
+const struct uapi_definition uverbs_def_obj_counters[] = {
+       UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_COUNTERS,
+                                     UAPI_DEF_OBJ_NEEDS_FN(destroy_counters)),
+       {}
+};
index 5b5f205..f94fd87 100644 (file)
@@ -207,3 +207,9 @@ DECLARE_UVERBS_NAMED_OBJECT(
        &UVERBS_METHOD(UVERBS_METHOD_CQ_DESTROY)
 #endif
 );
+
+const struct uapi_definition uverbs_def_obj_cq[] = {
+       UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_CQ,
+                                     UAPI_DEF_OBJ_NEEDS_FN(destroy_cq)),
+       {}
+};
index edc3ff7..c403533 100644 (file)
@@ -109,3 +109,9 @@ DECLARE_UVERBS_NAMED_OBJECT(UVERBS_OBJECT_DM,
                            UVERBS_TYPE_ALLOC_IDR(uverbs_free_dm),
                            &UVERBS_METHOD(UVERBS_METHOD_DM_ALLOC),
                            &UVERBS_METHOD(UVERBS_METHOD_DM_FREE));
+
+const struct uapi_definition uverbs_def_obj_dm[] = {
+       UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_DM,
+                                     UAPI_DEF_OBJ_NEEDS_FN(dealloc_dm)),
+       {}
+};
index cb9486a..24ac332 100644 (file)
@@ -438,3 +438,10 @@ DECLARE_UVERBS_NAMED_OBJECT(
        &UVERBS_METHOD(UVERBS_METHOD_FLOW_ACTION_ESP_CREATE),
        &UVERBS_METHOD(UVERBS_METHOD_FLOW_ACTION_DESTROY),
        &UVERBS_METHOD(UVERBS_METHOD_FLOW_ACTION_ESP_MODIFY));
+
+const struct uapi_definition uverbs_def_obj_flow_action[] = {
+       UAPI_DEF_CHAIN_OBJ_TREE_NAMED(
+               UVERBS_OBJECT_FLOW_ACTION,
+               UAPI_DEF_OBJ_NEEDS_FN(destroy_flow_action)),
+       {}
+};
index cf02e77..c400fd3 100644 (file)
@@ -147,3 +147,9 @@ DECLARE_UVERBS_NAMED_OBJECT(
        UVERBS_OBJECT_MR,
        UVERBS_TYPE_ALLOC_IDR(uverbs_free_mr),
        &UVERBS_METHOD(UVERBS_METHOD_DM_MR_REG));
+
+const struct uapi_definition uverbs_def_obj_mr[] = {
+       UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_MR,
+                                     UAPI_DEF_OBJ_NEEDS_FN(dereg_mr)),
+       {}
+};
index 9a904dd..363a2d2 100644 (file)
@@ -448,7 +448,12 @@ void uverbs_destroy_api(struct uverbs_api *uapi)
 }
 
 static const struct uapi_definition uverbs_core_api[] = {
+       UAPI_DEF_CHAIN(uverbs_def_obj_counters),
+       UAPI_DEF_CHAIN(uverbs_def_obj_cq),
+       UAPI_DEF_CHAIN(uverbs_def_obj_dm),
+       UAPI_DEF_CHAIN(uverbs_def_obj_flow_action),
        UAPI_DEF_CHAIN(uverbs_def_obj_intf),
+       UAPI_DEF_CHAIN(uverbs_def_obj_mr),
        {},
 };