Skip to content

Commit 0f63ef1

Browse files
Leon Romanovskyjgunthorpe
authored andcommitted
RDMA/core: Align abort/commit object scheme for write() and ioctl() paths
Create the same logic flow for the write() interface as we have for the ioctl() path by making sure that the object is committed or aborted automatically after HW object creation. Link: https://lore.kernel.org/r/20200719052223.75245-2-leon@kernel.org Signed-off-by: Leon Romanovsky <leonro@mellanox.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent c94e272 commit 0f63ef1

4 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎drivers/infiniband/core/uverbs_main.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
601601
memset(bundle.attr_present, 0, sizeof(bundle.attr_present));
602602
bundle.ufile = file;
603603
bundle.context = NULL; /* only valid if bundle has uobject */
604+
bundle.uobject = NULL;
604605
if (!method_elm->is_ex) {
605606
size_t in_len = hdr.in_words * 4 - sizeof(hdr);
606607
size_t out_len = hdr.out_words * 4;
@@ -664,6 +665,9 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf,
664665
}
665666

666667
ret = method_elm->handler(&bundle);
668+
if (bundle.uobject)
669+
uverbs_finalize_object(bundle.uobject, UVERBS_ACCESS_NEW, true,
670+
!ret, &bundle);
667671
out_unlock:
668672
srcu_read_unlock(&file->device->disassociate_srcu, srcu_key);
669673
return (ret) ? : count;

‎drivers/infiniband/core/uverbs_std_types_device.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ static int UVERBS_HANDLER(UVERBS_METHOD_INVOKE_WRITE)(
3838
attrs->ucore.outlen < method_elm->resp_size)
3939
return -ENOSPC;
4040

41-
return method_elm->handler(attrs);
41+
attrs->uobject = NULL;
42+
rc = method_elm->handler(attrs);
43+
if (attrs->uobject)
44+
uverbs_finalize_object(attrs->uobject, UVERBS_ACCESS_NEW, true,
45+
!rc, attrs);
46+
return rc;
4247
}
4348

4449
DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_INVOKE_WRITE,

‎include/rdma/uverbs_ioctl.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,7 @@ struct uverbs_attr_bundle {
652652
struct ib_udata ucore;
653653
struct ib_uverbs_file *ufile;
654654
struct ib_ucontext *context;
655+
struct ib_uobject *uobject;
655656
DECLARE_BITMAP(attr_present, UVERBS_API_ATTR_BKEY_LEN);
656657
struct uverbs_attr attrs[];
657658
};

‎include/rdma/uverbs_std_types.h‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,20 @@ static inline void uobj_alloc_abort(struct ib_uobject *uobj,
110110
rdma_alloc_abort_uobject(uobj, attrs, false);
111111
}
112112

113+
static inline void uobj_finalize_uobj_create(struct ib_uobject *uobj,
114+
struct uverbs_attr_bundle *attrs)
115+
{
116+
/*
117+
* Tell the core code that the write() handler has completed
118+
* initializing the object and that the core should commit or
119+
* abort this object based upon the return code from the write()
120+
* method. Similar to what uverbs_finalize_uobj_create() does for
121+
* ioctl()
122+
*/
123+
WARN_ON(attrs->uobject);
124+
attrs->uobject = uobj;
125+
}
126+
113127
static inline struct ib_uobject *
114128
__uobj_alloc(const struct uverbs_api_object *obj,
115129
struct uverbs_attr_bundle *attrs, struct ib_device **ib_dev)

0 commit comments

Comments
 (0)