[PATCH] nvme: Add module reference counting for multipath nvme device
Wen Xiong
wenxiong at linux.ibm.com
Tue Aug 11 11:54:06 PDT 2026
On 2026-08-11 08:18, John Garry wrote:
> Can you demonstrate that this is a problem?
>
For example, the Linux root filesystem is located on a multipath NVMe
device. During system boot, the reference count of the nvme module is
zero. As a result, the tester can run rmmod nvme, which causes the
system to become unstable or crash.
linux was installed on /dev/nvme4n2.
#lsmod|grep nvme
nvme_fabrics 262144 0
nvme 262144 0 ----> reference count = 0 for nvme
module.
nvme_core 458752 4 nvme,nvme_fabrics
nvme_keyring 262144 2 nvme_core,nvme_fabrics
nvme_auth 262144 1 nvme_core
# rmmod nvme
[11312.100786][ T937] BTRFS error (device nvme4n1p2): bdev
/dev/nvme4n1p2 errs: wr 1, rd 0, flush 0, corrupt 0, gen 0
[11312.100855][ T937] BTRFS error (device nvme4n1p2): bdev
/dev/nvme4n1p2 errs: wr 2, rd 0, flush 0, corrupt 0, gen 0
[11338.724061][ T624] BTRFS error (device nvme4n1p2 state A):
Transaction aborted (error -5)
[11338.724075][ T624] BTRFS: error (device nvme4n1p2 state A) in
__btrfs_update_delayed_inode:1096: errno=-5 IO failure
# ls
ls: reading directory '.': Input/output error
In the current nvme module reference count increase/decrease logic, the
operation is skipped when the device is a multipath device. As a result,
the NVMe module reference count remains zero even though the NVMe device
is actively being used by the multipath stack.
static int nvme_ns_open(struct nvme_ns *ns)
{
/* should never be called due to GENHD_FL_HIDDEN */
if (WARN_ON_ONCE(nvme_ns_head_multipath(ns->head)))
goto fail;
if (!nvme_get_ns(ns))
goto fail;
if (!try_module_get(ns->ctrl->ops->module))
goto fail_put_ns;
This patch adds module reference count increase/decrease logic in
nvme_ns_head_open() and nvme_ns_head_release() for the multipath head
device. This mirrors the behavior of nvme_ns_open() for non-multipath
devices.
Thanks,
Wendy
More information about the Linux-nvme
mailing list