Skip to content

Commit fe9d782

Browse files
chiarameiohasrleon
authored andcommitted
RDMA/uverbs: Add support for UCAPs in context creation
Add support for file descriptor array attribute for GET_CONTEXT commands. Check that the file descriptor (fd) array represents fds for valid UCAPs. Store the enabled UCAPs from the fd array as a bitmask in ib_ucontext. Signed-off-by: Chiara Meiohas <cmeiohas@nvidia.com> Link: https://patch.msgid.link/ebfb30bc947e2259b193c96a319c80e82599045b.1741261611.git.leon@kernel.org Reviewed-by: Yishai Hadas <yishaih@nvidia.com> Signed-off-by: Leon Romanovsky <leon@kernel.org>
1 parent cf7174e commit fe9d782

4 files changed

Lines changed: 25 additions & 0 deletions

File tree

drivers/infiniband/core/uverbs_cmd.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
#include <rdma/uverbs_types.h>
4444
#include <rdma/uverbs_std_types.h>
45+
#include <rdma/ib_ucaps.h>
4546
#include "rdma_core.h"
4647

4748
#include "uverbs.h"
@@ -232,6 +233,8 @@ int ib_init_ucontext(struct uverbs_attr_bundle *attrs)
232233
{
233234
struct ib_ucontext *ucontext = attrs->context;
234235
struct ib_uverbs_file *file = attrs->ufile;
236+
int *fd_array;
237+
int fd_count;
235238
int ret;
236239

237240
if (!down_read_trylock(&file->hw_destroy_rwsem))
@@ -247,6 +250,22 @@ int ib_init_ucontext(struct uverbs_attr_bundle *attrs)
247250
if (ret)
248251
goto err;
249252

253+
if (uverbs_attr_is_valid(attrs, UVERBS_ATTR_GET_CONTEXT_FD_ARR)) {
254+
fd_count = uverbs_attr_ptr_get_array_size(attrs,
255+
UVERBS_ATTR_GET_CONTEXT_FD_ARR,
256+
sizeof(int));
257+
if (fd_count < 0) {
258+
ret = fd_count;
259+
goto err_uncharge;
260+
}
261+
262+
fd_array = uverbs_attr_get_alloced_ptr(attrs,
263+
UVERBS_ATTR_GET_CONTEXT_FD_ARR);
264+
ret = ib_get_ucaps(fd_array, fd_count, &ucontext->enabled_caps);
265+
if (ret)
266+
goto err_uncharge;
267+
}
268+
250269
ret = ucontext->device->ops.alloc_ucontext(ucontext,
251270
&attrs->driver_udata);
252271
if (ret)

drivers/infiniband/core/uverbs_std_types_device.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,10 @@ DECLARE_UVERBS_NAMED_METHOD(
437437
UVERBS_ATTR_TYPE(u32), UA_OPTIONAL),
438438
UVERBS_ATTR_PTR_OUT(UVERBS_ATTR_GET_CONTEXT_CORE_SUPPORT,
439439
UVERBS_ATTR_TYPE(u64), UA_OPTIONAL),
440+
UVERBS_ATTR_PTR_IN(UVERBS_ATTR_GET_CONTEXT_FD_ARR,
441+
UVERBS_ATTR_MIN_SIZE(sizeof(int)),
442+
UA_OPTIONAL,
443+
UA_ALLOC_AND_COPY),
440444
UVERBS_ATTR_UHW());
441445

442446
DECLARE_UVERBS_NAMED_METHOD(

include/rdma/ib_verbs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,6 +1530,7 @@ struct ib_ucontext {
15301530
struct ib_uverbs_file *ufile;
15311531

15321532
struct ib_rdmacg_object cg_obj;
1533+
u64 enabled_caps;
15331534
/*
15341535
* Implementation details of the RDMA core, don't use in drivers:
15351536
*/

include/uapi/rdma/ib_user_ioctl_cmds.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ enum uverbs_attrs_query_port_cmd_attr_ids {
8888
enum uverbs_attrs_get_context_attr_ids {
8989
UVERBS_ATTR_GET_CONTEXT_NUM_COMP_VECTORS,
9090
UVERBS_ATTR_GET_CONTEXT_CORE_SUPPORT,
91+
UVERBS_ATTR_GET_CONTEXT_FD_ARR,
9192
};
9293

9394
enum uverbs_attrs_query_context_attr_ids {

0 commit comments

Comments
 (0)