From: Nilay Shroff <nilay@linux.ibm.com>
To: axboe@kernel.dk, mt4022@columbia.edu, hch@lst.de,
mkhalfella@purestorage.com, bvanassche@acm.org,
kbusch@kernel.org, josef@toxicpanda.com, tom.leiming@gmail.com,
tz2294@columbia.edu, gjoyce@linux.ibm.com
Cc: linux-block@vger.kernel.org, Nilay Shroff <nilay@linux.ibm.com>
Subject: [PATCH 3/3] block: add context annotations for tag_list_lock and quiesce_lock
Date: Thu, 3 Dec 2026 20:52:39 +0530 [thread overview]
Message-ID: <20261203152318.654390-8-nilay@linux.ibm.com> (raw)
In-Reply-To: <20261203152318.654390-5-nilay@linux.ibm.com>
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.
Similarly, all accesses to ->quiesce_depth are protected by
quiesce_lock, so annotate it using __guarded_by(&quiesce_lock).
Additionally, annotate blk_mq_alloc_sched_ctx_batch(),
blk_mq_alloc_sched_res_batch(), blk_mq_update_tag_set_shared(),
blk_mq_del_queue_tag_set(), blk_mq_add_queue_tag_set(), and
__blk_mq_update_nr_hw_queues() with __must_hold(&tag_list_lock)
to document that tag_list_lock must be held when these functions
are called.
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.
Signed-off-by: Nilay Shroff <nilay@linux.ibm.com>
---
block/blk-mq-sched.h | 6 ++++--
block/blk-mq.c | 4 ++++
include/linux/blk-mq.h | 9 ++++++---
3 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/block/blk-mq-sched.h b/block/blk-mq-sched.h
index 50e19f5ca90a..5f3583fdfd47 100644
--- a/block/blk-mq-sched.h
+++ b/block/blk-mq-sched.h
@@ -30,9 +30,11 @@ int blk_mq_alloc_sched_res(struct request_queue *q,
struct elevator_resources *res,
unsigned int nr_hw_queues);
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);
void blk_mq_free_sched_ctx_batch(struct xarray *elv_tbl);
void blk_mq_free_sched_tags(struct elevator_tags *et,
struct blk_mq_tag_set *set);
diff --git a/block/blk-mq.c b/block/blk-mq.c
index b3d26f0ec1a7..cd4fb994cfda 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -4331,6 +4331,7 @@ static void queue_set_hctx_shared(struct request_queue *q, bool shared)
static void blk_mq_update_tag_set_shared(struct blk_mq_tag_set *set,
bool shared)
+ __must_hold(&set->tag_list_lock)
{
struct request_queue *q;
unsigned int memflags;
@@ -4345,6 +4346,7 @@ static void blk_mq_update_tag_set_shared(struct blk_mq_tag_set *set,
}
static void blk_mq_del_queue_tag_set(struct request_queue *q)
+ __must_hold(&q->tag_set->tag_list_lock)
{
struct blk_mq_tag_set *set = q->tag_set;
@@ -4363,6 +4365,7 @@ static void blk_mq_del_queue_tag_set(struct request_queue *q)
static void blk_mq_add_queue_tag_set(struct blk_mq_tag_set *set,
struct request_queue *q)
+ __must_hold(&set->tag_list_lock)
{
unsigned int i;
@@ -5170,6 +5173,7 @@ static int blk_mq_elv_switch_none(struct request_queue *q,
static void __blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set,
int nr_hw_queues)
+ __must_hold(&set->tag_list_lock)
{
struct request_queue *q;
int prev_nr_hw_queues = set->nr_hw_queues;
diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
index 3c9667854c46..b085328cbc73 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -552,9 +552,11 @@ struct blk_mq_tag_set {
struct blk_mq_tags *shared_tags;
struct mutex tag_list_lock;
- struct list_head tag_list;
+ struct list_head tag_list
+ __guarded_by(&tag_list_lock, &quiesce_lock);
spinlock_t quiesce_lock;
- unsigned int quiesce_depth;
+ unsigned int quiesce_depth
+ __guarded_by(&quiesce_lock);
struct srcu_struct *srcu;
struct rw_semaphore update_nr_hwq_lock;
@@ -745,7 +747,8 @@ int blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
struct request_queue *q);
void blk_mq_destroy_queue(struct request_queue *);
-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 */");
int blk_mq_alloc_sq_tag_set(struct blk_mq_tag_set *set,
const struct blk_mq_ops *ops, unsigned int queue_depth,
unsigned int set_flags);
--
2.53.0
next prev parent reply other threads:[~2026-12-03 15:24 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 ` Nilay Shroff [this message]
2026-12-03 16:43 ` [PATCH 3/3] block: add context annotations for tag_list_lock and quiesce_lock Bart Van Assche
2026-12-04 9:36 ` Nilay Shroff
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=20261203152318.654390-8-nilay@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 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.