Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp980276ybe; Wed, 4 Sep 2019 10:36:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqyTE67NgwggBDjBHkSWJbBq8kCpT7fU4VCugeaBOscP5EYyv5SWe/S0H6B4/4eOKMm8RxOq X-Received: by 2002:a17:90a:b292:: with SMTP id c18mr6188102pjr.1.1567618572235; Wed, 04 Sep 2019 10:36:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567618572; cv=none; d=google.com; s=arc-20160816; b=ORZ515JdeZ9VUrBhiLQF4YhOfgtHFMWne8R5mrlS3HMkXXEHGccXcieh1OHbjNdNQH omgzU6wWdbE5mRQgiB4Jd18qjqkZp1N3iYjVcEfOWIkHsA6c0wNnB4biBEPy5di34P/B nY9XISX2ClnoxRkiy8z7upehTEFDfrOZjfnTMX/nBYukBrsOjQNZuVoNsDZ0ThO4LN2K gzWjv4Awag2As3/fAodx2OY7ETodXIbcp+m93FxmhUde2LMPQGjosQJ88bwRZJLMnHUu ls0Astf6y05iW9+gJy+17JolT/gN2dFXpWJj4G9plRVzT2ugz0Bln4zqK8789JViqvgc E0OA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=Paye9mPEWBKagY8O8Z32oWyPsdYOQ5aZJd8SGNP6zi0=; b=GYuipJ7a7V7+7d6jqIZvSYNVZsKYjikVhDo0a/0mIPfnODUBOjJIQQBpLC9tneCyjZ UqqmpCJNWQhMUj0Wxcbn5U5ITqtYMJwN4i3Vmq+zoOZ2ecBr6hUR3tqrnh9NTgV07VCe gEXpjW/sB+2aiSAlH/QH9v7gKNTJONjFrNYmf6lyhv95CpjYMGDRfsc8ECDMG5SJNwqX 7DG/pW299safKywm0mk+JReUgFSDmABbC7XyUTzL4WQhBVEs+FXkfbsmwnvH7Xg5QYMM 9a4qsMLvDxIMfojVFRFmdEJ8J/6tIkFLbyafOaA+e+sGVLgCJA5w4pC+aJfzMBCpYkG2 5ITw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k16si17548206pgl.592.2019.09.04.10.35.53; Wed, 04 Sep 2019 10:36:12 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732107AbfIDRdu (ORCPT + 99 others); Wed, 4 Sep 2019 13:33:50 -0400 Received: from mga11.intel.com ([192.55.52.93]:31688 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730099AbfIDRdu (ORCPT ); Wed, 4 Sep 2019 13:33:50 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Sep 2019 10:33:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,467,1559545200"; d="scan'208";a="199078464" Received: from unknown (HELO localhost.lm.intel.com) ([10.232.112.69]) by fmsmga001.fm.intel.com with ESMTP; 04 Sep 2019 10:33:49 -0700 From: Keith Busch To: Christoph Hellwig , linux-nvme@lists.infradead.org, Sagi Grimberg Cc: Logan Gunthorpe , Hannes Reinecke , "Martin K . Petersen" , linux-kernel@vger.kernel.org, Jens Axboe , Keith Busch Subject: [PATCH] nvme: Restore device naming sanity Date: Wed, 4 Sep 2019 11:31:59 -0600 Message-Id: <20190904173159.22921-1-kbusch@kernel.org> X-Mailer: git-send-email 2.13.6 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The namespace names must be unique for the lifetime of the subsystem. This was accomplished by using their parent subsystems' instances which was independent of the controllers connected to that subsystem. The consequence of that naming scheme meant that name prefixes given to namespaces may match a controller from an unrelated subsystem. This has understandbly invited confusion when examining device nodes. Ensure the namespace's subsystem instance never clashes with a controller instance of another subsystem by transferring the instance ownership to parent subsystem from the first controller discovered in that subsystem. Reviewed-by: Logan Gunthorpe Signed-off-by: Keith Busch --- drivers/nvme/host/core.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 14c0bfb55615..8a8279ece5ee 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); @@ -2344,7 +2343,8 @@ 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); + if (subsys->instance >= 0) + ida_simple_remove(&nvme_instance_ida, subsys->instance); kfree(subsys); } @@ -2473,12 +2473,8 @@ 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 = -1; mutex_init(&subsys->lock); kref_init(&subsys->ref); INIT_LIST_HEAD(&subsys->ctrls); @@ -2497,7 +2493,7 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) subsys->dev.class = nvme_subsys_class; subsys->dev.release = nvme_release_subsystem; subsys->dev.groups = nvme_subsys_attrs_groups; - dev_set_name(&subsys->dev, "nvme-subsys%d", subsys->instance); + dev_set_name(&subsys->dev, "nvme-subsys%d", ctrl->instance); device_initialize(&subsys->dev); mutex_lock(&nvme_subsystems_lock); @@ -2528,6 +2524,8 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) goto out_put_subsystem; } + if (!found) + subsys->instance = ctrl->instance; ctrl->subsys = subsys; list_add_tail(&ctrl->subsys_entry, &subsys->ctrls); mutex_unlock(&nvme_subsystems_lock); @@ -3803,7 +3801,9 @@ static void nvme_free_ctrl(struct device *dev) container_of(dev, struct nvme_ctrl, ctrl_device); struct nvme_subsystem *subsys = ctrl->subsys; - ida_simple_remove(&nvme_instance_ida, ctrl->instance); + if (subsys && ctrl->instance != subsys->instance) + ida_simple_remove(&nvme_instance_ida, ctrl->instance); + kfree(ctrl->effects); nvme_mpath_uninit(ctrl); __free_page(ctrl->discard_page); @@ -4085,7 +4085,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.14.5