nvme: add missing SRCU grace period in error path
Subsystems (2)
PATCH 1/1 nvme: add missing SRCU grace period in error path
From: Tristan Madani <[email protected]>
nvme_alloc_ns() error path at out_unlink_ns removes ns from the namespace head siblings list with list_del_rcu(&ns->siblings) but does not wait for SRCU readers before freeing the namespace struct. Multipath code iterates the head->list under srcu_read_lock() in nvme_find_path() and nvme_mpath_revalidate_paths(), so a concurrent reader can still hold a reference to ns when kfree(ns) runs.
The normal removal path in nvme_ns_remove() correctly calls synchronize_srcu(&ns->head->srcu) after list_del_rcu() to wait for in-progress readers. Add the same grace period in the error path.
--- drivers/nvme/host/core.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/nvme/host/core.c +3 -0
@@ -4295,6 +4295,9 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info) last_path = true; }mutex_unlock (&ctrl->subsys->lock); + +/* guarantee not available in head->list */ +synchronize_srcu (&ns->head->srcu);if (last_path)nvme_put_ns_head (ns->head);nvme_put_ns_head (ns->head);
Signature · 1 line
2.47.3
Looks good:
Quoted 9 lines · Tristan Madani
From: Tristan Madani <[email protected]>
nvme_alloc_ns()error path atout_unlink_nsremoves ns from the namespace head siblings list withlist_del_rcu(&ns->siblings)but does not wait for SRCU readers before freeing the namespace struct. Multipath code iterates thehead->listundersrcu_read_lock()innvme_find_path()andnvme_mpath_revalidate_paths(), so a concurrent reader can still hold a reference to ns when kfree(ns) runs.
Quoted 3 lines
The normal removal path in
nvme_ns_remove()correctly callssynchronize_srcu(&ns->head->srcu)afterlist_del_rcu()to wait for in-progress readers. Add the same grace period in the error path.
Thanks, applied to nvme-7.3.