]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
blk-cgroup: don't nest queue_lock under blkcg->lock in blkcg_destroy_blkgs()
authorYu Kuai <yukuai@fygo.io>
Mon, 8 Jun 2026 03:42:47 +0000 (11:42 +0800)
committerJens Axboe <axboe@kernel.dk>
Wed, 24 Jun 2026 12:42:31 +0000 (06:42 -0600)
commit4cfd7c1cff8f4c863b99d420cdbe0563802a9e80
tree057aa4154351ec20f4ac20d22092eddba5ae9632
parent457d3c4f0fdd6cf8a4bd8115bf470809984a9f02
blk-cgroup: don't nest queue_lock under blkcg->lock in blkcg_destroy_blkgs()

The correct lock order is q->queue_lock before blkcg->lock, and in order
to prevent deadlock from blkcg_destroy_blkgs(), trylock is used for
q->queue_lock while blkcg->lock is already held, this is hacky.

Refactor blkcg_destroy_blkgs() to hold blkcg->lock only long enough to
get the first blkg and then release it. Then take q->queue_lock and
blkcg->lock in the correct order to destroy the blkg. This is a very cold
path, so the extra lock/unlock cycles are acceptable.

Also prepare to convert protecting blkcg with blkcg_mutex instead of
queue_lock.

Signed-off-by: Yu Kuai <yukuai@fygo.io>
Link: https://patch.msgid.link/00b03cf74a9937cb4d6dd67a189ddc00a3de0451.1780621988.git.yukuai@fygo.io
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-cgroup.c