2024-06-12 15:58:38

by Keith Busch

[permalink] [raw]
Subject: [PATCH 2/2] nvme: fix namespace removal list

From: Keith Busch <[email protected]>

This function wants to move a subset of a list from an element to the
end to another list, so do that with the new list_cut helper instead of
using the wrong list splice.

Fixes: be647e2c76b27f4 ("nvme: use srcu for iterating namespace list")
Reported-by: Venkat Rao Bagalkote <[email protected]>
Tested-by: Venkat Rao Bagalkote <[email protected]>
Signed-off-by: Keith Busch <[email protected]>
---
drivers/nvme/host/core.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index f5d150c62955d..30fec15872b3d 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3959,9 +3959,10 @@ static void nvme_remove_invalid_namespaces(struct nvme_ctrl *ctrl,

mutex_lock(&ctrl->namespaces_lock);
list_for_each_entry_safe(ns, next, &ctrl->namespaces, list) {
- if (ns->head->ns_id > nsid)
- list_splice_init_rcu(&ns->list, &rm_list,
- synchronize_rcu);
+ if (ns->head->ns_id > nsid) {
+ list_cut(&rm_list, &ctrl->namespaces, &ns->list);
+ break;
+ }
}
mutex_unlock(&ctrl->namespaces_lock);
synchronize_srcu(&ctrl->srcu);
--
2.43.0



2024-06-12 17:21:13

by Chaitanya Kulkarni

[permalink] [raw]
Subject: Re: [PATCH 2/2] nvme: fix namespace removal list

On 6/12/24 08:51, Keith Busch wrote:
> From: Keith Busch<[email protected]>
>
> This function wants to move a subset of a list from an element to the
> end to another list, so do that with the new list_cut helper instead of
> using the wrong list splice.
>
> Fixes: be647e2c76b27f4 ("nvme: use srcu for iterating namespace list")
> Reported-by: Venkat Rao Bagalkote<[email protected]>
> Tested-by: Venkat Rao Bagalkote<[email protected]>
> Signed-off-by: Keith Busch<[email protected]>

not a blocker, but it'd be really useful if we can get a blktests for this,
I've asked OP to provide steps at least ...

Looks good.

Reviewed-by: Chaitanya Kulkarni <[email protected]>

-ck


2024-06-12 17:24:25

by Keith Busch

[permalink] [raw]
Subject: Re: [PATCH 2/2] nvme: fix namespace removal list

On Wed, Jun 12, 2024 at 05:20:48PM +0000, Chaitanya Kulkarni wrote:
> On 6/12/24 08:51, Keith Busch wrote:
> > From: Keith Busch<[email protected]>
> >
> > This function wants to move a subset of a list from an element to the
> > end to another list, so do that with the new list_cut helper instead of
> > using the wrong list splice.
> >
> > Fixes: be647e2c76b27f4 ("nvme: use srcu for iterating namespace list")
> > Reported-by: Venkat Rao Bagalkote<[email protected]>
> > Tested-by: Venkat Rao Bagalkote<[email protected]>
> > Signed-off-by: Keith Busch<[email protected]>
>
> not a blocker, but it'd be really useful if we can get a blktests for this,
> I've asked OP to provide steps at least ...

Recreate the original report: detach the highest namespace id from your
controller. Let's say it's nsid 10, and let's assume your ctrlid is 0:

# nvme detach-ns /dev/nvme0 -c 0 -n 10

blktests supposedly has something that detaches namespaces through the
nvmet module, but it doesn't seem to be catching anything.