Message ID | 5b06d772447eaab3b69dfc76716a79519eb932b3.1588080449.git.zhangweiping@didiglobal.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Fix potential kernel panic when increase hardware queue | expand |
On Tue, Apr 28, 2020 at 9:29 PM Weiping Zhang <zhangweiping@didiglobal.com> wrote: > > For this error handle, it should free both map and request, > otherwise a memory leak occur. > > Allocation: > > __blk_mq_alloc_rq_map > blk_mq_alloc_rq_map > blk_mq_alloc_rq_map > tags = blk_mq_init_tags : kzalloc_node: > tags->rqs = kcalloc_node > tags->static_rqs = kcalloc_node > blk_mq_alloc_rqs > p = alloc_pages_node > tags->static_rqs[i] = p + offset; > > Free: > > blk_mq_free_rq_map > kfree(tags->rqs); > kfree(tags->static_rqs); > blk_mq_free_tags > kfree(tags); > > The page allocated in blk_mq_alloc_rqs cannot be released, > so we should use blk_mq_free_map_and_requests here. > > blk_mq_free_map_and_requests > blk_mq_free_rqs > __free_pages : cleanup for blk_mq_alloc_rqs > blk_mq_free_rq_map : cleanup for blk_mq_alloc_rq_map > > Signed-off-by: Weiping Zhang <zhangweiping@didiglobal.com> > --- > block/blk-mq.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/block/blk-mq.c b/block/blk-mq.c > index a7785df2c944..f789b3e1b3ab 100644 > --- a/block/blk-mq.c > +++ b/block/blk-mq.c > @@ -2995,7 +2995,7 @@ static int __blk_mq_alloc_rq_maps(struct blk_mq_tag_set *set) > > out_unwind: > while (--i >= 0) > - blk_mq_free_rq_map(set->tags[i]); > + blk_mq_free_map_and_requests(set, i); > > return -ENOMEM; > } > -- > 2.18.1 > Reviewed-by: Ming Lei <ming.lei@redhat.com> thanks, Ming Lei
diff --git a/block/blk-mq.c b/block/blk-mq.c index a7785df2c944..f789b3e1b3ab 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2995,7 +2995,7 @@ static int __blk_mq_alloc_rq_maps(struct blk_mq_tag_set *set) out_unwind: while (--i >= 0) - blk_mq_free_rq_map(set->tags[i]); + blk_mq_free_map_and_requests(set, i); return -ENOMEM; }
For this error handle, it should free both map and request, otherwise a memory leak occur. Allocation: __blk_mq_alloc_rq_map blk_mq_alloc_rq_map blk_mq_alloc_rq_map tags = blk_mq_init_tags : kzalloc_node: tags->rqs = kcalloc_node tags->static_rqs = kcalloc_node blk_mq_alloc_rqs p = alloc_pages_node tags->static_rqs[i] = p + offset; Free: blk_mq_free_rq_map kfree(tags->rqs); kfree(tags->static_rqs); blk_mq_free_tags kfree(tags); The page allocated in blk_mq_alloc_rqs cannot be released, so we should use blk_mq_free_map_and_requests here. blk_mq_free_map_and_requests blk_mq_free_rqs __free_pages : cleanup for blk_mq_alloc_rqs blk_mq_free_rq_map : cleanup for blk_mq_alloc_rq_map Signed-off-by: Weiping Zhang <zhangweiping@didiglobal.com> --- block/blk-mq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)