Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1279837ybe; Thu, 5 Sep 2019 13:03:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqw9H/3rfBC1VTofOZE/Go5YE9kr1qzRWSBUmM3pQRsXcoHs/I4BSpg5uhH/CTVH1jshE92y X-Received: by 2002:a65:5c4b:: with SMTP id v11mr4884260pgr.62.1567713787117; Thu, 05 Sep 2019 13:03:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567713787; cv=none; d=google.com; s=arc-20160816; b=b5adqSC8tIbcIdffmQRVWxjGASRT+UJfuD6MQqqLGOyhD+Hyqx6uQwyppBRyHpsy12 K6gMbb5uAvdoYgsni5ttIi/uAO1crEAd4e6yVXsxBtR0sxHvVk8pCduEi1JZgH/ZSGGf 1D/sHyLGgCx8ESotXWT5DJsToXFslUnXOhhkuawEPpcFzIQzM9Vzd2j36Mabh3n87i9B 1LCoEal/o8HJiOmpRJ8Q5SF2A6Hv0bHmmFziErgOYy5PsOFYDiNuAzHTpSDToy3JDBNe m71T3/8HrsD2A5fluokzEW4EJQ/en4lkT1nA+Pmt0C0GNlIPBPrfzuY9IZ8B+sdqFlAS 6a9w== 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=gyq63RpK5RJ1sZ8S4QaUxe9ZYbtgryJFYFLJecHyG30=; b=u9XwDFQryyQ111oXLoU9IXgSkmNzgqDg7Ef5Tr1pvluFY+QkUJ+9c+QJxbybVMfjQ5 zPf5uW+ZJ+ibMkDcI1EpSVz1LBAeujXzfOOBAueB2+3/Nbr3iogYJi0TwjzyBN1pkSIc Zamjuq7tQ5P5k6A0cqJI3zzDcwvHyQN+ePB+hceXKGcGLra3xMR10D3mYm9LI20GldqS P9O7dmfkkXz+7LaWc4LO30o4yPcXHKMNogUKyRpL05lGxz+PKBYMXGM3gO06mzPzIuGJ bvaHLbJ+2KcCMDW1wx2z0rekqd9PPAUCmFjYCNJu1y3LxFwtk2VKwGmrg5Si6XsTmcCf iM4g== 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 g26si3578077pfq.77.2019.09.05.13.02.51; Thu, 05 Sep 2019 13:03:07 -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 S2388943AbfIEQfe (ORCPT + 99 others); Thu, 5 Sep 2019 12:35:34 -0400 Received: from mga01.intel.com ([192.55.52.88]:3509 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725921AbfIEQfe (ORCPT ); Thu, 5 Sep 2019 12:35:34 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Sep 2019 09:35:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,470,1559545200"; d="scan'208";a="182875587" Received: from unknown (HELO localhost.lm.intel.com) ([10.232.112.69]) by fmsmga008.fm.intel.com with ESMTP; 05 Sep 2019 09:35:33 -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: [PATCHv2] nvme: Assign subsy instance from first ctrl Date: Thu, 5 Sep 2019 10:33:54 -0600 Message-Id: <20190905163354.25139-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 disk names must be unique for the lifetime of the subsystem. This was accomplished by using their parent subsystems' instances which were allocated independently from the controllers connected to that subsystem. This allowed name prefixes assigned to namespaces to match a controller from an unrelated subsystem, and has created confusion among users examining device nodes. Ensure a namespace's subsystem instance never clashes with a controller instance of another subsystem by transferring the instance ownership to the parent subsystem from the first controller discovered in that subsystem. Reviewed-by: Logan Gunthorpe Signed-off-by: Keith Busch --- v1 -> v2: Changelog: reduce sensationalism, fix spelling 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