Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2] nvme: Add module reference counting for multipath devices
@ 2026-08-12 22:32 wenxiong
  2026-08-20  4:19 ` Nares Bannoth
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: wenxiong @ 2026-08-12 22:32 UTC (permalink / raw)
  To: linux-nvme, kbusch; +Cc: gjoyce, wenxiong, Wen Xiong

From: Wen Xiong <wenxiong@linux.ibm.com>

Add proper module reference counting to prevent premature unloading of
NVMe transport modules while multipath namespaces are still active.

When a namespace is added to a multipath device via nvme_mpath_add_disk(),
the underlying transport module (PCIe, FC, RDMA, TCP, etc.) must remain
loaded as long as the multipath device references that namespace. Without
proper reference counting, the transport module could be unloaded while
the multipath device is still using resources from that module, leading
to the potential system crashes.

This ensures the transport module remains loaded for the entire lifetime
of the multipath namespace association.

Signed-off-by: Wen Xiong <wenxiong@linux.ibm.com>
---
 drivers/nvme/host/multipath.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index 9b9a657fa330..707b8f95727d 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -1348,6 +1348,8 @@ void nvme_mpath_remove_sysfs_link(struct nvme_ns *ns)
 	sysfs_remove_link_from_group(kobj, nvme_ns_mpath_attr_group.name,
 			dev_name(target));
 	clear_bit(NVME_NS_SYSFS_ATTR_LINK, &ns->flags);
+
+	module_put(ns->ctrl->ops->module);
 }
 
 void nvme_mpath_add_disk(struct nvme_ns *ns, __le32 anagrpid)
@@ -1379,6 +1381,9 @@ void nvme_mpath_add_disk(struct nvme_ns *ns, __le32 anagrpid)
 	if (blk_queue_is_zoned(ns->queue) && ns->head->disk)
 		ns->head->disk->nr_zones = ns->disk->nr_zones;
 #endif
+	if (!try_module_get(ns->ctrl->ops->module))
+		dev_err(disk_to_dev(ns->disk),
+				"Failed to get module reference\n");
 }
 
 void nvme_mpath_remove_disk(struct nvme_ns_head *head)
-- 
2.52.0



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

end of thread, other threads:[~2026-08-30 21:46 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-12 22:32 [PATCH V2] nvme: Add module reference counting for multipath devices wenxiong
2026-08-20  4:19 ` Nares Bannoth
2026-08-23  0:20 ` Sagi Grimberg
2026-08-23  0:46   ` Sagi Grimberg
2026-08-24 20:23     ` Wen Xiong
2026-08-25 19:11     ` Wen Xiong
2026-08-30 21:46       ` Sagi Grimberg
2026-08-26 12:40 ` Nilay Shroff
2026-08-26 14:23   ` Keith Busch
2026-08-26 16:18   ` Wen Xiong
2026-08-26 16:36     ` Keith Busch
2026-08-27 13:21       ` Nilay Shroff

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