Skip to content

Commit 9ad95a0

Browse files
yishaihrleon
authored andcommitted
RDMA/uverbs: Support external FD uobjects
Add support for uobjects that wrap externally allocated file descriptors (FDs). In this mode, the FD number still follows the standard uverbs allocation flow, but the file pointer is allocated externally and has its own fops and private data. As a result, alloc_begin_fd_uobject() must handle cases where fd_type->fops is NULL, and both alloc_commit_fd_uobject() and alloc_abort_fd_uobject() must account for whether filp->private_data exists, since it is populated outside the standard uverbs flow. Signed-off-by: Yishai Hadas <yishaih@nvidia.com> Signed-off-by: Edward Srouji <edwards@nvidia.com> Link: https://patch.msgid.link/20260201-dmabuf-export-v3-1-da238b614fe3@nvidia.com Signed-off-by: Leon Romanovsky <leon@kernel.org>
1 parent 06fddc7 commit 9ad95a0

1 file changed

Lines changed: 21 additions & 14 deletions

File tree

drivers/infiniband/core/rdma_core.c

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ alloc_begin_fd_uobject(const struct uverbs_api_object *obj,
465465

466466
fd_type =
467467
container_of(obj->type_attrs, struct uverbs_obj_fd_type, type);
468-
if (WARN_ON(fd_type->fops->release != &uverbs_uobject_fd_release &&
468+
if (WARN_ON(fd_type->fops && fd_type->fops->release != &uverbs_uobject_fd_release &&
469469
fd_type->fops->release != &uverbs_async_event_release)) {
470470
ret = ERR_PTR(-EINVAL);
471471
goto err_fd;
@@ -477,14 +477,16 @@ alloc_begin_fd_uobject(const struct uverbs_api_object *obj,
477477
goto err_fd;
478478
}
479479

480-
/* Note that uverbs_uobject_fd_release() is called during abort */
481-
filp = anon_inode_getfile(fd_type->name, fd_type->fops, NULL,
482-
fd_type->flags);
483-
if (IS_ERR(filp)) {
484-
ret = ERR_CAST(filp);
485-
goto err_getfile;
480+
if (fd_type->fops) {
481+
/* Note that uverbs_uobject_fd_release() is called during abort */
482+
filp = anon_inode_getfile(fd_type->name, fd_type->fops, NULL,
483+
fd_type->flags);
484+
if (IS_ERR(filp)) {
485+
ret = ERR_CAST(filp);
486+
goto err_getfile;
487+
}
488+
uobj->object = filp;
486489
}
487-
uobj->object = filp;
488490

489491
uobj->id = new_fd;
490492
return uobj;
@@ -561,7 +563,9 @@ static void alloc_abort_fd_uobject(struct ib_uobject *uobj)
561563
{
562564
struct file *filp = uobj->object;
563565

564-
fput(filp);
566+
if (filp)
567+
fput(filp);
568+
565569
put_unused_fd(uobj->id);
566570
}
567571

@@ -628,11 +632,14 @@ static void alloc_commit_fd_uobject(struct ib_uobject *uobj)
628632
/* This shouldn't be used anymore. Use the file object instead */
629633
uobj->id = 0;
630634

631-
/*
632-
* NOTE: Once we install the file we loose ownership of our kref on
633-
* uobj. It will be put by uverbs_uobject_fd_release()
634-
*/
635-
filp->private_data = uobj;
635+
if (!filp->private_data) {
636+
/*
637+
* NOTE: Once we install the file we loose ownership of our kref on
638+
* uobj. It will be put by uverbs_uobject_fd_release()
639+
*/
640+
filp->private_data = uobj;
641+
}
642+
636643
fd_install(fd, filp);
637644
}
638645

0 commit comments

Comments
 (0)