blk-cgroup: fix rcu lockdep warning in blkg_lookup()
authorMing Lei <ming.lei@redhat.com>
Tue, 19 Dec 2023 01:28:33 +0000 (09:28 +0800)
committerJens Axboe <axboe@kernel.dk>
Thu, 4 Jan 2024 23:08:54 +0000 (16:08 -0700)
blkg_lookup() is called with either queue_lock or rcu read lock, so
use rcu_dereference_check(lockdep_is_held(&q->queue_lock)) for
retrieving 'blkg', which way models the check exactly for covering
queue lock or rcu read lock.

Fix lockdep warning of "block/blk-cgroup.h:254 suspicious rcu_dereference_check() usage!"
from blkg_lookup().

Tested-by: Changhui Zhong <czhong@redhat.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Reviewed-by: Yu Kuai <yukuai3@huawei.com>
Fixes: 83462a6c971c ("blkcg: Drop unnecessary RCU read [un]locks from blkg_conf_prep/finish()")
Acked-by: Tejun Heo <tj@kernel.org>
Link: https://lore.kernel.org/r/20231219012833.2129540-1-ming.lei@redhat.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-cgroup.h

index fd482439afbc9aa810471db434217dcb5e06c296..b927a4a0ad0301db43a6aad657c49c67f4cb880b 100644 (file)
@@ -252,7 +252,8 @@ static inline struct blkcg_gq *blkg_lookup(struct blkcg *blkcg,
        if (blkcg == &blkcg_root)
                return q->root_blkg;
 
-       blkg = rcu_dereference(blkcg->blkg_hint);
+       blkg = rcu_dereference_check(blkcg->blkg_hint,
+                       lockdep_is_held(&q->queue_lock));
        if (blkg && blkg->q == q)
                return blkg;