Skip to content

Commit f43dbeb

Browse files
matanb10dledford
authored andcommitted
IB/core: Add support to finalize objects in one transaction
The new ioctl based infrastructure either commits or rollbacks all objects of the method as one transaction. In order to do that, we introduce a notion of dealing with a collection of objects that are related to a specific method. This also requires adding a notion of a method and attribute. A method contains a hash of attributes, where each bucket contains several attributes. The attributes are hashed according to their namespace which resides in the four upper bits of the id. For example, an object could be a CQ, which has an action of CREATE_CQ. This action has multiple attributes. For example, the CQ's new handle and the comp_channel. Each layer in this hierarchy - objects, methods and attributes is split into namespaces. The basic example for that is one namespace representing the default entities and another one representing the driver specific entities. When declaring these methods and attributes, we actually declare their specifications. When a method is executed, we actually allocates some space to hold auxiliary information. This auxiliary information contains meta-data about the required objects, such as pointers to their type information, pointers to the uobjects themselves (if exist), etc. The specification, along with the auxiliary information we allocated and filled is given to the finalize_objects function. Signed-off-by: Matan Barak <[email protected]> Reviewed-by: Yishai Hadas <[email protected]> Signed-off-by: Doug Ledford <[email protected]>
1 parent a0aa309 commit f43dbeb

File tree

3 files changed

+114
-1
lines changed

3 files changed

+114
-1
lines changed

drivers/infiniband/core/rdma_core.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,3 +683,43 @@ int uverbs_finalize_object(struct ib_uobject *uobj,
683683

684684
return ret;
685685
}
686+
687+
int uverbs_finalize_objects(struct uverbs_attr_bundle *attrs_bundle,
688+
struct uverbs_attr_spec_hash * const *spec_hash,
689+
size_t num,
690+
bool commit)
691+
{
692+
unsigned int i;
693+
int ret = 0;
694+
695+
for (i = 0; i < num; i++) {
696+
struct uverbs_attr_bundle_hash *curr_bundle =
697+
&attrs_bundle->hash[i];
698+
const struct uverbs_attr_spec_hash *curr_spec_bucket =
699+
spec_hash[i];
700+
unsigned int j;
701+
702+
for (j = 0; j < curr_bundle->num_attrs; j++) {
703+
struct uverbs_attr *attr;
704+
const struct uverbs_attr_spec *spec;
705+
706+
if (!uverbs_attr_is_valid_in_hash(curr_bundle, j))
707+
continue;
708+
709+
attr = &curr_bundle->attrs[j];
710+
spec = &curr_spec_bucket->attrs[j];
711+
712+
if (spec->type == UVERBS_ATTR_TYPE_IDR ||
713+
spec->type == UVERBS_ATTR_TYPE_FD) {
714+
int current_ret;
715+
716+
current_ret = uverbs_finalize_object(attr->obj_attr.uobject,
717+
spec->obj.access,
718+
commit);
719+
if (!ret)
720+
ret = current_ret;
721+
}
722+
}
723+
}
724+
return ret;
725+
}

drivers/infiniband/core/rdma_core.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ void uverbs_close_fd(struct file *f);
8282
* applicable.
8383
* This function could create (access == NEW), destroy (access == DESTROY)
8484
* or unlock (access == READ || access == WRITE) objects if required.
85-
* The action will be finalized only when uverbs_finalize_object is called.
85+
* The action will be finalized only when uverbs_finalize_object or
86+
* uverbs_finalize_objects are called.
8687
*/
8788
struct ib_uobject *uverbs_get_uobject_from_context(const struct uverbs_obj_type *type_attrs,
8889
struct ib_ucontext *ucontext,
@@ -91,5 +92,24 @@ struct ib_uobject *uverbs_get_uobject_from_context(const struct uverbs_obj_type
9192
int uverbs_finalize_object(struct ib_uobject *uobj,
9293
enum uverbs_obj_access access,
9394
bool commit);
95+
/*
96+
* Note that certain finalize stages could return a status:
97+
* (a) alloc_commit could return a failure if the object is committed at the
98+
* same time when the context is destroyed.
99+
* (b) remove_commit could fail if the object wasn't destroyed successfully.
100+
* Since multiple objects could be finalized in one transaction, it is very NOT
101+
* recommended to have several finalize actions which have side effects.
102+
* For example, it's NOT recommended to have a certain action which has both
103+
* a commit action and a destroy action or two destroy objects in the same
104+
* action. The rule of thumb is to have one destroy or commit action with
105+
* multiple lookups.
106+
* The first non zero return value of finalize_object is returned from this
107+
* function. For example, this could happen when we couldn't destroy an
108+
* object.
109+
*/
110+
int uverbs_finalize_objects(struct uverbs_attr_bundle *attrs_bundle,
111+
struct uverbs_attr_spec_hash * const *spec_hash,
112+
size_t num,
113+
bool commit);
94114

95115
#endif /* RDMA_CORE_H */

include/rdma/uverbs_ioctl.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,65 @@
4141
* =======================================
4242
*/
4343

44+
enum uverbs_attr_type {
45+
UVERBS_ATTR_TYPE_NA,
46+
UVERBS_ATTR_TYPE_IDR,
47+
UVERBS_ATTR_TYPE_FD,
48+
};
49+
4450
enum uverbs_obj_access {
4551
UVERBS_ACCESS_READ,
4652
UVERBS_ACCESS_WRITE,
4753
UVERBS_ACCESS_NEW,
4854
UVERBS_ACCESS_DESTROY
4955
};
5056

57+
struct uverbs_attr_spec {
58+
enum uverbs_attr_type type;
59+
struct {
60+
/*
61+
* higher bits mean the namespace and lower bits mean
62+
* the type id within the namespace.
63+
*/
64+
u16 obj_type;
65+
u8 access;
66+
} obj;
67+
};
68+
69+
struct uverbs_attr_spec_hash {
70+
size_t num_attrs;
71+
struct uverbs_attr_spec attrs[0];
72+
};
73+
74+
struct uverbs_obj_attr {
75+
struct ib_uobject *uobject;
76+
};
77+
78+
struct uverbs_attr {
79+
struct uverbs_obj_attr obj_attr;
80+
};
81+
82+
struct uverbs_attr_bundle_hash {
83+
/* if bit i is set, it means attrs[i] contains valid information */
84+
unsigned long *valid_bitmap;
85+
size_t num_attrs;
86+
/*
87+
* arrays of attributes, each element corresponds to the specification
88+
* of the attribute in the same index.
89+
*/
90+
struct uverbs_attr *attrs;
91+
};
92+
93+
struct uverbs_attr_bundle {
94+
size_t num_buckets;
95+
struct uverbs_attr_bundle_hash hash[];
96+
};
97+
98+
static inline bool uverbs_attr_is_valid_in_hash(const struct uverbs_attr_bundle_hash *attrs_hash,
99+
unsigned int idx)
100+
{
101+
return test_bit(idx, attrs_hash->valid_bitmap);
102+
}
103+
51104
#endif
52105

0 commit comments

Comments
 (0)