]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.9.70/md-free-unused-memory-after-bitmap-resize.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.9.70 / md-free-unused-memory-after-bitmap-resize.patch
1 From foo@baz Tue Dec 12 13:26:17 CET 2017
2 From: Zdenek Kabelac <zkabelac@redhat.com>
3 Date: Wed, 8 Nov 2017 13:44:56 +0100
4 Subject: md: free unused memory after bitmap resize
5
6 From: Zdenek Kabelac <zkabelac@redhat.com>
7
8
9 [ Upstream commit 0868b99c214a3d55486c700de7c3f770b7243e7c ]
10
11 When bitmap is resized, the old kalloced chunks just are not released
12 once the resized bitmap starts to use new space.
13
14 This fixes in particular kmemleak reports like this one:
15
16 unreferenced object 0xffff8f4311e9c000 (size 4096):
17 comm "lvm", pid 19333, jiffies 4295263268 (age 528.265s)
18 hex dump (first 32 bytes):
19 02 80 02 80 02 80 02 80 02 80 02 80 02 80 02 80 ................
20 02 80 02 80 02 80 02 80 02 80 02 80 02 80 02 80 ................
21 backtrace:
22 [<ffffffffa69471ca>] kmemleak_alloc+0x4a/0xa0
23 [<ffffffffa628c10e>] kmem_cache_alloc_trace+0x14e/0x2e0
24 [<ffffffffa676cfec>] bitmap_checkpage+0x7c/0x110
25 [<ffffffffa676d0c5>] bitmap_get_counter+0x45/0xd0
26 [<ffffffffa676d6b3>] bitmap_set_memory_bits+0x43/0xe0
27 [<ffffffffa676e41c>] bitmap_init_from_disk+0x23c/0x530
28 [<ffffffffa676f1ae>] bitmap_load+0xbe/0x160
29 [<ffffffffc04c47d3>] raid_preresume+0x203/0x2f0 [dm_raid]
30 [<ffffffffa677762f>] dm_table_resume_targets+0x4f/0xe0
31 [<ffffffffa6774b52>] dm_resume+0x122/0x140
32 [<ffffffffa6779b9f>] dev_suspend+0x18f/0x290
33 [<ffffffffa677a3a7>] ctl_ioctl+0x287/0x560
34 [<ffffffffa677a693>] dm_ctl_ioctl+0x13/0x20
35 [<ffffffffa62d6b46>] do_vfs_ioctl+0xa6/0x750
36 [<ffffffffa62d7269>] SyS_ioctl+0x79/0x90
37 [<ffffffffa6956d41>] entry_SYSCALL_64_fastpath+0x1f/0xc2
38
39 Signed-off-by: Zdenek Kabelac <zkabelac@redhat.com>
40 Signed-off-by: Shaohua Li <shli@fb.com>
41 Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
42 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
43 ---
44 drivers/md/bitmap.c | 9 +++++++++
45 1 file changed, 9 insertions(+)
46
47 --- a/drivers/md/bitmap.c
48 +++ b/drivers/md/bitmap.c
49 @@ -2084,6 +2084,7 @@ int bitmap_resize(struct bitmap *bitmap,
50 for (k = 0; k < page; k++) {
51 kfree(new_bp[k].map);
52 }
53 + kfree(new_bp);
54
55 /* restore some fields from old_counts */
56 bitmap->counts.bp = old_counts.bp;
57 @@ -2134,6 +2135,14 @@ int bitmap_resize(struct bitmap *bitmap,
58 block += old_blocks;
59 }
60
61 + if (bitmap->counts.bp != old_counts.bp) {
62 + unsigned long k;
63 + for (k = 0; k < old_counts.pages; k++)
64 + if (!old_counts.bp[k].hijacked)
65 + kfree(old_counts.bp[k].map);
66 + kfree(old_counts.bp);
67 + }
68 +
69 if (!init) {
70 int i;
71 while (block < (chunks << chunkshift)) {