From patchwork Wed Jun 7 12:22:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matan Barak X-Patchwork-Id: 9771439 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 B4416603B4 for ; Wed, 7 Jun 2017 12:23:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89BD727F10 for ; Wed, 7 Jun 2017 12:23:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E9CA283AD; Wed, 7 Jun 2017 12:23:47 +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 CD8AA28472 for ; Wed, 7 Jun 2017 12:23:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751520AbdFGMXZ (ORCPT ); Wed, 7 Jun 2017 08:23:25 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:42895 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751516AbdFGMXJ (ORCPT ); Wed, 7 Jun 2017 08:23:09 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from matanb@mellanox.com) with ESMTPS (AES256-SHA encrypted); 7 Jun 2017 15:23:03 +0300 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 v57CMxxS016058; Wed, 7 Jun 2017 15:23:02 +0300 From: Matan Barak To: Doug Ledford Cc: linux-rdma@vger.kernel.org, Jason Gunthorpe , Sean Hefty , Liran Liss , Yishai Hadas , Leon Romanovsky , Tal Alon , Christoph Lameter , Ira Weiny , Majd Dibbiny , Matan Barak Subject: [PATCH for-next 06/13] IB/core: Initialize uverbs types specification Date: Wed, 7 Jun 2017 15:22:45 +0300 Message-Id: <1496838172-39671-7-git-send-email-matanb@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1496838172-39671-1-git-send-email-matanb@mellanox.com> References: <1496838172-39671-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 accelerate the validation and parsing process, we calculate the number of attributes of all groups in an action and the mandatory attributes bitmask in advance. Signed-off-by: Matan Barak Reviewed-by: Yishai Hadas --- drivers/infiniband/core/uverbs.h | 3 ++ drivers/infiniband/core/uverbs_ioctl.c | 58 ++++++++++++++++++++++++++++++++++ drivers/infiniband/core/uverbs_main.c | 3 ++ 3 files changed, 64 insertions(+) diff --git a/drivers/infiniband/core/uverbs.h b/drivers/infiniband/core/uverbs.h index 64d494a..6bb1302 100644 --- a/drivers/infiniband/core/uverbs.h +++ b/drivers/infiniband/core/uverbs.h @@ -191,7 +191,10 @@ struct ib_ucq_object { u32 async_events_reported; }; +struct uverbs_type_group; + extern const struct file_operations uverbs_event_fops; +void uverbs_initialize_type_group(const struct uverbs_type_group *type_group); void ib_uverbs_init_event_queue(struct ib_uverbs_event_queue *ev_queue); struct file *ib_uverbs_alloc_async_event_file(struct ib_uverbs_file *uverbs_file, struct ib_device *ib_dev); diff --git a/drivers/infiniband/core/uverbs_ioctl.c b/drivers/infiniband/core/uverbs_ioctl.c index a375a7b..4f7491e 100644 --- a/drivers/infiniband/core/uverbs_ioctl.c +++ b/drivers/infiniband/core/uverbs_ioctl.c @@ -358,3 +358,61 @@ long ib_uverbs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) return err; } + +static void uverbs_initialize_action(struct uverbs_action *action) +{ + size_t attr_group_idx; + + for (attr_group_idx = 0; attr_group_idx < action->num_groups; + attr_group_idx++) { + struct uverbs_attr_spec_group *attr_group = + action->attr_groups[attr_group_idx]; + size_t attr_idx; + + if (!attr_group) + continue; + action->num_child_attrs += attr_group->num_attrs; + for (attr_idx = 0; attr_idx < attr_group->num_attrs; + attr_idx++) { + struct uverbs_attr_spec *attr = + &attr_group->attrs[attr_idx]; + + if (attr->flags & UVERBS_ATTR_SPEC_F_MANDATORY) + set_bit(attr_idx, + attr_group->mandatory_attrs_bitmask); + } + } +} + +void uverbs_initialize_type_group(const struct uverbs_type_group *type_group) +{ + size_t type_idx; + + for (type_idx = 0; type_idx < type_group->num_types; type_idx++) { + const struct uverbs_type *type = type_group->types[type_idx]; + size_t action_group_idx; + + if (!type) + continue; + for (action_group_idx = 0; + action_group_idx < type->num_groups; + action_group_idx++) { + const struct uverbs_action_group *action_group = + type->action_groups[action_group_idx]; + size_t action_idx; + + if (!action_group) + continue; + for (action_idx = 0; + action_idx < action_group->num_actions; + action_idx++) { + struct uverbs_action *action = + action_group->actions[action_idx]; + + if (!action) + continue; + uverbs_initialize_action(action); + } + } + } +} diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c index 3d26096..1836a36 100644 --- a/drivers/infiniband/core/uverbs_main.c +++ b/drivers/infiniband/core/uverbs_main.c @@ -45,6 +45,7 @@ #include #include #include +#include #include @@ -1254,6 +1255,8 @@ static int __init ib_uverbs_init(void) { int ret; + uverbs_initialize_type_group(&uverbs_common_types); + ret = register_chrdev_region(IB_UVERBS_BASE_DEV, IB_UVERBS_MAX_DEVICES, "infiniband_verbs"); if (ret) {