From c44534436fade5ce4b397b3df073a78c01cface3 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 May 2023 15:38:53 -0700 Subject: [PATCH] BACKPORT: FROMGIT: block: BFQ: Add several invariant checks If anything goes wrong with the counters that track the number of requests, I/O locks up. Make such scenarios easier to debug by adding invariant checks for the request counters. Additionally, check that BFQ queues are empty before these are freed. Cc: Jan Kara Cc: Yu Kuai Change-Id: I566e972e4c9c5c3e8bb256e6be39f5bb6bec7256 Signed-off-by: Bart Van Assche Link: https://lore.kernel.org/r/20230516223853.1385255-1-bvanassche@acm.org Signed-off-by: Jens Axboe Bug: 275581839 (cherry picked from commit 3e49c1e4a6152b6ad758a28ecce8fb470f46f6ed https://git.kernel.dk/cgit/linux/) [ bvanassche: backported to kernel v5.15 ] Signed-off-by: Bart Van Assche --- block/bfq-iosched.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c index e5fc6d16f329..178f115eaca7 100644 --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -5197,6 +5197,10 @@ void bfq_put_queue(struct bfq_queue *bfqq) if (bfqq->bfqd && bfqq->bfqd->last_completed_rq_bfqq == bfqq) bfqq->bfqd->last_completed_rq_bfqq = NULL; + WARN_ON_ONCE(!list_empty(&bfqq->fifo)); + WARN_ON_ONCE(!RB_EMPTY_ROOT(&bfqq->sort_list)); + WARN_ON_ONCE(bfqq->dispatched); + kmem_cache_free(bfq_pool, bfqq); bfqg_and_blkg_put(bfqg); } @@ -6896,6 +6900,8 @@ static void bfq_exit_queue(struct elevator_queue *e) bfq_deactivate_bfqq(bfqd, bfqq, false, false); spin_unlock_irq(&bfqd->lock); + WARN_ON_ONCE(bfqd->rq_in_driver); + hrtimer_cancel(&bfqd->idle_slice_timer); /* release oom-queue reference to root group */