All of lore.kernel.org
 help / color / mirror / Atom feed
* [dm-devel] [PATCH] dm: fix dm_revalidate_zones() memory allocation
@ 2021-06-18 23:15 Damien Le Moal
  0 siblings, 0 replies; only message in thread
From: Damien Le Moal @ 2021-06-18 23:15 UTC (permalink / raw)
  To: dm-devel, Mike Snitzer; +Cc: Dan Carpenter

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 <dan.carpenter@oracle.com>
Fixes: bb37d77239af ("dm: introduce zone append emulation")
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 drivers/md/dm-zone.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/md/dm-zone.c b/drivers/md/dm-zone.c
index c2f26949f5ee..6d82a34438c8 100644
--- a/drivers/md/dm-zone.c
+++ b/drivers/md/dm-zone.c
@@ -205,7 +205,7 @@ static int dm_zone_revalidate_cb(struct blk_zone *zone, unsigned int idx,
 		if (!md->zwp_offset) {
 			md->zwp_offset =
 				kvcalloc(q->nr_zones, sizeof(unsigned int),
-					 GFP_NOIO);
+					 GFP_KERNEL);
 			if (!md->zwp_offset)
 				return -ENOMEM;
 		}
@@ -230,6 +230,7 @@ static int dm_zone_revalidate_cb(struct blk_zone *zone, unsigned int idx,
 static int dm_revalidate_zones(struct mapped_device *md, struct dm_table *t)
 {
 	struct request_queue *q = md->queue;
+	unsigned int noio_flag;
 	int ret;
 
 	/*
@@ -241,9 +242,14 @@ static int dm_revalidate_zones(struct mapped_device *md, struct dm_table *t)
 	if (md->nr_zones)
 		return 0;
 
-	/* Scan all zones to initialize everything */
+	/*
+	 * Scan all zones to initialize everything. Ensure that all vmalloc
+	 * operations in this context are done as if GFP_NOIO was specified.
+	 */
+	noio_flag = memalloc_noio_save();
 	ret = dm_blk_do_report_zones(md, t, 0, q->nr_zones,
 				     dm_zone_revalidate_cb, md);
+	memalloc_noio_restore(noio_flag);
 	if (ret < 0)
 		goto err;
 	if (ret != q->nr_zones) {
-- 
2.31.1

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-06-18 23:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-18 23:15 [dm-devel] [PATCH] dm: fix dm_revalidate_zones() memory allocation Damien Le Moal

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.