Skip to contentSkip to conversation

block: kmemleak: Track the page allocations for struct request

PATCH In review Catalin Marinas 3 participants 5 messages Sep 14, 2015 – Nov 25, 2015 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: kmemleak: Track the page allocations for struct request

The pages allocated for struct request contain pointers to other slab allocations (via ops->init_request). Since kmemleak does not track/scan page allocations, the slab objects will be reported as leaks (false positives). This patch adds kmemleak callbacks to allow tracking of such pages.

---

Jens,

I just realised that no-one has picked this patch up for -rc1. It was discussed here previously:

http://lkml.kernel.org/r/[email protected]

Since it touches the block layer, are you fine with merging it?

Thanks,

Catalin

 block/blk-mq.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
block/blk-mq.c +11 -0
index f2d67b4047a0..2077f0d2f95f 100644
@@ -9,6 +9,7 @@
 #include <linux/backing-dev.h>
 #include <linux/bio.h>
 #include <linux/blkdev.h>
+#include <linux/kmemleak.h>
 #include <linux/mm.h>
 #include <linux/init.h>
 #include <linux/slab.h>
@@ -1438,6 +1439,11 @@ static void blk_mq_free_rq_map(struct blk_mq_tag_set *set,
 	while (!list_empty(&tags->page_list)) {
 		page = list_first_entry(&tags->page_list, struct page, lru);
 		list_del_init(&page->lru);
+		/*
+		 * Remove kmemleak object previously allocated in
+		 * blk_mq_init_rq_map().
+		 */
+		kmemleak_free(page_address(page));
 		__free_pages(page, page->private);
 	}
 
@@ -1510,6 +1516,11 @@ static struct blk_mq_tags *blk_mq_init_rq_map(struct blk_mq_tag_set *set,
 		list_add_tail(&page->lru, &tags->page_list);
 
 		p = page_address(page);
+		/*
+		 * Allow kmemleak to scan these pages as they contain pointers
+		 * to additional allocations like via ops->init_request().
+		 */
+		kmemleak_alloc(p, order_to_size(this_order), 1, GFP_KERNEL);
 		entries_per_page = order_to_size(this_order) / rq_size;
 		to_do = min(entries_per_page, set->queue_depth - i);
 		left -= to_do * rq_size;
maintainer
#1 lore raw
Quoted 13 lines · Catalin Marinas

The pages allocated for struct request contain pointers to other slab allocations (via ops->init_request). Since kmemleak does not track/scan page allocations, the slab objects will be reported as leaks (false positives). This patch adds kmemleak callbacks to allow tracking of such pages.

---

Quoted 8 lines

Jens,

I just realised that no-one has picked this patch up for -rc1. It was discussed here previously:

http://lkml.kernel.org/r/[email protected]

Since it touches the block layer, are you fine with merging it?

Yeah looks simple enough for me, not sure why it got missed. I'll add it for 4.4-rc1, thanks.

Signature · 1 line
Jens Axboe
#2 lore raw

Hi Jens,

Quoted 21 lines · Jens Axboe
Quoted 20 lines · Catalin Marinas

The pages allocated for struct request contain pointers to other slab allocations (via ops->init_request). Since kmemleak does not track/scan page allocations, the slab objects will be reported as leaks (false positives). This patch adds kmemleak callbacks to allow tracking of such pages.

---

Jens,

I just realised that no-one has picked this patch up for -rc1. It was discussed here previously:

Quoted 7 lines
Quoted 3 lines

http://lkml.kernel.org/r/[email protected]

Since it touches the block layer, are you fine with merging it?

Yeah looks simple enough for me, not sure why it got missed. I'll add it for 4.4-rc1, thanks.

I saw the related kmemleaks reports on my v4.1.x kernel. Since it's actually fixing these wrong reports, do you think it could be a good candidate for -stable tree?

Thanks,

Signature · 1 line
William
maintainer
#3 lore raw
Quoted 29 lines · William Dauchy

Hi Jens,

Quoted 26 lines · Jens Axboe
Quoted 23 lines · Catalin Marinas

The pages allocated for struct request contain pointers to other slab allocations (via ops->init_request). Since kmemleak does not track/scan page allocations, the slab objects will be reported as leaks (false positives). This patch adds kmemleak callbacks to allow tracking of such pages.

---

Jens,

I just realised that no-one has picked this patch up for -rc1. It was discussed here previously:

http://lkml.kernel.org/r/[email protected]

Since it touches the block layer, are you fine with merging it?

Quoted 6 lines
Quoted 2 lines

Yeah looks simple enough for me, not sure why it got missed. I'll add it for 4.4-rc1, thanks.

I saw the related kmemleaks reports on my v4.1.x kernel. Since it's actually fixing these wrong reports, do you think it could be a good candidate for -stable tree?

I'd say it's borderline. It's fixing a tracking bug. Unless others feel strongly otherwise, I don't think it's stable material.

Signature · 1 line
Jens Axboe
#4 lore raw
Quoted 2 lines · Jens Axboe

I'd say it's borderline. It's fixing a tracking bug. Unless others feel strongly otherwise, I don't think it's stable material.

ok thanks for your feedback.

Signature · 1 line
William