forked from Minki/linux
blk-mq: make blk_mq_alloc_request_hctx() allocate a scheduler request
blk_mq_alloc_request_hctx() allocates a driver request directly, unlike its blk_mq_alloc_request() counterpart. It also crashes because it doesn't update the tags->rqs map. Fix it by making it allocate a scheduler request. Reported-by: Sagi Grimberg <sagi@grimberg.me> Signed-off-by: Omar Sandoval <osandov@fb.com> Signed-off-by: Jens Axboe <axboe@fb.com> Tested-by: Sagi Grimberg <sagi@grimberg.me>
This commit is contained in:
parent
415b806de5
commit
6d2809d51a
@ -110,15 +110,14 @@ struct request *blk_mq_sched_get_request(struct request_queue *q,
|
||||
struct blk_mq_alloc_data *data)
|
||||
{
|
||||
struct elevator_queue *e = q->elevator;
|
||||
struct blk_mq_hw_ctx *hctx;
|
||||
struct blk_mq_ctx *ctx;
|
||||
struct request *rq;
|
||||
|
||||
blk_queue_enter_live(q);
|
||||
ctx = blk_mq_get_ctx(q);
|
||||
hctx = blk_mq_map_queue(q, ctx->cpu);
|
||||
|
||||
blk_mq_set_alloc_data(data, q, data->flags, ctx, hctx);
|
||||
data->q = q;
|
||||
if (likely(!data->ctx))
|
||||
data->ctx = blk_mq_get_ctx(q);
|
||||
if (likely(!data->hctx))
|
||||
data->hctx = blk_mq_map_queue(q, data->ctx->cpu);
|
||||
|
||||
if (e) {
|
||||
data->flags |= BLK_MQ_REQ_INTERNAL;
|
||||
|
@ -273,10 +273,9 @@ EXPORT_SYMBOL(blk_mq_alloc_request);
|
||||
struct request *blk_mq_alloc_request_hctx(struct request_queue *q, int rw,
|
||||
unsigned int flags, unsigned int hctx_idx)
|
||||
{
|
||||
struct blk_mq_hw_ctx *hctx;
|
||||
struct blk_mq_ctx *ctx;
|
||||
struct blk_mq_alloc_data alloc_data = { .flags = flags };
|
||||
struct request *rq;
|
||||
struct blk_mq_alloc_data alloc_data;
|
||||
unsigned int cpu;
|
||||
int ret;
|
||||
|
||||
/*
|
||||
@ -299,25 +298,23 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q, int rw,
|
||||
* Check if the hardware context is actually mapped to anything.
|
||||
* If not tell the caller that it should skip this queue.
|
||||
*/
|
||||
hctx = q->queue_hw_ctx[hctx_idx];
|
||||
if (!blk_mq_hw_queue_mapped(hctx)) {
|
||||
ret = -EXDEV;
|
||||
goto out_queue_exit;
|
||||
alloc_data.hctx = q->queue_hw_ctx[hctx_idx];
|
||||
if (!blk_mq_hw_queue_mapped(alloc_data.hctx)) {
|
||||
blk_queue_exit(q);
|
||||
return ERR_PTR(-EXDEV);
|
||||
}
|
||||
ctx = __blk_mq_get_ctx(q, cpumask_first(hctx->cpumask));
|
||||
cpu = cpumask_first(alloc_data.hctx->cpumask);
|
||||
alloc_data.ctx = __blk_mq_get_ctx(q, cpu);
|
||||
|
||||
blk_mq_set_alloc_data(&alloc_data, q, flags, ctx, hctx);
|
||||
rq = __blk_mq_alloc_request(&alloc_data, rw);
|
||||
if (!rq) {
|
||||
ret = -EWOULDBLOCK;
|
||||
goto out_queue_exit;
|
||||
}
|
||||
rq = blk_mq_sched_get_request(q, NULL, rw, &alloc_data);
|
||||
|
||||
blk_mq_put_ctx(alloc_data.ctx);
|
||||
blk_queue_exit(q);
|
||||
|
||||
if (!rq)
|
||||
return ERR_PTR(-EWOULDBLOCK);
|
||||
|
||||
return rq;
|
||||
|
||||
out_queue_exit:
|
||||
blk_queue_exit(q);
|
||||
return ERR_PTR(ret);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(blk_mq_alloc_request_hctx);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user