Commit bf0beec0607d ("blk-mq: drain I/O when all CPUs in a hctx are offline") prevents new request from being allocated on hctx which is going to be inactive, meantime drains all in-queue requests. We needn't to prevent driver tag from being allocated during cpu hotplug, more importantly we have to provide driver tag for requests, so that the cpu hotplug handling can move on. blk_mq_get_tag() is shared for allocating both internal tag and drive tag, so driver tag allocation may fail because the hctx is marked as inactive. Fix the issue by moving BLK_MQ_S_INACTIVE check to __blk_mq_alloc_request(). Cc: Dongli Zhang <dongli.zhang@xxxxxxxxxx> Cc: John Garry <john.garry@xxxxxxxxxx> Cc: Christoph Hellwig <hch@xxxxxx> Cc: Hannes Reinecke <hare@xxxxxxx> Cc: Daniel Wagner <dwagner@xxxxxxx> Fixes: bf0beec0607d ("blk-mq: drain I/O when all CPUs in a hctx are offline") Signed-off-by: Ming Lei <ming.lei@xxxxxxxxxx> --- block/blk-mq-tag.c | 8 -------- block/blk-mq.c | 27 ++++++++++++++++++++------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/block/blk-mq-tag.c b/block/blk-mq-tag.c index 96a39d0724a2..762198b62088 100644 --- a/block/blk-mq-tag.c +++ b/block/blk-mq-tag.c @@ -180,14 +180,6 @@ unsigned int blk_mq_get_tag(struct blk_mq_alloc_data *data) sbitmap_finish_wait(bt, ws, &wait); found_tag: - /* - * Give up this allocation if the hctx is inactive. The caller will - * retry on an active hctx. - */ - if (unlikely(test_bit(BLK_MQ_S_INACTIVE, &data->hctx->state))) { - blk_mq_put_tag(tags, data->ctx, tag + tag_offset); - return BLK_MQ_NO_TAG; - } return tag + tag_offset; } diff --git a/block/blk-mq.c b/block/blk-mq.c index a98a19353461..c5acf4858abf 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -347,6 +347,24 @@ static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data, return rq; } +static inline unsigned int blk_mq_get_request_tag( + struct blk_mq_alloc_data *data) +{ + /* + * Waiting allocations only fail because of an inactive hctx. In that + * case just retry the hctx assignment and tag allocation as CPU hotplug + * should have migrated us to an online CPU by now. + */ + int tag = blk_mq_get_tag(data); + if (unlikely(test_bit(BLK_MQ_S_INACTIVE, &data->hctx->state) && + tag != BLK_MQ_NO_TAG)) { + blk_mq_put_tag(blk_mq_tags_from_data(data), data->ctx, tag); + tag = BLK_MQ_NO_TAG; + } + + return tag; +} + static struct request *__blk_mq_alloc_request(struct blk_mq_alloc_data *data) { struct request_queue *q = data->q; @@ -381,12 +399,7 @@ static struct request *__blk_mq_alloc_request(struct blk_mq_alloc_data *data) if (!(data->flags & BLK_MQ_REQ_INTERNAL)) blk_mq_tag_busy(data->hctx); - /* - * Waiting allocations only fail because of an inactive hctx. In that - * case just retry the hctx assignment and tag allocation as CPU hotplug - * should have migrated us to an online CPU by now. - */ - tag = blk_mq_get_tag(data); + tag = blk_mq_get_request_tag(data); if (tag == BLK_MQ_NO_TAG) { if (data->flags & BLK_MQ_REQ_NOWAIT) return NULL; @@ -480,7 +493,7 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q, blk_mq_tag_busy(data.hctx); ret = -EWOULDBLOCK; - tag = blk_mq_get_tag(&data); + tag = blk_mq_get_request_tag(&data); if (tag == BLK_MQ_NO_TAG) goto out_queue_exit; return blk_mq_rq_ctx_init(&data, tag, alloc_time_ns); -- 2.25.2