blk-cgroup: use GFP_NOIO for radix tree preload in blkg_conf_prep
Subsystems (4)
PATCH 1/1 blk-cgroup: use GFP_NOIO for radix tree preload in blkg_conf_prep
blkg_conf_prep() allocates a new blkg with GFP_NOIO after dropping queue_lock, but still preloads the radix tree node with GFP_KERNEL while q->blkcg_mutex is held.
GFP_KERNEL may enter direct reclaim and acquire fs_reclaim, which adds the dependency
q->blkcg_mutex -> fs_reclaim
This completes a circular locking dependency with the existing path
fs_reclaim -> q->q_usage_counter -> q->blkcg_mutex
and triggers a lockdep warning when configuring blkcg policies.
Use GFP_NOIO for radix_tree_preload() so that the preload context matches the rest of this allocation path and does not recurse into reclaim while q->blkcg_mutex is held.
--- block/blk-cgroup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
block/blk-cgroup.c +2 -2
@@ -873,7 +873,7 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol, parent =blkcg_parent (parent); } -/* Drop locks to do new blkg allocation with GFP_KERNEL. */ +/* Drop queue_lock to do new blkg allocation with GFP_NOIO. */ spin_unlock_irq (&q->queue_lock); new_blkg =blkg_alloc (pos, disk,GFP_NOIO );
@@ -882,7 +882,7 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol, goto fail_exit; } -if (radix_tree_preload (GFP_KERNEL )) { +if (radix_tree_preload (GFP_NOIO )) {blkg_free (new_blkg); ret = -ENOMEM ; goto fail_exit;
Signature · 1 line
2.34.1
Hi,
Quoted 19 lines · Tao Yu
blkg_conf_prep()allocates a new blkg withGFP_NOIOafter droppingqueue_lock, but still preloads the radix tree node withGFP_KERNELwhileq->blkcg_mutexis held.
GFP_KERNELmay enter direct reclaim and acquirefs_reclaim, which adds the dependencyq->blkcg_mutex -> fs_reclaimThis completes a circular locking dependency with the existing path
fs_reclaim -> q->q_usage_counter -> q->blkcg_mutexand triggers a lockdep warning when configuring blkcg policies.
Use
GFP_NOIOforradix_tree_preload()so that the preload context matches the rest of this allocation path and does not recurse into reclaim whileq->blkcg_mutexis held.
Quoted 6 lines
Reported-by [email protected]Fixes f255c19b3ab46 ("blk-cgroup: Pre-allocate tree node on blkg_conf_prep")Signed-off-by Tao Yu <[email protected]>---
This problem is already fixed by following patch, the radix_tree_preload is removed.
[PATCH 1/3] blk-cgroup: use a request_queue rhashtable for blkg lookup - Yu Kuai
<https://lore.kernel.org/all/[email protected]/>
Quoted 25 lines
block/blk-cgroup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)block/blk-cgroup.c +2
-2@@ -873,7 +873,7 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol, parent =blkcg_parent (parent); } -/* Drop locks to do new blkg allocation with GFP_KERNEL. */ +/* Drop queue_lock to do new blkg allocation with GFP_NOIO. */ spin_unlock_irq (&q->queue_lock); new_blkg =blkg_alloc (pos, disk,GFP_NOIO );@@ -882,7 +882,7 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol, goto fail_exit; } -if (radix_tree_preload (GFP_KERNEL )) { +if (radix_tree_preload (GFP_NOIO )) {blkg_free (new_blkg); ret = -ENOMEM ; goto fail_exit;
Signature · 2 lines
Thanks, Kuai