Skip to contentSkip to conversation

blk-cgroup: fix rcu lockdep warning in blkg_lookup()

PATCH Applied Ming Lei 4 participants 7 messages Dec 19, 2023 – Jan 4, 2024 Block layer

lore
Share & tools
lore

Ming Lei

author
#0 lore raw

PATCH 1/1 blk-cgroup: fix rcu lockdep warning in blkg_lookup()

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().

---
 block/blk-cgroup.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
block/blk-cgroup.h +2 -1
index fd482439afbc..b927a4a0ad03 100644
@@ -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;
 
Signature · 1 line
2.42.0
author
#1 lore raw
Quoted 20 lines · Ming Lei

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().

---
 block/blk-cgroup.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
block/blk-cgroup.h +0 -0
index fd482439afbc..b927a4a0ad03 100644

block/blk-cgroup.h static inline struct blkcg_gq *blkg_lookup(struct blkcg *blkcg, · line 258

Quoted 8 lines
block/blk-cgroup.h +2 -1
@@ -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;

Hello,

Ping...

Thanks,

Acked-by
#2 lore raw
Quoted 7 lines · Ming Lei
Quoted 6 lines · Ming Lei

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.

Quoted 5 lines
Quoted 5 lines

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

Thanks.

Signature · 1 line
tejun
#3 lore raw
In reply to Ming Lei

Hi,

Quoted 19 lines · Ming Lei

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().

---
  block/blk-cgroup.h | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
block/blk-cgroup.h +0 -0
index fd482439afbc..b927a4a0ad03 100644

block/blk-cgroup.h static inline struct blkcg_gq *blkg_lookup(struct blkcg *blkcg, · line 256

Quoted 6 lines
block/blk-cgroup.h +2 -1
@@ -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));

This patch itself is correct, and in fact this is a false positive warning.

I noticed that commit 83462a6c971c ("blkcg: Drop unnecessary RCU read [un]locks from blkg_conf_prep/finish()") drop rcu_read_lock/unlock() because 'queue_lock' is held. This is correct, however you add this back for tg_conf_updated() later in commit 27b13e209ddc ("blk-throttle: fix lockdep warning of "cgroup_mutex or RCU read lock required!"") because rcu_read_lock_held() from blkg_lookup() is triggered. And this patch is again another use case cased by commit 83462a6c971c.

I just wonder, with the respect of rcu implementation, is it possible to add preemptible() check directly in rcu_read_lock_held() to bypass all this kind of false positive warning?

Thanks,
Kuai

Quoted 4 lines
block/blk-cgroup.h +0 -0
  	if (blkg && blkg->q == q)
  		return blkg;
 
author
#4 lore raw
Quoted 17 lines · Yu Kuai

Hi,

Quoted 14 lines · Ming Lei

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().

---
  block/blk-cgroup.h | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 13 lines

block/blk-cgroup.h static inline struct blkcg_gq *blkg_lookup(struct blkcg *blkcg, · line 255

Quoted 10 lines
block/blk-cgroup.h +2 -1
index fd482439afbc..b927a4a0ad03 100644
@@ -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));

This patch itself is correct, and in fact this is a false positive warning.

Yeah, it is, but we always teach lockdep to not trigger warning,

Quoted 8 lines

I noticed that commit 83462a6c971c ("blkcg: Drop unnecessary RCU read [un]locks from blkg_conf_prep/finish()") drop rcu_read_lock/unlock() because 'queue_lock' is held. This is correct, however you add this back for tg_conf_updated() later in commit 27b13e209ddc ("blk-throttle: fix lockdep warning of "cgroup_mutex or RCU read lock required!"") because rcu_read_lock_held() from blkg_lookup() is triggered. And this patch is again another use case cased by commit 83462a6c971c.

We should add:

Fixes 83462a6c971c ("blkcg: Drop unnecessary RCU read [un]locks from blkg_conf_prep/finish()")
Quoted 4 lines

I just wonder, with the respect of rcu implementation, is it possible to add preemptible() check directly in rcu_read_lock_held() to bypass all this kind of false positive warning?

It isn't related with rcu_read_lock_held(), and the check is done in RCU_LOCKDEP_WARN(). rcu_dereference_check() does cover this situation, and no need to invent wheel for avoiding the warning.

Thanks,
Ming

Reviewed-by
#5 lore raw
Quoted 43 lines · Ming Lei
Quoted 17 lines · Yu Kuai

Hi,

Quoted 14 lines · Ming Lei

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().

---
   block/blk-cgroup.h | 3 ++-
   1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 13 lines

block/blk-cgroup.h static inline struct blkcg_gq *blkg_lookup(struct blkcg *blkcg, · line 255

Quoted 10 lines
block/blk-cgroup.h +2 -1
index fd482439afbc..b927a4a0ad03 100644
@@ -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));

This patch itself is correct, and in fact this is a false positive warning.

Yeah, it is, but we always teach lockdep to not trigger warning,

Quoted 8 lines

I noticed that commit 83462a6c971c ("blkcg: Drop unnecessary RCU read [un]locks from blkg_conf_prep/finish()") drop rcu_read_lock/unlock() because 'queue_lock' is held. This is correct, however you add this back for tg_conf_updated() later in commit 27b13e209ddc ("blk-throttle: fix lockdep warning of "cgroup_mutex or RCU read lock required!"") because rcu_read_lock_held() from blkg_lookup() is triggered. And this patch is again another use case cased by commit 83462a6c971c.

Quoted 3 lines

We should add:

Fixes 83462a6c971c ("blkcg: Drop unnecessary RCU read [un]locks from blkg_conf_prep/finish()")

With the above fix tag,

Quoted 16 lines
Quoted 5 lines

I just wonder, with the respect of rcu implementation, is it possible to add preemptible() check directly in rcu_read_lock_held() to bypass all this kind of false positive warning?

It isn't related with rcu_read_lock_held(), and the check is done in RCU_LOCKDEP_WARN(). rcu_dereference_check() does cover this situation, and no need to invent wheel for avoiding the warning.

Thanks,
Ming

.

maintainer Applied
#6 lore raw
In reply to Ming Lei
Quoted 9 lines · Ming Lei

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().

[...]

Applied, thanks!

[1/1] blk-cgroup: fix rcu lockdep warning in blkg_lookup()

      commit: 393cd8ffd832f23eec3a105553eff622e8198918

Best regards,

Signature · 1 line
Jens Axboe