From: John Garry <john.g.garry@oracle.com>
To: wenxiong@linux.ibm.com, linux-nvme@lists.infradead.org,
kbusch@kernel.org
Cc: gjoyce@linux.ibm.com, wenxiong@us.ibm.com
Subject: Re: [PATCH] nvme: Add module reference counting for multipath nvme device
Date: Tue, 11 Aug 2026 14:18:42 +0100 [thread overview]
Message-ID: <92d55da9-2cb6-43aa-8fee-51f2c86101f8@oracle.com> (raw)
In-Reply-To: <20260810235034.544797-1-wenxiong@linux.ibm.com>
On 11/08/2026 00:50, wenxiong@linux.ibm.com wrote:
> From: Wen Xiong<wenxiong@linux.ibm.com>
>
> Ensure proper module reference counting for NVMe multipath head devices
> on open, preventing the controller module from being unloaded while
> the multipath head device is still open or in use.
>
> This patch acquires a module reference in nvme_ns_head_open() and
> releases it in nvme_ns_head_release()
Can you demonstrate that this is a problem?
Can we remove the controller driver while the NS head bdev is open? If
we could, then any NSes must disappear as we could not unload the
controller driver module while the controller is registered and has
NSes, right? Then with no NSes we cannot find a path from
nvme_ns_head_submit_bio() -> nvme_find_path() or similar and would
error. Or if we have a NS reference from nvme_ns_head_submit_bio() ->
nvme_find_path() and then remove the controller and its module, the NS
removal must be part of the controller teardown which does a scru sync
per NS, which must wait for nvme_ns_head_submit_bio() to complete.
That's the way I see it ... but maybe I am missing something.
>
> Signed-off-by: Wen Xiong<wenxiong@linux.ibm.com>
> ---
> drivers/nvme/host/multipath.c | 29 +++++++++++++++++++++++++++--
> 1 file changed, 27 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
> index 9b9a657fa330..74c3710bf5f7 100644
> --- a/drivers/nvme/host/multipath.c
> +++ b/drivers/nvme/host/multipath.c
> @@ -554,14 +554,39 @@ static void nvme_ns_head_submit_bio(struct bio *bio)
>
> static int nvme_ns_head_open(struct gendisk *disk, blk_mode_t mode)
> {
> - if (!nvme_tryget_ns_head(disk->private_data))
> + struct nvme_ns_head *head = disk->private_data;
> + struct nvme_ns *ns;
> + int srcu_idx;
> +
> + if (!nvme_tryget_ns_head(head))
> return -ENXIO;
> +
> + /* Get module reference from any available path */
> + srcu_idx = srcu_read_lock(&head->srcu);
> + ns = nvme_find_path(head);
> + if (ns && !try_module_get(ns->ctrl->ops->module)) {
If you cannot find a path then why even allow the nvme_ns_head_open() to
succeed?
> + srcu_read_unlock(&head->srcu, srcu_idx);
> + nvme_put_ns_head(head);
> + return -ENXIO;
> + }
> + srcu_read_unlock(&head->srcu, srcu_idx);
> +
> return 0;
> }
>
> static void nvme_ns_head_release(struct gendisk *disk)
> {
> - nvme_put_ns_head(disk->private_data);
> + struct nvme_ns_head *head = disk->private_data;
> + struct nvme_ns *ns;
> + int srcu_idx;
> +
> + srcu_idx = srcu_read_lock(&head->srcu);
> + ns = nvme_find_path(head);
> + if (ns)
> + module_put(ns->ctrl->ops->module);
> + srcu_read_unlock(&head->srcu, srcu_idx);
> +
> + nvme_put_ns_head(head);
> }
>
> static int nvme_ns_head_get_unique_id(struct gendisk *disk, u8 id[16],
> --
> 2.52.0
>
next prev parent reply other threads:[~2026-08-11 13:18 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-10 23:50 [PATCH] nvme: Add module reference counting for multipath nvme device wenxiong
2026-08-11 13:18 ` John Garry [this message]
2026-08-11 18:54 ` Wen Xiong
2026-08-12 8:43 ` John Garry
2026-08-12 14:32 ` Wen Xiong
2026-08-11 19:12 ` Keith Busch
2026-08-11 20:33 ` Wen Xiong
2026-08-11 20:49 ` Keith Busch
2026-08-12 3:59 ` Wen Xiong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=92d55da9-2cb6-43aa-8fee-51f2c86101f8@oracle.com \
--to=john.g.garry@oracle.com \
--cc=gjoyce@linux.ibm.com \
--cc=kbusch@kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=wenxiong@linux.ibm.com \
--cc=wenxiong@us.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox