All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] null_blk: mem garbage on NUMA systems during init
@ 2013-12-10 15:50 Matias Bjorling
  2013-12-15 20:17 ` Linus Torvalds
  0 siblings, 1 reply; 3+ messages in thread
From: Matias Bjorling @ 2013-12-10 15:50 UTC (permalink / raw)
  To: axboe; +Cc: linux-kernel, Matias Bjorling

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 <m@bjorling.me>
---
 drivers/block/null_blk.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
index ea192ec..f370fc1 100644
--- a/drivers/block/null_blk.c
+++ b/drivers/block/null_blk.c
@@ -495,23 +495,23 @@ static int null_add_dev(void)
 
 	spin_lock_init(&nullb->lock);
 
+	if (queue_mode == NULL_Q_MQ && use_per_node_hctx)
+		submit_queues = nr_online_nodes;
+
 	if (setup_queues(nullb))
 		goto err;
 
 	if (queue_mode == NULL_Q_MQ) {
 		null_mq_reg.numa_node = home_node;
 		null_mq_reg.queue_depth = hw_queue_depth;
+		null_mq_reg.nr_hw_queues = submit_queues;
 
 		if (use_per_node_hctx) {
 			null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
 			null_mq_reg.ops->free_hctx = null_free_hctx;
-
-			null_mq_reg.nr_hw_queues = nr_online_nodes;
 		} else {
 			null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
 			null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
-
-			null_mq_reg.nr_hw_queues = submit_queues;
 		}
 
 		nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] null_blk: mem garbage on NUMA systems during init
  2013-12-10 15:50 [PATCH] null_blk: mem garbage on NUMA systems during init Matias Bjorling
@ 2013-12-15 20:17 ` Linus Torvalds
  2013-12-15 20:32   ` Jens Axboe
  0 siblings, 1 reply; 3+ messages in thread
From: Linus Torvalds @ 2013-12-15 20:17 UTC (permalink / raw)
  To: Matias Bjorling; +Cc: Jens Axboe, Linux Kernel Mailing List

Jens, ping?

Patch looks fine, and it looks completely bogus to set

     null_mq_reg.nr_hw_queues

to 'nr_online_nodes', when we've potentially done "setup_queues()"
with just a single queue.

So I'm going to apply this as-is, I'm just wondering why I haven't
heard anything from you..

                     Linus


On Tue, Dec 10, 2013 at 7:50 AM, Matias Bjorling <m@bjorling.me> wrote:
> 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 <m@bjorling.me>
> ---
>  drivers/block/null_blk.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
> index ea192ec..f370fc1 100644
> --- a/drivers/block/null_blk.c
> +++ b/drivers/block/null_blk.c
> @@ -495,23 +495,23 @@ static int null_add_dev(void)
>
>         spin_lock_init(&nullb->lock);
>
> +       if (queue_mode == NULL_Q_MQ && use_per_node_hctx)
> +               submit_queues = nr_online_nodes;
> +
>         if (setup_queues(nullb))
>                 goto err;
>
>         if (queue_mode == NULL_Q_MQ) {
>                 null_mq_reg.numa_node = home_node;
>                 null_mq_reg.queue_depth = hw_queue_depth;
> +               null_mq_reg.nr_hw_queues = submit_queues;
>
>                 if (use_per_node_hctx) {
>                         null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
>                         null_mq_reg.ops->free_hctx = null_free_hctx;
> -
> -                       null_mq_reg.nr_hw_queues = nr_online_nodes;
>                 } else {
>                         null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
>                         null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
> -
> -                       null_mq_reg.nr_hw_queues = submit_queues;
>                 }
>
>                 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
> --
> 1.8.3.2
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] null_blk: mem garbage on NUMA systems during init
  2013-12-15 20:17 ` Linus Torvalds
@ 2013-12-15 20:32   ` Jens Axboe
  0 siblings, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2013-12-15 20:32 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Matias Bjorling, Linux Kernel Mailing List

On Sun, Dec 15 2013, Linus Torvalds wrote:
> Jens, ping?
> 
> Patch looks fine, and it looks completely bogus to set
> 
>      null_mq_reg.nr_hw_queues
> 
> to 'nr_online_nodes', when we've potentially done "setup_queues()"
> with just a single queue.
> 
> So I'm going to apply this as-is, I'm just wondering why I haven't
> heard anything from you..

Sorry, I talked with Matias on IM about it, hence no lkml reference to
it. It is queued up. You can apply as-is too, that's fine too.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-12-15 20:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-10 15:50 [PATCH] null_blk: mem garbage on NUMA systems during init Matias Bjorling
2013-12-15 20:17 ` Linus Torvalds
2013-12-15 20:32   ` Jens Axboe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.