From patchwork Wed Feb 13 04:12:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 10809111 X-Patchwork-Delegate: jgg@ziepe.ca 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 E1B781390 for ; Wed, 13 Feb 2019 04:13:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8EF42BFAF for ; Wed, 13 Feb 2019 04:13:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD1342C06B; Wed, 13 Feb 2019 04:13:08 +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 2EBE12BFE1 for ; Wed, 13 Feb 2019 04:13:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726902AbfBMENH (ORCPT ); Tue, 12 Feb 2019 23:13:07 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:35799 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730431AbfBMENF (ORCPT ); Tue, 12 Feb 2019 23:13:05 -0500 Received: by mail-pl1-f193.google.com with SMTP id p8so549316plo.2 for ; Tue, 12 Feb 2019 20:13:05 -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=DhkZYOB0dd3ZnD0POvbXl6eCxkekf5bzjMa0QEm8y9U=; b=jgCbVjpfYysnT8Ciw/a2VLi4Q5nMpR/3sWsvkn1aswcuesdIfauHlHzquO6McWVfsw iipebmqvm92DMAAddUy13Gjw9DJKZpZzuxNeGSmrt22XULfaxDjWDErsRyBrF8AkZqDB ufmUcY5JOE7gK+uSQsKTO5PjoGVCPkQ0sT8rcWNrYk7c4Iv5JdewOnNPsdNMHCRM3tav l5rtn9MtIcCYN6otbsiZwjVqwe9ZUh9ecU0ab8MG90ye1Eo+29lJsI+AvH64XCLBHv1c KZtDX44+vvfUvued7injo/Nr+2CBQbq8oYViPUOmdN78qFBJQ6c9Azvpru2J6u8Gb+xe XDiQ== 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=DhkZYOB0dd3ZnD0POvbXl6eCxkekf5bzjMa0QEm8y9U=; b=BhK0XftjGRWWPQh0Ep7U8BdwH7BiNAUe3hC1KtR/fzR+cKUJjmDP6VoLvXTEyqC4ld 5x6G45TLJxSI8jMcAlo5yQ3td7wSE0c9tDaaMLxhIzuBmr4QVo7/xfExfhM/KbBEHCuo 2GEY0fvHtnidOaSCCXYeLP1a+pwfIzTGhYkoMBHT8vhRaE5d6tDVczKiHJu6sKHMPHo6 u4CQiFT+v67W/RxxYnldGaPN8qRMvNL7ewcIRBvSZU98kouJ4GntiptT29tEm28hr35i ptqEGmqPStRPm1KLsyO89/Rra+Tof8UpVs0R1WZZb9g7GIHs/vLcOwPYhZzeZGbcwK38 q7rw== X-Gm-Message-State: AHQUAuYl5tnVustP/MSJnx7Sq0NB8rZBweGThWz4nLMYyfFir1HE+9et A050IlM3ltuQlLfEeQ+6NcomKDAF130= X-Google-Smtp-Source: AHgI3IYsk8ENAuJMRh3jt2JVko5hyfNC5svtybhsUvo1kdO8EkSsUzZ6o50By0xjpyd2KzrHb2zuYw== X-Received: by 2002:a17:902:f096:: with SMTP id go22mr1280291plb.23.1550031184826; Tue, 12 Feb 2019 20:13:04 -0800 (PST) Received: from ziepe.ca (S010614cc2056d97f.ed.shawcable.net. [174.3.196.123]) by smtp.gmail.com with ESMTPSA id z62sm25877252pfi.4.2019.02.12.20.13.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Feb 2019 20:13:03 -0800 (PST) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1gtluu-0005sm-4c; Tue, 12 Feb 2019 21:13:00 -0700 From: Jason Gunthorpe To: linux-rdma@vger.kernel.org Cc: Jason Gunthorpe Subject: [PATCH 09/10] RDMA/rxe: Add ib_device_get_by_name() and use it in rxe Date: Tue, 12 Feb 2019 21:12:55 -0700 Message-Id: <20190213041256.22437-10-jgg@ziepe.ca> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190213041256.22437-1-jgg@ziepe.ca> References: <20190213041256.22437-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 rxe has an open coded version of this that is not as safe as the core version. This lets us eliminate the internal device list entirely from rxe. Signed-off-by: Jason Gunthorpe --- drivers/infiniband/core/device.c | 28 +++++++++++++++++++++++++++ drivers/infiniband/sw/rxe/rxe.c | 3 --- drivers/infiniband/sw/rxe/rxe.h | 2 -- drivers/infiniband/sw/rxe/rxe_net.c | 22 --------------------- drivers/infiniband/sw/rxe/rxe_sysfs.c | 9 ++++----- drivers/infiniband/sw/rxe/rxe_verbs.h | 1 - 6 files changed, 32 insertions(+), 33 deletions(-) diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c index f6c755b675a86a..c8cacc19625708 100644 --- a/drivers/infiniband/core/device.c +++ b/drivers/infiniband/core/device.c @@ -239,6 +239,34 @@ static struct ib_device *__ib_device_get_by_name(const char *name) return NULL; } +/** + * ib_device_get_by_name - Find an IB device by name + * @name: The name to look for + * @driver_id: The driver ID that must match (RDMA_DRIVER_UNKNOWN matches all) + * + * Find and hold an ib_device by its name. The caller must call + * ib_device_put() on the returned pointer. + */ +struct ib_device *ib_device_get_by_name(const char *name, + enum rdma_driver_id driver_id) +{ + struct ib_device *device; + + down_read(&devices_rwsem); + device = __ib_device_get_by_name(name); + if (device && driver_id != RDMA_DRIVER_UNKNOWN && + device->driver_id != driver_id) + device = NULL; + + if (device) { + if (!ib_device_try_get(device)) + device = NULL; + } + up_read(&devices_rwsem); + return device; +} +EXPORT_SYMBOL(ib_device_get_by_name); + int ib_device_rename(struct ib_device *ibdev, const char *name) { int ret; diff --git a/drivers/infiniband/sw/rxe/rxe.c b/drivers/infiniband/sw/rxe/rxe.c index cd93c546c008cd..08a45ce9cab551 100644 --- a/drivers/infiniband/sw/rxe/rxe.c +++ b/drivers/infiniband/sw/rxe/rxe.c @@ -69,8 +69,6 @@ void rxe_dealloc(struct ib_device *ib_dev) if (rxe->tfm) crypto_free_shash(rxe->tfm); - - list_del(&rxe->list); } /* initialize rxe device parameters */ @@ -275,7 +273,6 @@ static int rxe_init(struct rxe_dev *rxe) spin_lock_init(&rxe->mmap_offset_lock); spin_lock_init(&rxe->pending_lock); INIT_LIST_HEAD(&rxe->pending_mmaps); - INIT_LIST_HEAD(&rxe->list); mutex_init(&rxe->usdev_lock); diff --git a/drivers/infiniband/sw/rxe/rxe.h b/drivers/infiniband/sw/rxe/rxe.h index ce4bf05cd85550..63b3b89b894a2e 100644 --- a/drivers/infiniband/sw/rxe/rxe.h +++ b/drivers/infiniband/sw/rxe/rxe.h @@ -99,8 +99,6 @@ int rxe_add(struct rxe_dev *rxe, unsigned int mtu); void rxe_rcv(struct sk_buff *skb); -struct rxe_dev *get_rxe_by_name(const char *name); - /* The caller must do a matching ib_device_put(&dev->ib_dev) */ static inline struct rxe_dev *rxe_get_dev_from_net(struct net_device *ndev) { diff --git a/drivers/infiniband/sw/rxe/rxe_net.c b/drivers/infiniband/sw/rxe/rxe_net.c index d56a967ff90be2..d6dfbcf6a47e7b 100644 --- a/drivers/infiniband/sw/rxe/rxe_net.c +++ b/drivers/infiniband/sw/rxe/rxe_net.c @@ -45,25 +45,6 @@ #include "rxe_net.h" #include "rxe_loc.h" -static LIST_HEAD(rxe_dev_list); -static DEFINE_SPINLOCK(dev_list_lock); /* spinlock for device list */ - -struct rxe_dev *get_rxe_by_name(const char *name) -{ - struct rxe_dev *rxe; - struct rxe_dev *found = NULL; - - spin_lock_bh(&dev_list_lock); - list_for_each_entry(rxe, &rxe_dev_list, list) { - if (!strcmp(name, dev_name(&rxe->ib_dev.dev))) { - found = rxe; - break; - } - } - spin_unlock_bh(&dev_list_lock); - return found; -} - static struct rxe_recv_sockets recv_sockets; struct device *rxe_dma_device(struct rxe_dev *rxe) @@ -553,9 +534,6 @@ struct rxe_dev *rxe_net_add(struct net_device *ndev) return NULL; } - spin_lock_bh(&dev_list_lock); - list_add_tail(&rxe->list, &rxe_dev_list); - spin_unlock_bh(&dev_list_lock); return rxe; } diff --git a/drivers/infiniband/sw/rxe/rxe_sysfs.c b/drivers/infiniband/sw/rxe/rxe_sysfs.c index c8630638cd57ad..d51b55b0a311c5 100644 --- a/drivers/infiniband/sw/rxe/rxe_sysfs.c +++ b/drivers/infiniband/sw/rxe/rxe_sysfs.c @@ -101,7 +101,7 @@ static int rxe_param_set_remove(const char *val, const struct kernel_param *kp) { int len; char intf[32]; - struct rxe_dev *rxe; + struct ib_device *ib_dev; len = sanitize_arg(val, intf, sizeof(intf)); if (!len) { @@ -115,14 +115,13 @@ static int rxe_param_set_remove(const char *val, const struct kernel_param *kp) return 0; } - rxe = get_rxe_by_name(intf); - - if (!rxe) { + ib_dev = ib_device_get_by_name(intf, RDMA_DRIVER_RXE); + if (!ib_dev) { pr_err("not configured on %s\n", intf); return -EINVAL; } - ib_unregister_device(&rxe->ib_dev); + ib_unregister_device_and_put(ib_dev); return 0; } diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.h b/drivers/infiniband/sw/rxe/rxe_verbs.h index ad5574d8e8ba77..a22822526a62c6 100644 --- a/drivers/infiniband/sw/rxe/rxe_verbs.h +++ b/drivers/infiniband/sw/rxe/rxe_verbs.h @@ -411,7 +411,6 @@ struct rxe_dev { atomic64_t stats_counters[RXE_NUM_OF_COUNTERS]; struct rxe_port port; - struct list_head list; struct crypto_shash *tfm; };