From patchwork Sat Jan 12 02:37:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 10760881 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 BC6E691E for ; Sat, 12 Jan 2019 02:38:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC2A12A136 for ; Sat, 12 Jan 2019 02:38:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D61D2A13B; Sat, 12 Jan 2019 02:38:14 +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 3CCE82A136 for ; Sat, 12 Jan 2019 02:38:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726491AbfALCiN (ORCPT ); Fri, 11 Jan 2019 21:38:13 -0500 Received: from mail-eopbgr20089.outbound.protection.outlook.com ([40.107.2.89]:38784 "EHLO EUR02-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726227AbfALCiM (ORCPT ); Fri, 11 Jan 2019 21:38:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JGXG5q/nnphTtini9Hs/Wk+jVjrEkmLW+RsXxQdFC3M=; b=VZr0OLnwcEg3fuqTOjXhE9mlIuHvS+An8qaXksHjuO7wnR17Ypfzt0glp4roYpRFXkUaXnjbUG17BCKbJ7n/AsVcfuiG5zty9r/jE9A+m0pJXgz7o+malYVO5Sl9nN/pkLD49TIRabkKvHJoTWUIVIde2KpvIJLXZrtXSr7R2z8= Received: from VI1PR05MB4607.eurprd05.prod.outlook.com (20.176.3.140) by VI1PR05MB5022.eurprd05.prod.outlook.com (20.177.52.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1516.18; Sat, 12 Jan 2019 02:38:00 +0000 Received: from VI1PR05MB4607.eurprd05.prod.outlook.com ([fe80::c87:33e8:75b2:c4c1]) by VI1PR05MB4607.eurprd05.prod.outlook.com ([fe80::c87:33e8:75b2:c4c1%4]) with mapi id 15.20.1516.016; Sat, 12 Jan 2019 02:38:00 +0000 From: Jason Gunthorpe To: "linux-rdma@vger.kernel.org" Subject: [PATCH] RDMA/device: Add ib_device_get_by_name() and use it in rxe Thread-Topic: [PATCH] RDMA/device: Add ib_device_get_by_name() and use it in rxe Thread-Index: AQHUqh/VLYHZEgDRp0iwUhhdRdLM5w== Date: Sat, 12 Jan 2019 02:37:59 +0000 Message-ID: <20190112023752.GA24713@ziepe.ca> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MWHPR1201CA0005.namprd12.prod.outlook.com (2603:10b6:301:4a::15) To VI1PR05MB4607.eurprd05.prod.outlook.com (2603:10a6:802:5f::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=jgg@mellanox.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [174.3.196.123] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;VI1PR05MB5022;6:2WulLDXLfC3PXr06FMcVQ2THsOJb0vWdDoKyFHkozg37NepcrkQaTOHIMN1MjD6i1RqoKFHlrWbUnRaoIwP+dyRfn03uyx3TUeBZSqjCzhDmGpq+PMq8fGPeoGBnXS3vEDmj8uzrpR4xw+1Puu0Lt2smVbJc4qKm9bH7uGQwng6kIogu+caFQRtHOQH52u2mEoMkw0TID2tLfbiUUPsjkyh1WMlFomXQScwrMKqnijEzes+xC4lOTJk7h2VhBk1ctXV2jRlsCu/iB1tKPtJStlkcezGjjnyQukxG6gy2LQ1rxPQPhcGI8HyAw3P+YfG4PTayYqOIOzuE25+FOYM2f1MCPKwmgJZ2rrEGZz7S5XKxHJZ6Uv5r4tgwjI3sNRPKkPzBgpjpY4Rck7Nuu4lZ9KJ+8fw7oqoYEFLoe6lPhAafywkRAf95vwSrvQyNFFTguWcK3bfsJ9DE88Wx/CcIFA==;5:AZtiykrxChmjZX/AaWiGaVv5WnGdQ0kAG133zLyPQXoLOsqWYl5aHv1VJLNbboK2ytapJ8kLfufjCEYbnqmRcfKpAK9hlihRxU9U089c4mg4yDBRSV2KxqLZ0c+3RRg88XaprGNIWFjVIP+fbw9hlKUZ4XNEoLJpDO29HG9PKA/h2xlKMs/wal1K9NNzZANaGiaLEoCKqCgh3AuGmvtoeA==;7:RUPM2NXVp+e7q5pUqvuE7jZJwkWOsEusR/qGSB0tu5ctGaMAzvI2lE4BYUZ7graGFCprWvCjyNqhXwMzOQ7el2Iicr3V/z6fvyqhctz5frQlglqrlE8G0Syr4PqSQxJiblMwxneYwHn+D+X+YkS2tg== x-ms-office365-filtering-correlation-id: 4f79fa1d-9593-4752-a2af-08d67836f762 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600109)(711020)(4618075)(2017052603328)(7153060)(7193020);SRVR:VI1PR05MB5022; x-ms-traffictypediagnostic: VI1PR05MB5022: x-microsoft-antispam-prvs: x-forefront-prvs: 0915875B28 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(376002)(366004)(136003)(396003)(39860400002)(346002)(199004)(189003)(486006)(66066001)(6916009)(305945005)(2906002)(52116002)(33656002)(478600001)(102836004)(316002)(106356001)(25786009)(36756003)(86362001)(6506007)(575784001)(386003)(2351001)(33896004)(71200400001)(71190400001)(26005)(3846002)(186003)(105586002)(6486002)(6512007)(81166006)(97736004)(6116002)(9686003)(53936002)(6436002)(1076003)(5660300001)(99286004)(14454004)(14444005)(5640700003)(68736007)(476003)(81156014)(8936002)(8676002)(7736002)(2501003)(256004);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR05MB5022;H:VI1PR05MB4607.eurprd05.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: bCpcYhDZlpuwhjTxZAxaaKnG4wQkWXoD8TFhJ2QJ/kcZ5IChz4PBLE7QSkSULeCHssOxZGf7mxQdx4OXIxll2Bsnem83gEU51FS9icK1MCYwYGxHwM9PSRZ9Y9ftzf2odMzl/rWAwCELyOA2MBCep98gb4Einym+iea1zhKAlUJOZvt6uRtfJOuEvQdUI1UUOw8cob39ljtuR0J6+SSVunMu1UdhCJVNX2MqjiuuHUUXKndVacynASWLreZR2bF7anTIwMt8m+srwNKx06gYA8Pdn041H5UUN5V2M3n9qMWNMBl/FHyii0FWd1ayvjGAsohubW0VPAYnO4ij0zf6K3geCBiU720zvrifhmqXaYq2GFCKgpx7t/JnB1EdMmOGdg3yiXkfVjmc6hvuXWgKziUGpkDzpvEkROkUYcUrW1U= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-ID: MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4f79fa1d-9593-4752-a2af-08d67836f762 X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Jan 2019 02:37:59.3507 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR05MB5022 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 rxe has an open coded version of this that is not as safe as the core version can be. Signed-off-by: Jason Gunthorpe Reviewed-by: Zhu Yanjun --- drivers/infiniband/core/device.c | 28 +++++++++++++++++++++++++++ drivers/infiniband/sw/rxe/rxe.h | 1 - drivers/infiniband/sw/rxe/rxe_net.c | 17 ---------------- drivers/infiniband/sw/rxe/rxe_sysfs.c | 8 +++++--- include/rdma/ib_verbs.h | 2 ++ 5 files changed, 35 insertions(+), 21 deletions(-) More usage of device_try_get/put() Requires the advise_mr series sent to for-rc diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c index 9b5c72d3c85a88..1311d6e5f28c03 100644 --- a/drivers/infiniband/core/device.c +++ b/drivers/infiniband/core/device.c @@ -181,6 +181,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(&lists_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(&lists_rwsem); + return device; +} +EXPORT_SYMBOL(ib_device_get_by_name); + int ib_device_rename(struct ib_device *ibdev, const char *name) { struct ib_device *device; diff --git a/drivers/infiniband/sw/rxe/rxe.h b/drivers/infiniband/sw/rxe/rxe.h index 5bde2ad964d277..4f8653c5d1ca5e 100644 --- a/drivers/infiniband/sw/rxe/rxe.h +++ b/drivers/infiniband/sw/rxe/rxe.h @@ -106,7 +106,6 @@ static inline void rxe_dev_put(struct rxe_dev *rxe) kref_put(&rxe->ref_cnt, rxe_release); } struct rxe_dev *net_to_rxe(struct net_device *ndev); -struct rxe_dev *get_rxe_by_name(const char *name); void rxe_port_up(struct rxe_dev *rxe); void rxe_port_down(struct rxe_dev *rxe); diff --git a/drivers/infiniband/sw/rxe/rxe_net.c b/drivers/infiniband/sw/rxe/rxe_net.c index 8fd03ae20efc17..6a4f58a8656578 100644 --- a/drivers/infiniband/sw/rxe/rxe_net.c +++ b/drivers/infiniband/sw/rxe/rxe_net.c @@ -65,23 +65,6 @@ struct rxe_dev *net_to_rxe(struct net_device *ndev) return found; } -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) diff --git a/drivers/infiniband/sw/rxe/rxe_sysfs.c b/drivers/infiniband/sw/rxe/rxe_sysfs.c index 95a15892f7e659..66c39049cb2d18 100644 --- a/drivers/infiniband/sw/rxe/rxe_sysfs.c +++ b/drivers/infiniband/sw/rxe/rxe_sysfs.c @@ -100,6 +100,7 @@ static int rxe_param_set_remove(const char *val, const struct kernel_param *kp) { int len; char intf[32]; + struct ib_device *ib_dev; struct rxe_dev *rxe; len = sanitize_arg(val, intf, sizeof(intf)); @@ -114,15 +115,16 @@ 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; } + rxe = container_of(ib_dev, struct rxe_dev, ib_dev); list_del(&rxe->list); rxe_remove(rxe); + ib_device_put(ib_dev); return 0; } diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index 85e9dab17b9b92..d4d6bd6c0ae121 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h @@ -3944,6 +3944,8 @@ static inline bool ib_device_try_get(struct ib_device *dev) } void ib_device_put(struct ib_device *device); +struct ib_device *ib_device_get_by_name(const char *name, + enum rdma_driver_id driver_id); struct net_device *ib_get_net_dev_by_params(struct ib_device *dev, u8 port, u16 pkey, const union ib_gid *gid, const struct sockaddr *addr);