Skip to content

Commit 28436ba

Browse files
damien-lemoalsnitm
authored andcommitted
dm zone: fix dm_revalidate_zones() memory allocation
Make sure that the zone write pointer offset array is allocated with a vmalloc in dm_zone_revalidate_cb() by passing GFP_KERNEL gfp flag to kvcalloc(). However, since we do not want to trigger IOs while revalidating zones, change dm_revalidate_zones() to have the zone scan done in GFP_NOIO context using memalloc_noio_save/restore calls. Reported-by: Dan Carpenter <[email protected]> Fixes: bb37d77 ("dm: introduce zone append emulation") Signed-off-by: Damien Le Moal <[email protected]> Signed-off-by: Mike Snitzer <[email protected]>
1 parent 326dbde commit 28436ba

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

drivers/md/dm-zone.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ static int dm_zone_revalidate_cb(struct blk_zone *zone, unsigned int idx,
205205
if (!md->zwp_offset) {
206206
md->zwp_offset =
207207
kvcalloc(q->nr_zones, sizeof(unsigned int),
208-
GFP_NOIO);
208+
GFP_KERNEL);
209209
if (!md->zwp_offset)
210210
return -ENOMEM;
211211
}
@@ -230,6 +230,7 @@ static int dm_zone_revalidate_cb(struct blk_zone *zone, unsigned int idx,
230230
static int dm_revalidate_zones(struct mapped_device *md, struct dm_table *t)
231231
{
232232
struct request_queue *q = md->queue;
233+
unsigned int noio_flag;
233234
int ret;
234235

235236
/*
@@ -241,9 +242,14 @@ static int dm_revalidate_zones(struct mapped_device *md, struct dm_table *t)
241242
if (md->nr_zones)
242243
return 0;
243244

244-
/* Scan all zones to initialize everything */
245+
/*
246+
* Scan all zones to initialize everything. Ensure that all vmalloc
247+
* operations in this context are done as if GFP_NOIO was specified.
248+
*/
249+
noio_flag = memalloc_noio_save();
245250
ret = dm_blk_do_report_zones(md, t, 0, q->nr_zones,
246251
dm_zone_revalidate_cb, md);
252+
memalloc_noio_restore(noio_flag);
247253
if (ret < 0)
248254
goto err;
249255
if (ret != q->nr_zones) {

0 commit comments

Comments
 (0)