Commit 1f07e08f authored by Matan Barak's avatar Matan Barak Committed by Jason Gunthorpe

IB/uverbs: Enable compact representation of uverbs_attr_spec

Downstream patches extend uverbs_attr_spec with new fields.
In order to save space, we move the type and flags fields to
the various attribute flavors contained in the union.
Reviewed-by: default avatarYishai Hadas <yishaih@mellanox.com>
Signed-off-by: default avatarMatan Barak <matanb@mellanox.com>
Signed-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent 0ede73bc
...@@ -69,9 +69,9 @@ static int uverbs_process_attr(struct ib_device *ibdev, ...@@ -69,9 +69,9 @@ static int uverbs_process_attr(struct ib_device *ibdev,
switch (spec->type) { switch (spec->type) {
case UVERBS_ATTR_TYPE_PTR_IN: case UVERBS_ATTR_TYPE_PTR_IN:
case UVERBS_ATTR_TYPE_PTR_OUT: case UVERBS_ATTR_TYPE_PTR_OUT:
if (uattr->len < spec->len || if (uattr->len < spec->ptr.len ||
(!(spec->flags & UVERBS_ATTR_SPEC_F_MIN_SZ) && (!(spec->flags & UVERBS_ATTR_SPEC_F_MIN_SZ) &&
uattr->len > spec->len)) uattr->len > spec->ptr.len))
return -EINVAL; return -EINVAL;
e->ptr_attr.data = uattr->data; e->ptr_attr.data = uattr->data;
......
...@@ -66,11 +66,25 @@ enum { ...@@ -66,11 +66,25 @@ enum {
UVERBS_ATTR_SPEC_F_MIN_SZ = 1U << 1, UVERBS_ATTR_SPEC_F_MIN_SZ = 1U << 1,
}; };
/* Specification of a single attribute inside the ioctl message */
struct uverbs_attr_spec { struct uverbs_attr_spec {
enum uverbs_attr_type type;
union { union {
u16 len; /* Header shared by all following union members - to reduce space. */
struct { struct {
enum uverbs_attr_type type;
/* Combination of bits from enum UVERBS_ATTR_SPEC_F_XXXX */
u8 flags;
};
struct {
enum uverbs_attr_type type;
/* Combination of bits from enum UVERBS_ATTR_SPEC_F_XXXX */
u8 flags;
u16 len;
} ptr;
struct {
enum uverbs_attr_type type;
/* Combination of bits from enum UVERBS_ATTR_SPEC_F_XXXX */
u8 flags;
/* /*
* higher bits mean the namespace and lower bits mean * higher bits mean the namespace and lower bits mean
* the type id within the namespace. * the type id within the namespace.
...@@ -79,8 +93,6 @@ struct uverbs_attr_spec { ...@@ -79,8 +93,6 @@ struct uverbs_attr_spec {
u8 access; u8 access;
} obj; } obj;
}; };
/* Combination of bits from enum UVERBS_ATTR_SPEC_F_XXXX */
u8 flags;
}; };
struct uverbs_attr_spec_hash { struct uverbs_attr_spec_hash {
...@@ -167,10 +179,10 @@ struct uverbs_object_tree_def { ...@@ -167,10 +179,10 @@ struct uverbs_object_tree_def {
#define UA_FLAGS(_flags) .flags = _flags #define UA_FLAGS(_flags) .flags = _flags
#define __UVERBS_ATTR0(_id, _len, _type, ...) \ #define __UVERBS_ATTR0(_id, _len, _type, ...) \
((const struct uverbs_attr_def) \ ((const struct uverbs_attr_def) \
{.id = _id, .attr = {.type = _type, {.len = _len}, .flags = 0, } }) {.id = _id, .attr = {{.ptr = {.type = _type, .len = _len, .flags = 0, } }, } })
#define __UVERBS_ATTR1(_id, _len, _type, _flags) \ #define __UVERBS_ATTR1(_id, _len, _type, _flags) \
((const struct uverbs_attr_def) \ ((const struct uverbs_attr_def) \
{.id = _id, .attr = {.type = _type, {.len = _len}, _flags, } }) {.id = _id, .attr = {{.ptr = {.type = _type, .len = _len, _flags } },} })
#define __UVERBS_ATTR(_id, _len, _type, _flags, _n, ...) \ #define __UVERBS_ATTR(_id, _len, _type, _flags, _n, ...) \
__UVERBS_ATTR##_n(_id, _len, _type, _flags) __UVERBS_ATTR##_n(_id, _len, _type, _flags)
/* /*
...@@ -203,15 +215,13 @@ struct uverbs_object_tree_def { ...@@ -203,15 +215,13 @@ struct uverbs_object_tree_def {
#define ___UVERBS_ATTR_OBJ0(_id, _obj_class, _obj_type, _access, ...)\ #define ___UVERBS_ATTR_OBJ0(_id, _obj_class, _obj_type, _access, ...)\
((const struct uverbs_attr_def) \ ((const struct uverbs_attr_def) \
{.id = _id, \ {.id = _id, \
.attr = {.type = _obj_class, \ .attr = { {.obj = {.type = _obj_class, .obj_type = _obj_type, \
{.obj = {.obj_type = _obj_type, .access = _access } },\ .access = _access, .flags = 0 } }, } })
.flags = 0} })
#define ___UVERBS_ATTR_OBJ1(_id, _obj_class, _obj_type, _access, _flags)\ #define ___UVERBS_ATTR_OBJ1(_id, _obj_class, _obj_type, _access, _flags)\
((const struct uverbs_attr_def) \ ((const struct uverbs_attr_def) \
{.id = _id, \ {.id = _id, \
.attr = {.type = _obj_class, \ .attr = { {.obj = {.type = _obj_class, .obj_type = _obj_type, \
{.obj = {.obj_type = _obj_type, .access = _access} }, \ .access = _access, _flags} }, } })
_flags} })
#define ___UVERBS_ATTR_OBJ(_id, _obj_class, _obj_type, _access, _flags, \ #define ___UVERBS_ATTR_OBJ(_id, _obj_class, _obj_type, _access, _flags, \
_n, ...) \ _n, ...) \
___UVERBS_ATTR_OBJ##_n(_id, _obj_class, _obj_type, _access, _flags) ___UVERBS_ATTR_OBJ##_n(_id, _obj_class, _obj_type, _access, _flags)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment