From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ED57CCD1284 for ; Fri, 5 Apr 2024 04:42:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:To:From:Reply-To: Cc:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=TMvoMpXWNcwaFoO7OIlE9hsfF8M0T0jtnDrS2Vtr6Zk=; b=0I9/RXVGfBJDOXTP+Uq2wMVGud MGB83VQhNTZr82dKw2nd6Iy5qsaUTihrgntD1CZMFQmiQhncxEO6w9ChdgNmJIRzNkRedQkhUI63o 37OABh24zYEfANn8QUqQoy3tmbuGmE5Tl6twckfH5iTMpDtcuuCMrVSsEtUWdOFYCQ73xv0W0EN3r iTt59M76mZ9W//jTOtiAOSz6ZnZPk5l06fsgF9Ox0JHJei2txE+Ef1NejDX0v2I2Cr4EdysHJlc4D eu4Ub4+xhssqX9bn+bOJef+HXR5vvHGFahdM9YpcbsGSfZZkYid9YJsGASVNQT8X+oJ90EIeBjZU0 XVW+Z1sw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsbPI-00000005BIf-3XOL; Fri, 05 Apr 2024 04:42:28 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsbPB-00000005BAz-0IP0 for linux-nvme@lists.infradead.org; Fri, 05 Apr 2024 04:42:23 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 24E03CE35DE; Fri, 5 Apr 2024 04:42:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 431DAC433F1; Fri, 5 Apr 2024 04:42:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712292138; bh=FIR28aVGhJW8E0GXpe6VFYz9Z36VPZVoS0wi8u1x8o8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=FSrHjTVM8pNJbl5S+mxTEsyATbQmDb3BjbXAjzuTRQkqvXegQefFcdcINzthyw4dv gmkPaz00As9wQWxxJ1ymam9SgIlkaC1pCYLcD1G8ZSo3g1tWRzZ3UuNfwkZyRyXUm1 rdN6p/Sfx0fP9clsmyYmXbV0YYKDo/NsAGN89CdhKmiDrb9+CKptKxZnOePbzRWqsw LIe/kMYALiTp7WiCd2nwLFSbUolJo6V4iU2XqYOnuEnxn8s1s/e2CsY3PXG2pZj2m1 jZunoHR3zhZchOaAL/jbL5jP4HFLLoAfRDe1/ap5YNOlL6DYxnd5sBG1rHj1DadzzQ EOR4f6F+mjEOA== From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , linux-scsi@vger.kernel.org, "Martin K . Petersen" , dm-devel@lists.linux.dev, Mike Snitzer , linux-nvme@lists.infradead.org, Keith Busch , Christoph Hellwig Subject: [PATCH v6 06/28] block: Remember zone capacity when revalidating zones Date: Fri, 5 Apr 2024 13:41:45 +0900 Message-ID: <20240405044207.1123462-7-dlemoal@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240405044207.1123462-1-dlemoal@kernel.org> References: <20240405044207.1123462-1-dlemoal@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240404_214221_608769_95D3A882 X-CRM114-Status: GOOD ( 19.16 ) X-BeenThere: linux-nvme@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-nvme" Errors-To: linux-nvme-bounces+linux-nvme=archiver.kernel.org@lists.infradead.org In preparation for adding zone write plugging, modify blk_revalidate_disk_zones() to get the capacity of zones of a zoned block device. This capacity value as a number of 512B sectors is stored in the gendisk zone_capacity field. Given that host-managed SMR disks (including zoned UFS drives) and all known NVMe ZNS devices have the same zone capacity for all zones blk_revalidate_disk_zones() returns an error if different capacities are detected for different zones. This also adds check to verify that the values reported by the device for zone capacities are correct, that is, that the zone capacity is never 0, does not exceed the zone size and is equal to the zone size for conventional zones. Signed-off-by: Damien Le Moal Reviewed-by: Christoph Hellwig Reviewed-by: Hannes Reinecke Reviewed-by: Bart Van Assche Tested-by: Hans Holmberg --- block/blk-zoned.c | 26 ++++++++++++++++++++++++++ include/linux/blkdev.h | 1 + 2 files changed, 27 insertions(+) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index da0f4b2a8fa0..23d9bb21c459 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -438,6 +438,7 @@ struct blk_revalidate_zone_args { unsigned long *conv_zones_bitmap; unsigned long *seq_zones_wlock; unsigned int nr_zones; + unsigned int zone_capacity; sector_t sector; }; @@ -482,9 +483,20 @@ static int blk_revalidate_zone_cb(struct blk_zone *zone, unsigned int idx, return -ENODEV; } + if (!zone->capacity || zone->capacity > zone->len) { + pr_warn("%s: Invalid zone capacity\n", + disk->disk_name); + return -ENODEV; + } + /* Check zone type */ switch (zone->type) { case BLK_ZONE_TYPE_CONVENTIONAL: + if (zone->capacity != zone->len) { + pr_warn("%s: Invalid conventional zone capacity\n", + disk->disk_name); + return -ENODEV; + } if (!args->conv_zones_bitmap) { args->conv_zones_bitmap = blk_alloc_zone_bitmap(q->node, args->nr_zones); @@ -500,6 +512,18 @@ static int blk_revalidate_zone_cb(struct blk_zone *zone, unsigned int idx, if (!args->seq_zones_wlock) return -ENOMEM; } + + /* + * Remember the capacity of the first sequential zone and check + * if it is constant for all zones. + */ + if (!args->zone_capacity) + args->zone_capacity = zone->capacity; + if (zone->capacity != args->zone_capacity) { + pr_warn("%s: Invalid variable zone capacity\n", + disk->disk_name); + return -ENODEV; + } break; case BLK_ZONE_TYPE_SEQWRITE_PREF: default: @@ -595,6 +619,7 @@ int blk_revalidate_disk_zones(struct gendisk *disk, blk_mq_freeze_queue(q); if (ret > 0) { disk->nr_zones = args.nr_zones; + disk->zone_capacity = args.zone_capacity; swap(disk->seq_zones_wlock, args.seq_zones_wlock); swap(disk->conv_zones_bitmap, args.conv_zones_bitmap); if (update_driver_data) @@ -608,6 +633,7 @@ int blk_revalidate_disk_zones(struct gendisk *disk, kfree(args.seq_zones_wlock); kfree(args.conv_zones_bitmap); + return ret; } EXPORT_SYMBOL_GPL(blk_revalidate_disk_zones); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index ec7bd7091467..4e81f714cca7 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -191,6 +191,7 @@ struct gendisk { * blk_mq_unfreeze_queue(). */ unsigned int nr_zones; + unsigned int zone_capacity; unsigned long *conv_zones_bitmap; unsigned long *seq_zones_wlock; #endif /* CONFIG_BLK_DEV_ZONED */ -- 2.44.0