From patchwork Thu Oct 27 14:43:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matan Barak X-Patchwork-Id: 9399611 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 5A3816059C for ; Thu, 27 Oct 2016 14:45:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 446BA2A304 for ; Thu, 27 Oct 2016 14:45:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 394092A307; Thu, 27 Oct 2016 14:45:48 +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 636442A315 for ; Thu, 27 Oct 2016 14:45:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936684AbcJ0Onl (ORCPT ); Thu, 27 Oct 2016 10:43:41 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:37325 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934980AbcJ0On2 (ORCPT ); Thu, 27 Oct 2016 10:43:28 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from matanb@mellanox.com) with ESMTPS (AES256-SHA encrypted); 27 Oct 2016 16:43:21 +0200 Received: from dev-r-vrt-064.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 u9REhKIG011255; Thu, 27 Oct 2016 17:43:21 +0300 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 V5 04/10] RDMA/core: Add initialize and cleanup of common types Date: Thu, 27 Oct 2016 17:43:12 +0300 Message-Id: <1477579398-6875-5-git-send-email-matanb@mellanox.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1477579398-6875-1-git-send-email-matanb@mellanox.com> References: <1477579398-6875-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 The new ABI infrastructure introduced types per driver. Since current drivers use common types, we mimics the current release ucontext process using the new process. Signed-off-by: Matan Barak Signed-off-by: Haggai Eran Signed-off-by: Leon Romanovsky --- drivers/infiniband/core/uverbs.h | 9 +- drivers/infiniband/core/uverbs_ioctl_cmd.c | 128 +++++++++++++++++++++++++++++ drivers/infiniband/core/uverbs_main.c | 123 ++------------------------- include/rdma/uverbs_ioctl_cmd.h | 42 ++++++++++ 4 files changed, 182 insertions(+), 120 deletions(-) diff --git a/drivers/infiniband/core/uverbs.h b/drivers/infiniband/core/uverbs.h index d78c060..fa37c2a 100644 --- a/drivers/infiniband/core/uverbs.h +++ b/drivers/infiniband/core/uverbs.h @@ -179,8 +179,6 @@ struct ib_ucq_object { u32 async_events_reported; }; -void idr_remove_uobj(struct ib_uobject *uobj); - struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file, struct ib_device *ib_dev, int is_async); @@ -204,6 +202,13 @@ void ib_uverbs_event_handler(struct ib_event_handler *handler, void ib_uverbs_dealloc_xrcd(struct ib_uverbs_device *dev, struct ib_xrcd *xrcd); int uverbs_dealloc_mw(struct ib_mw *mw); +void ib_uverbs_release_ucq(struct ib_uverbs_file *file, + struct ib_uverbs_event_file *ev_file, + struct ib_ucq_object *uobj); +void ib_uverbs_release_uevent(struct ib_uverbs_file *file, + struct ib_uevent_object *uobj); +void ib_uverbs_detach_umcast(struct ib_qp *qp, + struct ib_uqp_object *uobj); struct ib_uverbs_flow_spec { union { diff --git a/drivers/infiniband/core/uverbs_ioctl_cmd.c b/drivers/infiniband/core/uverbs_ioctl_cmd.c index cde86b9..9ec76d9 100644 --- a/drivers/infiniband/core/uverbs_ioctl_cmd.c +++ b/drivers/infiniband/core/uverbs_ioctl_cmd.c @@ -31,8 +31,11 @@ */ #include +#include #include #include +#include +#include "rdma_core.h" #include "uverbs.h" int ib_uverbs_std_dist(__u16 *id, void *priv) @@ -75,3 +78,128 @@ int uverbs_action_std_ctx_handle(struct ib_device *ib_dev, } EXPORT_SYMBOL(uverbs_action_std_ctx_handle); +void uverbs_free_ah(const struct uverbs_type_alloc_action *uobject_type, + struct ib_uobject *uobject) +{ + ib_destroy_ah((struct ib_ah *)uobject->object); +} +EXPORT_SYMBOL(uverbs_free_ah); + +void uverbs_free_flow(const struct uverbs_type_alloc_action *type_alloc_action, + struct ib_uobject *uobject) +{ + ib_destroy_flow((struct ib_flow *)uobject->object); +} +EXPORT_SYMBOL(uverbs_free_flow); + +void uverbs_free_mw(const struct uverbs_type_alloc_action *type_alloc_action, + struct ib_uobject *uobject) +{ + uverbs_dealloc_mw((struct ib_mw *)uobject->object); +} +EXPORT_SYMBOL(uverbs_free_mw); + +void uverbs_free_qp(const struct uverbs_type_alloc_action *type_alloc_action, + struct ib_uobject *uobject) +{ + struct ib_qp *qp = uobject->object; + struct ib_uqp_object *uqp = + container_of(uobject, struct ib_uqp_object, uevent.uobject); + + if (qp != qp->real_qp) { + ib_close_qp(qp); + } else { + ib_uverbs_detach_umcast(qp, uqp); + ib_destroy_qp(qp); + } + ib_uverbs_release_uevent(uobject->context->ufile, &uqp->uevent); +} +EXPORT_SYMBOL(uverbs_free_qp); + +void uverbs_free_rwq_ind_tbl(const struct uverbs_type_alloc_action *type_alloc_action, + struct ib_uobject *uobject) +{ + struct ib_rwq_ind_table *rwq_ind_tbl = uobject->object; + struct ib_wq **ind_tbl = rwq_ind_tbl->ind_tbl; + + ib_destroy_rwq_ind_table(rwq_ind_tbl); + kfree(ind_tbl); +} +EXPORT_SYMBOL(uverbs_free_rwq_ind_tbl); + +void uverbs_free_wq(const struct uverbs_type_alloc_action *type_alloc_action, + struct ib_uobject *uobject) +{ + struct ib_wq *wq = uobject->object; + struct ib_uwq_object *uwq = + container_of(uobject, struct ib_uwq_object, uevent.uobject); + + ib_destroy_wq(wq); + ib_uverbs_release_uevent(uobject->context->ufile, &uwq->uevent); +} +EXPORT_SYMBOL(uverbs_free_wq); + +void uverbs_free_srq(const struct uverbs_type_alloc_action *type_alloc_action, + struct ib_uobject *uobject) +{ + struct ib_srq *srq = uobject->object; + struct ib_uevent_object *uevent = + container_of(uobject, struct ib_uevent_object, uobject); + + ib_destroy_srq(srq); + ib_uverbs_release_uevent(uobject->context->ufile, uevent); +} +EXPORT_SYMBOL(uverbs_free_srq); + +void uverbs_free_cq(const struct uverbs_type_alloc_action *type_alloc_action, + struct ib_uobject *uobject) +{ + struct ib_cq *cq = uobject->object; + struct ib_uverbs_event_file *ev_file = cq->cq_context; + struct ib_ucq_object *ucq = + container_of(uobject, struct ib_ucq_object, uobject); + + ib_destroy_cq(cq); + ib_uverbs_release_ucq(uobject->context->ufile, ev_file, ucq); +} +EXPORT_SYMBOL(uverbs_free_cq); + +void uverbs_free_mr(const struct uverbs_type_alloc_action *type_alloc_action, + struct ib_uobject *uobject) +{ + ib_dereg_mr((struct ib_mr *)uobject->object); +} +EXPORT_SYMBOL(uverbs_free_mr); + +void uverbs_free_xrcd(const struct uverbs_type_alloc_action *type_alloc_action, + struct ib_uobject *uobject) +{ + struct ib_xrcd *xrcd = uobject->object; + + mutex_lock(&uobject->context->ufile->device->xrcd_tree_mutex); + ib_uverbs_dealloc_xrcd(uobject->context->ufile->device, xrcd); + mutex_unlock(&uobject->context->ufile->device->xrcd_tree_mutex); +} +EXPORT_SYMBOL(uverbs_free_xrcd); + +void uverbs_free_pd(const struct uverbs_type_alloc_action *type_alloc_action, + struct ib_uobject *uobject) +{ + ib_dealloc_pd((struct ib_pd *)uobject->object); +} +EXPORT_SYMBOL(uverbs_free_pd); + +void uverbs_free_event_file(const struct uverbs_type_alloc_action *type_alloc_action, + struct ib_uobject *uobject) +{ + struct ib_uverbs_event_file *event_file = (void *)(uobject + 1); + + spin_lock_irq(&event_file->lock); + event_file->is_closed = 1; + spin_unlock_irq(&event_file->lock); + + wake_up_interruptible(&event_file->poll_wait); + kill_fasync(&event_file->async_queue, SIGIO, POLL_IN); +}; +EXPORT_SYMBOL(uverbs_free_event_file); + diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c index 4bb2fc6..ff43ff4 100644 --- a/drivers/infiniband/core/uverbs_main.c +++ b/drivers/infiniband/core/uverbs_main.c @@ -52,6 +52,7 @@ #include #include "uverbs.h" +#include "rdma_core.h" MODULE_AUTHOR("Roland Dreier"); MODULE_DESCRIPTION("InfiniBand userspace verbs access"); @@ -200,8 +201,8 @@ void ib_uverbs_release_uevent(struct ib_uverbs_file *file, spin_unlock_irq(&file->async_file->lock); } -static void ib_uverbs_detach_umcast(struct ib_qp *qp, - struct ib_uqp_object *uobj) +void ib_uverbs_detach_umcast(struct ib_qp *qp, + struct ib_uqp_object *uobj) { struct ib_uverbs_mcast_entry *mcast, *tmp; @@ -215,124 +216,10 @@ static void ib_uverbs_detach_umcast(struct ib_qp *qp, static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file, struct ib_ucontext *context) { - struct ib_uobject *uobj, *tmp; - down_write(&file->close_sem); context->closing = 1; - - list_for_each_entry_safe(uobj, tmp, &context->ah_list, list) { - struct ib_ah *ah = uobj->object; - - idr_remove_uobj(uobj); - ib_destroy_ah(ah); - kfree(uobj); - } - - /* Remove MWs before QPs, in order to support type 2A MWs. */ - list_for_each_entry_safe(uobj, tmp, &context->mw_list, list) { - struct ib_mw *mw = uobj->object; - - idr_remove_uobj(uobj); - uverbs_dealloc_mw(mw); - kfree(uobj); - } - - list_for_each_entry_safe(uobj, tmp, &context->rule_list, list) { - struct ib_flow *flow_id = uobj->object; - - idr_remove_uobj(uobj); - ib_destroy_flow(flow_id); - kfree(uobj); - } - - list_for_each_entry_safe(uobj, tmp, &context->qp_list, list) { - struct ib_qp *qp = uobj->object; - struct ib_uqp_object *uqp = - container_of(uobj, struct ib_uqp_object, uevent.uobject); - - idr_remove_uobj(uobj); - if (qp != qp->real_qp) { - ib_close_qp(qp); - } else { - ib_uverbs_detach_umcast(qp, uqp); - ib_destroy_qp(qp); - } - ib_uverbs_release_uevent(file, &uqp->uevent); - kfree(uqp); - } - - list_for_each_entry_safe(uobj, tmp, &context->rwq_ind_tbl_list, list) { - struct ib_rwq_ind_table *rwq_ind_tbl = uobj->object; - struct ib_wq **ind_tbl = rwq_ind_tbl->ind_tbl; - - idr_remove_uobj(uobj); - ib_destroy_rwq_ind_table(rwq_ind_tbl); - kfree(ind_tbl); - kfree(uobj); - } - - list_for_each_entry_safe(uobj, tmp, &context->wq_list, list) { - struct ib_wq *wq = uobj->object; - struct ib_uwq_object *uwq = - container_of(uobj, struct ib_uwq_object, uevent.uobject); - - idr_remove_uobj(uobj); - ib_destroy_wq(wq); - ib_uverbs_release_uevent(file, &uwq->uevent); - kfree(uwq); - } - - list_for_each_entry_safe(uobj, tmp, &context->srq_list, list) { - struct ib_srq *srq = uobj->object; - struct ib_uevent_object *uevent = - container_of(uobj, struct ib_uevent_object, uobject); - - idr_remove_uobj(uobj); - ib_destroy_srq(srq); - ib_uverbs_release_uevent(file, uevent); - kfree(uevent); - } - - list_for_each_entry_safe(uobj, tmp, &context->cq_list, list) { - struct ib_cq *cq = uobj->object; - struct ib_uverbs_event_file *ev_file = cq->cq_context; - struct ib_ucq_object *ucq = - container_of(uobj, struct ib_ucq_object, uobject); - - idr_remove_uobj(uobj); - ib_destroy_cq(cq); - ib_uverbs_release_ucq(file, ev_file, ucq); - kfree(ucq); - } - - list_for_each_entry_safe(uobj, tmp, &context->mr_list, list) { - struct ib_mr *mr = uobj->object; - - idr_remove_uobj(uobj); - ib_dereg_mr(mr); - kfree(uobj); - } - - mutex_lock(&file->device->xrcd_tree_mutex); - list_for_each_entry_safe(uobj, tmp, &context->xrcd_list, list) { - struct ib_xrcd *xrcd = uobj->object; - struct ib_uxrcd_object *uxrcd = - container_of(uobj, struct ib_uxrcd_object, uobject); - - idr_remove_uobj(uobj); - ib_uverbs_dealloc_xrcd(file->device, xrcd); - kfree(uxrcd); - } - mutex_unlock(&file->device->xrcd_tree_mutex); - - list_for_each_entry_safe(uobj, tmp, &context->pd_list, list) { - struct ib_pd *pd = uobj->object; - - idr_remove_uobj(uobj); - ib_dealloc_pd(pd); - kfree(uobj); - } - + ib_uverbs_uobject_type_cleanup_ucontext(context, + context->device->types_group); put_pid(context->tgid); up_write(&file->close_sem); diff --git a/include/rdma/uverbs_ioctl_cmd.h b/include/rdma/uverbs_ioctl_cmd.h index 728389e..e0299a2 100644 --- a/include/rdma/uverbs_ioctl_cmd.h +++ b/include/rdma/uverbs_ioctl_cmd.h @@ -66,5 +66,47 @@ struct uverbs_action_std_ctx_handler { void *priv; }; +void uverbs_free_ah(const struct uverbs_type_alloc_action *type_alloc_action, + struct ib_uobject *uobject); +void uverbs_free_flow(const struct uverbs_type_alloc_action *type_alloc_action, + struct ib_uobject *uobject); +void uverbs_free_mw(const struct uverbs_type_alloc_action *type_alloc_action, + struct ib_uobject *uobject); +void uverbs_free_qp(const struct uverbs_type_alloc_action *type_alloc_action, + struct ib_uobject *uobject); +void uverbs_free_rwq_ind_tbl(const struct uverbs_type_alloc_action *type_alloc_action, + struct ib_uobject *uobject); +void uverbs_free_wq(const struct uverbs_type_alloc_action *type_alloc_action, + struct ib_uobject *uobject); +void uverbs_free_srq(const struct uverbs_type_alloc_action *type_alloc_action, + struct ib_uobject *uobject); +void uverbs_free_cq(const struct uverbs_type_alloc_action *type_alloc_action, + struct ib_uobject *uobject); +void uverbs_free_mr(const struct uverbs_type_alloc_action *type_alloc_action, + struct ib_uobject *uobject); +void uverbs_free_xrcd(const struct uverbs_type_alloc_action *type_alloc_action, + struct ib_uobject *uobject); +void uverbs_free_pd(const struct uverbs_type_alloc_action *type_alloc_action, + struct ib_uobject *uobject); +void uverbs_free_event_file(const struct uverbs_type_alloc_action *type_alloc_action, + struct ib_uobject *uobject); + +enum uverbs_common_types { + UVERBS_TYPE_DEVICE, /* Don't use IDRs here */ + UVERBS_TYPE_PD, + UVERBS_TYPE_COMP_CHANNEL, + UVERBS_TYPE_CQ, + UVERBS_TYPE_QP, + UVERBS_TYPE_SRQ, + UVERBS_TYPE_AH, + UVERBS_TYPE_MR, + UVERBS_TYPE_MW, + UVERBS_TYPE_FLOW, + UVERBS_TYPE_XRCD, + UVERBS_TYPE_RWQ_IND_TBL, + UVERBS_TYPE_WQ, + UVERBS_TYPE_LAST, +}; + #endif