linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] blk-mq: fix updating tags depth
@ 2018-08-02 10:23 Ming Lei
  2018-08-02 19:27 ` Marco Patalano
  2018-08-02 20:48 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Ming Lei @ 2018-08-02 10:23 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-block, Ming Lei, Marco Patalano, Ewan D. Milne,
	Christoph Hellwig, Bart Van Assche, Omar Sandoval

The passed 'nr' from userspace represents the total depth, meantime
inside 'struct blk_mq_tags', 'nr_tags' stores the total tag depth,
and 'nr_reserved_tags' stores the reserved part.

There are two issues in blk_mq_tag_update_depth() now:

1) for growing tags, we should have used the passed 'nr', and keep the
number of reserved tags not changed.

2) the passed 'nr' should have been used for checking against
'tags->nr_tags', instead of number of the normal part.

This patch fixes the above two cases, and avoids kernel crash caused
by wrong resizing sbitmap queue.

Cc: Marco Patalano <mpatalan@redhat.com>
Cc: "Ewan D. Milne" <emilne@redhat.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Bart Van Assche <bart.vanassche@sandisk.com>
Cc: Omar Sandoval <osandov@fb.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 block/blk-mq-tag.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/block/blk-mq-tag.c b/block/blk-mq-tag.c
index 09b2ee6694fb..c43b3398d7b4 100644
--- a/block/blk-mq-tag.c
+++ b/block/blk-mq-tag.c
@@ -399,8 +399,6 @@ int blk_mq_tag_update_depth(struct blk_mq_hw_ctx *hctx,
 	if (tdepth <= tags->nr_reserved_tags)
 		return -EINVAL;
 
-	tdepth -= tags->nr_reserved_tags;
-
 	/*
 	 * If we are allowed to grow beyond the original size, allocate
 	 * a new set of tags before freeing the old one.
@@ -420,7 +418,8 @@ int blk_mq_tag_update_depth(struct blk_mq_hw_ctx *hctx,
 		if (tdepth > 16 * BLKDEV_MAX_RQ)
 			return -EINVAL;
 
-		new = blk_mq_alloc_rq_map(set, hctx->queue_num, tdepth, 0);
+		new = blk_mq_alloc_rq_map(set, hctx->queue_num, tdepth,
+				tags->nr_reserved_tags);
 		if (!new)
 			return -ENOMEM;
 		ret = blk_mq_alloc_rqs(set, new, hctx->queue_num, tdepth);
@@ -437,7 +436,8 @@ int blk_mq_tag_update_depth(struct blk_mq_hw_ctx *hctx,
 		 * Don't need (or can't) update reserved tags here, they
 		 * remain static and should never need resizing.
 		 */
-		sbitmap_queue_resize(&tags->bitmap_tags, tdepth);
+		sbitmap_queue_resize(&tags->bitmap_tags,
+				tdepth - tags->nr_reserved_tags);
 	}
 
 	return 0;
-- 
2.9.5

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

* Re: [PATCH] blk-mq: fix updating tags depth
  2018-08-02 10:23 [PATCH] blk-mq: fix updating tags depth Ming Lei
@ 2018-08-02 19:27 ` Marco Patalano
  2018-08-02 20:48 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Marco Patalano @ 2018-08-02 19:27 UTC (permalink / raw)
  To: Ming Lei; +Cc: Jens Axboe, linux-block, Ewan D. Milne

[-- Attachment #1: Type: text/plain, Size: 2594 bytes --]

Tested by: Marco Patalano <mpatalan@redhat.com>

On Thu, Aug 2, 2018 at 6:23 AM, Ming Lei <ming.lei@redhat.com> wrote:

> The passed 'nr' from userspace represents the total depth, meantime
> inside 'struct blk_mq_tags', 'nr_tags' stores the total tag depth,
> and 'nr_reserved_tags' stores the reserved part.
>
> There are two issues in blk_mq_tag_update_depth() now:
>
> 1) for growing tags, we should have used the passed 'nr', and keep the
> number of reserved tags not changed.
>
> 2) the passed 'nr' should have been used for checking against
> 'tags->nr_tags', instead of number of the normal part.
>
> This patch fixes the above two cases, and avoids kernel crash caused
> by wrong resizing sbitmap queue.
>
> Cc: Marco Patalano <mpatalan@redhat.com>
> Cc: "Ewan D. Milne" <emilne@redhat.com>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Bart Van Assche <bart.vanassche@sandisk.com>
> Cc: Omar Sandoval <osandov@fb.com>
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
> ---
>  block/blk-mq-tag.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/block/blk-mq-tag.c b/block/blk-mq-tag.c
> index 09b2ee6694fb..c43b3398d7b4 100644
> --- a/block/blk-mq-tag.c
> +++ b/block/blk-mq-tag.c
> @@ -399,8 +399,6 @@ int blk_mq_tag_update_depth(struct blk_mq_hw_ctx *hctx,
>         if (tdepth <= tags->nr_reserved_tags)
>                 return -EINVAL;
>
> -       tdepth -= tags->nr_reserved_tags;
> -
>         /*
>          * If we are allowed to grow beyond the original size, allocate
>          * a new set of tags before freeing the old one.
> @@ -420,7 +418,8 @@ int blk_mq_tag_update_depth(struct blk_mq_hw_ctx *hctx,
>                 if (tdepth > 16 * BLKDEV_MAX_RQ)
>                         return -EINVAL;
>
> -               new = blk_mq_alloc_rq_map(set, hctx->queue_num, tdepth, 0);
> +               new = blk_mq_alloc_rq_map(set, hctx->queue_num, tdepth,
> +                               tags->nr_reserved_tags);
>                 if (!new)
>                         return -ENOMEM;
>                 ret = blk_mq_alloc_rqs(set, new, hctx->queue_num, tdepth);
> @@ -437,7 +436,8 @@ int blk_mq_tag_update_depth(struct blk_mq_hw_ctx *hctx,
>                  * Don't need (or can't) update reserved tags here, they
>                  * remain static and should never need resizing.
>                  */
> -               sbitmap_queue_resize(&tags->bitmap_tags, tdepth);
> +               sbitmap_queue_resize(&tags->bitmap_tags,
> +                               tdepth - tags->nr_reserved_tags);
>         }
>
>         return 0;
> --
> 2.9.5
>
>

[-- Attachment #2: Type: text/html, Size: 4078 bytes --]

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

* Re: [PATCH] blk-mq: fix updating tags depth
  2018-08-02 10:23 [PATCH] blk-mq: fix updating tags depth Ming Lei
  2018-08-02 19:27 ` Marco Patalano
@ 2018-08-02 20:48 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2018-08-02 20:48 UTC (permalink / raw)
  To: Ming Lei
  Cc: linux-block, Marco Patalano, Ewan D. Milne, Christoph Hellwig,
	Bart Van Assche, Omar Sandoval

On 8/2/18 4:23 AM, Ming Lei wrote:
> The passed 'nr' from userspace represents the total depth, meantime
> inside 'struct blk_mq_tags', 'nr_tags' stores the total tag depth,
> and 'nr_reserved_tags' stores the reserved part.
> 
> There are two issues in blk_mq_tag_update_depth() now:
> 
> 1) for growing tags, we should have used the passed 'nr', and keep the
> number of reserved tags not changed.
> 
> 2) the passed 'nr' should have been used for checking against
> 'tags->nr_tags', instead of number of the normal part.
> 
> This patch fixes the above two cases, and avoids kernel crash caused
> by wrong resizing sbitmap queue.

Applied, thanks.

-- 
Jens Axboe

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

end of thread, other threads:[~2018-08-02 20:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-02 10:23 [PATCH] blk-mq: fix updating tags depth Ming Lei
2018-08-02 19:27 ` Marco Patalano
2018-08-02 20:48 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).