From patchwork Wed Apr 19 15:20:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matan Barak X-Patchwork-Id: 9687833 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 C80346037F for ; Wed, 19 Apr 2017 15:20:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA42528450 for ; Wed, 19 Apr 2017 15:20:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AEDD328459; Wed, 19 Apr 2017 15:20:58 +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 D9D5228450 for ; Wed, 19 Apr 2017 15:20:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935520AbdDSPUw (ORCPT ); Wed, 19 Apr 2017 11:20:52 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:46428 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S937053AbdDSPUs (ORCPT ); Wed, 19 Apr 2017 11:20:48 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from matanb@mellanox.com) with ESMTPS (AES256-SHA encrypted); 19 Apr 2017 18:20:43 +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 v3JFKhHj022196; Wed, 19 Apr 2017 18:20:43 +0300 From: Matan Barak To: linux-rdma@vger.kernel.org Cc: Doug Ledford , Jason Gunthorpe , Sean Hefty , Liran Liss , Majd Dibbiny , Yishai Hadas , Ira Weiny , Christoph Lameter , Leon Romanovsky , Tal Alon , Matan Barak Subject: [PATCH RFC 06/10] IB/core: Initialize uverbs types specification Date: Wed, 19 Apr 2017 18:20:21 +0300 Message-Id: <1492615225-55118-7-git-send-email-matanb@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1492615225-55118-1-git-send-email-matanb@mellanox.com> References: <1492615225-55118-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 --- 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 a3230b6..6e59a00 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 3465a18..18c0799 100644 --- a/drivers/infiniband/core/uverbs_ioctl.c +++ b/drivers/infiniband/core/uverbs_ioctl.c @@ -349,3 +349,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 b282daf..44c4d92 100644 --- a/drivers/infiniband/core/uverbs_main.c +++ b/drivers/infiniband/core/uverbs_main.c @@ -45,6 +45,7 @@ #include #include #include +#include #include @@ -1253,6 +1254,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) {