From patchwork Mon Feb 4 21:17:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 10796655 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 94C801823 for ; Mon, 4 Feb 2019 21:18:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 842CD2B500 for ; Mon, 4 Feb 2019 21:18:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 784F22B5CC; Mon, 4 Feb 2019 21:18:07 +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 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 BD6D22B500 for ; Mon, 4 Feb 2019 21:18:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729616AbfBDVSF (ORCPT ); Mon, 4 Feb 2019 16:18:05 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:40511 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729280AbfBDVSD (ORCPT ); Mon, 4 Feb 2019 16:18:03 -0500 Received: by mail-pl1-f195.google.com with SMTP id u18so514844plq.7 for ; Mon, 04 Feb 2019 13:18:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bKuQbi+FWksfdR9Byh3oXBx/j7YzSi1Vv/T28zYqiiA=; b=gD+yhSNGKeiZDsJ6wN4ckSPQyvOjPihPq5BQ5Keq2Uj3JPV7isDyW/p2ZNfJ60oJou ojBGYF5tGeUMjJxTHjei1DE24m7p8B+5Rk7JXBwxFkmw9Yg6oKRzdzpzBfYHlOVM5CS4 tXwYRqJVhssy2Fp71Te3+eOZ6sRFrXIb2peBVH3wWAn92yckz2PHc5mga+zttuQDMjWW ZPFEds+nmULSjF784GpEmVjvOaf0VCh6AxK251nKXgEVPdZbPmYWw4yDNkRWm/5XJb1j ybqd8fpwHiZMRu8gLvFzscDJBEhmJq5LJKSeqLGO5v176Y4reWXsO+yygnopMsasL0D4 Cyhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bKuQbi+FWksfdR9Byh3oXBx/j7YzSi1Vv/T28zYqiiA=; b=doap9RI4mIbraiwxsNDzNF5Wu+C7Tye7J5A82c5FBzFJRSLFQcveAGtnovHFM0wgsZ xExYv40CUvcN03yCLHlGxMdok8tjIz9O1GvQdjmy90Sg0/9N2Gcob/mHX+iv0Fyc2cRb upQ/OUKiX89ojxePICP82go2P2AlOkYBh+WaygvpgDsVWp5yGusmp6mPX2S2SCzWzbPW EIYIJdqyw985NbB+PK2DfSLZg8+Ij+6KPbGJNftM0uaLUjZR5dqF50usYsvWdUKVP9s/ 2yYkwu4v/xY6Q3umdYuCIBwWLKAjmkYKX5Gjm9dgrUlbKyrGEKSbCr5pkvefRqJPEo6z OHZA== X-Gm-Message-State: AHQUAuYodxCrveCd7/fwMKBGAgi4HWtsDm4KTU3W8H68Q0cbHd3i6zC1 nozS3WsY+f36Uuv5Pa5+B+x+tbT3+t4= X-Google-Smtp-Source: AHgI3Ia5YFTDTFRHND0ckIGMOph10xsS5XDirjA09EEXhXSDVwKxUSHI3emD6oQ2NC/OMcAL2pXHCA== X-Received: by 2002:a17:902:b01:: with SMTP id 1mr1432943plq.331.1549315082863; Mon, 04 Feb 2019 13:18:02 -0800 (PST) Received: from ziepe.ca (S010614cc2056d97f.ed.shawcable.net. [174.3.196.123]) by smtp.gmail.com with ESMTPSA id t5sm1186574pgo.70.2019.02.04.13.18.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Feb 2019 13:18:02 -0800 (PST) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1gqlct-0005Kl-IT; Mon, 04 Feb 2019 14:17:59 -0700 From: Jason Gunthorpe To: linux-rdma@vger.kernel.org Cc: Jason Gunthorpe , Matthew Wilcox , Parav Pandit Subject: [PATCH 6/8] RDMA/devices: Use xarray to store the clients Date: Mon, 4 Feb 2019 14:17:49 -0700 Message-Id: <20190204211751.19001-7-jgg@ziepe.ca> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190204211751.19001-1-jgg@ziepe.ca> References: <20190204211751.19001-1-jgg@ziepe.ca> MIME-Version: 1.0 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: Jason Gunthorpe This gives each client a unique ID and will let us move client_data to use xarray, and revise the locking scheme. clients have to be add/removed in strict FIFO/LIFO order as they interdepend. To support this the client_ids are assigned to increase in FIFO order. The existing linked list is kept to support reverse iteration until xarray can get a reverse iteration API. Signed-off-by: Jason Gunthorpe Reviewed-by: Parav Pandit --- drivers/infiniband/core/device.c | 50 ++++++++++++++++++++++++++++---- include/rdma/ib_verbs.h | 3 +- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c index 300a36beaa300c..f485e77223d429 100644 --- a/drivers/infiniband/core/device.c +++ b/drivers/infiniband/core/device.c @@ -65,15 +65,17 @@ struct workqueue_struct *ib_comp_unbound_wq; struct workqueue_struct *ib_wq; EXPORT_SYMBOL_GPL(ib_wq); -/* The device_list and client_list contain devices and clients after their +/* The device_list and clients contain devices and clients after their * registration has completed, and the devices and clients are removed * during unregistration. */ static LIST_HEAD(device_list); static LIST_HEAD(client_list); +#define CLIENT_REGISTERED XA_MARK_1 +static DEFINE_XARRAY_FLAGS(clients, XA_FLAGS_ALLOC); /* * device_mutex and lists_rwsem protect access to both device_list and - * client_list. device_mutex protects writer access by device and client + * clients. device_mutex protects writer access by device and client * registration / de-registration. lists_rwsem protects reader access to * these lists. Iterators of these lists must lock it for read, while updates * to the lists must be done with a write lock. A special case is when the @@ -563,6 +565,7 @@ int ib_register_device(struct ib_device *device, const char *name) { int ret; struct ib_client *client; + unsigned long index; setup_dma_device(device); @@ -607,7 +610,7 @@ int ib_register_device(struct ib_device *device, const char *name) refcount_set(&device->refcount, 1); - list_for_each_entry(client, &client_list, list) + xa_for_each_marked (&clients, index, client, CLIENT_REGISTERED) if (!add_client_context(device, client) && client->add) client->add(device); @@ -679,6 +682,32 @@ void ib_unregister_device(struct ib_device *device) } EXPORT_SYMBOL(ib_unregister_device); +static int assign_client_id(struct ib_client *client) +{ + int ret; + + /* + * The add/remove callbacks must be called in FIFO/LIFO order. To + * achieve this we assign client_ids so they are sorted in + * registration order, and retain a linked list we can reverse iterate + * to get the LIFO order. The extra linked list can go away if xarray + * learns to reverse iterate. + */ + if (list_empty(&client_list)) + client->client_id = 0; + else + client->client_id = + list_last_entry(&client_list, struct ib_client, list) + ->client_id; + ret = xa_alloc(&clients, &client->client_id, INT_MAX, client, + GFP_KERNEL); + if (ret) + goto out; + +out: + return ret; +} + /** * ib_register_client - Register an IB client * @client:Client to register @@ -695,15 +724,21 @@ EXPORT_SYMBOL(ib_unregister_device); int ib_register_client(struct ib_client *client) { struct ib_device *device; + int ret; mutex_lock(&device_mutex); + ret = assign_client_id(client); + if (ret) { + mutex_unlock(&device_mutex); + return ret; + } list_for_each_entry(device, &device_list, core_list) if (!add_client_context(device, client) && client->add) client->add(device); down_write(&lists_rwsem); - list_add_tail(&client->list, &client_list); + xa_set_mark(&clients, client->client_id, CLIENT_REGISTERED); up_write(&lists_rwsem); mutex_unlock(&device_mutex); @@ -728,7 +763,7 @@ void ib_unregister_client(struct ib_client *client) mutex_lock(&device_mutex); down_write(&lists_rwsem); - list_del(&client->list); + xa_clear_mark(&clients, client->client_id, CLIENT_REGISTERED); up_write(&lists_rwsem); list_for_each_entry(device, &device_list, core_list) { @@ -764,6 +799,10 @@ void ib_unregister_client(struct ib_client *client) kfree(found_context); } + down_write(&lists_rwsem); + list_del(&client->list); + xa_erase(&clients, client->client_id); + up_write(&lists_rwsem); mutex_unlock(&device_mutex); } EXPORT_SYMBOL(ib_unregister_client); @@ -1417,6 +1456,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); + WARN_ON(!xa_empty(&clients)); } MODULE_ALIAS_RDMA_NETLINK(RDMA_NL_LS, 4); diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index 76138ef4f839ea..84d7523984ee77 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h @@ -2596,7 +2596,7 @@ struct ib_device { }; struct ib_client { - char *name; + const char *name; void (*add) (struct ib_device *); void (*remove)(struct ib_device *, void *client_data); @@ -2623,6 +2623,7 @@ struct ib_client { const struct sockaddr *addr, void *client_data); struct list_head list; + u32 client_id; /* kverbs are not required by the client */ u8 no_kverbs_req:1;