The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] nvme: add missing SRCU grace period in error path
@ 2026-08-15  0:14 Tristan Madani
  2026-08-17  7:00 ` Christoph Hellwig
  0 siblings, 1 reply; 2+ messages in thread
From: Tristan Madani @ 2026-08-15  0:14 UTC (permalink / raw)
  To: Keith Busch, Jens Axboe, Christoph Hellwig
  Cc: Sagi Grimberg, Caleb Sander, linux-nvme, linux-kernel, stable,
	Tristan Madani

From: Tristan Madani <tristan@talencesecurity.com>

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.

Fixes: ed754e5deeb1 ("nvme: track shared namespaces")
Cc: stable@vger.kernel.org
Signed-off-by: Tristan Madani <tristan@talencesecurity.com>
---
 drivers/nvme/host/core.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 453c1f0b2dd09..0f5f13ce0b438 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -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);
-- 
2.47.3


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

* Re: [PATCH] nvme: add missing SRCU grace period in error path
  2026-08-15  0:14 [PATCH] nvme: add missing SRCU grace period in error path Tristan Madani
@ 2026-08-17  7:00 ` Christoph Hellwig
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2026-08-17  7:00 UTC (permalink / raw)
  To: Tristan Madani
  Cc: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
	Caleb Sander, linux-nvme, linux-kernel, stable, Tristan Madani

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>


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

end of thread, other threads:[~2026-08-17  7:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-15  0:14 [PATCH] nvme: add missing SRCU grace period in error path Tristan Madani
2026-08-17  7:00 ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox