Skip to content

Commit dcf6e2e

Browse files
zdhaysstorulf
authored andcommitted
mmc: block: handle complete_work on separate workqueue
The kblockd workqueue is created with the WQ_MEM_RECLAIM flag set. This generates a rescuer thread for that queue that will trigger when the CPU is under heavy load and collect the uncompleted work. In the case of mmc, this creates the possibility of a deadlock when there are multiple partitions on the device as other blk-mq work is also run on the same queue. For example: - worker 0 claims the mmc host to work on partition 1 - worker 1 attempts to claim the host for partition 2 but has to wait for worker 0 to finish - worker 0 schedules complete_work to release the host - rescuer thread is triggered after time-out and collects the dangling work - rescuer thread attempts to complete the work in order starting with claim host - the task to release host is now blocked by a task to claim it and will never be called The above results in multiple hung tasks that lead to failures to mount partitions. Handling complete_work on a separate workqueue avoids this by keeping the work completion tasks separate from the other blk-mq work. This allows the host to be released without getting blocked by other tasks attempting to claim the host. Signed-off-by: Zachary Hays <zhays@lexmark.com> Fixes: 8119697 ("mmc: block: Add blk-mq support") Cc: <stable@vger.kernel.org> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent d6f11e7 commit dcf6e2e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

drivers/mmc/core/block.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2112,7 +2112,7 @@ static void mmc_blk_mq_req_done(struct mmc_request *mrq)
21122112
if (waiting)
21132113
wake_up(&mq->wait);
21142114
else
2115-
kblockd_schedule_work(&mq->complete_work);
2115+
queue_work(mq->card->complete_wq, &mq->complete_work);
21162116

21172117
return;
21182118
}
@@ -2924,6 +2924,13 @@ static int mmc_blk_probe(struct mmc_card *card)
29242924

29252925
mmc_fixup_device(card, mmc_blk_fixups);
29262926

2927+
card->complete_wq = alloc_workqueue("mmc_complete",
2928+
WQ_MEM_RECLAIM | WQ_HIGHPRI, 0);
2929+
if (unlikely(!card->complete_wq)) {
2930+
pr_err("Failed to create mmc completion workqueue");
2931+
return -ENOMEM;
2932+
}
2933+
29272934
md = mmc_blk_alloc(card);
29282935
if (IS_ERR(md))
29292936
return PTR_ERR(md);
@@ -2987,6 +2994,7 @@ static void mmc_blk_remove(struct mmc_card *card)
29872994
pm_runtime_put_noidle(&card->dev);
29882995
mmc_blk_remove_req(md);
29892996
dev_set_drvdata(&card->dev, NULL);
2997+
destroy_workqueue(card->complete_wq);
29902998
}
29912999

29923000
static int _mmc_blk_suspend(struct mmc_card *card)

include/linux/mmc/card.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ struct mmc_card {
308308
unsigned int nr_parts;
309309

310310
unsigned int bouncesz; /* Bounce buffer size */
311+
struct workqueue_struct *complete_wq; /* Private workqueue */
311312
};
312313

313314
static inline bool mmc_large_sector(struct mmc_card *card)

0 commit comments

Comments
 (0)