All accesses of the flush state machine members of struct blk_flush_queue happen with mq_flush_lock held. Document this by annotating these members with __guarded_by() such that Clang's context analysis verifies that the lock is held when these members are accessed. Leave flush_rq unannotated because it is set once during allocation and read without holding mq_flush_lock. Initialize the flush_queue[] lists inside a spinlock_init scoped guard such that the context analysis accepts these initialization accesses. Signed-off-by: Bart Van Assche --- block/blk-flush.c | 8 ++++---- block/blk.h | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/block/blk-flush.c b/block/blk-flush.c index 34220e2dc480..37fe39578b13 100644 --- a/block/blk-flush.c +++ b/block/blk-flush.c @@ -495,16 +495,16 @@ struct blk_flush_queue *blk_alloc_flush_queue(int node, int cmd_size, if (!fq) goto fail; - spin_lock_init(&fq->mq_flush_lock); + scoped_guard(spinlock_init, &fq->mq_flush_lock) { + INIT_LIST_HEAD(&fq->flush_queue[0]); + INIT_LIST_HEAD(&fq->flush_queue[1]); + } rq_sz = round_up(rq_sz + cmd_size, cache_line_size()); fq->flush_rq = kzalloc_node(rq_sz, flags, node); if (!fq->flush_rq) goto fail_rq; - INIT_LIST_HEAD(&fq->flush_queue[0]); - INIT_LIST_HEAD(&fq->flush_queue[1]); - return fq; fail_rq: diff --git a/block/blk.h b/block/blk.h index c990d8f000c2..b60556e482b2 100644 --- a/block/blk.h +++ b/block/blk.h @@ -34,12 +34,18 @@ extern struct dentry *blk_debugfs_root; struct blk_flush_queue { spinlock_t mq_flush_lock; - unsigned int flush_pending_idx:1; - unsigned int flush_running_idx:1; - blk_status_t rq_status; - unsigned long flush_pending_since; - struct list_head flush_queue[2]; - unsigned long flush_data_in_flight; + unsigned int flush_pending_idx:1 + __guarded_by(&mq_flush_lock); + unsigned int flush_running_idx:1 + __guarded_by(&mq_flush_lock); + blk_status_t rq_status + __guarded_by(&mq_flush_lock); + unsigned long flush_pending_since + __guarded_by(&mq_flush_lock); + struct list_head flush_queue[2] + __guarded_by(&mq_flush_lock); + unsigned long flush_data_in_flight + __guarded_by(&mq_flush_lock); struct request *flush_rq; struct rcu_head rcu_head; };