stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nvme: Fix a race condition related to creation of /dev/nvme0n<x>
@ 2018-08-11  0:00 Bart Van Assche
  2018-08-11  7:18 ` Greg KH
  2018-08-17 21:55 ` Sagi Grimberg
  0 siblings, 2 replies; 3+ messages in thread
From: Bart Van Assche @ 2018-08-11  0:00 UTC (permalink / raw)
  To: Keith Busch
  Cc: linux-nvme, Christoph Hellwig, Bart Van Assche, Sagi Grimberg,
	Matias Bjorling, stable

For the udev rules that create symbolic links under /dev it is
essential that all sysfs attributes are registered before an object
becomes visible. This patch avoids that udevd fails to create the
/dev/disk/by-id/nvme-uuid.* symbolic link.

Fixes: 2b9b6e86bca7 ("NVMe: Export namespace attributes to sysfs")
Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Keith Busch <keith.busch@intel.com>
Cc: Sagi Grimberg <sagi@grimberg.me>
Cc: Matias Bjorling <mb@lightnvm.io>
Cc: <stable@vger.kernel.org>
---
 drivers/nvme/host/core.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index dd8ec1dd9219..f4b880c8abe6 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2734,6 +2734,11 @@ const struct attribute_group nvme_ns_id_attr_group = {
 	.is_visible	= nvme_ns_id_attrs_are_visible,
 };
 
+static const struct attribute_group *nvme_attr_groups[] = {
+	&nvme_ns_id_attr_group,
+	NULL
+};
+
 #define nvme_show_str_function(field)						\
 static ssize_t  field##_show(struct device *dev,				\
 			    struct device_attribute *attr, char *buf)		\
@@ -3099,11 +3104,13 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
 
 	nvme_get_ctrl(ctrl);
 
+	WARN_ON_ONCE(disk_to_dev(ns->disk)->groups);
+	disk_to_dev(ns->disk)->groups = nvme_attr_groups;
 	device_add_disk(ctrl->device, ns->disk);
-	if (sysfs_create_group(&disk_to_dev(ns->disk)->kobj,
-					&nvme_ns_id_attr_group))
-		pr_warn("%s: failed to create sysfs group for identification\n",
-			ns->disk->disk_name);
+	/*
+	 * To do: remove nvme_nvm_register_sysfs() and add the nvm attribute
+	 * groups to nvme_attr_groups.
+	 */
 	if (ns->ndev && nvme_nvm_register_sysfs(ns))
 		pr_warn("%s: failed to register lightnvm sysfs group for identification\n",
 			ns->disk->disk_name);
@@ -3132,8 +3139,6 @@ static void nvme_ns_remove(struct nvme_ns *ns)
 
 	nvme_fault_inject_fini(ns);
 	if (ns->disk && ns->disk->flags & GENHD_FL_UP) {
-		sysfs_remove_group(&disk_to_dev(ns->disk)->kobj,
-					&nvme_ns_id_attr_group);
 		if (ns->ndev)
 			nvme_nvm_unregister_sysfs(ns);
 		del_gendisk(ns->disk);
-- 
2.18.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] nvme: Fix a race condition related to creation of /dev/nvme0n<x>
  2018-08-11  0:00 [PATCH] nvme: Fix a race condition related to creation of /dev/nvme0n<x> Bart Van Assche
@ 2018-08-11  7:18 ` Greg KH
  2018-08-17 21:55 ` Sagi Grimberg
  1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2018-08-11  7:18 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Keith Busch, linux-nvme, Christoph Hellwig, Sagi Grimberg,
	Matias Bjorling, stable

On Fri, Aug 10, 2018 at 05:00:22PM -0700, Bart Van Assche wrote:
> For the udev rules that create symbolic links under /dev it is
> essential that all sysfs attributes are registered before an object
> becomes visible. This patch avoids that udevd fails to create the
> /dev/disk/by-id/nvme-uuid.* symbolic link.

It's nice to see this finally get fixed up :)



> 
> Fixes: 2b9b6e86bca7 ("NVMe: Export namespace attributes to sysfs")
> Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
> Cc: Keith Busch <keith.busch@intel.com>
> Cc: Sagi Grimberg <sagi@grimberg.me>
> Cc: Matias Bjorling <mb@lightnvm.io>
> Cc: <stable@vger.kernel.org>
> ---
>  drivers/nvme/host/core.c | 17 +++++++++++------
>  1 file changed, 11 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index dd8ec1dd9219..f4b880c8abe6 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -2734,6 +2734,11 @@ const struct attribute_group nvme_ns_id_attr_group = {
>  	.is_visible	= nvme_ns_id_attrs_are_visible,
>  };
>  
> +static const struct attribute_group *nvme_attr_groups[] = {
> +	&nvme_ns_id_attr_group,
> +	NULL
> +};
> +
>  #define nvme_show_str_function(field)						\
>  static ssize_t  field##_show(struct device *dev,				\
>  			    struct device_attribute *attr, char *buf)		\
> @@ -3099,11 +3104,13 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
>  
>  	nvme_get_ctrl(ctrl);
>  
> +	WARN_ON_ONCE(disk_to_dev(ns->disk)->groups);

Why?  Who is going to care or be able to do anything about this if it
triggers?

> +	disk_to_dev(ns->disk)->groups = nvme_attr_groups;
>  	device_add_disk(ctrl->device, ns->disk);
> -	if (sysfs_create_group(&disk_to_dev(ns->disk)->kobj,
> -					&nvme_ns_id_attr_group))
> -		pr_warn("%s: failed to create sysfs group for identification\n",
> -			ns->disk->disk_name);
> +	/*
> +	 * To do: remove nvme_nvm_register_sysfs() and add the nvm attribute
> +	 * groups to nvme_attr_groups.
> +	 */

Why not do that now?  And normally it is "TODO" not "To do" to make it
easier to search for.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] nvme: Fix a race condition related to creation of /dev/nvme0n<x>
  2018-08-11  0:00 [PATCH] nvme: Fix a race condition related to creation of /dev/nvme0n<x> Bart Van Assche
  2018-08-11  7:18 ` Greg KH
@ 2018-08-17 21:55 ` Sagi Grimberg
  1 sibling, 0 replies; 3+ messages in thread
From: Sagi Grimberg @ 2018-08-17 21:55 UTC (permalink / raw)
  To: Bart Van Assche, Keith Busch
  Cc: linux-nvme, Christoph Hellwig, Matias Bjorling, stable

Reviewed-by: Sagi Grimberg <sagi@grimberg.me>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-08-18  1:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-11  0:00 [PATCH] nvme: Fix a race condition related to creation of /dev/nvme0n<x> Bart Van Assche
2018-08-11  7:18 ` Greg KH
2018-08-17 21:55 ` Sagi Grimberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).