summaryrefslogtreecommitdiffstats
path: root/block/blk-mq.c
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2016-03-19 06:30:33 -0400
committerJens Axboe <axboe@fb.com>2016-03-20 11:34:02 -0400
commit897bb0c7f1ea82d7cc882b19790b5e1df00ffc29 (patch)
tree97b9ef1ba99b9c0f76ca57e398a55fa124ec3f7e /block/blk-mq.c
parent5173cb814b36439a9d9537016965e75798b9f130 (diff)
blk-mq: Use proper cpumask iterator
queue_for_each_ctx() iterates over per_cpu variables under the assumption that the possible cpu mask cannot have holes. That's wrong as all cpumasks can have holes. In case there are holes the iteration ends up accessing uninitialized memory and crashing as a result. Replace the macro by a proper for_each_possible_cpu() loop and drop the unused macro blk_ctx_sum() which references queue_for_each_ctx(). Reported-by: Xiong Zhou <jencce.kernel@gmail.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'block/blk-mq.c')
-rw-r--r--block/blk-mq.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/block/blk-mq.c b/block/blk-mq.c
index 050f7a13021b..1699baf39b78 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1798,11 +1798,12 @@ static void blk_mq_map_swqueue(struct request_queue *q,
1798 /* 1798 /*
1799 * Map software to hardware queues 1799 * Map software to hardware queues
1800 */ 1800 */
1801 queue_for_each_ctx(q, ctx, i) { 1801 for_each_possible_cpu(i) {
1802 /* If the cpu isn't online, the cpu is mapped to first hctx */ 1802 /* If the cpu isn't online, the cpu is mapped to first hctx */
1803 if (!cpumask_test_cpu(i, online_mask)) 1803 if (!cpumask_test_cpu(i, online_mask))
1804 continue; 1804 continue;
1805 1805
1806 ctx = per_cpu_ptr(q->queue_ctx, i);
1806 hctx = q->mq_ops->map_queue(q, i); 1807 hctx = q->mq_ops->map_queue(q, i);
1807 1808
1808 cpumask_set_cpu(i, hctx->cpumask); 1809 cpumask_set_cpu(i, hctx->cpumask);