Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp944998ybe; Wed, 4 Sep 2019 10:03:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqyYobVODlbkMmhaaRoaQEGP7yPcTu4FbFuDJ9wH9RRq/Wdzpj2i4BdVVWEjUko6mw823+jz X-Received: by 2002:a62:6489:: with SMTP id y131mr46321986pfb.124.1567616596083; Wed, 04 Sep 2019 10:03:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567616596; cv=none; d=google.com; s=arc-20160816; b=rt16jbYm+reB1/ldQwIfaD7gO2IIOR0Z3FewBCskHZe/e2MBO12qtsV7S4R6F5wQwH dGXr9xDvPNdbNTmMZDoha7cLf9YQ2gzb0jcN4lt77m4onO9Tb6AfAuV/YI3cj6QI3y/l 5mnzZ5BTkUir5Wrg9nZChE8j5MgE5bB4wDpD5X88U613+pi3TSZiZoN/XatZn68n+3vZ I53V1RbameEponGM0FTfH7iizxWpttRLk++XT639yhsjbPJKbxlYmimWxlzkNJ0oj2lB mlWK7js2o+v+9ae47fIdsYzpNQN50ZH70XioX6+2eGbzzP5KDyT90SPACyB/y6Fqatc2 IXGw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to; bh=qx/h4JxOUDFyYvMvCyFx9tRyjA9pRrRa3MXlfPYj35o=; b=ndlywpQntvppnbA0KyTDVY/0IVtgnPCvYTpBC1RhFWZ3hn6N/tRSkHlpWbo2MTxvTA 1lZC19zUcdc5/0u9l7uBtU6cfBhKyiCUqAmG1iKOhYbHmsXPge/2fs1QUaM5gn17D6cz OZ8FT9AbLrGMGcicu5dtvhMtOd858iCG6dbSVetkt2Weo/4z1LifEFX4ncmpqjY2VzwA B5kacxbTJPSdCMdo9ftLntFEOCd3TaxbUepeHSdZUn7qvDKS9dcgKdCADtnWG0n8nKTm MMVOafhTT2w4px+Y8jOUYR5LFBNxKJHpPDr7z9JnfYxl0DzQF/COY3DN7xcC6Mz45Umn ybmw== 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 u6si17824307plr.69.2019.09.04.10.02.52; Wed, 04 Sep 2019 10:03:16 -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 S1732467AbfIDRBd (ORCPT + 99 others); Wed, 4 Sep 2019 13:01:33 -0400 Received: from ale.deltatee.com ([207.54.116.67]:58466 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731580AbfIDRBd (ORCPT ); Wed, 4 Sep 2019 13:01:33 -0400 Received: from s0106ac1f6bb1ecac.cg.shawcable.net ([70.73.163.230] helo=[192.168.11.155]) by ale.deltatee.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1i5Yes-0007q5-5s; Wed, 04 Sep 2019 11:01:27 -0600 To: Keith Busch Cc: Christoph Hellwig , Jens Axboe , Hannes Reinecke , Sagi Grimberg , "Martin K . Petersen" , linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, Keith Busch References: <20190831000139.7662-1-logang@deltatee.com> <20190831152910.GA29439@localhost.localdomain> <33af4d94-9f6d-9baa-01fa-0f75ccee263e@deltatee.com> <20190903164620.GA20847@localhost.localdomain> <20190904060558.GA10849@lst.de> <20190904144426.GB21302@localhost.localdomain> <20190904154215.GA20422@lst.de> <20190904155445.GD21302@localhost.localdomain> <20190904163557.GF21302@localhost.localdomain> From: Logan Gunthorpe Message-ID: Date: Wed, 4 Sep 2019 11:01:22 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190904163557.GF21302@localhost.localdomain> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 70.73.163.230 X-SA-Exim-Rcpt-To: keith.busch@intel.com, linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, martin.petersen@oracle.com, sagi@grimberg.me, hare@suse.com, axboe@fb.com, hch@lst.de, kbusch@kernel.org X-SA-Exim-Mail-From: logang@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.7 required=5.0 tests=ALL_TRUSTED,BAYES_00, GREYLIST_ISWHITE,MYRULES_FREE autolearn=ham autolearn_force=no version=3.4.2 Subject: Re: [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 On 2019-09-04 10:35 a.m., Keith Busch wrote: > On Wed, Sep 04, 2019 at 10:07:12AM -0600, Logan Gunthorpe wrote: >> Yes, I agree, we can't solve the mismatch problem in the general case: >> with sequences of hot plug events there will always be a case that >> mismatches. I just think we can do better in the simple common default case. > > This may be something where udev can help us. I might be able to find > some time to look at that, but not today. > >>> Can we just ensure there is never a matching controller then? This >>> patch will accomplish that and simpler than wrapping the instance in a >>> refcount'ed object: >>> >>> http://lists.infradead.org/pipermail/linux-nvme/2019-May/024142.html >> >> I don't really like that idea. It reduces the confusion caused by >> mismatching numbers, but causes the controller to never match the >> namespace, which is also confusing but in a different way. >> >> I like the nvme_instance idea. It's not going to be perfect but it has >> some nice properties: the subsystem will try to match the controller's >> instance whenever possible, but in cases where it doesn't, the instance >> number of the subsystem will never be the same as an existing controller. >> >> I'll see if I can work up a quick patch set and see what people think. > > How about this: we have the subsys copy the controller's instance, > and the nvme_free_ctrl() doesn't release it if its subsys matches? Oh, yes that's simpler than the struct/kref method and looks like it will accomplish the same thing. I did some brief testing with it and it seems to work for me (though I don't have any subsystems with multiple controllers). If you want to make a patch out of it you can add my Reviewed-by: Logan Gunthorpe Thanks! Logan > --- > 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); > -- >