From patchwork Thu Jun 30 13:39:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matan Barak X-Patchwork-Id: 9207565 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 7E78E60752 for ; Thu, 30 Jun 2016 13:41:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 70735285C3 for ; Thu, 30 Jun 2016 13:41:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 64D862866B; Thu, 30 Jun 2016 13:41:16 +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 0ABAF285C3 for ; Thu, 30 Jun 2016 13:41:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752352AbcF3NlP (ORCPT ); Thu, 30 Jun 2016 09:41:15 -0400 Received: from [193.47.165.129] ([193.47.165.129]:59255 "EHLO mellanox.co.il" rhost-flags-FAIL-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752351AbcF3NlO (ORCPT ); Thu, 30 Jun 2016 09:41:14 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from matanb@mellanox.com) with ESMTPS (AES256-SHA encrypted); 30 Jun 2016 16:39:57 +0300 Received: from rsws33.mtr.labs.mlnx (dev-r-vrt-064.mtr.labs.mlnx [10.212.64.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id u5UDduVj025363; Thu, 30 Jun 2016 16:39:57 +0300 From: Matan Barak To: linux-rdma@vger.kernel.org Cc: Doug Ledford , Jason Gunthorpe , Sean Hefty , Tal Alon , Liran Liss , Haggai Eran , Matan Barak , Majd Dibbiny , Christoph Lameter , Leon Romanovsky Subject: [RFC ABI V1 5/8] RDMA/core: Introduce add/remove uobj from types Date: Thu, 30 Jun 2016 16:39:28 +0300 Message-Id: <1467293971-25688-6-git-send-email-matanb@mellanox.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1467293971-25688-1-git-send-email-matanb@mellanox.com> References: <1467293971-25688-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 We introduce here adding new user objects to the type list. Adding an object is done in two parts. First, an object is allocated and added to IDR. Then, the command's handlers (in downstream patches) could work on this object and fill its required details. After a successful command, ib_uverbs_uobject_enable is called and this user object becomes ucontext visible. Removing an uboject is done by calling ib_uverbs_uobject_remove. We should make sure IDR (per-device) and lists (per-ucontext) could be accessed concurrently without corrupting them (some parts are missing here). Signed-off-by: Matan Barak Signed-off-by: Haggai Eran Signed-off-by: Leon Romanovsky --- drivers/infiniband/core/uobject.c | 33 +++++++++++++++++++++++++++++++++ drivers/infiniband/core/uobject.h | 5 +++++ 2 files changed, 38 insertions(+) diff --git a/drivers/infiniband/core/uobject.c b/drivers/infiniband/core/uobject.c index bc15be1..c480b3b 100644 --- a/drivers/infiniband/core/uobject.c +++ b/drivers/infiniband/core/uobject.c @@ -118,6 +118,39 @@ err: return err; } +int ib_uverbs_uobject_add(struct ib_uobject *uobject, + struct uverbs_uobject_type *uobject_type) +{ + int ret = -EINVAL; + struct uverbs_uobject_list *type; + + /* TODO: add locking */ + list_for_each_entry(type, &uobject->context->uobjects_lists, type_list) + if (type->type == uobject_type) { + uobject->type = type; + ret = idr_add_uobj(uobject); + return ret; + } + + return ret; +} + +void ib_uverbs_uobject_remove(struct ib_uobject *uobject) +{ + spin_lock(&uobject->context->device->idr_lock); + list_del(&uobject->idr_list); + spin_unlock(&uobject->context->device->idr_lock); + idr_remove_uobj(uobject); +} + +void ib_uverbs_uobject_enable(struct ib_uobject *uobject) +{ + spin_lock(&uobject->context->device->idr_lock); + list_add(&uobject->idr_list, &uobject->type->list); + spin_unlock(&uobject->context->device->idr_lock); + uobject->live = 1; +} + /* * The ib_uobject locking scheme is as follows: * diff --git a/drivers/infiniband/core/uobject.h b/drivers/infiniband/core/uobject.h index 40f6ff1..13fdaef 100644 --- a/drivers/infiniband/core/uobject.h +++ b/drivers/infiniband/core/uobject.h @@ -58,6 +58,11 @@ struct uverbs_uobject_list { struct list_head type_list; }; +int ib_uverbs_uobject_add(struct ib_uobject *uobject, + struct uverbs_uobject_type *uobject_type); +void ib_uverbs_uobject_remove(struct ib_uobject *uobject); +void ib_uverbs_uobject_enable(struct ib_uobject *uobject); + void init_uobj(struct ib_uobject *uobj, u64 user_handle, struct ib_ucontext *context, struct uverbs_lock_class *c);