]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
nvme: fix inconsistent RCU list manipulation in nvme_ns_add_to_ctrl_list()
authorZheng Qixing <zhengqixing@huawei.com>
Tue, 1 Jul 2025 07:17:17 +0000 (15:17 +0800)
committerChristoph Hellwig <hch@lst.de>
Mon, 14 Jul 2025 13:50:32 +0000 (15:50 +0200)
When inserting a namespace into the controller's namespace list, the
function uses list_add_rcu() when the namespace is inserted in the middle
of the list, but falls back to a regular list_add() when adding at the
head of the list.

This inconsistency could lead to race conditions during concurrent
access, as users might observe a partially updated list. Fix this by
consistently using list_add_rcu() in both code paths to ensure proper
RCU protection throughout the entire function.

Fixes: be647e2c76b2 ("nvme: use srcu for iterating namespace list")
Signed-off-by: Zheng Qixing <zhengqixing@huawei.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/nvme/host/core.c

index 7493e5aa984c8b5a769d708e93f2bf98a7729e7a..5eb45d26c553bd6e40d55f388f8c1b3c9494894c 100644 (file)
@@ -4077,7 +4077,7 @@ static void nvme_ns_add_to_ctrl_list(struct nvme_ns *ns)
                        return;
                }
        }
-       list_add(&ns->list, &ns->ctrl->namespaces);
+       list_add_rcu(&ns->list, &ns->ctrl->namespaces);
 }
 
 static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info)