Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1364532ybl; Fri, 30 Aug 2019 17:03:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqzhmSdaRmyv96NvVQmCCNWjdKeGl91e5P8evlx6JlEx1RXpiZixn3GIa/dUhAkmkSZ1G+HQ X-Received: by 2002:a17:902:524:: with SMTP id 33mr18544665plf.27.1567209800573; Fri, 30 Aug 2019 17:03:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567209800; cv=none; d=google.com; s=arc-20160816; b=BYj1TXKD7nA3ev7vUWXX5U5Mb8NCsjqn8sgOkJY4VYdDsocXmz/uP3BQGxJWwwvAoI Bo9Cd/YVTwjGdozPGSXmi6fs5DH4VJPwj37nOByd/hn2TyFsdD/rUZT9nNGMm7V3A7fa oJD0FMx8nUQpyuCQYYCTS3w7x2x6HUzBmj+SGpi8GbiRJS7+oPrUBNz/Q519UQzrJfUw MGTzQndZi4/5pQSr0H047RFYffU1S9pNABbTSgWqdnZ5yBjpLttecYB0b4Ik1tW0WKc1 +Xz+S/xXqboSSjiEDACYbq34neL775REA+d+i67lYG4DmEmov9VWCJxEEd25+CgberOB 9SDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:content-transfer-encoding :mime-version:message-id:date:cc:to:from; bh=UkDpoijmY0KXleuV0hW/D8yQRZrIZYz0y/ejo5suNLc=; b=GMNx0H7OEmBESuDBwEujYDp8VkzYIlTHZJ1K1NuTGyzHRJywvv66g6BpORAJJlrkdU 4Vu0QXv3miIUNiUvdaPv9gRi78C6RBzdvZdIthVB1aU9RUk8jQEp2E0Vf64NTo8RsJg9 /1JoRrG66CSY/WQw+dmDlO/uocquHXT1Zu7vC7FJVPIjz4UXZi8/tTPPl5/qO61P8gRP 8Ln52umpJlYk/hCSuz++h+30AnLdfX4zeu9pstC+2Jzl3iVm1/jt6h8IXZndEgDFc3GW LifJMZmYttpygpft1PpxcKcjV5QylLdCMy4STB2bzESDJnwSFMp2Nyd+wbN3WiDT/r3A gn0g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u9si5473258pgr.196.2019.08.30.17.03.03; Fri, 30 Aug 2019 17:03:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728275AbfHaACJ (ORCPT + 99 others); Fri, 30 Aug 2019 20:02:09 -0400 Received: from ale.deltatee.com ([207.54.116.67]:34626 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727708AbfHaACJ (ORCPT ); Fri, 30 Aug 2019 20:02:09 -0400 Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1i3qqE-0003Cm-6L; Fri, 30 Aug 2019 18:02:07 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.92) (envelope-from ) id 1i3qqC-00020M-63; Fri, 30 Aug 2019 18:02:04 -0600 From: Logan Gunthorpe To: linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, Christoph Hellwig Cc: Sagi Grimberg , Jens Axboe , Keith Busch , Hannes Reinecke , "Martin K . Petersen" , Logan Gunthorpe Date: Fri, 30 Aug 2019 18:01:39 -0600 Message-Id: <20190831000139.7662-1-logang@deltatee.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, hch@lst.de, sagi@grimberg.me, axboe@fb.com, kbusch@kernel.org, hare@suse.com, martin.petersen@oracle.com, logang@deltatee.com X-SA-Exim-Mail-From: gunthorp@deltatee.com X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on ale.deltatee.com X-Spam-Level: X-Spam-Status: No, score=-8.5 required=5.0 tests=ALL_TRUSTED,BAYES_00, GREYLIST_ISWHITE,MYRULES_FREE,MYRULES_NO_TEXT autolearn=ham autolearn_force=no version=3.4.2 Subject: [PATCH] nvme-core: Fix subsystem instance mismatches X-SA-Exim-Version: 4.2.1 (built Tue, 02 Aug 2016 21:08:31 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With multipath enabled (which is now default in many distros), nvme controllers and their respective namespaces can be numbered differently. For example: nvme0n1 might actually belong to controller nvme1, which is super confusing (and may have broken any scripts that rely on the numbering relation). To make matters worse, the mismatches can sometimes change from boot to boot so anyone dealing with the nvme control device has to inspect sysfs every boot to ensure they get the right one. The reason for this is that the X in nvmeXn1 is the subsystem's instance number (when multipath is enabled) which is distinct from the controller's instance and the subsystem instance is assigned from a separate IDA after the controller gets identified and this can race a bit when multiple controllers are being setup. To fix this, assign the subsystem's instance based on the instance number of the controller's instance that first created it. There should always be fewer subsystems than controllers so the should not be a need to create extra subsystems that overlap existing controllers. Signed-off-by: Logan Gunthorpe --- drivers/nvme/host/core.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index d3d6b7bd6903..ca201b71ab49 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -81,7 +81,6 @@ EXPORT_SYMBOL_GPL(nvme_reset_wq); struct workqueue_struct *nvme_delete_wq; EXPORT_SYMBOL_GPL(nvme_delete_wq); -static DEFINE_IDA(nvme_subsystems_ida); static LIST_HEAD(nvme_subsystems); static DEFINE_MUTEX(nvme_subsystems_lock); @@ -2332,7 +2331,6 @@ static void nvme_release_subsystem(struct device *dev) struct nvme_subsystem *subsys = container_of(dev, struct nvme_subsystem, dev); - ida_simple_remove(&nvme_subsystems_ida, subsys->instance); kfree(subsys); } @@ -2461,12 +2459,7 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) subsys = kzalloc(sizeof(*subsys), GFP_KERNEL); if (!subsys) return -ENOMEM; - ret = ida_simple_get(&nvme_subsystems_ida, 0, 0, GFP_KERNEL); - if (ret < 0) { - kfree(subsys); - return ret; - } - subsys->instance = ret; + subsys->instance = ctrl->instance; mutex_init(&subsys->lock); kref_init(&subsys->ref); INIT_LIST_HEAD(&subsys->ctrls); @@ -4074,7 +4067,6 @@ static int __init nvme_core_init(void) static void __exit nvme_core_exit(void) { - ida_destroy(&nvme_subsystems_ida); class_destroy(nvme_subsys_class); class_destroy(nvme_class); unregister_chrdev_region(nvme_chr_devt, NVME_MINORS); -- 2.20.1