From patchwork Mon Jan 7 14:39:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shamir Rabinovitch X-Patchwork-Id: 10750677 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8C79F14E5 for ; Mon, 7 Jan 2019 14:40:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A5C028A3B for ; Mon, 7 Jan 2019 14:40:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E9E928A8C; Mon, 7 Jan 2019 14:40:29 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,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 028A628A3B for ; Mon, 7 Jan 2019 14:40:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728811AbfAGOk2 (ORCPT ); Mon, 7 Jan 2019 09:40:28 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:37222 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728618AbfAGOk2 (ORCPT ); Mon, 7 Jan 2019 09:40:28 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id x07EXkvf067369; Mon, 7 Jan 2019 14:40:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=G/F6IL7XclP4Iuir2QZaVAe0KKuJhIUUa91ao735jMg=; b=tKP/EnOKEga3soRC+gVx6uItC+nUDq/c6u/dlqxn7dI0OsPzzG8xtUSSv6dcuqXRWH4b EgfM2YBKBtlEUWNpOz+JCcMJHZofFIu5FfY7f+hNEO/XSMNZ5bcJuVnM9LTJRnv+pplM lagxlIh4lBk09MNTbAardWbbGnvVPLZMhMnFDDQelHJOkG9CLWgolBvzyoVIP/QwvrAK 7jY6DiwwHZZatdcvn1PHrh1TyCZJydSz2iEyIMM6J/vv1nqihVbKre051ZMlthT/1xJb mwqdOpiNwyNQyjpWLwUNAs+9ZSYC4P94ly6qITVdPKldWlFQ0JLCuVbDJWCAVFjQa7a4 NQ== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2130.oracle.com with ESMTP id 2ptj3dp9ny-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 07 Jan 2019 14:40:21 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x07EeLHB013286 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 7 Jan 2019 14:40:21 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x07EeL8s029496; Mon, 7 Jan 2019 14:40:21 GMT Received: from localhost.localdomain (/10.175.23.6) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 07 Jan 2019 06:40:17 -0800 From: Shamir Rabinovitch To: linux-rdma@vger.kernel.org Cc: dledford@redhat.com, jgg@ziepe.ca, monis@mellanox.com Subject: [RFC for-next 1/2] IB/{core,uverbs}: ib_uverbs callback registration in ib_core Date: Mon, 7 Jan 2019 16:39:29 +0200 Message-Id: <20190107143930.4922-2-shamir.rabinovitch@oracle.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190107143930.4922-1-shamir.rabinovitch@oracle.com> References: <20190107143930.4922-1-shamir.rabinovitch@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9128 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=703 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901070129 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 From: shamir rabinovitch next patch will add dependency from ib_umem_get to ib_uverbs. this require ib_uverbs callback registartion to prevent circular dependecy of the form ib_core -> ib_uverbs -> ib_core that fail in depmod check. Signed-off-by: shamir rabinovitch --- drivers/infiniband/core/device.c | 51 +++++++++++++++++++++++++++ drivers/infiniband/core/uverbs_main.c | 11 ++++++ include/rdma/ib_verbs.h | 12 +++++++ 3 files changed, 74 insertions(+) diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c index 47ab34ee1a9d..416180805a6a 100644 --- a/drivers/infiniband/core/device.c +++ b/drivers/infiniband/core/device.c @@ -789,6 +789,56 @@ void ib_unregister_client(struct ib_client *client) } EXPORT_SYMBOL(ib_unregister_client); +static DEFINE_MUTEX(uverbs_lock); +static struct ib_uverbs __rcu *ib_core_uverbs; + +int ib_register_uverbs(struct ib_uverbs *uverbs) +{ + struct ib_uverbs *core_uverbs; + int ret = 0; + + mutex_lock(&uverbs_lock); + if (ib_core_uverbs) { + ret = -EEXIST; + goto unlock; + } + + core_uverbs = kzalloc(sizeof(*core_uverbs), GFP_KERNEL); + if (!core_uverbs) { + ret = -ENOMEM; + goto unlock; + } + + *core_uverbs = *uverbs; + rcu_assign_pointer(ib_core_uverbs, core_uverbs); +unlock: + mutex_unlock(&uverbs_lock); + + return ret; +} +EXPORT_SYMBOL(ib_register_uverbs); + +void ib_unregister_uverbs(void) +{ + struct ib_uverbs *core_uverbs; + + mutex_lock(&uverbs_lock); + if (!ib_core_uverbs) + goto unlock; + core_uverbs = ib_core_uverbs; + rcu_assign_pointer(ib_core_uverbs, NULL); + synchronize_rcu(); + kfree(core_uverbs); +unlock: + mutex_unlock(&uverbs_lock); +} +EXPORT_SYMBOL(ib_unregister_uverbs); + +struct ib_uverbs *ib_get_uverbs(void) +{ + return rcu_dereference(ib_core_uverbs); +} + /** * ib_get_client_data - Get IB client context * @device:Device to get context for @@ -1435,6 +1485,7 @@ static void __exit ib_core_cleanup(void) destroy_workqueue(ib_comp_wq); /* Make sure that any pending umem accounting work is done. */ destroy_workqueue(ib_wq); + ib_unregister_uverbs(); } MODULE_ALIAS_RDMA_NETLINK(RDMA_NL_LS, 4); diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c index 9f9172eb1512..e0574cd5e850 100644 --- a/drivers/infiniband/core/uverbs_main.c +++ b/drivers/infiniband/core/uverbs_main.c @@ -1370,6 +1370,7 @@ static char *uverbs_devnode(struct device *dev, umode_t *mode) static int __init ib_uverbs_init(void) { + struct ib_uverbs uverbs = {0}; int ret; ret = register_chrdev_region(IB_UVERBS_BASE_DEV, @@ -1409,8 +1410,17 @@ static int __init ib_uverbs_init(void) goto out_class; } + ret = ib_register_uverbs(&uverbs); + if (ret) { + pr_err("user_verbs: couldn't register uverbs\n"); + goto out_client; + } + return 0; +out_client: + ib_unregister_client(&uverbs_client); + out_class: class_destroy(uverbs_class); @@ -1428,6 +1438,7 @@ static int __init ib_uverbs_init(void) static void __exit ib_uverbs_cleanup(void) { + ib_unregister_uverbs(); ib_unregister_client(&uverbs_client); class_destroy(uverbs_class); unregister_chrdev_region(IB_UVERBS_BASE_DEV, diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index 0ec15d673d92..cd8c5886a1e6 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h @@ -2617,6 +2617,10 @@ struct ib_client { struct list_head list; }; +struct ib_uverbs { + /* uverbs callbacks used by ib_core */ +}; + struct ib_device *ib_alloc_device(size_t size); void ib_dealloc_device(struct ib_device *device); @@ -2630,6 +2634,14 @@ void ib_unregister_device(struct ib_device *device); int ib_register_client (struct ib_client *client); void ib_unregister_client(struct ib_client *client); +int ib_register_uverbs(struct ib_uverbs *uverbs); +void ib_unregister_uverbs(void); +/* + * return uverbs callbacks or NULL. + * rcu read lock must be held as long as uverbs callbacks are in use. + */ +struct ib_uverbs *ib_get_uverbs(void); + void *ib_get_client_data(struct ib_device *device, struct ib_client *client); void ib_set_client_data(struct ib_device *device, struct ib_client *client, void *data);