Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Nilay Shroff <nilay@linux.ibm.com>
To: Bart Van Assche <bvanassche@acm.org>,
	kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, axboe@kernel.dk,
	chaitanyak@nvidia.com
Cc: gjoyce@linux.ibm.com, elver@google.com, linux-nvme@lists.infradead.org
Subject: Re: [PATCH v2 01/22] nvmet: add context annotation for nvmet_ns::bdev
Date: Thu, 19 Nov 2026 12:33:28 +0530	[thread overview]
Message-ID: <6956e2fc-2548-48c4-b7ec-4dc3b58f243f@linux.ibm.com> (raw)
In-Reply-To: <829201ae-e646-44ee-afc5-39f63117bfe6@acm.org>

On 11/19/26 5:55 AM, Bart Van Assche wrote:
> On 11/17/26 11:34 PM, Nilay Shroff wrote:
>> +/*
>> + * The accessors generated by this macro are annotated with __context_unsafe()
>> + * because they are intended for use in I/O hotpaths and request-processing
>> + * paths where a namespace reference is held. These paths access namespace
>> + * fields that are guaranteed not to change while the reference is held and the
>> + * I/O or request processing is in progress.
>> + */
>> +#define NVMET_NS_ACCESSOR(_type, _name)                        \
>> +static inline _type nvmet_ns_##_name(struct nvmet_ns *ns)            \
>> +    __context_unsafe(/* access _name after getting ns reference */)        \
>> +{                                        \
>> +    return ns->_name;                            \
>> +}
> 
> Lock context analysis enables thread-safety checking at compile time.
> The accessors defined by NVMET_NS_ACCESSOR() disable compile time
> thread-safety checks. So these accessors defeat the purpose of this
> patch series, isn't it?
> 
By design, the NVMe target I/O hotpaths access namespace parameters without holding
subsys->lock. Instead, they acquire a namespace reference before accessing these
parameters.

The namespace reference provides the required synchronization guarantee: namespace
parameters cannot be modified while outstanding namespace references exist. When a
namespace is disabled, the target first prevents new references from being acquired
and then waits for all outstanding references to drain before allowing namespace
parameters to be modified. This allows I/O hotpaths to safely access namespace
parameters without acquiring subsys->lock, avoiding the overhead of taking a mutex
in the I/O and request-processing paths.

On the other hand, control paths that access or modify namespace parameters must continue
to hold subsys->lock. The problem is that Clang's context annotations can express
lock-based access requirements, but cannot currently express the above reference-
counting-based synchronization guarantee. That's why I introduced the NVMET_NS_ACCESSOR()
macro. The accessors generated by this macro are marked with __context_unsafe() to
explicitly opt out of context checking for these particular accesses. They are intended
to be used only in I/O hotpaths and request-processing paths where a namespace reference
has already been acquired.

This does not eliminate context checking for namespace parameter accesses in general.
Control-path accesses are still subject to the __guarded_by(&subsys->lock) annotations
and must satisfy the corresponding locking requirements.

Thanks,
--Nilay



  reply	other threads:[~2026-11-19  7:03 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18  7:34 [PATCH v2 00/22] nvmet: add context annotation for params in struct nvmet_ns Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 01/22] nvmet: add context annotation for nvmet_ns::bdev Nilay Shroff
2026-11-19  0:06   ` Bart Van Assche
2026-11-19 14:20     ` Nilay Shroff
2026-11-19  0:25   ` Bart Van Assche
2026-11-19  7:03     ` Nilay Shroff [this message]
2026-11-18  7:34 ` [PATCH v2 02/22] nvmet: fix nvmet_ns::bdev access using nvmet_subsys::lock Nilay Shroff
2026-11-19  0:08   ` Bart Van Assche
2026-11-19  9:10     ` Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 03/22] nvmet: add context annotation for nvmet_ns::file Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 04/22] nvmet: add context annotation for nvmet_ns::bdev_file Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 05/22] nvmet: add context annotation for nvmet_ns::readonly Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 06/22] nvmet: add context annotation for nvmet_ns::blksize_shift Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 07/22] nvmet: add context annotation for nvmet_ns::size Nilay Shroff
2026-11-18  7:50   ` sashiko-bot
2026-11-18  7:34 ` [PATCH v2 08/22] nvmet: add context annotation for nvmet_ns::nguid Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 09/22] nvmet: add context annotation for nvmet_ns::uuid Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 10/22] nvmet: fix nvmet_ns::uuid access using nvmet_subsys::lock Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 11/22] nvmet: add context annotation for nvmet_ns::buffered_io Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 12/22] nvmet: fix nvmet_ns::buffered_io access using nvmet_subsys::lock Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 13/22] nvmet: add context annotation for nvmet_ns::enabled Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 14/22] nvmet: fix nvmet_ns::enable access using nvmet_subsys::lock Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 15/22] nvmet: add context annotation for nvmet_ns::device_path Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 16/22] nvmet: fix nvmet_ns::device_path access using nvmet_subsys::lock Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 17/22] nvmet: add context annotation for PCI P2P parameters in struct nvmet_ns Nilay Shroff
2026-11-18  7:34 ` [PATCH v2 18/22] nvmet: fix PCI P2P parameters access using nvmet_subsys::lock Nilay Shroff
2026-11-18  7:55   ` sashiko-bot
2026-11-18  7:35 ` [PATCH v2 19/22] nvmet: add context annotation for integrity params in struct nvmet_ns Nilay Shroff
2026-11-18  7:35 ` [PATCH v2 20/22] nvmet: add context annotation for nvmet_ns::csi Nilay Shroff
2026-11-18  7:35 ` [PATCH v2 21/22] nvmet: fix nvmet_ns::csi access using nvmet_subsys::lock Nilay Shroff
2026-11-18  7:35 ` [PATCH v2 22/22] nvmet: add context annotation for nvmet_ns::debugfs_dir 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=6956e2fc-2548-48c4-b7ec-4dc3b58f243f@linux.ibm.com \
    --to=nilay@linux.ibm.com \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=chaitanyak@nvidia.com \
    --cc=elver@google.com \
    --cc=gjoyce@linux.ibm.com \
    --cc=hch@lst.de \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox