aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2014-04-08 22:25:43 -0400
committerNeilBrown <neilb@suse.de>2014-04-09 00:42:23 -0400
commitda1aab3dca9aa88ae34ca392470b8943159e25fe (patch)
tree435a7a9ea35a3a68b6943e4bbf24b6c9b09281e3
parent035328c202d26a824b8632fd3b00635db5aee5a2 (diff)
md/raid1: r1buf_pool_alloc: free allocate pages when subsequent allocation fails.
When performing a user-request check/repair (MD_RECOVERY_REQUEST is set) on a raid1, we allocate multiple bios each with their own set of pages. If the page allocations for one bio fails, we currently do *not* free the pages allocated for the previous bios, nor do we free the bio itself. This patch frees all the already-allocate pages, and makes sure that all the bios are freed as well. This bug can cause a memory leak which can ultimately OOM a machine. It was introduced in 3.10-rc1. Fixes: a07876064a0b73ab5ef1ebcf14b1cf0231c07858 Cc: Kent Overstreet <koverstreet@google.com> Cc: stable@vger.kernel.org (3.10+) Reported-by: Russell King - ARM Linux <linux@arm.linux.org.uk> Signed-off-by: NeilBrown <neilb@suse.de>
-rw-r--r--drivers/md/raid1.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 4a6ca1cb2e78..56e24c072b62 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -97,6 +97,7 @@ static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data)
97 struct pool_info *pi = data; 97 struct pool_info *pi = data;
98 struct r1bio *r1_bio; 98 struct r1bio *r1_bio;
99 struct bio *bio; 99 struct bio *bio;
100 int need_pages;
100 int i, j; 101 int i, j;
101 102
102 r1_bio = r1bio_pool_alloc(gfp_flags, pi); 103 r1_bio = r1bio_pool_alloc(gfp_flags, pi);
@@ -119,15 +120,15 @@ static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data)
119 * RESYNC_PAGES for each bio. 120 * RESYNC_PAGES for each bio.
120 */ 121 */
121 if (test_bit(MD_RECOVERY_REQUESTED, &pi->mddev->recovery)) 122 if (test_bit(MD_RECOVERY_REQUESTED, &pi->mddev->recovery))
122 j = pi->raid_disks; 123 need_pages = pi->raid_disks;
123 else 124 else
124 j = 1; 125 need_pages = 1;
125 while(j--) { 126 for (j = 0; j < need_pages; j++) {
126 bio = r1_bio->bios[j]; 127 bio = r1_bio->bios[j];
127 bio->bi_vcnt = RESYNC_PAGES; 128 bio->bi_vcnt = RESYNC_PAGES;
128 129
129 if (bio_alloc_pages(bio, gfp_flags)) 130 if (bio_alloc_pages(bio, gfp_flags))
130 goto out_free_bio; 131 goto out_free_pages;
131 } 132 }
132 /* If not user-requests, copy the page pointers to all bios */ 133 /* If not user-requests, copy the page pointers to all bios */
133 if (!test_bit(MD_RECOVERY_REQUESTED, &pi->mddev->recovery)) { 134 if (!test_bit(MD_RECOVERY_REQUESTED, &pi->mddev->recovery)) {
@@ -141,6 +142,14 @@ static void * r1buf_pool_alloc(gfp_t gfp_flags, void *data)
141 142
142 return r1_bio; 143 return r1_bio;
143 144
145out_free_pages:
146 while (--j >= 0) {
147 struct bio_vec *bv;
148
149 bio_for_each_segment_all(bv, r1_bio->bios[j], i)
150 __free_page(bv->bv_page);
151 }
152
144out_free_bio: 153out_free_bio:
145 while (++j < pi->raid_disks) 154 while (++j < pi->raid_disks)
146 bio_put(r1_bio->bios[j]); 155 bio_put(r1_bio->bios[j]);