Skip to contentSkip to conversation

blk-cgroup: use GFP_NOIO for radix tree preload in blkg_conf_prep

PATCH In review Tao Yu 2 participants 2 messages Aug 31

Subsystems (4)
lore
Share & tools
lore

Tao Yu

author
#0 lore raw

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.

Reported-by [email protected]
Fixes f255c19b3ab46 ("blk-cgroup: Pre-allocate tree node on blkg_conf_prep")
---
 block/blk-cgroup.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
block/blk-cgroup.c +2 -2
index 2b5c29434e426..27e00180e4cc1 100644
@@ -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
#1 lore raw

Hi,

Quoted 19 lines · Tao Yu

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.

Quoted 6 lines
Reported-by [email protected]
Fixes f255c19b3ab46 ("blk-cgroup: Pre-allocate tree node on blkg_conf_prep")

---

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
index 2b5c29434e426..27e00180e4cc1 100644
@@ -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