From: Akinobu Mita Date: Sat, 26 Sep 2015 17:09:19 +0000 (+0900) Subject: blk-mq: avoid setting hctx->tags->cpumask before allocation X-Git-Tag: v4.2.4~5 X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5781175fab1a2c8b0339644fb27d64bf24c9fda4;p=linux blk-mq: avoid setting hctx->tags->cpumask before allocation commit 1356aae08338f1c19ce1c67bf8c543a267688fc3 upstream. When unmapped hw queue is remapped after CPU topology is changed, hctx->tags->cpumask has to be set after hctx->tags is setup in blk_mq_map_swqueue(), otherwise it causes null pointer dereference. Fixes: f26cdc8536 ("blk-mq: Shared tag enhancements") Signed-off-by: Akinobu Mita Cc: Keith Busch Cc: Ming Lei Reviewed-by: Christoph Hellwig Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- diff --git a/block/blk-mq.c b/block/blk-mq.c index 176262ec3731..c69902695136 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -1807,7 +1807,6 @@ static void blk_mq_map_swqueue(struct request_queue *q) hctx = q->mq_ops->map_queue(q, i); cpumask_set_cpu(i, hctx->cpumask); - cpumask_set_cpu(i, hctx->tags->cpumask); ctx->index_hw = hctx->nr_ctx; hctx->ctxs[hctx->nr_ctx++] = ctx; } @@ -1847,6 +1846,14 @@ static void blk_mq_map_swqueue(struct request_queue *q) hctx->next_cpu = cpumask_first(hctx->cpumask); hctx->next_cpu_batch = BLK_MQ_CPU_WORK_BATCH; } + + queue_for_each_ctx(q, ctx, i) { + if (!cpu_online(i)) + continue; + + hctx = q->mq_ops->map_queue(q, i); + cpumask_set_cpu(i, hctx->tags->cpumask); + } } static void blk_mq_update_tag_set_depth(struct blk_mq_tag_set *set)