[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220525154957.393656-8-p.raghav@samsung.com>
Date: Wed, 25 May 2022 17:49:56 +0200
From: Pankaj Raghav <p.raghav@...sung.com>
To: axboe@...nel.dk, damien.lemoal@...nsource.wdc.com,
snitzer@...hat.com, Johannes.Thumshirn@....com, hch@....de,
hare@...e.de
Cc: dsterba@...e.com, dm-devel@...hat.com, jiangbo.365@...edance.com,
linux-block@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-nvme@...ts.infradead.org, jaegeuk@...nel.org,
gost.dev@...sung.com, Luis Chamberlain <mcgrof@...nel.org>,
Pankaj Raghav <p.raghav@...sung.com>
Subject: [PATCH v6 7/8] dm-zoned: ensure only power of 2 zone sizes are
allowed
From: Luis Chamberlain <mcgrof@...nel.org>
Today dm-zoned relies on the assumption that you have a zone size
with a power of 2. Even though the block layer today enforces this
requirement, these devices do exist and so provide a stop-gap measure
to ensure these devices cannot be used by mistake
Reviewed-by: Hannes Reinecke <hare@...e.de>
Signed-off-by: Luis Chamberlain <mcgrof@...nel.org>
Signed-off-by: Pankaj Raghav <p.raghav@...sung.com>
---
drivers/md/dm-zone.c | 10 ++++++++++
drivers/md/dm-zoned-target.c | 8 ++++++++
2 files changed, 18 insertions(+)
diff --git a/drivers/md/dm-zone.c b/drivers/md/dm-zone.c
index 57daa86c19cf..41188091fe6b 100644
--- a/drivers/md/dm-zone.c
+++ b/drivers/md/dm-zone.c
@@ -231,6 +231,16 @@ 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;
+ struct block_device *bdev = md->disk->part0;
+ sector_t zone_sectors;
+
+ zone_sectors = bdev_zone_sectors(bdev);
+
+ if (!is_power_of_2(zone_sectors)) {
+ DMWARN("%s: %pg only power of two zone size supported",
+ dm_device_name(md), bdev);
+ return -EINVAL;
+ }
/*
* Check if something changed. If yes, cleanup the current resources
diff --git a/drivers/md/dm-zoned-target.c b/drivers/md/dm-zoned-target.c
index cac295cc8840..e4cef1b1b46c 100644
--- a/drivers/md/dm-zoned-target.c
+++ b/drivers/md/dm-zoned-target.c
@@ -792,6 +792,10 @@ static int dmz_fixup_devices(struct dm_target *ti)
return -EINVAL;
}
zone_nr_sectors = blk_queue_zone_sectors(q);
+ if (!is_power_of_2(zone_nr_sectors)) {
+ ti->error = "Zone size not power of 2";
+ return -EINVAL;
+ }
zoned_dev->zone_nr_sectors = zone_nr_sectors;
zoned_dev->nr_zones =
blkdev_nr_zones(zoned_dev->bdev->bd_disk);
@@ -806,6 +810,10 @@ static int dmz_fixup_devices(struct dm_target *ti)
q = bdev_get_queue(zoned_dev->bdev);
zoned_dev->zone_nr_sectors = blk_queue_zone_sectors(q);
zoned_dev->nr_zones = blkdev_nr_zones(zoned_dev->bdev->bd_disk);
+ if (!is_power_of_2(zone_nr_sectors)) {
+ ti->error = "Zone size not power of 2";
+ return -EINVAL;
+ }
}
if (reg_dev) {
--
2.25.1
Powered by blists - more mailing lists