From patchwork Tue Dec 18 12:15:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 10735545 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 70B116C5 for ; Tue, 18 Dec 2018 12:16:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 603BA2A13E for ; Tue, 18 Dec 2018 12:16:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 547F52A146; Tue, 18 Dec 2018 12:16:16 +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 E74F52A13E for ; Tue, 18 Dec 2018 12:16:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726663AbeLRMQP (ORCPT ); Tue, 18 Dec 2018 07:16:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:45652 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726548AbeLRMQP (ORCPT ); Tue, 18 Dec 2018 07:16:15 -0500 Received: from localhost (unknown [193.47.165.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2F3A4217D9; Tue, 18 Dec 2018 12:16:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1545135374; bh=9xcLyseZuQ475Nr46I6rU/LwcA8mrxU/VLb5IqQz3Xw=; h=From:To:Cc:Subject:Date:From; b=sSs1cF9JiQD6KKrgPa7k3l2vDdf4KRYsa97ERh3BlgruPx+Z8J1R9Uage+QzdTxNh 2loyMA3I2uPAFSmVZGZCRENkrSox7qDAPyZM/lyydUB2ow+ZP1Z5njm6SQniuG05Ai iHVyBbU+b8Jci/hV2teQwsVdd7BMK2K038uExqG0= From: Leon Romanovsky To: Doug Ledford , Jason Gunthorpe Cc: Leon Romanovsky , RDMA mailing list , Greg Kroah-Hartman Subject: [PATCH rdma-next] IB/cm: Properly create sysfs layout of RDMA devices with InfiniBand link layer Date: Tue, 18 Dec 2018 14:15:52 +0200 Message-Id: <20181218121552.24829-1-leon@kernel.org> X-Mailer: git-send-email 2.19.2 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: Leon Romanovsky The sysfs layout is created by CM incorrectly presented RDMA devices with InfiniBand link layer. Layout of such devices represents device tree of connections. It means that the following issues are fixed by the this change: * Symlink name - It used device name instead of specific identifier. * Target location - It was supposed to point to PCI-ID/infiniband_cm/ instead of PCI-ID/infiniband/ * Target name - It created extra device file under already existing device folder, e.g. mlx5_0/mlx5_0 Fix it by changing sysfs device CM creation logic. Before the change: [leonro@server ~]$ ls -l /sys/class/infiniband_cm/ lrwxrwxrwx 1 root root 0 Dec 14 10:31 mlx5_0 -> ../../devices/pci0000:00/0000:00:0c.0/infiniband/mlx5_0/mlx5_0 After the change: [leonro@server ~]$ ls -l /sys/class/infiniband_cm/ lrwxrwxrwx 1 root root 0 Dec 14 10:47 cm0 -> ../../devices/pci0000:00/0000:00:0c.0/infiniband_cm/cm0 At the end, we will have same logic and representation as for uverbs, mad and issm sysfs classes. Fixes: 110cf374a809 ("infiniband: make cm_device use a struct device and not a kobject.") Signed-off-by: Leon Romanovsky --- I think that it should be forwarded to stable@ too. --- drivers/infiniband/core/cm.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) -- 2.19.1 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c index edb2cb758be7..e3bee04fb641 100644 --- a/drivers/infiniband/core/cm.c +++ b/drivers/infiniband/core/cm.c @@ -93,6 +93,8 @@ static const char * const ibcm_rej_reason_strs[] = { [IB_CM_REJ_INVALID_ALT_FLOW_LABEL] = "invalid alt flow label", }; +static DEFINE_IDA(cm_ida); + const char *__attribute_const__ ibcm_reject_msg(int reason) { size_t index = reason; @@ -220,6 +222,7 @@ struct cm_device { struct list_head list; struct ib_device *ib_device; struct device *device; + int devnum; u8 ack_delay; int going_down; struct cm_port *port[0]; @@ -4368,13 +4371,12 @@ static void cm_add_one(struct ib_device *ib_device) cm_dev->ib_device = ib_device; cm_dev->ack_delay = ib_device->attrs.local_ca_ack_delay; cm_dev->going_down = 0; - cm_dev->device = device_create(&cm_class, &ib_device->dev, + cm_dev->devnum = ida_alloc(&cm_ida, GFP_KERNEL); + cm_dev->device = device_create(&cm_class, ib_device->dev.parent, MKDEV(0, 0), NULL, - "%s", dev_name(&ib_device->dev)); - if (IS_ERR(cm_dev->device)) { - kfree(cm_dev); - return; - } + "cm%d", cm_dev->devnum); + if (IS_ERR(cm_dev->device)) + goto devreg; set_bit(IB_MGMT_METHOD_SEND, reg_req.method_mask); for (i = 1; i <= ib_device->phys_port_cnt; i++) { @@ -4442,6 +4444,8 @@ static void cm_add_one(struct ib_device *ib_device) } free: device_unregister(cm_dev->device); +devreg: + ida_free(&cm_ida, cm_dev->devnum); kfree(cm_dev); } @@ -4496,6 +4500,7 @@ static void cm_remove_one(struct ib_device *ib_device, void *client_data) } device_unregister(cm_dev->device); + ida_free(&cm_ida, cm_dev->devnum); kfree(cm_dev); }