Skip to content

Commit 57053d8

Browse files
MatiasBjorlingtorvalds
authored andcommitted
null_blk: mem garbage on NUMA systems during init
For NUMA systems, initializing the blk-mq layer and using per node hctx. We initialize submit queues to 1, while blk-mq nr_hw_queues is initialized to the number of NUMA nodes. This makes the null_init_hctx function overwrite memory outside of what it allocated. In my case it lead to writing garbage into struct request_queue's mq_map. Signed-off-by: Matias Bjorling <[email protected]> Cc: Jens Axboe <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent e4158f1 commit 57053d8

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/block/null_blk.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,23 +495,23 @@ static int null_add_dev(void)
495495

496496
spin_lock_init(&nullb->lock);
497497

498+
if (queue_mode == NULL_Q_MQ && use_per_node_hctx)
499+
submit_queues = nr_online_nodes;
500+
498501
if (setup_queues(nullb))
499502
goto err;
500503

501504
if (queue_mode == NULL_Q_MQ) {
502505
null_mq_reg.numa_node = home_node;
503506
null_mq_reg.queue_depth = hw_queue_depth;
507+
null_mq_reg.nr_hw_queues = submit_queues;
504508

505509
if (use_per_node_hctx) {
506510
null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
507511
null_mq_reg.ops->free_hctx = null_free_hctx;
508-
509-
null_mq_reg.nr_hw_queues = nr_online_nodes;
510512
} else {
511513
null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
512514
null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
513-
514-
null_mq_reg.nr_hw_queues = submit_queues;
515515
}
516516

517517
nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);

0 commit comments

Comments
 (0)