* [PATCH] blk-cgroup: fix rcu lockdep warning in blkg_lookup()
@ 2023-12-19 1:28 Ming Lei
2024-01-02 7:38 ` Ming Lei
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Ming Lei @ 2023-12-19 1:28 UTC (permalink / raw)
To: Jens Axboe; +Cc: linux-block, Ming Lei, Changhui Zhong
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>
---
block/blk-cgroup.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/block/blk-cgroup.h b/block/blk-cgroup.h
index fd482439afbc..b927a4a0ad03 100644
--- a/block/blk-cgroup.h
+++ b/block/blk-cgroup.h
@@ -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;
--
2.42.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH] blk-cgroup: fix rcu lockdep warning in blkg_lookup() 2023-12-19 1:28 [PATCH] blk-cgroup: fix rcu lockdep warning in blkg_lookup() Ming Lei @ 2024-01-02 7:38 ` Ming Lei 2024-01-04 22:04 ` Tejun Heo 2024-01-02 10:32 ` Yu Kuai 2024-01-04 23:10 ` Jens Axboe 2 siblings, 1 reply; 7+ messages in thread From: Ming Lei @ 2024-01-02 7:38 UTC (permalink / raw) To: Jens Axboe; +Cc: linux-block, Changhui Zhong, tj On Tue, Dec 19, 2023 at 9:28 AM Ming Lei <ming.lei@redhat.com> wrote: > > 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> > --- > block/blk-cgroup.h | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/block/blk-cgroup.h b/block/blk-cgroup.h > index fd482439afbc..b927a4a0ad03 100644 > --- a/block/blk-cgroup.h > +++ b/block/blk-cgroup.h > @@ -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, ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] blk-cgroup: fix rcu lockdep warning in blkg_lookup() 2024-01-02 7:38 ` Ming Lei @ 2024-01-04 22:04 ` Tejun Heo 0 siblings, 0 replies; 7+ messages in thread From: Tejun Heo @ 2024-01-04 22:04 UTC (permalink / raw) To: Ming Lei; +Cc: Jens Axboe, linux-block, Changhui Zhong On Tue, Jan 02, 2024 at 03:38:10PM +0800, Ming Lei wrote: > On Tue, Dec 19, 2023 at 9:28 AM Ming Lei <ming.lei@redhat.com> wrote: > > > > 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> Acked-by: Tejun Heo <tj@kernel.org> Thanks. -- tejun ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] blk-cgroup: fix rcu lockdep warning in blkg_lookup() 2023-12-19 1:28 [PATCH] blk-cgroup: fix rcu lockdep warning in blkg_lookup() Ming Lei 2024-01-02 7:38 ` Ming Lei @ 2024-01-02 10:32 ` Yu Kuai 2024-01-02 11:27 ` Ming Lei 2024-01-04 23:10 ` Jens Axboe 2 siblings, 1 reply; 7+ messages in thread From: Yu Kuai @ 2024-01-02 10:32 UTC (permalink / raw) To: Ming Lei, Jens Axboe; +Cc: linux-block, Changhui Zhong, yukuai (C) Hi, 在 2023/12/19 9:28, 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(). > > Tested-by: Changhui Zhong <czhong@redhat.com> > Signed-off-by: Ming Lei <ming.lei@redhat.com> > --- > block/blk-cgroup.h | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/block/blk-cgroup.h b/block/blk-cgroup.h > index fd482439afbc..b927a4a0ad03 100644 > --- a/block/blk-cgroup.h > +++ b/block/blk-cgroup.h > @@ -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 > if (blkg && blkg->q == q) > return blkg; > > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] blk-cgroup: fix rcu lockdep warning in blkg_lookup() 2024-01-02 10:32 ` Yu Kuai @ 2024-01-02 11:27 ` Ming Lei 2024-01-03 1:05 ` Yu Kuai 0 siblings, 1 reply; 7+ messages in thread From: Ming Lei @ 2024-01-02 11:27 UTC (permalink / raw) To: Yu Kuai; +Cc: Jens Axboe, linux-block, Changhui Zhong, yukuai (C) On Tue, Jan 02, 2024 at 06:32:13PM +0800, Yu Kuai wrote: > Hi, > > 在 2023/12/19 9:28, 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(). > > > > Tested-by: Changhui Zhong <czhong@redhat.com> > > Signed-off-by: Ming Lei <ming.lei@redhat.com> > > --- > > block/blk-cgroup.h | 3 ++- > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > diff --git a/block/blk-cgroup.h b/block/blk-cgroup.h > > index fd482439afbc..b927a4a0ad03 100644 > > --- a/block/blk-cgroup.h > > +++ b/block/blk-cgroup.h > > @@ -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, > > 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()") > > 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 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] blk-cgroup: fix rcu lockdep warning in blkg_lookup() 2024-01-02 11:27 ` Ming Lei @ 2024-01-03 1:05 ` Yu Kuai 0 siblings, 0 replies; 7+ messages in thread From: Yu Kuai @ 2024-01-03 1:05 UTC (permalink / raw) To: Ming Lei, Yu Kuai; +Cc: Jens Axboe, linux-block, Changhui Zhong, yukuai (C) 在 2024/01/02 19:27, Ming Lei 写道: > On Tue, Jan 02, 2024 at 06:32:13PM +0800, Yu Kuai wrote: >> Hi, >> >> 在 2023/12/19 9:28, 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(). >>> >>> Tested-by: Changhui Zhong <czhong@redhat.com> >>> Signed-off-by: Ming Lei <ming.lei@redhat.com> >>> --- >>> block/blk-cgroup.h | 3 ++- >>> 1 file changed, 2 insertions(+), 1 deletion(-) >>> >>> diff --git a/block/blk-cgroup.h b/block/blk-cgroup.h >>> index fd482439afbc..b927a4a0ad03 100644 >>> --- a/block/blk-cgroup.h >>> +++ b/block/blk-cgroup.h >>> @@ -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, > >> >> 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()") With the above fix tag, Reviewed-by: Yu Kuai <yukuai3@huawei.com> > >> >> 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 > > > . > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] blk-cgroup: fix rcu lockdep warning in blkg_lookup() 2023-12-19 1:28 [PATCH] blk-cgroup: fix rcu lockdep warning in blkg_lookup() Ming Lei 2024-01-02 7:38 ` Ming Lei 2024-01-02 10:32 ` Yu Kuai @ 2024-01-04 23:10 ` Jens Axboe 2 siblings, 0 replies; 7+ messages in thread From: Jens Axboe @ 2024-01-04 23:10 UTC (permalink / raw) To: Ming Lei; +Cc: linux-block, Changhui Zhong On Tue, 19 Dec 2023 09:28:33 +0800, Ming Lei wrote: > 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, -- Jens Axboe ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-01-04 23:10 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-12-19 1:28 [PATCH] blk-cgroup: fix rcu lockdep warning in blkg_lookup() Ming Lei 2024-01-02 7:38 ` Ming Lei 2024-01-04 22:04 ` Tejun Heo 2024-01-02 10:32 ` Yu Kuai 2024-01-02 11:27 ` Ming Lei 2024-01-03 1:05 ` Yu Kuai 2024-01-04 23:10 ` Jens Axboe
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox