From patchwork Mon Jan 28 10:11:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shamir Rabinovitch X-Patchwork-Id: 10783533 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CBF1413B5 for ; Mon, 28 Jan 2019 10:12:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BACD32A882 for ; Mon, 28 Jan 2019 10:12:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE4652A7FE; Mon, 28 Jan 2019 10:12:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F0CB12A8A6 for ; Mon, 28 Jan 2019 10:12:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726772AbfA1KMR (ORCPT ); Mon, 28 Jan 2019 05:12:17 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:49990 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726369AbfA1KMR (ORCPT ); Mon, 28 Jan 2019 05:12:17 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id x0SA90Aa168952; Mon, 28 Jan 2019 10:12:00 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=sRiXRVVcqahJZLGLvq9ALwSmFrb12CZAhVFvxJb8UkM=; b=32MjES+Lw751LcEdgT80D/bjsxzKwoUtwyUiLdZkKWThZYmH7o+EFoUVVcSYbXM00qTD BCFA2Vi9HUelsNOxJprCieb0r7Wua3UjRD89BhPwD5xWy9e7+080+XtQJotDx2fu2nnm fbgPbjsGgQJh/7TuI4xb6Yf0peLY0suArnHX80V1Gp6j2o1jaqyNRiHwnSihYD4q7wrE FxHbS0TI0/TY6gtET2+x+tS5ExrOa0X+1xtn+ixOd8oNzQ8I53A4sR4Fzi8dRMWPRZV/ ZPsvamuYy9Yvdk2dxl1uR7pDtI5cx5uVq1HnBbiQgwrWWPsb7+HkMx4dZOleaXObNb4q DQ== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2q8eyu579j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 28 Jan 2019 10:12:00 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x0SABt5F019978 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 28 Jan 2019 10:11:55 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x0SABsIi023008; Mon, 28 Jan 2019 10:11:54 GMT Received: from localhost.localdomain (/10.175.62.22) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 28 Jan 2019 02:11:53 -0800 From: Shamir Rabinovitch To: linux-rdma@vger.kernel.org Cc: shamir.rabinovitch@oracle.com, jgg@ziepe.ca, dledford@redhat.com, Leon Romanovsky , Yishai Hadas , Mark Bloch , Ariel Levkovich , Matan Barak , Guy Levi , Parav Pandit , "Wei Hu(Xavier)" , Dennis Dalessandro Subject: [PATCH for-next v2 1/3] IB/uverbs: add ib_ucontext to uverbs_attr_bundle sent from ioctl and cmd flows Date: Mon, 28 Jan 2019 12:11:15 +0200 Message-Id: <20190128101130.2539-1-shamir.rabinovitch@oracle.com> X-Mailer: git-send-email 2.17.2 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9149 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901280083 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add ib_ucontext to the uverbs_attr_bundle sent down the iocl and cmd flows as soon as the flow has ib_uobject to make sure the function rdma_get_ucontext will never fail in those flows. Signed-off-by: Shamir Rabinovitch --- drivers/infiniband/core/uverbs_cmd.c | 2 +- drivers/infiniband/core/uverbs_ioctl.c | 3 ++ drivers/infiniband/core/uverbs_main.c | 12 ++----- drivers/infiniband/core/uverbs_std_types.c | 37 ++++++++++++++++++++++ include/rdma/uverbs_ioctl.h | 1 + include/rdma/uverbs_std_types.h | 16 ++++++---- 6 files changed, 54 insertions(+), 17 deletions(-) diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c index d4f1a2ef5015..bd8bcab01e86 100644 --- a/drivers/infiniband/core/uverbs_cmd.c +++ b/drivers/infiniband/core/uverbs_cmd.c @@ -2620,7 +2620,7 @@ void flow_resources_add(struct ib_uflow_resources *uflow_res, } EXPORT_SYMBOL(flow_resources_add); -static int kern_spec_to_ib_spec_action(const struct uverbs_attr_bundle *attrs, +static int kern_spec_to_ib_spec_action(struct uverbs_attr_bundle *attrs, struct ib_uverbs_flow_spec *kern_spec, union ib_flow_spec *ib_spec, struct ib_uflow_resources *uflow_res) diff --git a/drivers/infiniband/core/uverbs_ioctl.c b/drivers/infiniband/core/uverbs_ioctl.c index 8c81ff698052..5d3251a51850 100644 --- a/drivers/infiniband/core/uverbs_ioctl.c +++ b/drivers/infiniband/core/uverbs_ioctl.c @@ -198,6 +198,7 @@ static int uverbs_process_idrs_array(struct bundle_priv *pbundle, ret = PTR_ERR(attr->uobjects[i]); break; } + pbundle->bundle.context = attr->uobjects[i]->context; } attr->len = i; @@ -315,6 +316,7 @@ static int uverbs_process_attr(struct bundle_priv *pbundle, uattr->data_s64); if (IS_ERR(o_attr->uobject)) return PTR_ERR(o_attr->uobject); + pbundle->bundle.context = o_attr->uobject->context; __set_bit(attr_bkey, pbundle->uobj_finalize); if (spec->u.obj.access == UVERBS_ACCESS_NEW) { @@ -564,6 +566,7 @@ static int ib_uverbs_cmd_verbs(struct ib_uverbs_file *ufile, pbundle->method_elm = method_elm; pbundle->method_key = attrs_iter.index; pbundle->bundle.ufile = ufile; + pbundle->bundle.context = NULL; /* only valid if bundle has uobject */ pbundle->radix = &uapi->radix; pbundle->radix_slots = slot; pbundle->radix_slots_len = radix_tree_chunk_size(&attrs_iter); diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c index 996f167d1436..fb2f6f98204e 100644 --- a/drivers/infiniband/core/uverbs_main.c +++ b/drivers/infiniband/core/uverbs_main.c @@ -113,15 +113,8 @@ struct ib_ucontext *rdma_get_ucontext(struct ib_udata *udata) if (!udata) return ERR_PTR(-EIO); - /* - * FIXME: Really all cases that get here with a udata will have - * already called ib_uverbs_get_ucontext_file, or located a uobject - * that points to a ucontext. We could store that result in the udata - * so this function can't fail. - */ - return ib_uverbs_get_ucontext_file( - container_of(udata, struct uverbs_attr_bundle, driver_udata) - ->ufile); + return (container_of(udata, struct uverbs_attr_bundle, driver_udata) + ->context) ? : ERR_PTR(-EIO); } EXPORT_SYMBOL(rdma_get_ucontext); @@ -715,6 +708,7 @@ static ssize_t ib_uverbs_write(struct file *filp, const char __user *buf, buf += sizeof(hdr); bundle.ufile = file; + bundle.context = NULL; /* only valid if bundle has uobject */ if (!method_elm->is_ex) { size_t in_len = hdr.in_words * 4 - sizeof(hdr); size_t out_len = hdr.out_words * 4; diff --git a/drivers/infiniband/core/uverbs_std_types.c b/drivers/infiniband/core/uverbs_std_types.c index cbc72312eb41..e1113bc1928b 100644 --- a/drivers/infiniband/core/uverbs_std_types.c +++ b/drivers/infiniband/core/uverbs_std_types.c @@ -39,6 +39,43 @@ #include "rdma_core.h" #include "uverbs.h" +struct ib_uobject *uobj_get_read(enum uverbs_default_objects type, + u32 object_id, + struct uverbs_attr_bundle *attrs) +{ + struct ib_uobject *uobj; + + uobj = rdma_lookup_get_uobject(uobj_get_type(attrs, type), + attrs->ufile, + _uobj_check_id(object_id), + UVERBS_LOOKUP_READ); + if (IS_ERR(uobj)) + return uobj; + + attrs->context = uobj->context; + + return uobj; +} + +struct ib_uobject *uobj_get_write(enum uverbs_default_objects type, + u32 object_id, + struct uverbs_attr_bundle *attrs) +{ + struct ib_uobject *uobj; + + uobj = rdma_lookup_get_uobject(uobj_get_type(attrs, type), + attrs->ufile, + _uobj_check_id(object_id), + UVERBS_LOOKUP_WRITE); + + if (IS_ERR(uobj)) + return uobj; + + attrs->context = uobj->context; + + return uobj; +} + static int uverbs_free_ah(struct ib_uobject *uobject, enum rdma_remove_reason why) { diff --git a/include/rdma/uverbs_ioctl.h b/include/rdma/uverbs_ioctl.h index 27da906beea7..b14a9ee786e9 100644 --- a/include/rdma/uverbs_ioctl.h +++ b/include/rdma/uverbs_ioctl.h @@ -652,6 +652,7 @@ struct uverbs_attr_bundle { struct ib_udata driver_udata; struct ib_udata ucore; struct ib_uverbs_file *ufile; + struct ib_ucontext *context; DECLARE_BITMAP(attr_present, UVERBS_API_ATTR_BKEY_LEN); struct uverbs_attr attrs[]; }; diff --git a/include/rdma/uverbs_std_types.h b/include/rdma/uverbs_std_types.h index 883abcf6d36e..e19d0eec16fa 100644 --- a/include/rdma/uverbs_std_types.h +++ b/include/rdma/uverbs_std_types.h @@ -48,9 +48,9 @@ #define uobj_get_type(_attrs, _object) \ uapi_get_object((_attrs)->ufile->device->uapi, _object) -#define uobj_get_read(_type, _id, _attrs) \ - rdma_lookup_get_uobject(uobj_get_type(_attrs, _type), (_attrs)->ufile, \ - _uobj_check_id(_id), UVERBS_LOOKUP_READ) +struct ib_uobject *uobj_get_read(enum uverbs_default_objects type, + u32 object_id, + struct uverbs_attr_bundle *attrs); #define ufd_get_read(_type, _fdnum, _attrs) \ rdma_lookup_get_uobject(uobj_get_type(_attrs, _type), (_attrs)->ufile, \ @@ -67,9 +67,9 @@ static inline void *_uobj_get_obj_read(struct ib_uobject *uobj) ((struct ib_##_object *)_uobj_get_obj_read( \ uobj_get_read(_type, _id, _attrs))) -#define uobj_get_write(_type, _id, _attrs) \ - rdma_lookup_get_uobject(uobj_get_type(_attrs, _type), (_attrs)->ufile, \ - _uobj_check_id(_id), UVERBS_LOOKUP_WRITE) +struct ib_uobject *uobj_get_write(enum uverbs_default_objects type, + u32 object_id, + struct uverbs_attr_bundle *attrs); int __uobj_perform_destroy(const struct uverbs_api_object *obj, u32 id, const struct uverbs_attr_bundle *attrs); @@ -123,8 +123,10 @@ __uobj_alloc(const struct uverbs_api_object *obj, { struct ib_uobject *uobj = rdma_alloc_begin_uobject(obj, attrs->ufile); - if (!IS_ERR(uobj)) + if (!IS_ERR(uobj)) { *ib_dev = uobj->context->device; + attrs->context = uobj->context; + } return uobj; }