All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvme: ensure reset state check ordering
@ 2023-10-27 18:07 Keith Busch
  2023-10-30 13:27 ` Christoph Hellwig
  0 siblings, 1 reply; 5+ messages in thread
From: Keith Busch @ 2023-10-27 18:07 UTC (permalink / raw)
  To: linux-nvme, hch; +Cc: sagi, Keith Busch, Minh Hoang

From: Keith Busch <kbusch@kernel.org>

A different CPU may be setting the ctrl->state value while flushing the
reset work, so ensure proper barriers to prevent reading a stale state.
Reading the wrong state can report unexpected ENETRESET errors when
everything was successful.

Fixes: 8000d1fdb07e36 ("nvme-rdma: fix sysfs invoked reset_ctrl error flow")
Reported-by: Minh Hoang <mh2022@meta.com>
Signed-off-by: Keith Busch <kbusch@kernel.org>
---
 drivers/nvme/host/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 62612f87aafa2..9ec7ce8cc802e 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -201,7 +201,7 @@ int nvme_reset_ctrl_sync(struct nvme_ctrl *ctrl)
 	ret = nvme_reset_ctrl(ctrl);
 	if (!ret) {
 		flush_work(&ctrl->reset_work);
-		if (ctrl->state != NVME_CTRL_LIVE)
+		if (smp_load_acquire(&ctrl->state) != NVME_CTRL_LIVE)
 			ret = -ENETRESET;
 	}
 
-- 
2.34.1



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

* Re: [PATCH] nvme: ensure reset state check ordering
  2023-10-27 18:07 [PATCH] nvme: ensure reset state check ordering Keith Busch
@ 2023-10-30 13:27 ` Christoph Hellwig
  2023-11-20 13:53   ` Sagi Grimberg
  0 siblings, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2023-10-30 13:27 UTC (permalink / raw)
  To: Keith Busch; +Cc: linux-nvme, hch, sagi, Keith Busch, Minh Hoang

On Fri, Oct 27, 2023 at 11:07:52AM -0700, Keith Busch wrote:
> From: Keith Busch <kbusch@kernel.org>
> 
> A different CPU may be setting the ctrl->state value while flushing the
> reset work, so ensure proper barriers to prevent reading a stale state.
> Reading the wrong state can report unexpected ENETRESET errors when
> everything was successful.

smp_load_acquire needs to be paired with a smp_store_release.

We should either always hold the lock or use WRITE_ONCE/READ_ONCE



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

* Re: [PATCH] nvme: ensure reset state check ordering
  2023-10-30 13:27 ` Christoph Hellwig
@ 2023-11-20 13:53   ` Sagi Grimberg
  2023-11-20 14:26     ` Christoph Hellwig
  0 siblings, 1 reply; 5+ messages in thread
From: Sagi Grimberg @ 2023-11-20 13:53 UTC (permalink / raw)
  To: Christoph Hellwig, Keith Busch; +Cc: linux-nvme, Keith Busch, Minh Hoang


>> From: Keith Busch <kbusch@kernel.org>
>>
>> A different CPU may be setting the ctrl->state value while flushing the
>> reset work, so ensure proper barriers to prevent reading a stale state.
>> Reading the wrong state can report unexpected ENETRESET errors when
>> everything was successful.
> 
> smp_load_acquire needs to be paired with a smp_store_release.
> 
> We should either always hold the lock or use WRITE_ONCE/READ_ONCE

which lock?


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

* Re: [PATCH] nvme: ensure reset state check ordering
  2023-11-20 13:53   ` Sagi Grimberg
@ 2023-11-20 14:26     ` Christoph Hellwig
  2023-11-20 14:36       ` Sagi Grimberg
  0 siblings, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2023-11-20 14:26 UTC (permalink / raw)
  To: Sagi Grimberg
  Cc: Christoph Hellwig, Keith Busch, linux-nvme, Keith Busch,
	Minh Hoang

On Mon, Nov 20, 2023 at 03:53:59PM +0200, Sagi Grimberg wrote:
>
>>> From: Keith Busch <kbusch@kernel.org>
>>>
>>> A different CPU may be setting the ctrl->state value while flushing the
>>> reset work, so ensure proper barriers to prevent reading a stale state.
>>> Reading the wrong state can report unexpected ENETRESET errors when
>>> everything was successful.
>>
>> smp_load_acquire needs to be paired with a smp_store_release.
>>
>> We should either always hold the lock or use WRITE_ONCE/READ_ONCE
>
> which lock?

in this case: ctrl->lock.


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

* Re: [PATCH] nvme: ensure reset state check ordering
  2023-11-20 14:26     ` Christoph Hellwig
@ 2023-11-20 14:36       ` Sagi Grimberg
  0 siblings, 0 replies; 5+ messages in thread
From: Sagi Grimberg @ 2023-11-20 14:36 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Keith Busch, linux-nvme, Keith Busch, Minh Hoang


>>>> From: Keith Busch <kbusch@kernel.org>
>>>>
>>>> A different CPU may be setting the ctrl->state value while flushing the
>>>> reset work, so ensure proper barriers to prevent reading a stale state.
>>>> Reading the wrong state can report unexpected ENETRESET errors when
>>>> everything was successful.
>>>
>>> smp_load_acquire needs to be paired with a smp_store_release.
>>>
>>> We should either always hold the lock or use WRITE_ONCE/READ_ONCE
>>
>> which lock?
> 
> in this case: ctrl->lock.

Yes, we can do either. READ/WRITE_ONCE seems more appropriate. Worth
a comment because we don't use it in other places where it is advisory.


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

end of thread, other threads:[~2023-11-20 14:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-27 18:07 [PATCH] nvme: ensure reset state check ordering Keith Busch
2023-10-30 13:27 ` Christoph Hellwig
2023-11-20 13:53   ` Sagi Grimberg
2023-11-20 14:26     ` Christoph Hellwig
2023-11-20 14:36       ` 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.