Commit e11d80a8 authored by Tejun Heo's avatar Tejun Heo Committed by Jens Axboe

blk-stat: make q->stats->lock irqsafe

blk-iocost calls blk_stat_enable_accounting() while holding an irqsafe lock
which triggers a lockdep splat because q->stats->lock isn't irqsafe. Let's
make it irqsafe.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Fixes: cd006509 ("blk-iocost: account for IO size when testing latencies")
Cc: stable@vger.kernel.org # v5.8+
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 5aeac7c4
...@@ -137,6 +137,7 @@ void blk_stat_add_callback(struct request_queue *q, ...@@ -137,6 +137,7 @@ void blk_stat_add_callback(struct request_queue *q,
struct blk_stat_callback *cb) struct blk_stat_callback *cb)
{ {
unsigned int bucket; unsigned int bucket;
unsigned long flags;
int cpu; int cpu;
for_each_possible_cpu(cpu) { for_each_possible_cpu(cpu) {
...@@ -147,20 +148,22 @@ void blk_stat_add_callback(struct request_queue *q, ...@@ -147,20 +148,22 @@ void blk_stat_add_callback(struct request_queue *q,
blk_rq_stat_init(&cpu_stat[bucket]); blk_rq_stat_init(&cpu_stat[bucket]);
} }
spin_lock(&q->stats->lock); spin_lock_irqsave(&q->stats->lock, flags);
list_add_tail_rcu(&cb->list, &q->stats->callbacks); list_add_tail_rcu(&cb->list, &q->stats->callbacks);
blk_queue_flag_set(QUEUE_FLAG_STATS, q); blk_queue_flag_set(QUEUE_FLAG_STATS, q);
spin_unlock(&q->stats->lock); spin_unlock_irqrestore(&q->stats->lock, flags);
} }
void blk_stat_remove_callback(struct request_queue *q, void blk_stat_remove_callback(struct request_queue *q,
struct blk_stat_callback *cb) struct blk_stat_callback *cb)
{ {
spin_lock(&q->stats->lock); unsigned long flags;
spin_lock_irqsave(&q->stats->lock, flags);
list_del_rcu(&cb->list); list_del_rcu(&cb->list);
if (list_empty(&q->stats->callbacks) && !q->stats->enable_accounting) if (list_empty(&q->stats->callbacks) && !q->stats->enable_accounting)
blk_queue_flag_clear(QUEUE_FLAG_STATS, q); blk_queue_flag_clear(QUEUE_FLAG_STATS, q);
spin_unlock(&q->stats->lock); spin_unlock_irqrestore(&q->stats->lock, flags);
del_timer_sync(&cb->timer); del_timer_sync(&cb->timer);
} }
...@@ -183,10 +186,12 @@ void blk_stat_free_callback(struct blk_stat_callback *cb) ...@@ -183,10 +186,12 @@ void blk_stat_free_callback(struct blk_stat_callback *cb)
void blk_stat_enable_accounting(struct request_queue *q) void blk_stat_enable_accounting(struct request_queue *q)
{ {
spin_lock(&q->stats->lock); unsigned long flags;
spin_lock_irqsave(&q->stats->lock, flags);
q->stats->enable_accounting = true; q->stats->enable_accounting = true;
blk_queue_flag_set(QUEUE_FLAG_STATS, q); blk_queue_flag_set(QUEUE_FLAG_STATS, q);
spin_unlock(&q->stats->lock); spin_unlock_irqrestore(&q->stats->lock, flags);
} }
EXPORT_SYMBOL_GPL(blk_stat_enable_accounting); EXPORT_SYMBOL_GPL(blk_stat_enable_accounting);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment