From: Nilay Shroff <nilay@linux.ibm.com>
To: Bart Van Assche <bvanassche@acm.org>,
axboe@kernel.dk, mt4022@columbia.edu, hch@lst.de,
mkhalfella@purestorage.com, kbusch@kernel.org,
josef@toxicpanda.com, tom.leiming@gmail.com, tz2294@columbia.edu,
gjoyce@linux.ibm.com
Cc: linux-block@vger.kernel.org
Subject: Re: [PATCH 3/3] block: add context annotations for tag_list_lock and quiesce_lock
Date: Fri, 4 Dec 2026 15:06:13 +0530 [thread overview]
Message-ID: <ac1e67a1-9822-4bc4-b0b4-ec1c88e71faf@linux.ibm.com> (raw)
In-Reply-To: <9d8dd1c0-e9ee-4329-9d57-3d3eb07a4fe4@acm.org>
On 12/3/26 10:13 PM, Bart Van Assche wrote:
> On 12/3/26 7:22 AM, Nilay Shroff wrote:
> > Access to ->tag_list is protected by either tag_list_lock or
> > quiesce_lock for reads, and by both locks for writes. Annotate
> > ->tag_list using __guarded_by(&tag_list_lock, &quiesce_lock)
> > to document this locking requirement.
>
> Please mention that the compiler does not verify the "both locks for
> writes" requirement for this list. Passing &set->tag_list to
> list_add_tail() is treated as a read access, and list_del() does not
> reference set->tag_list at all. If I remove the quiesce_lock
> lock/unlock calls from blk_mq_add_queue_tag_set() and
> blk_mq_del_queue_tag_set(), Clang does not complain.
>
Yes agreed and that's the reason commit message only mentions that
__guarded_by(&tag_list_lock, &quiesce_lock) just documents this
locking requirement. But yes I should be more explicit here. I will
update the description accordingly in the next revision of the patch.
> > Finally, mark blk_mq_alloc_tag_set() with __context_unsafe()
> > because it initializes lock-guarded variables before they are
> > published and accessed by other contexts. This avoids false
> > positive warnings from the context analyzer during initialization.
>
> [ ... ]
>
> > -int blk_mq_alloc_tag_set(struct blk_mq_tag_set *set);
> > +int blk_mq_alloc_tag_set(struct blk_mq_tag_set *set)
> > + __context_unsafe("/* initialize unpublished/lock-guarded variables */");
>
> I see three issues with this change:
> - This disables context analysis for all of blk_mq_alloc_tag_set().
> That is a large function with several error paths.
> Please use the *_init guards.
> - Disabling context analysis is not part of the interface of a
> function. Hence, such an attribute should occur in the function
> definition instead of in the declaration in the header file.
> - All other __context_unsafe() users pass a comment as argument instead
> of a string literal, e.g. __context_unsafe(/* conditional locking */).
>
Yes noted all points. Regarding last point, I think that was typo and
not intention to add comment as literal string.
> Please consider leaving the blk_mq_alloc_tag_set() declaration
> unmodified and making the following change instead:
>
> - mutex_init(&set->tag_list_lock);
> - INIT_LIST_HEAD(&set->tag_list);
> - spin_lock_init(&set->quiesce_lock);
> - set->quiesce_depth = 0;
> + scoped_guard(mutex_init, &set->tag_list_lock)
> + INIT_LIST_HEAD(&set->tag_list);
> + scoped_guard(spinlock_init, &set->quiesce_lock)
> + set->quiesce_depth = 0;
>
> With this change block/ builds without context analysis warnings on
> my setup (Clang, CONFIG_WARN_CONTEXT_ANALYSIS=y).
>
I did consider using scoped_guard(_init, ...) helper here, but
then realized that doing so would make lockdep class name and key
for these locks registered as "_T->lock" instead of &set->tag_list_lock
or &set->quiesce_lock respectively. And that then might make the
lockdep splat involving these locks difficult to trace, isn't it?
Does this unintentionally degrade lockdep class identity or diagnostics?
grepping through kernel source, I found only handful of mutex_init/
spinlock_init guard users. Still if you think scoped_guard(_init, ...)
is the only alternative here, I'd do this but other preference would
be to create inline helper involving initialization of set->tag_list
and set->quiesce_depth and marking the helper with __context_unsafe.
Alternatively, I could also directly make use of context_unsafe(...)
as a statement expression and add both initialization under it, like
shown below:
context_unsafe(
INIT_LIST_HEAD(&set->tag_list);
set->quiesce_depth = 0;
);
> > struct mutex tag_list_lock;
> > - struct list_head tag_list;
> > + struct list_head tag_list
> > + __guarded_by(&tag_list_lock, &quiesce_lock);
>
> The kernel-doc comment above this struct still says "@tag_list_lock:
> Serializes tag_list accesses." Please update that comment such that it
> matches the above annotation or remove it.
>
Yes okay will update comment.
> > int blk_mq_alloc_sched_res_batch(struct xarray *elv_tbl,
> > - struct blk_mq_tag_set *set, unsigned int nr_hw_queues);
> > + struct blk_mq_tag_set *set, unsigned int nr_hw_queues)
> > + __must_hold(&set->tag_list_lock);
> > int blk_mq_alloc_sched_ctx_batch(struct xarray *elv_tbl,
> > - struct blk_mq_tag_set *set);
> > + struct blk_mq_tag_set *set)
> > + __must_hold(&set->tag_list_lock);
>
> Both functions have a lockdep_assert_held_write() call for
> set->update_nr_hwq_lock. Has it been considered to add
> __must_hold(&set->update_nr_hwq_lock) to these declarations too?
>
Yes I considered doing that but then realized the scope of
annotating set->update_nr_hwq_lock is much bigger then only
annotating these two functions and so thought I'd address it
in a different patch covering all relevant annotation needed
for set->update_nr_hwq_lock instead of adding it in this series.
That said, if you prefer, I could add one more patch in the same
series to address locking requirement of set->update_nr_hwq_lock.
Thanks,
--Nilay
next prev parent reply other threads:[~2026-12-04 9:36 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 15:22 [PATCH 0/3] block: remove RCU protection and add context annotation Nilay Shroff
2026-12-03 15:22 ` [PATCH 1/3] block: remove RCU protection for tag_set_list Nilay Shroff
2026-12-03 16:41 ` Bart Van Assche
2026-12-03 15:22 ` [PATCH 2/3] block: remove unused blk_mq_free_sched_res_batch() Nilay Shroff
2026-12-03 16:42 ` Bart Van Assche
2026-12-03 15:22 ` [PATCH 3/3] block: add context annotations for tag_list_lock and quiesce_lock Nilay Shroff
2026-12-03 16:43 ` Bart Van Assche
2026-12-04 9:36 ` Nilay Shroff [this message]
2026-12-04 16:27 ` Bart Van Assche
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=ac1e67a1-9822-4bc4-b0b4-ec1c88e71faf@linux.ibm.com \
--to=nilay@linux.ibm.com \
--cc=axboe@kernel.dk \
--cc=bvanassche@acm.org \
--cc=gjoyce@linux.ibm.com \
--cc=hch@lst.de \
--cc=josef@toxicpanda.com \
--cc=kbusch@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=mkhalfella@purestorage.com \
--cc=mt4022@columbia.edu \
--cc=tom.leiming@gmail.com \
--cc=tz2294@columbia.edu \
/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