All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Guixin Liu" <kanie@linux.alibaba.com>
Cc: linux-nvme@lists.infradead.org
Subject: Re: [PATCH v3] nvme-multipath: serialize ana_log_buf lifecycle with ana_lock
Date: Tue, 01 Dec 2026 08:08:13 +0000	[thread overview]
Message-ID: <sashiko-outbox-242814@kernel.org> (raw)
In-Reply-To: <20261201074919.1051448-1-kanie@linux.alibaba.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] nvme-multipath: TOCTOU race on ana_log_buf in
  nvme_mpath_add_disk()
--

commit f8acdff41f6798914e6883d82fb65ecaaa130b49
Author: Guixin Liu <kanie@linux.alibaba.com>

nvme-multipath: serialize ana_log_buf lifecycle with ana_lock

This commit serializes ctrl->ana_log_buf freeing and reallocation with
ctrl->ana_lock and makes nvme_parse_ana_log() and nvme_read_ana_log() bail
out when ctrl->ana_log_buf is NULL.

> diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
> index 27facdbb3d4c0..e0476af20f3e8 100644
> --- a/drivers/nvme/host/multipath.c
> +++ b/drivers/nvme/host/multipath.c
> @@ -867,6 +867,9 @@ static int nvme_parse_ana_log(struct nvme_ctrl *ctrl, void *data,
>  
>  	lockdep_assert_held(&ctrl->ana_lock);
>  
> +	if (!ctrl->ana_log_buf)
> +		return 0;

[Severity: Medium]
Can returning 0 here cause nvme_mpath_add_disk() to mistake a freed
ana_log_buf for a missing ANA group descriptor when racing with
nvme_mpath_uninit()?

drivers/nvme/host/multipath.c:nvme_mpath_add_disk() {
	if (nvme_ctrl_use_ana(ns->ctrl)) {
		struct nvme_ana_group_desc desc = {
			.grpid = anagrpid,
			.state = 0,
		};

		mutex_lock(&ns->ctrl->ana_lock);
		ns->ana_grpid = le32_to_cpu(anagrpid);
		nvme_parse_ana_log(ns->ctrl, &desc, nvme_lookup_ana_group_desc);
		mutex_unlock(&ns->ctrl->ana_lock);
		if (desc.state) {
			/* found the group desc: update */
			nvme_update_ns_ana_state(&desc, ns);
		} else {
			/* group desc not found: trigger a re-read */
			set_bit(NVME_NS_ANA_PENDING, &ns->flags);
			queue_work(nvme_wq, &ns->ctrl->ana_work);
		}
	} else {
		ns->ana_state = NVME_ANA_OPTIMIZED;
		nvme_mpath_set_live(ns);
	}
}

Because nvme_mpath_add_disk() checks nvme_ctrl_use_ana() outside ana_lock,
a concurrent nvme_mpath_uninit() can clear ana_log_buf before ana_lock is
acquired:

CPU0                                  CPU1
nvme_mpath_add_disk()                 nvme_mpath_init_identify()
  nvme_ctrl_use_ana() -> true           /* ana_log_size > max_transfer_size */
                                        nvme_mpath_uninit()
                                          cancel_work_sync(&ctrl->ana_work)
                                          mutex_lock(&ctrl->ana_lock)
                                          ctrl->ana_log_buf = NULL
                                          mutex_unlock(&ctrl->ana_lock)
  mutex_lock(&ctrl->ana_lock)
  nvme_parse_ana_log() -> 0
  mutex_unlock(&ctrl->ana_lock)
  /* desc.state == 0 */
  set_bit(NVME_NS_ANA_PENDING, ...)
  queue_work(..., &ctrl->ana_work)  <-- queued after ANA teardown

When nvme_mpath_init_identify() disables ANA because ana_log_size exceeds
max_transfer_size, it returns 0 and the controller proceeds without ANA.
CPU0 sets NVME_NS_ANA_PENDING instead of taking the non-ANA branch to mark
the namespace live, and nvme_read_ana_log() now bails out on the NULL
ana_log_buf, leaving the path stuck in NVME_PATH_DISABLED_ANA_PENDING.
Also, once ana_log_buf is NULL, nvme_mpath_stop() returns early because
nvme_ctrl_use_ana() is false, so it will not cancel the newly queued
ana_work.

Would rechecking nvme_ctrl_use_ana() under ana_lock in
nvme_mpath_add_disk() (or having nvme_parse_ana_log() return an error such
as -ENOENT when ana_log_buf is NULL) allow nvme_mpath_add_disk() to fall
back to the non-ANA path?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201074919.1051448-1-kanie@linux.alibaba.com?part=1


  reply	other threads:[~2026-12-01  8:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  7:49 [PATCH v3] nvme-multipath: serialize ana_log_buf lifecycle with ana_lock Guixin Liu
2026-12-01  8:08 ` sashiko-bot [this message]
2026-12-01 12:54 ` Nilay Shroff

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=sashiko-outbox-242814@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kanie@linux.alibaba.com \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.