[PATCH 01/23] nvmet: add context annotation for nvmet_ns::bdev

Bart Van Assche bvanassche at acm.org
Mon Nov 9 13:46:07 PST 2026


On 11/8/26 7:28 PM, Nilay Shroff wrote:
 > The nvmet_ns::bdev field is protected by nvmet_subsys::lock. Annotate
 > it with __guarded_by(&subsys->lock) so that the clang context analyzer
 > can validate accesses to this field.

This patch introduces a compiler error in nvmet_get_smart_log_all() when
built with CONFIG_WARN_CONTEXT_ANALYSIS=y:

   drivers/nvme/target/admin-cmd.c: error: reading variable 'bdev' requires
   holding mutex 'ns->subsys->lock' [-Werror,-Wthread-safety-precise]

This is only resolved in patch 02. Please make sure this series is
bisectable.

 > +	/*
 > +	 * Both ctrl->subsys->lock and ns->subsys->lock refers to the same 
lock.

"refers to" -> "refer to".

 > +	 * However there's no way for us to annotate such locking semantics
 > +	 * using clang context annotation. So explicitly assert the capability.
 > +	 */
 > +	__assume_ctx_lock(&ns->subsys->lock);

__assume_ctx_lock() wouldn't be necessary if subsys would be passed
as a function argument, isn't it? In general, I strongly prefer to
add a function argument rather than using __assume_ctx_lock().

Thanks,

Bart.



More information about the Linux-nvme mailing list