From patchwork Sun Dec 11 12:58:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matan Barak X-Patchwork-Id: 9469745 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4F6C5607D3 for ; Sun, 11 Dec 2016 12:58:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 463E92847B for ; Sun, 11 Dec 2016 12:58:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 376C1284A3; Sun, 11 Dec 2016 12:58:54 +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=-6.9 required=2.0 tests=BAYES_00, 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 C282A28481 for ; Sun, 11 Dec 2016 12:58:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753571AbcLKM6v (ORCPT ); Sun, 11 Dec 2016 07:58:51 -0500 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:57678 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753560AbcLKM6u (ORCPT ); Sun, 11 Dec 2016 07:58:50 -0500 Received: from Internal Mail-Server by MTLPINE1 (envelope-from matanb@mellanox.com) with ESMTPS (AES256-SHA encrypted); 11 Dec 2016 14:58:44 +0200 Received: from gen-l-vrt-078.mtl.labs.mlnx. (gen-l-vrt-078.mtl.labs.mlnx [10.137.78.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id uBBCwVO5018366; Sun, 11 Dec 2016 14:58:44 +0200 From: Matan Barak To: linux-rdma@vger.kernel.org Cc: Doug Ledford , Jason Gunthorpe , Sean Hefty , Christoph Lameter , Liran Liss , Haggai Eran , Majd Dibbiny , Matan Barak , Tal Alon , Leon Romanovsky Subject: [RFC ABI V6 13/14] IB/core: Support getting IOCTL header/SGEs from kernel space Date: Sun, 11 Dec 2016 14:58:07 +0200 Message-Id: <1481461088-56355-14-git-send-email-matanb@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1481461088-56355-1-git-send-email-matanb@mellanox.com> References: <1481461088-56355-1-git-send-email-matanb@mellanox.com> 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 In order to allow compatibility header, allow passing ib_uverbs_ioctl_hdr and ib_uverbs_attr from kernel space. Signed-off-by: Matan Barak --- drivers/infiniband/core/uverbs.h | 6 ++++ drivers/infiniband/core/uverbs_ioctl.c | 56 ++++++++++++++++++++++------------ 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/drivers/infiniband/core/uverbs.h b/drivers/infiniband/core/uverbs.h index 7c038a3..72858e5 100644 --- a/drivers/infiniband/core/uverbs.h +++ b/drivers/infiniband/core/uverbs.h @@ -84,7 +84,13 @@ * released when the CQ is destroyed. */ +struct ib_uverbs_ioctl_hdr; long ib_uverbs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); +long ib_uverbs_cmd_verbs(struct ib_device *ib_dev, + struct ib_uverbs_file *file, + struct ib_uverbs_ioctl_hdr *hdr, + void __user *buf, + bool w_legacy); struct ib_uverbs_device { atomic_t refcount; diff --git a/drivers/infiniband/core/uverbs_ioctl.c b/drivers/infiniband/core/uverbs_ioctl.c index 406b735..6050a64 100644 --- a/drivers/infiniband/core/uverbs_ioctl.c +++ b/drivers/infiniband/core/uverbs_ioctl.c @@ -41,7 +41,8 @@ static int uverbs_validate_attr(struct ib_device *ibdev, u16 attr_id, const struct uverbs_attr_spec_group *attr_spec_group, struct uverbs_attr_array *attr_array, - struct ib_uverbs_attr __user *uattr_ptr) + struct ib_uverbs_attr __user *uattr_ptr, + bool w_legacy) { const struct uverbs_attr_spec *spec; struct uverbs_attr *e; @@ -113,10 +114,14 @@ static int uverbs_validate_attr(struct ib_device *ibdev, if (spec->obj.access == UVERBS_IDR_ACCESS_NEW) { u64 idr = o_attr->uobject->id; - if (put_user(idr, &o_attr->uattr->ptr_idr)) { - uverbs_rollback_object(o_attr->uobject, - UVERBS_IDR_ACCESS_NEW); - return -EFAULT; + if (!w_legacy) { + if (put_user(idr, &o_attr->uattr->ptr_idr)) { + uverbs_rollback_object(o_attr->uobject, + UVERBS_IDR_ACCESS_NEW); + return -EFAULT; + } + } else { + o_attr->uattr->ptr_idr = idr; } } @@ -135,7 +140,8 @@ static int uverbs_validate(struct ib_device *ibdev, size_t num_attrs, const struct uverbs_action *action, struct uverbs_attr_array *attr_array, - struct ib_uverbs_attr __user *uattr_ptr) + struct ib_uverbs_attr __user *uattr_ptr, + bool w_legacy) { size_t i; int ret; @@ -161,7 +167,7 @@ static int uverbs_validate(struct ib_device *ibdev, attr_spec_group = action->attr_groups[ret]; ret = uverbs_validate_attr(ibdev, ucontext, uattr, attr_id, attr_spec_group, &attr_array[ret], - uattr_ptr++); + uattr_ptr++, w_legacy); if (ret) { uverbs_commit_objects(attr_array, n_val, action, false); @@ -178,14 +184,16 @@ static int uverbs_handle_action(struct ib_uverbs_attr __user *uattr_ptr, struct ib_device *ibdev, struct ib_uverbs_file *ufile, const struct uverbs_action *handler, - struct uverbs_attr_array *attr_array) + struct uverbs_attr_array *attr_array, + bool w_legacy) { int ret; int n_val; unsigned int i; n_val = uverbs_validate(ibdev, ufile->ucontext, uattrs, num_attrs, - handler, attr_array, uattr_ptr); + handler, attr_array, uattr_ptr, + w_legacy); if (n_val <= 0) return n_val; @@ -212,10 +220,11 @@ cleanup: #ifdef UVERBS_OPTIMIZE_USING_STACK #define UVERBS_MAX_STACK_USAGE 512 #endif -static long ib_uverbs_cmd_verbs(struct ib_device *ib_dev, - struct ib_uverbs_file *file, - struct ib_uverbs_ioctl_hdr *hdr, - void __user *buf) +long ib_uverbs_cmd_verbs(struct ib_device *ib_dev, + struct ib_uverbs_file *file, + struct ib_uverbs_ioctl_hdr *hdr, + void __user *buf, + bool w_legacy) { const struct uverbs_type *type; const struct uverbs_action *action; @@ -281,15 +290,21 @@ static long ib_uverbs_cmd_verbs(struct ib_device *ib_dev, curr_bitmap += BITS_TO_LONGS(curr_num_attrs); } - err = copy_from_user(ctx->uattrs, buf, - sizeof(*ctx->uattrs) * hdr->num_attrs); - if (err) { - err = -EFAULT; - goto out; + if (w_legacy) { + memcpy(ctx->uattrs, buf, + sizeof(*ctx->uattrs) * hdr->num_attrs); + } else { + err = copy_from_user(ctx->uattrs, buf, + sizeof(*ctx->uattrs) * hdr->num_attrs); + if (err) { + err = -EFAULT; + goto out; + } } err = uverbs_handle_action(buf, ctx->uattrs, hdr->num_attrs, ib_dev, - file, action, ctx->uverbs_attr_array); + file, action, ctx->uverbs_attr_array, + w_legacy); out: #ifdef UVERBS_OPTIMIZE_USING_STACK if (ctx_size > UVERBS_MAX_STACK_USAGE) @@ -344,7 +359,8 @@ long ib_uverbs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) } err = ib_uverbs_cmd_verbs(ib_dev, file, &hdr, - (__user void *)arg + sizeof(hdr)); + (__user void *)arg + sizeof(hdr), + false); } out: srcu_read_unlock(&file->device->disassociate_srcu, srcu_key);