dm zoned: check zone capacity
authorDamien Le Moal <damien.lemoal@wdc.com>
Wed, 19 May 2021 01:26:16 +0000 (10:26 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 19 Jul 2021 07:45:01 +0000 (09:45 +0200)
commit bab68499428ed934f0493ac74197ed6f36204260 upstream.

The dm-zoned target cannot support zoned block devices with zones that
have a capacity smaller than the zone size (e.g. NVMe zoned namespaces)
due to the current chunk zone mapping implementation as it is assumed
that zones and chunks have the same size with all blocks usable.
If a zoned drive is found to have zones with a capacity different from
the zone size, fail the target initialization.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Cc: stable@vger.kernel.org # v5.9+
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/md/dm-zoned-metadata.c

index b298fef..5100907 100644 (file)
@@ -1390,6 +1390,13 @@ static int dmz_init_zone(struct blk_zone *blkz, unsigned int num, void *data)
                return -ENXIO;
        }
 
+       /*
+        * Devices that have zones with a capacity smaller than the zone size
+        * (e.g. NVMe zoned namespaces) are not supported.
+        */
+       if (blkz->capacity != blkz->len)
+               return -ENXIO;
+
        switch (blkz->type) {
        case BLK_ZONE_TYPE_CONVENTIONAL:
                set_bit(DMZ_RND, &zone->flags);