The software queue request lists in struct blk_mq_ctx are only modified and traversed with blk_mq_ctx::lock held. Mark them with __guarded_by(&lock) so that Clang's context analysis can check this. Use scoped_guard(spinlock_init) when initializing the lists, and add a __must_hold() annotation to the debugfs seq_file ->next() callback. That callback runs with the lock held, because ->start() acquires it and ->stop() releases it. The lockless check in blk_mq_sched_bio_merge() uses list_empty_careful(), which is already annotated as an intentional lockless access, so it does not need any changes. Signed-off-by: Bart Van Assche --- block/blk-mq-debugfs.c | 1 + block/blk-mq.c | 6 +++--- block/blk-mq.h | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/block/blk-mq-debugfs.c b/block/blk-mq-debugfs.c index 6754d8f9449c..1a8b655952f6 100644 --- a/block/blk-mq-debugfs.c +++ b/block/blk-mq-debugfs.c @@ -506,6 +506,7 @@ static void *ctx_##name##_rq_list_start(struct seq_file *m, loff_t *pos) \ \ static void *ctx_##name##_rq_list_next(struct seq_file *m, void *v, \ loff_t *pos) \ + __must_hold(&TO_CTX(m)->lock) \ { \ struct blk_mq_ctx *ctx = m->private; \ \ diff --git a/block/blk-mq.c b/block/blk-mq.c index 79433fd00b78..2e704b501ac9 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -4167,9 +4167,9 @@ static void blk_mq_init_cpu_queues(struct request_queue *q, int k; __ctx->cpu = i; - spin_lock_init(&__ctx->lock); - for (k = HCTX_TYPE_DEFAULT; k < HCTX_MAX_TYPES; k++) - INIT_LIST_HEAD(&__ctx->rq_lists[k]); + scoped_guard(spinlock_init, &__ctx->lock) + for (k = HCTX_TYPE_DEFAULT; k < HCTX_MAX_TYPES; k++) + INIT_LIST_HEAD(&__ctx->rq_lists[k]); __ctx->queue = q; diff --git a/block/blk-mq.h b/block/blk-mq.h index a9203dfbbc2f..7d5e59f5c33a 100644 --- a/block/blk-mq.h +++ b/block/blk-mq.h @@ -19,7 +19,7 @@ struct blk_mq_ctxs { struct blk_mq_ctx { struct { spinlock_t lock; - struct list_head rq_lists[HCTX_MAX_TYPES]; + struct list_head rq_lists[HCTX_MAX_TYPES] __guarded_by(&lock); } ____cacheline_aligned_in_smp; unsigned int cpu;