Pass the bfqd pointer explicitly to bfq_bic_update_cgroup(), bfq_init_rq() and bfq_exit_icq_bfqq() instead of deriving it from the bic, the request or the bfqq. All callers of these functions hold bfqd->lock. This change prepares for annotating these functions with __must_hold(&bfqd->lock). Clang's context analysis cannot determine that e.g. bic_to_bfqd(bic)->lock and q->elevator->elevator_data->lock refer to the same spinlock. Remove the bfqd == NULL check from bfq_bic_update_cgroup() since it is dead code: both callers dereference bfqd by locking bfqd->lock before calling this function. Remove the bfqd == NULL check from bfq_exit_icq_bfqq() since bfqq->bfqd is never NULL. Make bic_to_bfqd() static since it no longer has any callers outside block/bfq-iosched.c. No functional change is intended since bic_to_bfqd(bic), rq->q's elevator data and bfqq->bfqd all equal the bfqd pointer passed by the callers. Signed-off-by: Bart Van Assche --- block/bfq-cgroup.c | 11 +++++++---- block/bfq-iosched.c | 28 +++++++++++----------------- block/bfq-iosched.h | 4 ++-- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/block/bfq-cgroup.c b/block/bfq-cgroup.c index ef9d63e8542e..811df3a5216b 100644 --- a/block/bfq-cgroup.c +++ b/block/bfq-cgroup.c @@ -779,9 +779,9 @@ static void __bfq_bic_change_cgroup(struct bfq_data *bfqd, } } -void bfq_bic_update_cgroup(struct bfq_io_cq *bic, struct bio *bio) +void bfq_bic_update_cgroup(struct bfq_data *bfqd, struct bfq_io_cq *bic, + struct bio *bio) { - struct bfq_data *bfqd = bic_to_bfqd(bic); struct bfq_group *bfqg = bfq_bio_bfqg(bfqd, bio); uint64_t serial_nr; @@ -791,7 +791,7 @@ void bfq_bic_update_cgroup(struct bfq_io_cq *bic, struct bio *bio) * Check whether blkcg has changed. The condition may trigger * spuriously on a newly created cic but there's no harm. */ - if (unlikely(!bfqd) || likely(bic->blkcg_serial_nr == serial_nr)) + if (likely(bic->blkcg_serial_nr == serial_nr)) return; /* @@ -1430,7 +1430,10 @@ void bfq_init_entity(struct bfq_entity *entity, struct bfq_group *bfqg) entity->sched_data = &bfqg->sched_data; } -void bfq_bic_update_cgroup(struct bfq_io_cq *bic, struct bio *bio) {} +void bfq_bic_update_cgroup(struct bfq_data *bfqd, struct bfq_io_cq *bic, + struct bio *bio) +{ +} void bfq_end_wr_async(struct bfq_data *bfqd) { diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c index 20a473c43fba..6d88d1350b30 100644 --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -433,7 +433,7 @@ void bic_set_bfqq(struct bfq_io_cq *bic, } } -struct bfq_data *bic_to_bfqd(struct bfq_io_cq *bic) +static struct bfq_data *bic_to_bfqd(struct bfq_io_cq *bic) { return bic->icq.q->elevator->elevator_data; } @@ -2459,7 +2459,7 @@ static bool bfq_bio_merge(struct request_queue *q, struct bio *bio, * Make sure cgroup info is uptodate for current process before * considering the merge. */ - bfq_bic_update_cgroup(bic, bio); + bfq_bic_update_cgroup(bfqd, bic, bio); bfqd->bio_bfqq = bic_to_bfqq(bic, op_is_sync(bio->bi_opf), bfq_actuator_index(bfqd, bio)); @@ -5446,16 +5446,12 @@ static void bfq_exit_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq) bfq_release_process_ref(bfqd, bfqq); } -static void bfq_exit_icq_bfqq(struct bfq_io_cq *bic, bool is_sync, - unsigned int actuator_idx) +static void bfq_exit_icq_bfqq(struct bfq_data *bfqd, struct bfq_io_cq *bic, + bool is_sync, unsigned int actuator_idx) { struct bfq_queue *bfqq = bic_to_bfqq(bic, is_sync, actuator_idx); - struct bfq_data *bfqd; - - if (bfqq) - bfqd = bfqq->bfqd; /* NULL if scheduler already exited */ - if (bfqq && bfqd) { + if (bfqq) { bic_set_bfqq(bic, NULL, is_sync, actuator_idx); bfq_exit_bfqq(bfqd, bfqq); } @@ -5477,8 +5473,8 @@ static void bfq_exit_icq(struct io_cq *icq) if (bfqq_data[act_idx].stable_merge_bfqq) bfq_put_stable_ref(bfqq_data[act_idx].stable_merge_bfqq); - bfq_exit_icq_bfqq(bic, true, act_idx); - bfq_exit_icq_bfqq(bic, false, act_idx); + bfq_exit_icq_bfqq(bfqd, bic, true, act_idx); + bfq_exit_icq_bfqq(bfqd, bic, false, act_idx); } spin_unlock_irqrestore(&bfqd->lock, flags); } @@ -6216,7 +6212,7 @@ static inline void bfq_update_insert_stats(struct request_queue *q, blk_opf_t cmd_flags) {} #endif /* CONFIG_BFQ_CGROUP_DEBUG */ -static struct bfq_queue *bfq_init_rq(struct request *rq); +static struct bfq_queue *bfq_init_rq(struct bfq_data *bfqd, struct request *rq); static void bfq_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq, blk_insert_t flags) @@ -6233,7 +6229,7 @@ static void bfq_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq, bfqg_stats_update_legacy_io(q, rq); #endif spin_lock_irq(&bfqd->lock); - bfqq = bfq_init_rq(rq); + bfqq = bfq_init_rq(bfqd, rq); if (blk_mq_sched_try_insert_merge(q, rq, &free)) { spin_unlock_irq(&bfqd->lock); blk_mq_free_requests(&free); @@ -6909,11 +6905,9 @@ static struct bfq_queue *bfq_get_bfqq_handle_split(struct bfq_data *bfqd, * rq after rq has been inserted or merged. So, it is safe to execute * these preparation operations when rq is finally inserted or merged. */ -static struct bfq_queue *bfq_init_rq(struct request *rq) +static struct bfq_queue *bfq_init_rq(struct bfq_data *bfqd, struct request *rq) { - struct request_queue *q = rq->q; struct bio *bio = rq->bio; - struct bfq_data *bfqd = q->elevator->elevator_data; struct bfq_io_cq *bic; const int is_sync = rq_is_sync(rq); struct bfq_queue *bfqq; @@ -6934,7 +6928,7 @@ static struct bfq_queue *bfq_init_rq(struct request *rq) bic = icq_to_bic(rq->elv.icq); bfq_check_ioprio_change(bic, bio); - bfq_bic_update_cgroup(bic, bio); + bfq_bic_update_cgroup(bfqd, bic, bio); bfqq = bfq_get_bfqq_handle_split(bfqd, bic, bio, a_idx, is_sync); bfqq_request_allocated(bfqq); diff --git a/block/bfq-iosched.h b/block/bfq-iosched.h index 355a731e2c04..91adf1a31599 100644 --- a/block/bfq-iosched.h +++ b/block/bfq-iosched.h @@ -1046,7 +1046,6 @@ struct bfq_queue *bic_to_bfqq(struct bfq_io_cq *bic, bool is_sync, unsigned int actuator_idx); void bic_set_bfqq(struct bfq_io_cq *bic, struct bfq_queue *bfqq, bool is_sync, unsigned int actuator_idx); -struct bfq_data *bic_to_bfqd(struct bfq_io_cq *bic); void bfq_pos_tree_add_move(struct bfq_data *bfqd, struct bfq_queue *bfqq); void bfq_weights_tree_add(struct bfq_queue *bfqq); void bfq_weights_tree_remove(struct bfq_queue *bfqq); @@ -1082,7 +1081,8 @@ void bfqg_stats_update_avg_queue_size(struct bfq_group *bfqg); #endif void bfq_init_entity(struct bfq_entity *entity, struct bfq_group *bfqg); -void bfq_bic_update_cgroup(struct bfq_io_cq *bic, struct bio *bio); +void bfq_bic_update_cgroup(struct bfq_data *bfqd, struct bfq_io_cq *bic, + struct bio *bio); void bfq_end_wr_async(struct bfq_data *bfqd); struct bfq_group *bfq_bio_bfqg(struct bfq_data *bfqd, struct bio *bio); struct blkcg_gq *bfqg_to_blkg(struct bfq_group *bfqg);