/* Specification of a single attribute inside the ioctl message */ /* good size 16 */ struct uverbs_attr_spec {
u8 type;
/* * Support extending attributes by length. Allow the user to provide * more bytes than ptr.len, but check that everything after is zero'd * by the user.
*/
u8 zero_trailing:1; /* * Valid only for PTR_IN. Allocate and copy the data inside * the parser
*/
u8 alloc_and_copy:1;
u8 mandatory:1; /* True if this is from UVERBS_ATTR_UHW */
u8 is_udata:1;
union { struct { /* Current known size to kernel */
u16 len; /* User isn't allowed to provide something < min_len */
u16 min_len;
} ptr;
struct { /* * higher bits mean the namespace and lower bits mean * the type id within the namespace.
*/
u16 obj_type;
u8 access;
} obj;
struct {
u8 num_elems;
} enum_def;
} u;
/* This weird split lets us remove some padding */ union { struct { /* * The enum attribute can select one of the attributes * contained in the ids array. Currently only PTR_IN * attributes are supported in the ids array.
*/ conststruct uverbs_attr_spec *ids;
} enum_def;
struct { /* * higher bits mean the namespace and lower bits mean * the type id within the namespace.
*/
u16 obj_type;
u16 min_len;
u16 max_len;
u8 access;
} objs_arr;
} u2;
};
/* * Information about the API is loaded into a radix tree. For IOCTL we start * with a tuple of: * object_id, attr_id, method_id * * Which is a 48 bit value, with most of the bits guaranteed to be zero. Based * on the current kernel support this is compressed into 16 bit key for the * radix tree. Since this compression is entirely internal to the kernel the * below limits can be revised if the kernel gains additional data. * * With 64 leafs per node this is a 3 level radix tree. * * The tree encodes multiple types, and uses a scheme where OBJ_ID,0,0 returns * the object slot, and OBJ_ID,METH_ID,0 and returns the method slot. * * This also encodes the tables for the write() and write() extended commands * using the coding * OBJ_ID,UVERBS_API_METHOD_IS_WRITE,command # * OBJ_ID,UVERBS_API_METHOD_IS_WRITE_EX,command_ex # * ie the WRITE path is treated as a special method type in the ioctl * framework.
*/ enum uapi_radix_data {
UVERBS_API_NS_FLAG = 1U << UVERBS_ID_NS_SHIFT,
/* This id guaranteed to not exist in the radix tree */
UVERBS_API_KEY_ERR = 0xFFFFFFFF,
};
staticinline __attribute_const__ u32 uapi_key_obj(u32 id)
{ if (id & UVERBS_API_NS_FLAG) {
id &= ~UVERBS_API_NS_FLAG; if (id >= UVERBS_API_OBJ_KEY_NUM_DRIVER) return UVERBS_API_KEY_ERR;
id = id + UVERBS_API_OBJ_KEY_NUM_CORE;
} else { if (id >= UVERBS_API_OBJ_KEY_NUM_CORE) return UVERBS_API_KEY_ERR;
}
staticinline __attribute_const__ u32 uapi_key_ioctl_method(u32 id)
{ if (id & UVERBS_API_NS_FLAG) {
id &= ~UVERBS_API_NS_FLAG; if (id >= UVERBS_API_METHOD_KEY_NUM_DRIVER) return UVERBS_API_KEY_ERR;
id = id + UVERBS_API_METHOD_KEY_NUM_CORE;
} else {
id++; if (id >= UVERBS_API_METHOD_KEY_NUM_CORE) return UVERBS_API_KEY_ERR;
}
return id << UVERBS_API_METHOD_KEY_SHIFT;
}
staticinline __attribute_const__ u32 uapi_key_write_method(u32 id)
{ if (id >= UVERBS_API_WRITE_KEY_NUM) return UVERBS_API_KEY_ERR; return UVERBS_API_METHOD_IS_WRITE | id;
}
staticinline __attribute_const__ u32 uapi_key_write_ex_method(u32 id)
{ if (id >= UVERBS_API_WRITE_KEY_NUM) return UVERBS_API_KEY_ERR; return UVERBS_API_METHOD_IS_WRITE_EX | id;
}
staticinline __attribute_const__ u32 uapi_key_attrs_start(u32 ioctl_method_key)
{ /* 0 is the method slot itself */ return ioctl_method_key + 1;
}
staticinline __attribute_const__ u32 uapi_key_attr(u32 id)
{ /* * The attr is designed to fit in the typical single radix tree node * of 64 entries. Since allmost all methods have driver attributes we * organize things so that the driver and core attributes interleave to * reduce the length of the attributes array in typical cases.
*/ if (id & UVERBS_API_NS_FLAG) {
id &= ~UVERBS_API_NS_FLAG;
id++; if (id >= 1 << (UVERBS_API_ATTR_KEY_BITS - 1)) return UVERBS_API_KEY_ERR;
id = (id << 1) | 0;
} else { if (id >= 1 << (UVERBS_API_ATTR_KEY_BITS - 1)) return UVERBS_API_KEY_ERR;
id = (id << 1) | 1;
}
return id;
}
/* Only true for ioctl methods */ staticinline __attribute_const__ bool uapi_key_is_attr(u32 key)
{ unsignedint method = key & UVERBS_API_METHOD_KEY_MASK;
/* * This returns a value in the range [0 to UVERBS_API_ATTR_BKEY_LEN), * basically it undoes the reservation of 0 in the ID numbering. attr_key * must already be masked with UVERBS_API_ATTR_KEY_MASK, or be the output of * uapi_key_attr().
*/ staticinline __attribute_const__ u32 uapi_bkey_attr(u32 attr_key)
{ return attr_key - 1;
}
/* * Object is only supported if the function pointer named ibdev_fn in struct * ib_device is not NULL.
*/ #define UAPI_DEF_OBJ_NEEDS_FN(ibdev_fn) \
{ \
.kind = UAPI_DEF_IS_SUPPORTED_DEV_FN, \
.scope = UAPI_SCOPE_OBJECT, \
.needs_fn_offset = \
offsetof(struct ib_device_ops, ibdev_fn) + \
BUILD_BUG_ON_ZERO(sizeof_field(struct ib_device_ops, \
ibdev_fn) != \ sizeof(void *)), \
}
/* * Method is only supported if the function pointer named ibdev_fn in struct * ib_device is not NULL.
*/ #define UAPI_DEF_METHOD_NEEDS_FN(ibdev_fn) \
{ \
.kind = UAPI_DEF_IS_SUPPORTED_DEV_FN, \
.scope = UAPI_SCOPE_METHOD, \
.needs_fn_offset = \
offsetof(struct ib_device_ops, ibdev_fn) + \
BUILD_BUG_ON_ZERO(sizeof_field(struct ib_device_ops, \
ibdev_fn) != \ sizeof(void *)), \
}
/* Call a function to determine if the entire object is supported or not */ #define UAPI_DEF_IS_OBJ_SUPPORTED(_func) \
{ \
.kind = UAPI_DEF_IS_SUPPORTED_FUNC, \
.scope = UAPI_SCOPE_OBJECT, .func_is_supported = _func, \
}
/* Include another struct uapi_definition in this one */ #define UAPI_DEF_CHAIN(_def_var) \
{ \
.kind = UAPI_DEF_CHAIN, .chain = _def_var, \
}
/* Temporary until the tree base description is replaced */ #define UAPI_DEF_CHAIN_OBJ_TREE(_object_enum, _object_ptr, ...) \
{ \
.kind = UAPI_DEF_CHAIN_OBJ_TREE, \
.object_start = { .object_id = _object_enum }, \
.chain_obj_tree = _object_ptr, \
}, \ ##__VA_ARGS__ #define UAPI_DEF_CHAIN_OBJ_TREE_NAMED(_object_enum, ...) \
UAPI_DEF_CHAIN_OBJ_TREE(_object_enum, \
PTR_IF(IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS), \
&UVERBS_OBJECT(_object_enum)), \ ##__VA_ARGS__)
/* * Specifies a uapi structure that cannot be extended. The user must always * supply the whole structure and nothing more. The structure must be declared * in a header under include/uapi/rdma.
*/ #define UVERBS_ATTR_TYPE(_type) \
.u.ptr.min_len = sizeof(_type), .u.ptr.len = sizeof(_type) /* * Specifies a uapi structure where the user must provide at least up to * member 'last'. Anything after last and up until the end of the structure * can be non-zero, anything longer than the end of the structure must be * zero. The structure must be declared in a header under include/uapi/rdma.
*/ #define UVERBS_ATTR_STRUCT(_type, _last) \
.zero_trailing = 1, \
UVERBS_ATTR_SIZE(offsetofend(_type, _last), sizeof(_type)) /* * Specifies at least min_len bytes must be passed in, but the amount can be * larger, up to the protocol maximum size. No check for zeroing is done.
*/ #define UVERBS_ATTR_MIN_SIZE(_min_len) UVERBS_ATTR_SIZE(_min_len, USHRT_MAX)
/* Must be used in the '...' of any UVERBS_ATTR */ #define UA_ALLOC_AND_COPY .alloc_and_copy = 1 #define UA_MANDATORY .mandatory = 1 #define UA_OPTIONAL .mandatory = 0
/* * Only for use with UVERBS_ATTR_IDR, allows any uobject type to be accepted, * the user must validate the type of the uobject instead.
*/ #define UVERBS_IDR_ANY_OBJECT 0xFFFF
/* An input value that is a member in the enum _enum_type. */ #define UVERBS_ATTR_CONST_IN(_attr_id, _enum_type, ...) \
UVERBS_ATTR_PTR_IN( \
_attr_id, \
UVERBS_ATTR_SIZE( \ sizeof(u64) + BUILD_BUG_ON_ZERO(!sizeof(_enum_type)), \ sizeof(u64)), \
__VA_ARGS__)
/* * An input value that is a bitwise combination of values of _enum_type. * This permits the flag value to be passed as either a u32 or u64, it must * be retrieved via uverbs_get_flag().
*/ #define UVERBS_ATTR_FLAGS_IN(_attr_id, _enum_type, ...) \
UVERBS_ATTR_PTR_IN( \
_attr_id, \
UVERBS_ATTR_SIZE(sizeof(u32) + BUILD_BUG_ON_ZERO( \
!sizeof(_enum_type *)), \ sizeof(u64)), \
__VA_ARGS__)
/* * This spec is used in order to pass information to the hardware driver in a * legacy way. Every verb that could get driver specific data should get this * spec.
*/ #define UVERBS_ATTR_UHW() \
UVERBS_ATTR_PTR_IN(UVERBS_ATTR_UHW_IN, \
UVERBS_ATTR_MIN_SIZE(0), \
UA_OPTIONAL, \
.is_udata = 1), \
UVERBS_ATTR_PTR_OUT(UVERBS_ATTR_UHW_OUT, \
UVERBS_ATTR_MIN_SIZE(0), \
UA_OPTIONAL, \
.is_udata = 1)
struct uverbs_ptr_attr { /* * If UVERBS_ATTR_SPEC_F_ALLOC_AND_COPY is set then the 'ptr' is * used.
*/ union { void *ptr;
u64 data;
};
u16 len;
u16 uattr_idx;
u8 enum_id;
};
/** * rdma_udata_to_drv_context - Helper macro to get the driver's context out of * ib_udata which is embedded in uverbs_attr_bundle. * * If udata is not NULL this cannot fail. Otherwise a NULL udata will result * in a NULL ucontext pointer, as a safety precaution. Callers should be using * 'udata' to determine if the driver call is in user or kernel mode, not * 'ucontext'. *
*/ staticinlinestruct uverbs_attr_bundle *
rdma_udata_to_uverbs_attr_bundle(struct ib_udata *udata)
{ return container_of(udata, struct uverbs_attr_bundle, driver_udata);
}
/* * uverbs_attr_ptr_get_array_size() - Get array size pointer by a ptr * attribute. * @attrs: The attribute bundle * @idx: The ID of the attribute * @elem_size: The size of the element in the array
*/ staticinlineint
uverbs_attr_ptr_get_array_size(struct uverbs_attr_bundle *attrs, u16 idx,
size_t elem_size)
{ int size = uverbs_attr_get_len(attrs, idx);
if (size < 0) return size;
if (size % elem_size) return -EINVAL;
return size / elem_size;
}
/** * uverbs_attr_get_uobjs_arr() - Provides array's properties for attribute for * UVERBS_ATTR_TYPE_IDRS_ARRAY. * @arr: Returned pointer to array of pointers for uobjects or NULL if * the attribute isn't provided. * * Return: The array length or 0 if no attribute was provided.
*/ staticinlineint uverbs_attr_get_uobjs_arr( conststruct uverbs_attr_bundle *attrs_bundle, u16 attr_idx, struct ib_uobject ***arr)
{ conststruct uverbs_attr *attr =
uverbs_attr_get(attrs_bundle, attr_idx);
/* * Validation ensures attr->ptr_attr.len >= size. If the caller is * using UVERBS_ATTR_SPEC_F_MIN_SZ_OR_ZERO then it must call * uverbs_copy_from_or_zero.
*/ if (unlikely(size < attr->ptr_attr.len)) return -EINVAL;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.