mbox series

[v3,0/7] Fix potential kernel panic when increase hardware queue

Message ID cover.1586199103.git.zhangweiping@didiglobal.com (mailing list archive)
Headers show
Series Fix potential kernel panic when increase hardware queue | expand

Message

Weiping Zhang April 6, 2020, 7:35 p.m. UTC
Hi,

This series do some improvement base on V2, and also fix two memleaks.
And V2 import a regression for blktest/block/test/029, this test case
will increase and decrease hardware queue count quickly.


Memleak 1:

__blk_mq_alloc_rq_maps
	__blk_mq_alloc_rq_map

if fail
	blk_mq_free_rq_map

Actually, __blk_mq_alloc_rq_map alloc both map and request, here
also need free request.

Memleak 2:
When driver decrease hardware queue, set->nr_hw_queues will be changed
firstly in blk_mq_realloc_tag_set_tags or __blk_mq_update_nr_hw_queues,
then blk_mq_realloc_hw_ctxs and blk_mq_map_swqueue, even
blk_mq_free_tag_set have no chance to free these hardware queue resource,
because they iterate hardware queue by
for (i = 0; i < set->nr_hw_queues; i++).

Patch1~3: rename some function name, no function change.
Patch4: fix first memleak.
Patch5: fix prev_nr_hw_queues issue, need be saved before change.
Patch6: alloc map and request to fix potential kernel panic.


Changes since V2:
 * rename some functions name and fix memleak when free map and requests
 * Not free new allocated map and request, they will be relased when tagset gone

Changes since V1:
 * Add fix for potential kernel panic when increase hardware queue

Weiping Zhang (7):
  block: rename __blk_mq_alloc_rq_map
  block: rename __blk_mq_alloc_rq_maps
  block: rename blk_mq_alloc_rq_maps
  block: free both map and request
  block: save previous hardware queue count before udpate
  block: refactor __blk_mq_alloc_rq_map_and_requests
  block: alloc map and request for new hardware queue

 block/blk-mq.c         | 49 ++++++++++++++++++++++++++++++------------
 include/linux/blk-mq.h |  1 +
 2 files changed, 36 insertions(+), 14 deletions(-)

Comments

Weiping Zhang April 8, 2020, 12:25 p.m. UTC | #1
Weiping Zhang <zhangweiping@didiglobal.com> 于2020年4月7日周二 上午3:36写道:
>
> Hi,
>
> This series do some improvement base on V2, and also fix two memleaks.
> And V2 import a regression for blktest/block/test/029, this test case
> will increase and decrease hardware queue count quickly.
>
>
> Memleak 1:
>
> __blk_mq_alloc_rq_maps
>         __blk_mq_alloc_rq_map
>
> if fail
>         blk_mq_free_rq_map
>
> Actually, __blk_mq_alloc_rq_map alloc both map and request, here
> also need free request.
>
> Memleak 2:
> When driver decrease hardware queue, set->nr_hw_queues will be changed
> firstly in blk_mq_realloc_tag_set_tags or __blk_mq_update_nr_hw_queues,
> then blk_mq_realloc_hw_ctxs and blk_mq_map_swqueue, even
> blk_mq_free_tag_set have no chance to free these hardware queue resource,
> because they iterate hardware queue by
> for (i = 0; i < set->nr_hw_queues; i++).
>
> Patch1~3: rename some function name, no function change.
> Patch4: fix first memleak.
> Patch5: fix prev_nr_hw_queues issue, need be saved before change.
> Patch6: alloc map and request to fix potential kernel panic.
>
Update patch description:
Patch1~3: rename some function name, no function change.
Patch4: fix first memleak.
Patch5: fix prev_nr_hw_queues issue, need be saved before change.
Patch6: add nr_allocated_map_rqs to struct blk_mq_tag_set to record how
may rq and maps were allocated for this tag set, and also fix memleak2.

Patch7: fix kernel panic when update hardware queue count > cpu count,
when use multiple maps. Patch7's commit message has more detail information
about this issue.

>
> Changes since V2:
>  * rename some functions name and fix memleak when free map and requests
>  * Not free new allocated map and request, they will be relased when tagset gone
>
> Changes since V1:
>  * Add fix for potential kernel panic when increase hardware queue
>
> Weiping Zhang (7):
>   block: rename __blk_mq_alloc_rq_map
>   block: rename __blk_mq_alloc_rq_maps
>   block: rename blk_mq_alloc_rq_maps
>   block: free both map and request
>   block: save previous hardware queue count before udpate
>   block: refactor __blk_mq_alloc_rq_map_and_requests
>   block: alloc map and request for new hardware queue
>
>  block/blk-mq.c         | 49 ++++++++++++++++++++++++++++++------------
>  include/linux/blk-mq.h |  1 +
>  2 files changed, 36 insertions(+), 14 deletions(-)
>
> --
> 2.18.1
>
Weiping Zhang April 20, 2020, 11:15 a.m. UTC | #2
Hi Jens,

Ping

On Wed, Apr 8, 2020 at 8:25 PM Weiping Zhang <zwp10758@gmail.com> wrote:
>
> Weiping Zhang <zhangweiping@didiglobal.com> 于2020年4月7日周二 上午3:36写道:
> >
> > Hi,
> >
> > This series do some improvement base on V2, and also fix two memleaks.
> > And V2 import a regression for blktest/block/test/029, this test case
> > will increase and decrease hardware queue count quickly.
> >
> >
> > Memleak 1:
> >
> > __blk_mq_alloc_rq_maps
> >         __blk_mq_alloc_rq_map
> >
> > if fail
> >         blk_mq_free_rq_map
> >
> > Actually, __blk_mq_alloc_rq_map alloc both map and request, here
> > also need free request.
> >
> > Memleak 2:
> > When driver decrease hardware queue, set->nr_hw_queues will be changed
> > firstly in blk_mq_realloc_tag_set_tags or __blk_mq_update_nr_hw_queues,
> > then blk_mq_realloc_hw_ctxs and blk_mq_map_swqueue, even
> > blk_mq_free_tag_set have no chance to free these hardware queue resource,
> > because they iterate hardware queue by
> > for (i = 0; i < set->nr_hw_queues; i++).
> >
> > Patch1~3: rename some function name, no function change.
> > Patch4: fix first memleak.
> > Patch5: fix prev_nr_hw_queues issue, need be saved before change.
> > Patch6: alloc map and request to fix potential kernel panic.
> >
> Update patch description:
> Patch1~3: rename some function name, no function change.
> Patch4: fix first memleak.
> Patch5: fix prev_nr_hw_queues issue, need be saved before change.
> Patch6: add nr_allocated_map_rqs to struct blk_mq_tag_set to record how
> may rq and maps were allocated for this tag set, and also fix memleak2.
>
> Patch7: fix kernel panic when update hardware queue count > cpu count,
> when use multiple maps. Patch7's commit message has more detail information
> about this issue.
>
> >
> > Changes since V2:
> >  * rename some functions name and fix memleak when free map and requests
> >  * Not free new allocated map and request, they will be relased when tagset gone
> >
> > Changes since V1:
> >  * Add fix for potential kernel panic when increase hardware queue
> >
> > Weiping Zhang (7):
> >   block: rename __blk_mq_alloc_rq_map
> >   block: rename __blk_mq_alloc_rq_maps
> >   block: rename blk_mq_alloc_rq_maps
> >   block: free both map and request
> >   block: save previous hardware queue count before udpate
> >   block: refactor __blk_mq_alloc_rq_map_and_requests
> >   block: alloc map and request for new hardware queue
> >
> >  block/blk-mq.c         | 49 ++++++++++++++++++++++++++++++------------
> >  include/linux/blk-mq.h |  1 +
> >  2 files changed, 36 insertions(+), 14 deletions(-)
> >
> > --
> > 2.18.1
> >
Jens Axboe April 20, 2020, 7:30 p.m. UTC | #3
On 4/20/20 5:15 AM, Weiping Zhang wrote:
> Hi Jens,
> 
> Ping

I'd really like for Bart/Ming to weigh in here.