Skip to content

Commit 351de7c

Browse files
committed
RDMA/core: Add UVERBS_ATTR_RAW_FD
Bugzilla: https://bugzilla.redhat.com/2123401 commit 015bda8 Author: Jason Gunthorpe <jgg@ziepe.ca> Date: Thu Sep 1 11:20:54 2022 -0300 RDMA/core: Add UVERBS_ATTR_RAW_FD This uses the same passing protocol as UVERBS_ATTR_FD (eg len = 0 data_s64 = fd), except that the FD is not required to be a uverbs object and the core code does not covert the FD to an object handle automatically. Access to the int fd is provided by uverbs_get_raw_fd(). Link: https://lore.kernel.org/r/2-v1-bd147097458e+ede-umem_dmabuf_jgg@nvidia.com Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Kamal Heib <kheib@redhat.com>
1 parent 78361b1 commit 351de7c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

drivers/infiniband/core/uverbs_ioctl.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,14 @@ static int uverbs_process_attr(struct bundle_priv *pbundle,
337337

338338
break;
339339

340+
case UVERBS_ATTR_TYPE_RAW_FD:
341+
if (uattr->attr_data.reserved || uattr->len != 0 ||
342+
uattr->data_s64 < INT_MIN || uattr->data_s64 > INT_MAX)
343+
return -EINVAL;
344+
/* _uverbs_get_const_signed() is the accessor */
345+
e->ptr_attr.data = uattr->data_s64;
346+
break;
347+
340348
case UVERBS_ATTR_TYPE_IDRS_ARRAY:
341349
return uverbs_process_idrs_array(pbundle, attr_uapi,
342350
&e->objs_arr_attr, uattr,

include/rdma/uverbs_ioctl.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ enum uverbs_attr_type {
2424
UVERBS_ATTR_TYPE_PTR_OUT,
2525
UVERBS_ATTR_TYPE_IDR,
2626
UVERBS_ATTR_TYPE_FD,
27+
UVERBS_ATTR_TYPE_RAW_FD,
2728
UVERBS_ATTR_TYPE_ENUM_IN,
2829
UVERBS_ATTR_TYPE_IDRS_ARRAY,
2930
};
@@ -521,6 +522,11 @@ struct uapi_definition {
521522
.u.obj.access = _access, \
522523
__VA_ARGS__ } })
523524

525+
#define UVERBS_ATTR_RAW_FD(_attr_id, ...) \
526+
(&(const struct uverbs_attr_def){ \
527+
.id = (_attr_id), \
528+
.attr = { .type = UVERBS_ATTR_TYPE_RAW_FD, __VA_ARGS__ } })
529+
524530
#define UVERBS_ATTR_PTR_IN(_attr_id, _type, ...) \
525531
(&(const struct uverbs_attr_def){ \
526532
.id = _attr_id, \
@@ -999,4 +1005,11 @@ _uverbs_get_const_unsigned(u64 *to,
9991005
uverbs_get_const_default_unsigned(_to, _attrs_bundle, _idx, \
10001006
_default))
10011007

1008+
static inline int
1009+
uverbs_get_raw_fd(int *to, const struct uverbs_attr_bundle *attrs_bundle,
1010+
size_t idx)
1011+
{
1012+
return uverbs_get_const_signed(to, attrs_bundle, idx);
1013+
}
1014+
10021015
#endif

0 commit comments

Comments
 (0)