Prepare the code for shared ib_x model. uobj_put_obj_read rely on ib_x uobject pointer. Having single pointer in ib_x object is not aligned with future shared ib_x model. In future shared ib_x model each ib_x object can belong to 1 or more ib_uobject. Thus the ib_uobject used in the macro cannot come from the ib_x object. Signed-off-by: Shamir Rabinovitch <shamir.rabinovitch@xxxxxxxxxx> --- drivers/infiniband/core/uverbs_cmd.c | 96 ++++++++++++++-------------- include/rdma/uverbs_std_types.h | 10 ++- 2 files changed, 56 insertions(+), 50 deletions(-) diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c index 31b5e733c018..0203c9587502 100644 --- a/drivers/infiniband/core/uverbs_cmd.c +++ b/drivers/infiniband/core/uverbs_cmd.c @@ -732,7 +732,7 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file, goto err_copy; } - uobj_put_obj_read(pd); + uobj_put_obj_read(pd, pd_uobj); return uobj_alloc_commit(uobj, in_len); @@ -740,7 +740,7 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file, ib_dereg_mr(mr); err_put: - uobj_put_obj_read(pd); + uobj_put_obj_read(pd, pd_uobj); err_free: uobj_alloc_abort(uobj); @@ -759,7 +759,7 @@ ssize_t ib_uverbs_rereg_mr(struct ib_uverbs_file *file, struct ib_pd *old_pd; int ret; struct ib_uobject *uobj; - struct ib_uobject *pd_uobj; + struct ib_uobject *pd_uobj = NULL; if (out_len < sizeof(resp)) return -ENOSPC; @@ -831,7 +831,7 @@ ssize_t ib_uverbs_rereg_mr(struct ib_uverbs_file *file, put_uobj_pd: if (cmd.flags & IB_MR_REREG_PD) - uobj_put_obj_read(pd); + uobj_put_obj_read(pd, pd_uobj); put_uobjs: uobj_put_write(uobj); @@ -910,13 +910,13 @@ ssize_t ib_uverbs_alloc_mw(struct ib_uverbs_file *file, goto err_copy; } - uobj_put_obj_read(pd); + uobj_put_obj_read(pd, pd_uobj); return uobj_alloc_commit(uobj, in_len); err_copy: uverbs_dealloc_mw(mw); err_put: - uobj_put_obj_read(pd); + uobj_put_obj_read(pd, pd_uobj); err_free: uobj_alloc_abort(uobj); return ret; @@ -1200,7 +1200,7 @@ ssize_t ib_uverbs_resize_cq(struct ib_uverbs_file *file, ret = -EFAULT; out: - uobj_put_obj_read(cq); + uobj_put_obj_read(cq, cq_uobj); return ret ? ret : in_len; } @@ -1284,7 +1284,7 @@ ssize_t ib_uverbs_poll_cq(struct ib_uverbs_file *file, ret = in_len; out_put: - uobj_put_obj_read(cq); + uobj_put_obj_read(cq, cq_uobj); return ret; } @@ -1307,7 +1307,7 @@ ssize_t ib_uverbs_req_notify_cq(struct ib_uverbs_file *file, ib_req_notify_cq(cq, cmd.solicited_only ? IB_CQ_SOLICITED : IB_CQ_NEXT_COMP); - uobj_put_obj_read(cq); + uobj_put_obj_read(cq, cq_uobj); return in_len; } @@ -1594,15 +1594,15 @@ static int create_qp(struct ib_uverbs_file *file, } if (pd) - uobj_put_obj_read(pd); + uobj_put_obj_read(pd, pd_uobj); if (scq) - uobj_put_obj_read(scq); + uobj_put_obj_read(scq, scq_uobj); if (rcq && rcq != scq) - uobj_put_obj_read(rcq); + uobj_put_obj_read(rcq, rcq_uobj); if (srq) - uobj_put_obj_read(srq); + uobj_put_obj_read(srq, srq_uobj); if (ind_tbl) - uobj_put_obj_read(ind_tbl); + uobj_put_obj_read(ind_tbl, ind_tbl_uobj); return uobj_alloc_commit(&obj->uevent.uobject, 0); err_cb: @@ -1612,15 +1612,15 @@ static int create_qp(struct ib_uverbs_file *file, if (!IS_ERR(xrcd_uobj)) uobj_put_read(xrcd_uobj); if (pd) - uobj_put_obj_read(pd); + uobj_put_obj_read(pd, pd_uobj); if (scq) - uobj_put_obj_read(scq); + uobj_put_obj_read(scq, scq_uobj); if (rcq && rcq != scq) - uobj_put_obj_read(rcq); + uobj_put_obj_read(rcq, rcq_uobj); if (srq) - uobj_put_obj_read(srq); + uobj_put_obj_read(srq, srq_uobj); if (ind_tbl) - uobj_put_obj_read(ind_tbl); + uobj_put_obj_read(ind_tbl, ind_tbl_uobj); uobj_alloc_abort(&obj->uevent.uobject); return ret; @@ -1870,7 +1870,7 @@ ssize_t ib_uverbs_query_qp(struct ib_uverbs_file *file, ret = ib_query_qp(qp, attr, cmd.attr_mask, init_attr); - uobj_put_obj_read(qp); + uobj_put_obj_read(qp, qp_uobj); if (ret) goto out; @@ -2087,7 +2087,7 @@ static int modify_qp(struct ib_uverbs_file *file, udata); release_qp: - uobj_put_obj_read(qp); + uobj_put_obj_read(qp, qp_uobj); out: kfree(attr); @@ -2369,11 +2369,11 @@ ssize_t ib_uverbs_post_send(struct ib_uverbs_file *file, ret = -EFAULT; out_put: - uobj_put_obj_read(qp); + uobj_put_obj_read(qp, qp_uobj); while (wr) { if (is_ud && ud_wr(wr)->ah) - uobj_put_obj_read(ud_wr(wr)->ah); + uobj_put_obj_read(ud_wr(wr)->ah, ah_uobj); next = wr->next; kfree(wr); wr = next; @@ -2506,7 +2506,7 @@ ssize_t ib_uverbs_post_recv(struct ib_uverbs_file *file, resp.bad_wr = 0; ret = qp->device->post_recv(qp->real_qp, wr, &bad_wr); - uobj_put_obj_read(qp); + uobj_put_obj_read(qp, qp_uobj); if (ret) { for (next = wr; next; next = next->next) { ++resp.bad_wr; @@ -2558,7 +2558,7 @@ ssize_t ib_uverbs_post_srq_recv(struct ib_uverbs_file *file, ret = srq->device->post_srq_recv ? srq->device->post_srq_recv(srq, wr, &bad_wr) : -EOPNOTSUPP; - uobj_put_obj_read(srq); + uobj_put_obj_read(srq, srq_uobj); if (ret) for (next = wr; next; next = next->next) { @@ -2657,14 +2657,14 @@ ssize_t ib_uverbs_create_ah(struct ib_uverbs_file *file, goto err_copy; } - uobj_put_obj_read(pd); + uobj_put_obj_read(pd, pd_uobj); return uobj_alloc_commit(uobj, in_len); err_copy: rdma_destroy_ah(ah); err_put: - uobj_put_obj_read(pd); + uobj_put_obj_read(pd, pd_uobj); err: uobj_alloc_abort(uobj); @@ -2729,7 +2729,7 @@ ssize_t ib_uverbs_attach_mcast(struct ib_uverbs_file *file, out_put: mutex_unlock(&obj->mcast_lock); - uobj_put_obj_read(qp); + uobj_put_obj_read(qp, qp_uobj); return ret ? ret : in_len; } @@ -2775,7 +2775,7 @@ ssize_t ib_uverbs_detach_mcast(struct ib_uverbs_file *file, out_put: mutex_unlock(&obj->mcast_lock); - uobj_put_obj_read(qp); + uobj_put_obj_read(qp, qp_uobj); return ret ? ret : in_len; } @@ -2896,7 +2896,7 @@ static int kern_spec_to_ib_spec_action(struct ib_uverbs_file *ufile, flow_resources_add(uflow_res, IB_FLOW_SPEC_ACTION_HANDLE, ib_spec->action.act); - uobj_put_obj_read(ib_spec->action.act); + uobj_put_obj_read(ib_spec->action.act, flow_act_uobj); break; case IB_FLOW_SPEC_ACTION_COUNT: if (kern_spec->flow_count.size != @@ -2915,7 +2915,7 @@ static int kern_spec_to_ib_spec_action(struct ib_uverbs_file *ufile, flow_resources_add(uflow_res, IB_FLOW_SPEC_ACTION_COUNT, ib_spec->flow_count.counters); - uobj_put_obj_read(ib_spec->flow_count.counters); + uobj_put_obj_read(ib_spec->flow_count.counters, cnt_uobj); break; default: return -EINVAL; @@ -3207,16 +3207,16 @@ int ib_uverbs_ex_create_wq(struct ib_uverbs_file *file, if (err) goto err_copy; - uobj_put_obj_read(pd); - uobj_put_obj_read(cq); + uobj_put_obj_read(pd, pd_uobj); + uobj_put_obj_read(cq, cq_uobj); return uobj_alloc_commit(&obj->uevent.uobject, 0); err_copy: ib_destroy_wq(wq, uhw); err_put_cq: - uobj_put_obj_read(cq); + uobj_put_obj_read(cq, cq_uobj); err_put_pd: - uobj_put_obj_read(pd); + uobj_put_obj_read(pd, pd_uobj); err_uobj: uobj_alloc_abort(&obj->uevent.uobject); @@ -3316,7 +3316,7 @@ int ib_uverbs_ex_modify_wq(struct ib_uverbs_file *file, } ret = wq->device->modify_wq(wq, &wq_attr, cmd.attr_mask, uhw); out: - uobj_put_obj_read(wq); + uobj_put_obj_read(wq, wq_uobj); return ret; } @@ -3454,7 +3454,7 @@ int ib_uverbs_ex_create_rwq_ind_table(struct ib_uverbs_file *file, kfree(wqs_handles); for (j = 0; j < num_read_wqs; j++) - uobj_put_obj_read(wqs[j]); + uobj_put_obj_read(wqs[j], wqs_uobj[j]); kfree(wqs_uobj); @@ -3466,7 +3466,7 @@ int ib_uverbs_ex_create_rwq_ind_table(struct ib_uverbs_file *file, uobj_alloc_abort(uobj); put_wqs: for (j = 0; j < num_read_wqs; j++) - uobj_put_obj_read(wqs[j]); + uobj_put_obj_read(wqs[j], wqs_uobj[j]); err_free: kfree(wqs_handles); kfree(wqs_uobj); @@ -3661,7 +3661,7 @@ int ib_uverbs_ex_create_flow(struct ib_uverbs_file *file, if (err) goto err_copy; - uobj_put_obj_read(qp); + uobj_put_obj_read(qp, qp_uobj); kfree(flow_attr); if (cmd.flow_attr.num_of_specs) kfree(kern_flow_attr); @@ -3674,7 +3674,7 @@ int ib_uverbs_ex_create_flow(struct ib_uverbs_file *file, err_free_flow_attr: kfree(flow_attr); err_put: - uobj_put_obj_read(qp); + uobj_put_obj_read(qp, qp_uobj); err_uobj: uobj_alloc_abort(uobj); err_free_attr: @@ -3716,7 +3716,7 @@ static int __uverbs_create_xsrq(struct ib_uverbs_file *file, struct ib_srq_init_attr attr; int ret; struct ib_device *ib_dev; - struct ib_uobject *cq_uobj; + struct ib_uobject *cq_uobj = NULL; struct ib_uobject *pd_uobj; obj = (struct ib_usrq_object *)uobj_alloc(UVERBS_OBJECT_SRQ, file, @@ -3818,20 +3818,20 @@ static int __uverbs_create_xsrq(struct ib_uverbs_file *file, uobj_put_read(xrcd_uobj); if (ib_srq_has_cq(cmd->srq_type)) - uobj_put_obj_read(attr.ext.cq); + uobj_put_obj_read(attr.ext.cq, cq_uobj); - uobj_put_obj_read(pd); + uobj_put_obj_read(pd, pd_uobj); return uobj_alloc_commit(&obj->uevent.uobject, 0); err_copy: ib_destroy_srq(srq); err_put: - uobj_put_obj_read(pd); + uobj_put_obj_read(pd, pd_uobj); err_put_cq: if (ib_srq_has_cq(cmd->srq_type)) - uobj_put_obj_read(attr.ext.cq); + uobj_put_obj_read(attr.ext.cq, cq_uobj); err_put_xrcd: if (cmd->srq_type == IB_SRQT_XRC) { @@ -3934,7 +3934,7 @@ ssize_t ib_uverbs_modify_srq(struct ib_uverbs_file *file, ret = srq->device->modify_srq(srq, &attr, cmd.attr_mask, &udata); - uobj_put_obj_read(srq); + uobj_put_obj_read(srq, srq_uobj); return ret ? ret : in_len; } @@ -3963,7 +3963,7 @@ ssize_t ib_uverbs_query_srq(struct ib_uverbs_file *file, ret = ib_query_srq(srq, &attr); - uobj_put_obj_read(srq); + uobj_put_obj_read(srq, srq_uobj); if (ret) return ret; @@ -4173,7 +4173,7 @@ int ib_uverbs_ex_modify_cq(struct ib_uverbs_file *file, ret = rdma_set_cq_moderation(cq, cmd.attr.cq_count, cmd.attr.cq_period); - uobj_put_obj_read(cq); + uobj_put_obj_read(cq, cq_uobj); return ret; } diff --git a/include/rdma/uverbs_std_types.h b/include/rdma/uverbs_std_types.h index 21eedc4183f8..895706ad9d0c 100644 --- a/include/rdma/uverbs_std_types.h +++ b/include/rdma/uverbs_std_types.h @@ -103,8 +103,14 @@ static inline void uobj_put_read(struct ib_uobject *uobj) rdma_lookup_put_uobject(uobj, UVERBS_LOOKUP_READ); } -#define uobj_put_obj_read(_obj) \ - uobj_put_read((_obj)->uobject) +static inline void uobj_put_obj_read(void *object, struct ib_uobject *uobject) +{ + if (WARN_ON(!object) || + WARN_ON(IS_ERR_OR_NULL(uobject)) || + WARN_ON(object != uobject->object)) + return; + uobj_put_read(uobject); +} static inline void uobj_put_write(struct ib_uobject *uobj) { -- 2.17.1