From: Bart Van Assche <bvanassche@acm.org>
To: Nilay Shroff <nilay@linux.ibm.com>,
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: Thu, 3 Dec 2026 08:43:57 -0800 [thread overview]
Message-ID: <9d8dd1c0-e9ee-4329-9d57-3d3eb07a4fe4@acm.org> (raw)
In-Reply-To: <20261203152318.654390-8-nilay@linux.ibm.com>
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.
> 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 */).
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).
> 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.
> 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?
Thanks,
Bart.
prev parent reply other threads:[~2026-12-03 16:44 UTC|newest]
Thread overview: 7+ 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 [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=9d8dd1c0-e9ee-4329-9d57-3d3eb07a4fe4@acm.org \
--to=bvanassche@acm.org \
--cc=axboe@kernel.dk \
--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=nilay@linux.ibm.com \
--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