Skip to content

Commit aa72c9a

Browse files
committed
IB/uverbs: Remove rdma_explicit_destroy() from the ioctl methods
The core code will destroy the HW object on behalf of the method, if the method provides an implementation it must simply copy data from the stub uobj into the response. Destroy methods cannot touch the HW object. Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 26e551c commit aa72c9a

File tree

3 files changed

+32
-22
lines changed

3 files changed

+32
-22
lines changed

drivers/infiniband/core/rdma_core.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -924,10 +924,7 @@ int uverbs_finalize_object(struct ib_uobject *uobj,
924924
rdma_lookup_put_uobject(uobj, true);
925925
break;
926926
case UVERBS_ACCESS_DESTROY:
927-
if (commit)
928-
ret = rdma_remove_commit_uobject(uobj);
929-
else
930-
rdma_lookup_put_uobject(uobj, true);
927+
rdma_lookup_put_uobject(uobj, true);
931928
break;
932929
case UVERBS_ACCESS_NEW:
933930
if (commit)

drivers/infiniband/core/uverbs_ioctl.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ static int uverbs_process_attr(struct ib_uverbs_file *ufile,
5151
u16 attr_id,
5252
const struct uverbs_attr_spec_hash *attr_spec_bucket,
5353
struct uverbs_attr_bundle_hash *attr_bundle_h,
54+
struct uverbs_obj_attr **destroy_attr,
5455
struct ib_uverbs_attr __user *uattr_ptr)
5556
{
5657
const struct uverbs_attr_spec *spec;
@@ -148,6 +149,12 @@ static int uverbs_process_attr(struct ib_uverbs_file *ufile,
148149
if (!object)
149150
return -EINVAL;
150151

152+
/* specs are allowed to have only one destroy attribute */
153+
WARN_ON(spec->u.obj.access == UVERBS_ACCESS_DESTROY &&
154+
*destroy_attr);
155+
if (spec->u.obj.access == UVERBS_ACCESS_DESTROY)
156+
*destroy_attr = o_attr;
157+
151158
/*
152159
* The type of uattr->data is u64 for UVERBS_ATTR_TYPE_IDR and
153160
* s64 for UVERBS_ATTR_TYPE_FD. We can cast the u64 to s64
@@ -235,6 +242,7 @@ static int uverbs_uattrs_process(struct ib_uverbs_file *ufile,
235242
size_t num_uattrs,
236243
const struct uverbs_method_spec *method,
237244
struct uverbs_attr_bundle *attr_bundle,
245+
struct uverbs_obj_attr **destroy_attr,
238246
struct ib_uverbs_attr __user *uattr_ptr)
239247
{
240248
size_t i;
@@ -268,7 +276,8 @@ static int uverbs_uattrs_process(struct ib_uverbs_file *ufile,
268276
attr_spec_bucket = method->attr_buckets[ret];
269277
ret = uverbs_process_attr(ufile, uattr, attr_id,
270278
attr_spec_bucket,
271-
&attr_bundle->hash[ret], uattr_ptr++);
279+
&attr_bundle->hash[ret], destroy_attr,
280+
uattr_ptr++);
272281
if (ret) {
273282
uverbs_finalize_attrs(attr_bundle,
274283
method->attr_buckets,
@@ -322,9 +331,11 @@ static int uverbs_handle_method(struct ib_uverbs_attr __user *uattr_ptr,
322331
int ret;
323332
int finalize_ret;
324333
int num_given_buckets;
334+
struct uverbs_obj_attr *destroy_attr = NULL;
325335

326-
num_given_buckets = uverbs_uattrs_process(
327-
ufile, uattrs, num_uattrs, method_spec, attr_bundle, uattr_ptr);
336+
num_given_buckets =
337+
uverbs_uattrs_process(ufile, uattrs, num_uattrs, method_spec,
338+
attr_bundle, &destroy_attr, uattr_ptr);
328339
if (num_given_buckets <= 0)
329340
return -EINVAL;
330341

@@ -333,7 +344,18 @@ static int uverbs_handle_method(struct ib_uverbs_attr __user *uattr_ptr,
333344
if (ret)
334345
goto cleanup;
335346

347+
/*
348+
* We destroy the HW object before invoking the handler, handlers do
349+
* not get to manipulate the HW objects.
350+
*/
351+
if (destroy_attr) {
352+
ret = rdma_explicit_destroy(destroy_attr->uobject);
353+
if (ret)
354+
goto cleanup;
355+
}
356+
336357
ret = method_spec->handler(ibdev, ufile, attr_bundle);
358+
337359
cleanup:
338360
finalize_ret = uverbs_finalize_attrs(attr_bundle,
339361
method_spec->attr_buckets,

drivers/infiniband/core/uverbs_std_types_cq.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -179,21 +179,12 @@ static int UVERBS_HANDLER(UVERBS_METHOD_CQ_DESTROY)(struct ib_device *ib_dev,
179179
{
180180
struct ib_uobject *uobj =
181181
uverbs_attr_get_uobject(attrs, UVERBS_ATTR_DESTROY_CQ_HANDLE);
182-
struct ib_uverbs_destroy_cq_resp resp;
183-
struct ib_ucq_object *obj;
184-
int ret;
185-
186-
if (IS_ERR(uobj))
187-
return PTR_ERR(uobj);
188-
189-
obj = container_of(uobj, struct ib_ucq_object, uobject);
190-
191-
ret = rdma_explicit_destroy(uobj);
192-
if (ret)
193-
return ret;
194-
195-
resp.comp_events_reported = obj->comp_events_reported;
196-
resp.async_events_reported = obj->async_events_reported;
182+
struct ib_ucq_object *obj =
183+
container_of(uobj, struct ib_ucq_object, uobject);
184+
struct ib_uverbs_destroy_cq_resp resp = {
185+
.comp_events_reported = obj->comp_events_reported,
186+
.async_events_reported = obj->async_events_reported
187+
};
197188

198189
return uverbs_copy_to(attrs, UVERBS_ATTR_DESTROY_CQ_RESP, &resp,
199190
sizeof(resp));

0 commit comments

Comments
 (0)