All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nilay Shroff <nilay@linux.ibm.com>
To: Guixin Liu <kanie@linux.alibaba.com>,
	Keith Busch <kbusch@kernel.org>, Jens Axboe <axboe@kernel.dk>,
	Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>,
	Daniel Wagner <dwagner@suse.de>, Hannes Reinecke <hare@suse.de>
Cc: linux-nvme@lists.infradead.org
Subject: Re: [PATCH v3] nvme-multipath: serialize ana_log_buf lifecycle with ana_lock
Date: Tue, 1 Dec 2026 18:24:55 +0530	[thread overview]
Message-ID: <7e50ed7f-3f4f-48cd-9bd2-517b6402b0f5@linux.ibm.com> (raw)
In-Reply-To: <20261201074919.1051448-1-kanie@linux.alibaba.com>

On 12/1/26 1:19 PM, Guixin Liu wrote:
> nvme_parse_ana_log() reads ctrl->ana_log_buf and ctrl->ana_log_size
> under ctrl->ana_lock, but the buffer lifecycle is not fully serialized
> against it:
> 
>   - nvme_mpath_uninit() frees the buffer without ana_lock, so a
>     concurrent parser in nvme_mpath_add_disk() can use freed memory.
>   - nvme_mpath_init_identify() reallocates the buffer and updates
>     ana_log_size outside ana_lock. nvme_mpath_add_disk() tests
>     nvme_ctrl_use_ana() before taking the lock, so it can pass the check
>     and then dereference a NULL buffer after nvme_mpath_uninit() cleared
>     it; and the freshly allocated buffer can be parsed before
>     nvme_read_ana_log() populates it, reading uninitialized memory.
>   - The shrink path leaves the old log in place while shrinking
>     ana_log_size, and anagrpmax is updated outside ana_lock, so a
>     concurrent parser validates stale descriptors against the new
>     limits and trips WARN_ON_ONCE().
>   - After nvme_mpath_uninit() clears the buffer, nvme_mpath_add_disk()
>     can still queue ana_work; nvme_read_ana_log() then calls
>     nvme_get_log() with a NULL buffer and size 0, and
>     nvme_bytes_to_numd(0) underflows to 0xffffffff.
> 
> Take ana_lock around the buffer release in nvme_mpath_uninit() and
> around the reallocation in nvme_mpath_init_identify(), updating
> ana_log_buf, ana_log_size and anagrpmax together so a parser never
> observes a freed or NULL buffer or stale limits. Allocate the new
> buffer outside the lock and zero it, and clear ngrps on the shrink
> path, so a parser running before nvme_read_ana_log() populates the log
> sees ngrps == 0. nvme_parse_ana_log() and nvme_read_ana_log() bail out
> when the buffer is NULL. Keep the ana_work drain outside the lock:
> ana_work itself takes ana_lock, so cancelling it under the lock would
> deadlock.
> 
Along with this change, can we also annotate relevant ANA fields
in struct nvme_ctrl using ctrl->ana_lock? That would help document
all fields protected with ana_lock as well as all references
to those fields would be also analyzed by thread-safety context
analyzer when compiled with clang.

Thanks,
--Nilay



      parent reply	other threads:[~2026-12-01 12:55 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
2026-12-01 12:54 ` Nilay Shroff [this message]

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=7e50ed7f-3f4f-48cd-9bd2-517b6402b0f5@linux.ibm.com \
    --to=nilay@linux.ibm.com \
    --cc=axboe@kernel.dk \
    --cc=dwagner@suse.de \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=kanie@linux.alibaba.com \
    --cc=kbusch@kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    /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.