Skip to content

Commit 9f00976

Browse files
author
CKI KWF Bot
committed
Merge: blk-cgroup: fix possible deadlock while configuring policy
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/7643 blk-cgroup: fix possible deadlock while configuring policy JIRA: https://issues.redhat.com/browse/RHEL-129939 Signed-off-by: Ming Lei <ming.lei@redhat.com> Approved-by: Jeff Moyer <jmoyer@redhat.com> Approved-by: Ewan D. Milne <emilne@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: CKI GitLab Kmaint Pipeline Bot <26919896-cki-kmaint-pipeline-bot@users.noreply.gitlab.com>
2 parents e605f20 + a3c3969 commit 9f00976

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

block/blk-cgroup.c

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -883,14 +883,8 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
883883
disk = ctx->bdev->bd_disk;
884884
q = disk->queue;
885885

886-
/*
887-
* blkcg_deactivate_policy() requires queue to be frozen, we can grab
888-
* q_usage_counter to prevent concurrent with blkcg_deactivate_policy().
889-
*/
890-
ret = blk_queue_enter(q, 0);
891-
if (ret)
892-
goto fail;
893-
886+
/* Prevent concurrent with blkcg_deactivate_policy() */
887+
mutex_lock(&q->blkcg_mutex);
894888
spin_lock_irq(&q->queue_lock);
895889

896890
if (!blkcg_policy_enabled(q, pol)) {
@@ -920,16 +914,16 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
920914
/* Drop locks to do new blkg allocation with GFP_KERNEL. */
921915
spin_unlock_irq(&q->queue_lock);
922916

923-
new_blkg = blkg_alloc(pos, disk, GFP_KERNEL);
917+
new_blkg = blkg_alloc(pos, disk, GFP_NOIO);
924918
if (unlikely(!new_blkg)) {
925919
ret = -ENOMEM;
926-
goto fail_exit_queue;
920+
goto fail_exit;
927921
}
928922

929923
if (radix_tree_preload(GFP_KERNEL)) {
930924
blkg_free(new_blkg);
931925
ret = -ENOMEM;
932-
goto fail_exit_queue;
926+
goto fail_exit;
933927
}
934928

935929
spin_lock_irq(&q->queue_lock);
@@ -957,17 +951,16 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
957951
goto success;
958952
}
959953
success:
960-
blk_queue_exit(q);
954+
mutex_unlock(&q->blkcg_mutex);
961955
ctx->blkg = blkg;
962956
return 0;
963957

964958
fail_preloaded:
965959
radix_tree_preload_end();
966960
fail_unlock:
967961
spin_unlock_irq(&q->queue_lock);
968-
fail_exit_queue:
969-
blk_queue_exit(q);
970-
fail:
962+
fail_exit:
963+
mutex_unlock(&q->blkcg_mutex);
971964
/*
972965
* If queue was bypassing, we should retry. Do so after a
973966
* short msleep(). It isn't strictly necessary but queue

0 commit comments

Comments
 (0)