All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] nvme: avoid "(efault)" from nvme_sysfs_show_subsysnqn()
@ 2021-02-02  0:59 mwilck
  2021-02-02  1:34 ` Chaitanya Kulkarni
  2021-02-02  7:58 ` Christoph Hellwig
  0 siblings, 2 replies; 10+ messages in thread
From: mwilck @ 2021-02-02  0:59 UTC (permalink / raw)
  To: Sagi Grimberg, Christoph Hellwig, Chaitanya Kulkarni
  Cc: Keith Busch, Hannes Reinecke, linux-nvme, Martin Wilck

From: Martin Wilck <mwilck@suse.com>

While a controller is still connecting, ctrl->subsys is NULL and
thus reading the controller's "subsysnqn" sysfs attribute returns
"(efault)". This happens all the time when user space processes
"add" events for NVMe controller devices.

Fix it by returning the nvmf_ctrl_options' subsysnqn attribute
if ctrl->subsys isn't initialized yet.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 drivers/nvme/host/core.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index f320273fc672..8b0fc4a07b31 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3538,8 +3538,14 @@ static ssize_t nvme_sysfs_show_subsysnqn(struct device *dev,
 					 char *buf)
 {
 	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+	char *subsysnqn = "unknown";
 
-	return snprintf(buf, PAGE_SIZE, "%s\n", ctrl->subsys->subnqn);
+	if (ctrl->subsys)
+		subsysnqn = ctrl->subsys->subnqn;
+	else if (ctrl->opts && ctrl->opts->subsysnqn)
+		subsysnqn = ctrl->opts->subsysnqn;
+
+	return snprintf(buf, PAGE_SIZE, "%s\n", subsysnqn);
 }
 static DEVICE_ATTR(subsysnqn, S_IRUGO, nvme_sysfs_show_subsysnqn, NULL);
 
-- 
2.29.2


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

* Re: [PATCH v2] nvme: avoid "(efault)" from nvme_sysfs_show_subsysnqn()
  2021-02-02  0:59 [PATCH v2] nvme: avoid "(efault)" from nvme_sysfs_show_subsysnqn() mwilck
@ 2021-02-02  1:34 ` Chaitanya Kulkarni
  2021-02-02  7:58 ` Christoph Hellwig
  1 sibling, 0 replies; 10+ messages in thread
From: Chaitanya Kulkarni @ 2021-02-02  1:34 UTC (permalink / raw)
  To: mwilck, Sagi Grimberg, Christoph Hellwig
  Cc: Keith Busch, Hannes Reinecke, linux-nvme

On 2/1/21 17:00, mwilck@suse.com wrote:
> From: Martin Wilck <mwilck@suse.com>
>
> While a controller is still connecting, ctrl->subsys is NULL and
> thus reading the controller's "subsysnqn" sysfs attribute returns
> "(efault)". This happens all the time when user space processes
> "add" events for NVMe controller devices.
>
> Fix it by returning the nvmf_ctrl_options' subsysnqn attribute
> if ctrl->subsys isn't initialized yet.
>
> Signed-off-by: Martin Wilck <mwilck@suse.com>
Please add the version history from next time, as it helps others
to review the patch easily than the first-reviewer.

Looks good.

Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

* Re: [PATCH v2] nvme: avoid "(efault)" from nvme_sysfs_show_subsysnqn()
  2021-02-02  0:59 [PATCH v2] nvme: avoid "(efault)" from nvme_sysfs_show_subsysnqn() mwilck
  2021-02-02  1:34 ` Chaitanya Kulkarni
@ 2021-02-02  7:58 ` Christoph Hellwig
  2021-02-03 10:01   ` Sagi Grimberg
  2021-02-03 12:31   ` Martin Wilck
  1 sibling, 2 replies; 10+ messages in thread
From: Christoph Hellwig @ 2021-02-02  7:58 UTC (permalink / raw)
  To: mwilck
  Cc: Sagi Grimberg, Chaitanya Kulkarni, linux-nvme, Hannes Reinecke,
	Keith Busch, Christoph Hellwig

On Tue, Feb 02, 2021 at 01:59:51AM +0100, mwilck@suse.com wrote:
> From: Martin Wilck <mwilck@suse.com>
> 
> While a controller is still connecting, ctrl->subsys is NULL and
> thus reading the controller's "subsysnqn" sysfs attribute returns
> "(efault)". This happens all the time when user space processes
> "add" events for NVMe controller devices.
> 
> Fix it by returning the nvmf_ctrl_options' subsysnqn attribute
> if ctrl->subsys isn't initialized yet.

This is just papering over symptoms.  We should not be sending
events or display sysfs files until the controlle is live.

In other wwords - I think we should remove the cdev_device_add
from nvme_init_ctrl to nvme_start_ctrl (+ any error handling changes
resulting from that).

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

* Re: [PATCH v2] nvme: avoid "(efault)" from nvme_sysfs_show_subsysnqn()
  2021-02-02  7:58 ` Christoph Hellwig
@ 2021-02-03 10:01   ` Sagi Grimberg
  2021-02-03 12:31   ` Martin Wilck
  1 sibling, 0 replies; 10+ messages in thread
From: Sagi Grimberg @ 2021-02-03 10:01 UTC (permalink / raw)
  To: Christoph Hellwig, mwilck
  Cc: Keith Busch, linux-nvme, Chaitanya Kulkarni, Hannes Reinecke


>> From: Martin Wilck <mwilck@suse.com>
>>
>> While a controller is still connecting, ctrl->subsys is NULL and
>> thus reading the controller's "subsysnqn" sysfs attribute returns
>> "(efault)". This happens all the time when user space processes
>> "add" events for NVMe controller devices.
>>
>> Fix it by returning the nvmf_ctrl_options' subsysnqn attribute
>> if ctrl->subsys isn't initialized yet.
> 
> This is just papering over symptoms.  We should not be sending
> events or display sysfs files until the controlle is live.
> 
> In other wwords - I think we should remove the cdev_device_add
> from nvme_init_ctrl to nvme_start_ctrl (+ any error handling changes
> resulting from that).

Maybe move it to nvme_init_identify? nvme_start_ctrl is after I/O queues
were created.

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

* Re: [PATCH v2] nvme: avoid "(efault)" from nvme_sysfs_show_subsysnqn()
  2021-02-02  7:58 ` Christoph Hellwig
  2021-02-03 10:01   ` Sagi Grimberg
@ 2021-02-03 12:31   ` Martin Wilck
  2021-02-03 16:51     ` Christoph Hellwig
  2021-02-03 16:52     ` Keith Busch
  1 sibling, 2 replies; 10+ messages in thread
From: Martin Wilck @ 2021-02-03 12:31 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Keith Busch, linux-nvme, Sagi Grimberg, Chaitanya Kulkarni,
	Hannes Reinecke

On Tue, 2021-02-02 at 08:58 +0100, Christoph Hellwig wrote:
> On Tue, Feb 02, 2021 at 01:59:51AM +0100, mwilck@suse.com wrote:
> > From: Martin Wilck <mwilck@suse.com>
> > 
> > While a controller is still connecting, ctrl->subsys is NULL and
> > thus reading the controller's "subsysnqn" sysfs attribute returns
> > "(efault)". This happens all the time when user space processes
> > "add" events for NVMe controller devices.
> > 
> > Fix it by returning the nvmf_ctrl_options' subsysnqn attribute
> > if ctrl->subsys isn't initialized yet.
> 
> This is just papering over symptoms.  We should not be sending
> events or display sysfs files until the controlle is live.

I don't follow. What's wrong with a "connecting" controller device in
sysfs? 

Controllers can loose connectivity any time. What's the difference
between a controller that is reconnecting after a connection loss and a
freshly created controller that's just not live yet? You wouldn't
delete the former from sysfs, I suppose.

From the user space point of view, it's the same, a controller device
that is not in usable state. I don't see a general problem with that.
Seeing a controller appear in connecting state might actually be useful
for user space.

The subsysnqn attribute is correct for controllers that were once
connected and lost connectivity. My patch was only intended to fix the
"just created and never connected" case, where it is not, nothing more.

Regards
Martin

> 
> In other wwords - I think we should remove the cdev_device_add
> from nvme_init_ctrl to nvme_start_ctrl (+ any error handling changes
> resulting from that).
> 



_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

* Re: [PATCH v2] nvme: avoid "(efault)" from nvme_sysfs_show_subsysnqn()
  2021-02-03 12:31   ` Martin Wilck
@ 2021-02-03 16:51     ` Christoph Hellwig
  2021-02-03 16:52     ` Keith Busch
  1 sibling, 0 replies; 10+ messages in thread
From: Christoph Hellwig @ 2021-02-03 16:51 UTC (permalink / raw)
  To: Martin Wilck
  Cc: Sagi Grimberg, Chaitanya Kulkarni, linux-nvme, Hannes Reinecke,
	Keith Busch, Christoph Hellwig

On Wed, Feb 03, 2021 at 01:31:13PM +0100, Martin Wilck wrote:
> > This is just papering over symptoms.  We should not be sending
> > events or display sysfs files until the controlle is live.
> 
> I don't follow. What's wrong with a "connecting" controller device in
> sysfs? 
> 
> Controllers can loose connectivity any time. What's the difference
> between a controller that is reconnecting after a connection loss and a
> freshly created controller that's just not live yet? You wouldn't
> delete the former from sysfs, I suppose.

What is wrong is that we should only add the device and thus send the
uevent notifcations when the device is fully set up.

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

* Re: [PATCH v2] nvme: avoid "(efault)" from nvme_sysfs_show_subsysnqn()
  2021-02-03 12:31   ` Martin Wilck
  2021-02-03 16:51     ` Christoph Hellwig
@ 2021-02-03 16:52     ` Keith Busch
  2021-02-03 22:19       ` Sagi Grimberg
  1 sibling, 1 reply; 10+ messages in thread
From: Keith Busch @ 2021-02-03 16:52 UTC (permalink / raw)
  To: Martin Wilck
  Cc: Hannes Reinecke, linux-nvme, Christoph Hellwig,
	Chaitanya Kulkarni, Sagi Grimberg

On Wed, Feb 03, 2021 at 01:31:13PM +0100, Martin Wilck wrote:
> On Tue, 2021-02-02 at 08:58 +0100, Christoph Hellwig wrote:
> > On Tue, Feb 02, 2021 at 01:59:51AM +0100, mwilck@suse.com wrote:
> > > From: Martin Wilck <mwilck@suse.com>
> > > 
> > > While a controller is still connecting, ctrl->subsys is NULL and
> > > thus reading the controller's "subsysnqn" sysfs attribute returns
> > > "(efault)". This happens all the time when user space processes
> > > "add" events for NVMe controller devices.
> > > 
> > > Fix it by returning the nvmf_ctrl_options' subsysnqn attribute
> > > if ctrl->subsys isn't initialized yet.
> > 
> > This is just papering over symptoms.  We should not be sending
> > events or display sysfs files until the controlle is live.
> 
> I don't follow. What's wrong with a "connecting" controller device in
> sysfs? 
> 
> Controllers can loose connectivity any time. What's the difference
> between a controller that is reconnecting after a connection loss and a
> freshly created controller that's just not live yet? You wouldn't
> delete the former from sysfs, I suppose.
> 
> From the user space point of view, it's the same, a controller device
> that is not in usable state. I don't see a general problem with that.
> Seeing a controller appear in connecting state might actually be useful
> for user space.
> 
> The subsysnqn attribute is correct for controllers that were once
> connected and lost connectivity. My patch was only intended to fix the
> "just created and never connected" case, where it is not, nothing more.

I think Christoph is suggesting just wait until we have all the
properties the driver exports rather than specifically exporting only
during a 'live' state. Something like this (untested) should do the
trick:

---
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 1a3cdc6b1036..4c0258d7eb91 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3069,6 +3069,9 @@ int nvme_init_identify(struct nvme_ctrl *ctrl)
 		if (ret)
 			goto out_free;
 
+		ret = cdev_device_add(&ctrl->cdev, ctrl->device);
+		if (ret)
+			goto out_free;
 		/*
 		 * Check for quirks.  Quirk can depend on firmware version,
 		 * so, in principle, the set of quirks present can change
@@ -4545,9 +4548,6 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
 	nvme_get_ctrl(ctrl);
 	cdev_init(&ctrl->cdev, &nvme_dev_fops);
 	ctrl->cdev.owner = ops->module;
-	ret = cdev_device_add(&ctrl->cdev, ctrl->device);
-	if (ret)
-		goto out_free_name;
 
 	/*
 	 * Initialize latency tolerance controls.  The sysfs files won't
@@ -4560,9 +4560,6 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
 	nvme_fault_inject_init(&ctrl->fault_inject, dev_name(ctrl->device));
 
 	return 0;
-out_free_name:
-	nvme_put_ctrl(ctrl);
-	kfree_const(ctrl->device->kobj.name);
 out_release_instance:
 	ida_simple_remove(&nvme_instance_ida, ctrl->instance);
 out:
--

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

* Re: [PATCH v2] nvme: avoid "(efault)" from nvme_sysfs_show_subsysnqn()
  2021-02-03 16:52     ` Keith Busch
@ 2021-02-03 22:19       ` Sagi Grimberg
  2021-02-04  2:42         ` Keith Busch
  0 siblings, 1 reply; 10+ messages in thread
From: Sagi Grimberg @ 2021-02-03 22:19 UTC (permalink / raw)
  To: Keith Busch, Martin Wilck
  Cc: Chaitanya Kulkarni, Hannes Reinecke, linux-nvme, Christoph Hellwig



On 2/3/21 8:52 AM, Keith Busch wrote:
> On Wed, Feb 03, 2021 at 01:31:13PM +0100, Martin Wilck wrote:
>> On Tue, 2021-02-02 at 08:58 +0100, Christoph Hellwig wrote:
>>> On Tue, Feb 02, 2021 at 01:59:51AM +0100, mwilck@suse.com wrote:
>>>> From: Martin Wilck <mwilck@suse.com>
>>>>
>>>> While a controller is still connecting, ctrl->subsys is NULL and
>>>> thus reading the controller's "subsysnqn" sysfs attribute returns
>>>> "(efault)". This happens all the time when user space processes
>>>> "add" events for NVMe controller devices.
>>>>
>>>> Fix it by returning the nvmf_ctrl_options' subsysnqn attribute
>>>> if ctrl->subsys isn't initialized yet.
>>>
>>> This is just papering over symptoms.  We should not be sending
>>> events or display sysfs files until the controlle is live.
>>
>> I don't follow. What's wrong with a "connecting" controller device in
>> sysfs?
>>
>> Controllers can loose connectivity any time. What's the difference
>> between a controller that is reconnecting after a connection loss and a
>> freshly created controller that's just not live yet? You wouldn't
>> delete the former from sysfs, I suppose.
>>
>>  From the user space point of view, it's the same, a controller device
>> that is not in usable state. I don't see a general problem with that.
>> Seeing a controller appear in connecting state might actually be useful
>> for user space.
>>
>> The subsysnqn attribute is correct for controllers that were once
>> connected and lost connectivity. My patch was only intended to fix the
>> "just created and never connected" case, where it is not, nothing more.
> 
> I think Christoph is suggesting just wait until we have all the
> properties the driver exports rather than specifically exporting only
> during a 'live' state. Something like this (untested) should do the
> trick:
> 
> ---
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 1a3cdc6b1036..4c0258d7eb91 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -3069,6 +3069,9 @@ int nvme_init_identify(struct nvme_ctrl *ctrl)
>   		if (ret)
>   			goto out_free;
>   
> +		ret = cdev_device_add(&ctrl->cdev, ctrl->device);
> +		if (ret)
> +			goto out_free;

This happens on every reset, we should probably just do this once?

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

* Re: [PATCH v2] nvme: avoid "(efault)" from nvme_sysfs_show_subsysnqn()
  2021-02-03 22:19       ` Sagi Grimberg
@ 2021-02-04  2:42         ` Keith Busch
  2021-02-04  7:44           ` Sagi Grimberg
  0 siblings, 1 reply; 10+ messages in thread
From: Keith Busch @ 2021-02-04  2:42 UTC (permalink / raw)
  To: Sagi Grimberg
  Cc: Chaitanya Kulkarni, Christoph Hellwig, Martin Wilck, linux-nvme,
	Hannes Reinecke

On Wed, Feb 03, 2021 at 02:19:44PM -0800, Sagi Grimberg wrote:
> 
> 
> On 2/3/21 8:52 AM, Keith Busch wrote:
> > On Wed, Feb 03, 2021 at 01:31:13PM +0100, Martin Wilck wrote:
> > > On Tue, 2021-02-02 at 08:58 +0100, Christoph Hellwig wrote:
> > > > On Tue, Feb 02, 2021 at 01:59:51AM +0100, mwilck@suse.com wrote:
> > > > > From: Martin Wilck <mwilck@suse.com>
> > > > > 
> > > > > While a controller is still connecting, ctrl->subsys is NULL and
> > > > > thus reading the controller's "subsysnqn" sysfs attribute returns
> > > > > "(efault)". This happens all the time when user space processes
> > > > > "add" events for NVMe controller devices.
> > > > > 
> > > > > Fix it by returning the nvmf_ctrl_options' subsysnqn attribute
> > > > > if ctrl->subsys isn't initialized yet.
> > > > 
> > > > This is just papering over symptoms.  We should not be sending
> > > > events or display sysfs files until the controlle is live.
> > > 
> > > I don't follow. What's wrong with a "connecting" controller device in
> > > sysfs?
> > > 
> > > Controllers can loose connectivity any time. What's the difference
> > > between a controller that is reconnecting after a connection loss and a
> > > freshly created controller that's just not live yet? You wouldn't
> > > delete the former from sysfs, I suppose.
> > > 
> > >  From the user space point of view, it's the same, a controller device
> > > that is not in usable state. I don't see a general problem with that.
> > > Seeing a controller appear in connecting state might actually be useful
> > > for user space.
> > > 
> > > The subsysnqn attribute is correct for controllers that were once
> > > connected and lost connectivity. My patch was only intended to fix the
> > > "just created and never connected" case, where it is not, nothing more.
> > 
> > I think Christoph is suggesting just wait until we have all the
> > properties the driver exports rather than specifically exporting only
> > during a 'live' state. Something like this (untested) should do the
> > trick:
> > 
> > ---
> > diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> > index 1a3cdc6b1036..4c0258d7eb91 100644
> > --- a/drivers/nvme/host/core.c
> > +++ b/drivers/nvme/host/core.c
> > @@ -3069,6 +3069,9 @@ int nvme_init_identify(struct nvme_ctrl *ctrl)
> >   		if (ret)
> >   			goto out_free;
> > +		ret = cdev_device_add(&ctrl->cdev, ctrl->device);
> > +		if (ret)
> > +			goto out_free;
> 
> This happens on every reset, we should probably just do this once?

Right, and while the function is invoked on each reset, the above code
sequence happens only once. You can't immediately tell from looking at
the diff, but it's in the 'if (!ctrl->identified)' code block.

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

* Re: [PATCH v2] nvme: avoid "(efault)" from nvme_sysfs_show_subsysnqn()
  2021-02-04  2:42         ` Keith Busch
@ 2021-02-04  7:44           ` Sagi Grimberg
  0 siblings, 0 replies; 10+ messages in thread
From: Sagi Grimberg @ 2021-02-04  7:44 UTC (permalink / raw)
  To: Keith Busch
  Cc: Chaitanya Kulkarni, Christoph Hellwig, Martin Wilck, linux-nvme,
	Hannes Reinecke


>>> I think Christoph is suggesting just wait until we have all the
>>> properties the driver exports rather than specifically exporting only
>>> during a 'live' state. Something like this (untested) should do the
>>> trick:
>>>
>>> ---
>>> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
>>> index 1a3cdc6b1036..4c0258d7eb91 100644
>>> --- a/drivers/nvme/host/core.c
>>> +++ b/drivers/nvme/host/core.c
>>> @@ -3069,6 +3069,9 @@ int nvme_init_identify(struct nvme_ctrl *ctrl)
>>>    		if (ret)
>>>    			goto out_free;
>>> +		ret = cdev_device_add(&ctrl->cdev, ctrl->device);
>>> +		if (ret)
>>> +			goto out_free;
>>
>> This happens on every reset, we should probably just do this once?
> 
> Right, and while the function is invoked on each reset, the above code
> sequence happens only once. You can't immediately tell from looking at
> the diff, but it's in the 'if (!ctrl->identified)' code block.

Yea, you're right...

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

end of thread, other threads:[~2021-02-04  7:44 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-02  0:59 [PATCH v2] nvme: avoid "(efault)" from nvme_sysfs_show_subsysnqn() mwilck
2021-02-02  1:34 ` Chaitanya Kulkarni
2021-02-02  7:58 ` Christoph Hellwig
2021-02-03 10:01   ` Sagi Grimberg
2021-02-03 12:31   ` Martin Wilck
2021-02-03 16:51     ` Christoph Hellwig
2021-02-03 16:52     ` Keith Busch
2021-02-03 22:19       ` Sagi Grimberg
2021-02-04  2:42         ` Keith Busch
2021-02-04  7:44           ` Sagi Grimberg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.