From patchwork Mon May 23 16:15:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12859249 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3FB3DC433F5 for ; Mon, 23 May 2022 16:16:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238589AbiEWQQN (ORCPT ); Mon, 23 May 2022 12:16:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238396AbiEWQQM (ORCPT ); Mon, 23 May 2022 12:16:12 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2111186FA for ; Mon, 23 May 2022 09:16:09 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20220523161606euoutp028476b436f8e6fd997e9f466548ddcdaf~xyB1oFCjH1865418654euoutp02I for ; Mon, 23 May 2022 16:16:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20220523161606euoutp028476b436f8e6fd997e9f466548ddcdaf~xyB1oFCjH1865418654euoutp02I DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1653322566; bh=rvHQ6KWAJnN/wTk9uOYb03xRJQdEtVRuH/wx1RtE7HE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WBsJ86uPBgkd1zGBINfTPSluZ/eUp/FPZX/vg3WS/MjB5tLR81q0rHEbBYRLkpLTv dYBunt9svDngg+yn/0YLWEf2uLKQQL97koSOjz2EuWVPEeX1D0JhyD1IEItGYZQ0Z5 AClXkk7/thGcTd9hQGk9+sI6hs1A4G5mUGSj8A+g= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220523161605eucas1p255aa2158f858eacd6ec421d41a1f2849~xyB0MFXqD2258022580eucas1p2u; Mon, 23 May 2022 16:16:05 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id FC.A9.10260.543BB826; Mon, 23 May 2022 17:16:05 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220523161604eucas1p2927e20dbd0602c08b6df4fc41e62dfbe~xyBz1_CQs1186311863eucas1p29; Mon, 23 May 2022 16:16:04 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220523161604eusmtrp21f0d4014a48df01085abb009a150ac3b~xyBz1Gxts0219002190eusmtrp2I; Mon, 23 May 2022 16:16:04 +0000 (GMT) X-AuditID: cbfec7f5-bddff70000002814-fc-628bb345b402 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id C8.92.09522.443BB826; Mon, 23 May 2022 17:16:04 +0100 (BST) Received: from localhost (unknown [106.210.248.20]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220523161604eusmtip262af8805d5f532401444730d338bcc3f~xyBzeftlD0812708127eusmtip2K; Mon, 23 May 2022 16:16:04 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, hch@lst.de, snitzer@redhat.com, damien.lemoal@opensource.wdc.com, hare@suse.de, Johannes.Thumshirn@wdc.com Cc: linux-nvme@lists.infradead.org, dm-devel@redhat.com, dsterba@suse.com, jiangbo.365@bytedance.com, linux-kernel@vger.kernel.org, gost.dev@samsung.com, linux-block@vger.kernel.org, jaegeuk@kernel.org, Pankaj Raghav , Luis Chamberlain Subject: [PATCH v5 1/7] block: make blkdev_nr_zones and blk_queue_zone_no generic for npo2 zsze Date: Mon, 23 May 2022 18:15:55 +0200 Message-Id: <20220523161601.58078-2-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220523161601.58078-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrDKsWRmVeSWpSXmKPExsWy7djP87qum7uTDDr+8lmsvtvPZvH77Hlm i73vZrNaXPjRyGRx88BOJos9iyYxWaxcfZTJ4sn6WcwWPQc+sFj87brHZLH3lrbF5V1z2Czm L3vKbnFjwlNGi89LW9gt2jZ+ZXQQ8Ph3Yg2bx+WzpR6bVnWyeWxeUu+x+2YDm8fO1vusHu/3 XWXz6NuyitFj/ZarLB6bT1d7fN4k59F+oJspgCeKyyYlNSezLLVI3y6BK+NS1zOWgpkiFd8a 77A2MD4R6GLk5JAQMJHYueomexcjF4eQwApGiSuf7jNBOF8YJXY/uQeV+cwoMX/ZDWaYlqUb LjBCJJYzSmyesQPKecEosW/1IiCHg4NNQEuisROsW0SgkVHi/dF5rCAOs8BsJolzD66xgowS FkiUaGy/zArSwCKgKrFgnRBImFfAUuLozI9sENvkJWZe+s4OYnMKWElcv3qVDaJGUOLkzCcs IDYzUE3z1tnMIPMlBNZzSsyb0cMCMlNCwEXi7XQ/iDnCEq+Ob2GHsGUk/u+czwRhV0s8vfEb qreFUaJ/53o2iF5rib4zOSAms4CmxPpd+hDljhI3Xi1lh6jgk7jxVhDiAj6JSdumM0OEeSU6 2oQgqpUkdv58ArVUQuJy0xwWCNtD4tyBu0wTGBVnIfllFpJfZiHsXcDIvIpRPLW0ODc9tdg4 L7Vcrzgxt7g0L10vOT93EyMwAZ7+d/zrDsYVrz7qHWJk4mA8xCjBwawkwrs9sSNJiDclsbIq tSg/vqg0J7X4EKM0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5II7/bEjiQh 3pTEyqrUovz4otKc1OJDjKZAZ09klhJNzgcmi7ySeEMzA1NDEzNLA1NLM2MlcV7Pgo5EIYH0 xJLU7NTUgtQimD4mDk6pBiaJLZmvjI9JfihXXDh53eKXwa8q5TJfST2wD56aWPr9jUt/tPtD oa2Cqx2XZeu7WGXEfzl85TVT1vFFlg8/vxE5L/qRqdL45OmQH8e/3dZTCStestx4yztTzT1H OWf9fqEhYH5zxU/tNyURhyUZeDmYd7uvmXPuiKTG7RxzJtH/trsnifj+C4uLbas2Oays0fFx 6qQfSxoP/Vjb9JDpRtGdcJGHlwWMv2YdttkqduDngcWxH2Q+r9QxC9g2b7PXFb8l+TbSBuw/ v5/Zrdruwio6ZZ/3WYULKcKq4RkxyTqvEqV6FH+YHBIq5vXz5e9e437lllZ49TNnb30r2/mK HA9frtGeWp5kybHd1SSsfZUSS3FGoqEWc1FxIgB2oD+lXgMAAA== X-CMS-MailID: 20220523161604eucas1p2927e20dbd0602c08b6df4fc41e62dfbe X-Msg-Generator: CA X-RootMTR: 20220523161604eucas1p2927e20dbd0602c08b6df4fc41e62dfbe X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220523161604eucas1p2927e20dbd0602c08b6df4fc41e62dfbe References: <20220523161601.58078-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Adapt blkdev_nr_zones and blk_queue_zone_no function so that it can also work for non-power-of-2 zone sizes. As the existing deployments of zoned devices had power-of-2 assumption, power-of-2 optimized calculation is kept for those devices. There are no direct hot paths modified and the changes just introduce one new branch per call. Reviewed-by: Luis Chamberlain Reviewed by: Adam Manzanares Reviewed-by: Hannes Reinecke Signed-off-by: Pankaj Raghav --- block/blk-zoned.c | 12 +++++++++--- include/linux/blkdev.h | 8 +++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 38cd840d8838..e7eec513dd42 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -111,16 +111,22 @@ EXPORT_SYMBOL_GPL(__blk_req_zone_write_unlock); * blkdev_nr_zones - Get number of zones * @disk: Target gendisk * - * Return the total number of zones of a zoned block device. For a block - * device without zone capabilities, the number of zones is always 0. + * Return the total number of zones of a zoned block device, including the + * eventual small last zone if present. For a block device without zone + * capabilities, the number of zones is always 0. */ unsigned int blkdev_nr_zones(struct gendisk *disk) { sector_t zone_sectors = blk_queue_zone_sectors(disk->queue); + sector_t capacity = get_capacity(disk); if (!blk_queue_is_zoned(disk->queue)) return 0; - return (get_capacity(disk) + zone_sectors - 1) >> ilog2(zone_sectors); + + if (is_power_of_2(zone_sectors)) + return (capacity + zone_sectors - 1) >> ilog2(zone_sectors); + + return div64_u64(capacity + zone_sectors - 1, zone_sectors); } EXPORT_SYMBOL_GPL(blkdev_nr_zones); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 60d016138997..c4e4c7071b7b 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -665,9 +665,15 @@ static inline unsigned int blk_queue_nr_zones(struct request_queue *q) static inline unsigned int blk_queue_zone_no(struct request_queue *q, sector_t sector) { + sector_t zone_sectors = blk_queue_zone_sectors(q); + if (!blk_queue_is_zoned(q)) return 0; - return sector >> ilog2(q->limits.chunk_sectors); + + if (is_power_of_2(zone_sectors)) + return sector >> ilog2(zone_sectors); + + return div64_u64(sector, zone_sectors); } static inline bool blk_queue_zone_is_seq(struct request_queue *q, From patchwork Mon May 23 16:15:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12859251 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1BFAAC433EF for ; Mon, 23 May 2022 16:16:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238435AbiEWQQQ (ORCPT ); Mon, 23 May 2022 12:16:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238610AbiEWQQN (ORCPT ); Mon, 23 May 2022 12:16:13 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C886C27FC6 for ; Mon, 23 May 2022 09:16:09 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220523161608euoutp01b1e2c41f85417ba901040efd2a13f955~xyB241bmd1912419124euoutp01l for ; Mon, 23 May 2022 16:16:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220523161608euoutp01b1e2c41f85417ba901040efd2a13f955~xyB241bmd1912419124euoutp01l DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1653322568; bh=7nBkOw49ughyqfbdOIrZLw3Pc1ezYb+68acQMGQePkk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IabzlFPlnvb4Z/k/spCL/Us4T28SpoFGRfoe32mVOxG+WgmnjYYvJIG58SCEudAXL OM5Scmw1koA6FG8ZqliRnExS0WADYDQ23gT7hwpqQFYDr7+DfuoxkLuDQWgwi77Z1b 3GZJo7e/nYx80tem2O/ZiwKWojiXy0Zflga/AYbs= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220523161606eucas1p2fb8987aab7d30ce848152c893d2bc01e~xyB1dqTQe1825618256eucas1p23; Mon, 23 May 2022 16:16:06 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 5E.A9.10260.643BB826; Mon, 23 May 2022 17:16:06 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220523161606eucas1p2676c4d47f9fcb145f69b29db1f04fe6e~xyB1A6R7V1186311863eucas1p2_; Mon, 23 May 2022 16:16:06 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220523161606eusmtrp299b69a721770b4ead0f2f5bd2f4f3d8f~xyB1ACxcW0219002190eusmtrp2M; Mon, 23 May 2022 16:16:06 +0000 (GMT) X-AuditID: cbfec7f5-bddff70000002814-00-628bb346e666 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 6C.19.09404.643BB826; Mon, 23 May 2022 17:16:06 +0100 (BST) Received: from localhost (unknown [106.210.248.20]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220523161605eusmtip29f8a9bdce98d621272bad00cf15f9614~xyB0s3W620632306323eusmtip2D; Mon, 23 May 2022 16:16:05 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, hch@lst.de, snitzer@redhat.com, damien.lemoal@opensource.wdc.com, hare@suse.de, Johannes.Thumshirn@wdc.com Cc: linux-nvme@lists.infradead.org, dm-devel@redhat.com, dsterba@suse.com, jiangbo.365@bytedance.com, linux-kernel@vger.kernel.org, gost.dev@samsung.com, linux-block@vger.kernel.org, jaegeuk@kernel.org, Pankaj Raghav , Luis Chamberlain Subject: [PATCH v5 2/7] block: allow blk-zoned devices to have non-power-of-2 zone size Date: Mon, 23 May 2022 18:15:56 +0200 Message-Id: <20220523161601.58078-3-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220523161601.58078-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrNKsWRmVeSWpS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6wPNd1n68Orp7g6 yT/fpL5A8Otuh/aqSUHrDyyd0L3QcjW3OV+6rL2x5zXlXLbvLKffXJ2smdvPIpO6eLtu7qv2 1ay2H6Mrf55LWOzvIP2h51jau4zqxIRFB+3Y4/ZU77usovdXTe15tmP3ciexvybf7q4qt/jW 9/7OrhXMoVuXNMYLnPnzUImlOCPRUIu5qDgRAEPzyrtfAwAA X-CMS-MailID: 20220523161606eucas1p2676c4d47f9fcb145f69b29db1f04fe6e X-Msg-Generator: CA X-RootMTR: 20220523161606eucas1p2676c4d47f9fcb145f69b29db1f04fe6e X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220523161606eucas1p2676c4d47f9fcb145f69b29db1f04fe6e References: <20220523161601.58078-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Checking if a given sector is aligned to a zone is a common operation that is performed for zoned devices. Add blk_queue_is_zone_start helper to check for this instead of opencoding it everywhere. Convert the calculations on zone size to be generic instead of relying on power_of_2 based logic in the block layer using the helpers wherever possible. The only hot path affected by this change for power_of_2 zoned devices is in blk_check_zone_append() but blk_queue_is_zone_start() helper is used to optimize the calculation for po2 zone sizes. Note that the append path cannot be accessed by direct raw access to the block device but only through a filesystem abstraction. Finally, allow non power of 2 zoned devices provided that their zone capacity and zone size are equal. The main motivation to allow non power_of_2 zoned device is to remove the unmapped LBA between zcap and zsze for devices that cannot have a power_of_2 zcap. Reviewed-by: Luis Chamberlain Signed-off-by: Pankaj Raghav Reviewed-by: Hannes Reinecke --- block/blk-core.c | 3 +-- block/blk-zoned.c | 26 ++++++++++++++++++++------ include/linux/blkdev.h | 21 +++++++++++++++++++++ 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index bc0506772152..bf1eae142118 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -630,8 +630,7 @@ static inline blk_status_t blk_check_zone_append(struct request_queue *q, return BLK_STS_NOTSUPP; /* The bio sector must point to the start of a sequential zone */ - if (pos & (blk_queue_zone_sectors(q) - 1) || - !blk_queue_zone_is_seq(q, pos)) + if (!blk_queue_is_zone_start(q, pos) || !blk_queue_zone_is_seq(q, pos)) return BLK_STS_IOERR; /* diff --git a/block/blk-zoned.c b/block/blk-zoned.c index e7eec513dd42..665993b13668 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -288,10 +288,10 @@ int blkdev_zone_mgmt(struct block_device *bdev, enum req_opf op, return -EINVAL; /* Check alignment (handle eventual smaller last zone) */ - if (sector & (zone_sectors - 1)) + if (!blk_queue_is_zone_start(q, sector)) return -EINVAL; - if ((nr_sectors & (zone_sectors - 1)) && end_sector != capacity) + if (!blk_queue_is_zone_start(q, nr_sectors) && end_sector != capacity) return -EINVAL; /* @@ -489,14 +489,28 @@ static int blk_revalidate_zone_cb(struct blk_zone *zone, unsigned int idx, * smaller last zone. */ if (zone->start == 0) { - if (zone->len == 0 || !is_power_of_2(zone->len)) { - pr_warn("%s: Invalid zoned device with non power of two zone size (%llu)\n", - disk->disk_name, zone->len); + if (zone->len == 0) { + pr_warn("%s: Invalid zone size", disk->disk_name); + return -ENODEV; + } + + /* + * Don't allow zoned device with non power_of_2 zone size with + * zone capacity less than zone size. + */ + if (!is_power_of_2(zone->len) && + zone->capacity < zone->len) { + pr_warn("%s: Invalid zone capacity for non power of 2 zone size", + disk->disk_name); return -ENODEV; } args->zone_sectors = zone->len; - args->nr_zones = (capacity + zone->len - 1) >> ilog2(zone->len); + /* + * Division is used to calculate nr_zones for both power_of_2 + * and non power_of_2 zone sizes as it is not in the hot path. + */ + args->nr_zones = div64_u64(capacity + zone->len - 1, zone->len); } else if (zone->start + args->zone_sectors < capacity) { if (zone->len != args->zone_sectors) { pr_warn("%s: Invalid zoned device with non constant zone size\n", diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index c4e4c7071b7b..f5c7a41032ba 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -676,6 +676,21 @@ static inline unsigned int blk_queue_zone_no(struct request_queue *q, return div64_u64(sector, zone_sectors); } +static inline bool blk_queue_is_zone_start(struct request_queue *q, sector_t sec) +{ + sector_t zone_sectors = blk_queue_zone_sectors(q); + u64 remainder = 0; + + if (!blk_queue_is_zoned(q)) + return false; + + if (is_power_of_2(zone_sectors)) + return IS_ALIGNED(sec, zone_sectors); + + div64_u64_rem(sec, zone_sectors, &remainder); + return remainder == 0; +} + static inline bool blk_queue_zone_is_seq(struct request_queue *q, sector_t sector) { @@ -722,6 +737,12 @@ static inline unsigned int blk_queue_zone_no(struct request_queue *q, { return 0; } + +static inline bool blk_queue_is_zone_start(struct request_queue *q, sector_t sec) +{ + return false; +} + static inline unsigned int queue_max_open_zones(const struct request_queue *q) { return 0; From patchwork Mon May 23 16:15:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12859250 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3F52C433EF for ; Mon, 23 May 2022 16:16:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238593AbiEWQQP (ORCPT ); Mon, 23 May 2022 12:16:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238578AbiEWQQM (ORCPT ); Mon, 23 May 2022 12:16:12 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FC6D2BB2C for ; Mon, 23 May 2022 09:16:11 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20220523161609euoutp0203c8953fd0db9b7e0c9b89ccd659dd67~xyB4gfFsh1844818448euoutp02Y for ; Mon, 23 May 2022 16:16:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20220523161609euoutp0203c8953fd0db9b7e0c9b89ccd659dd67~xyB4gfFsh1844818448euoutp02Y DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1653322569; bh=6J0Iplh4tce831c/jnAAFO2oDxaRYKcCTdK8i5OmHgA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b5+KIcOhpslMtERqQsgPnlcn04NYjXYmUEyrBFsrU4TmHrF50lX11vW/vH4VqhtH+ S7AW3KFSkmyB9ORlP0qIIfJbkA0ULebOghyqNRj+jL3aaBU4k+Sjo9sWmWTyQPxTVK VY+BbYnWhpFO8+kc819gAbP/LqgWpTeIw1LMZPXI= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20220523161608eucas1p143166bad2bfc87c8a63cae98d3176bc9~xyB2_9lVd1546315463eucas1p1P; Mon, 23 May 2022 16:16:08 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 37.7E.09887.843BB826; Mon, 23 May 2022 17:16:08 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220523161607eucas1p2b6245eafb81dee3e2efbec3ab86a854d~xyB2jZFqS0957009570eucas1p2Y; Mon, 23 May 2022 16:16:07 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220523161607eusmtrp233ab159abe41b38a4d3ff39500eb5828~xyB2inzO30219402194eusmtrp2F; Mon, 23 May 2022 16:16:07 +0000 (GMT) X-AuditID: cbfec7f4-45bff7000000269f-16-628bb3482653 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id FA.92.09522.743BB826; Mon, 23 May 2022 17:16:07 +0100 (BST) Received: from localhost (unknown [106.210.248.20]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220523161607eusmtip2323c9d601f46486d915afc977081c585~xyB2MHWoU0812708127eusmtip2M; Mon, 23 May 2022 16:16:07 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, hch@lst.de, snitzer@redhat.com, damien.lemoal@opensource.wdc.com, hare@suse.de, Johannes.Thumshirn@wdc.com Cc: linux-nvme@lists.infradead.org, dm-devel@redhat.com, dsterba@suse.com, jiangbo.365@bytedance.com, linux-kernel@vger.kernel.org, gost.dev@samsung.com, linux-block@vger.kernel.org, jaegeuk@kernel.org, Pankaj Raghav , Luis Chamberlain Subject: [PATCH v5 3/7] nvme: zns: Allow ZNS drives that have non-power_of_2 zone size Date: Mon, 23 May 2022 18:15:57 +0200 Message-Id: <20220523161601.58078-4-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220523161601.58078-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrLKsWRmVeSWpSXmKPExsWy7djP87oem7uTDF4s5rdYfbefzeL32fPM FnvfzWa1uPCjkcni5oGdTBZ7Fk1isli5+iiTxZP1s5gteg58YLH423WPyWLvLW2Ly7vmsFnM X/aU3eLGhKeMFp+XtrBbtG38yugg4PHvxBo2j8tnSz02repk89i8pN5j980GNo+drfdZPd7v u8rm0bdlFaPH+i1XWTw2n672+LxJzqP9QDdTAE8Ul01Kak5mWWqRvl0CV8bXiydYCq6IVly9 vZ61gfGZYBcjJ4eEgInEupmTmLsYuTiEBFYwShzc9pkFJCEk8IVR4vQ0H4jEZ0aJeTNPscF1 zJnKApFYzijx80MjG4TzglFiRv8exi5GDg42AS2Jxk52kLiIQCOj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DdTAE+Unk1RfmlJqkJGfnGJrVK0oYWRnqGlhZ6R iaWeobF5rJWRqZK+nU1Kak5mWWqRvl2CXsbXiydYCq6IVly9vZ61gfGZYBcjJ4eEgInEujlT WboYuTiEBJYySqxeeoYFIiEhcXthEyOELSzx51oXG0TRM0aJz3snADkcHGwCWhKNnewgcRGB TkaJoytOgU1iFljOJPFyzWKwbmGBMIm7k/ezgdgsAqoSPbPmsIPYvAKWEgubf7BCbJCXmHnp O1icU8BK4vrVq2D1QkA1p9ZPgKoXlDg58wnYdcxA9c1bZzNPYBSYhSQ1C0lqASPTKkaR1NLi 3PTcYkO94sTc4tK8dL3k/NxNjMB43Xbs5+YdjPNefdQ7xMjEwXiIUYKDWUmEd3tiR5IQb0pi ZVVqUX58UWlOavEhRlOguycyS4km5wMTRl5JvKGZgamhiZmlgamlmbGSOK9nQUeikEB6Yklq dmpqQWoRTB8TB6dUA1Ou8GyW5w7e4U2MEbvZffiyuzc5c892XjyJWd90PxN3+2quz32Hfqa6 F/X8+Trl24UnlyT1PE1XbYyZHLAr6pcf2/mr169/77uV8/7QwVe51TsPhpmLCc9afPQrX+Tr bVP/PS++ZNN9q7DzTKjhtgefu28V16a+v6viOVG+ceoBnqWreh73z1zXyJl60/Tcwa9q/pUb +J705756PVt2m2zPibXPJgsk3fx6zcZVt/2L2Hql5L1FIlPP31KukK9c5a56fZYME39SWW0U d/f+1ttrUyQWH364+/vcCB7GfbMdjv4Iz5/p22Ntbup8fdfm3Qevy0d/PaOz6d2l90xKMxOs lTb8bQl4tEZ+x4VO7nIOJZbijERDLeai4kQA/5ecNWADAAA= X-CMS-MailID: 20220523161607eucas1p2b6245eafb81dee3e2efbec3ab86a854d X-Msg-Generator: CA X-RootMTR: 20220523161607eucas1p2b6245eafb81dee3e2efbec3ab86a854d X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220523161607eucas1p2b6245eafb81dee3e2efbec3ab86a854d References: <20220523161601.58078-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Remove the condition which disallows non-power_of_2 zone size ZNS drive to be updated and use generic method to calculate number of zones instead of relying on log and shift based calculation on zone size. The power_of_2 calculation has been replaced directly with generic calculation without special handling. Both modified functions are not used in hot paths, they are only used during initialization & revalidation of the ZNS device. As rounddown macro from math.h does not work for 32 bit architectures, round down operation is open coded. Reviewed-by: Luis Chamberlain Reviewed by: Adam Manzanares Signed-off-by: Pankaj Raghav Reviewed-by: Hannes Reinecke --- drivers/nvme/host/zns.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/drivers/nvme/host/zns.c b/drivers/nvme/host/zns.c index 9f81beb4df4e..d92f937d5cb9 100644 --- a/drivers/nvme/host/zns.c +++ b/drivers/nvme/host/zns.c @@ -101,13 +101,6 @@ int nvme_update_zone_info(struct nvme_ns *ns, unsigned lbaf) } ns->zsze = nvme_lba_to_sect(ns, le64_to_cpu(id->lbafe[lbaf].zsze)); - if (!is_power_of_2(ns->zsze)) { - dev_warn(ns->ctrl->device, - "invalid zone size:%llu for namespace:%u\n", - ns->zsze, ns->head->ns_id); - status = -ENODEV; - goto free_data; - } blk_queue_set_zoned(ns->disk, BLK_ZONED_HM); blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, q); @@ -128,8 +121,13 @@ static void *nvme_zns_alloc_report_buffer(struct nvme_ns *ns, const size_t min_bufsize = sizeof(struct nvme_zone_report) + sizeof(struct nvme_zone_descriptor); + /* + * Division is used to calculate nr_zones with no special handling + * for power of 2 zone sizes as this function is not invoked in a + * hot path + */ nr_zones = min_t(unsigned int, nr_zones, - get_capacity(ns->disk) >> ilog2(ns->zsze)); + div64_u64(get_capacity(ns->disk), ns->zsze)); bufsize = sizeof(struct nvme_zone_report) + nr_zones * sizeof(struct nvme_zone_descriptor); @@ -182,6 +180,7 @@ int nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector, int ret, zone_idx = 0; unsigned int nz, i; size_t buflen; + u64 remainder = 0; if (ns->head->ids.csi != NVME_CSI_ZNS) return -EINVAL; @@ -197,7 +196,11 @@ int nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector, c.zmr.zrasf = NVME_ZRASF_ZONE_REPORT_ALL; c.zmr.pr = NVME_REPORT_ZONE_PARTIAL; - sector &= ~(ns->zsze - 1); + /* + * Round down the sector value to the nearest zone start + */ + div64_u64_rem(sector, ns->zsze, &remainder); + sector -= remainder; while (zone_idx < nr_zones && sector < get_capacity(ns->disk)) { memset(report, 0, buflen); From patchwork Mon May 23 16:15:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12859252 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 541C8C433F5 for ; Mon, 23 May 2022 16:16:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238572AbiEWQQY (ORCPT ); Mon, 23 May 2022 12:16:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238635AbiEWQQO (ORCPT ); Mon, 23 May 2022 12:16:14 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2ABC027FC5 for ; Mon, 23 May 2022 09:16:13 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20220523161611euoutp02d69b34420ef9b26c82e12c455fa063cd~xyB53sIBt1865418654euoutp02O for ; Mon, 23 May 2022 16:16:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20220523161611euoutp02d69b34420ef9b26c82e12c455fa063cd~xyB53sIBt1865418654euoutp02O DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1653322571; bh=9W1pLbbKKEsanlon70WFxiL7DVRrcoEEPxlxXdEW3tc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j+5dSK/d7b8Ph6xvXX8Q9EWPyzlu0EkiNlxa2nXL8c38PkTt5omi8GUyXEMibAPFe CISBDh+DsKGy6VMi0fkMfjFqZEnJtM6q56Sa5Ee4xSbg5j0mTGEluy+uZ6jHkS6DAO mCegylTPqTYKnGCQm12kKriPUdale5Hm4p3jmfLg= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220523161609eucas1p27754a51739628374be85028f4954b683~xyB4VyB3q0957009570eucas1p2Z; Mon, 23 May 2022 16:16:09 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id E4.A4.10009.943BB826; Mon, 23 May 2022 17:16:09 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220523161609eucas1p16c381cd9438240905bfdb0a739132e65~xyB3z4X131867318673eucas1p1E; Mon, 23 May 2022 16:16:09 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220523161609eusmtrp2b6776808758c9ecadcc8ec5d2a7ac2a3~xyB3zBIlt0219002190eusmtrp2N; Mon, 23 May 2022 16:16:09 +0000 (GMT) X-AuditID: cbfec7f2-e7fff70000002719-13-628bb3493b82 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 7D.19.09404.943BB826; Mon, 23 May 2022 17:16:09 +0100 (BST) Received: from localhost (unknown [106.210.248.20]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220523161608eusmtip23cd80bf73bf7fb5af10d44d04beb495e~xyB3eFHeK0812708127eusmtip2N; Mon, 23 May 2022 16:16:08 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, hch@lst.de, snitzer@redhat.com, damien.lemoal@opensource.wdc.com, hare@suse.de, Johannes.Thumshirn@wdc.com Cc: linux-nvme@lists.infradead.org, dm-devel@redhat.com, dsterba@suse.com, jiangbo.365@bytedance.com, linux-kernel@vger.kernel.org, gost.dev@samsung.com, linux-block@vger.kernel.org, jaegeuk@kernel.org, Pankaj Raghav , Bart Van Assche , Johannes Thumshirn , Luis Chamberlain Subject: [PATCH v5 4/7] nvmet: Allow ZNS target to support non-power_of_2 zone sizes Date: Mon, 23 May 2022 18:15:58 +0200 Message-Id: <20220523161601.58078-5-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220523161601.58078-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrCKsWRmVeSWpSXmKPExsWy7djPc7qem7uTDA73aVisvtvPZjHtw09m i99nzzNb7H03m9Xiwo9GJoubB3YyWexZNInJYuXqo0wWT9bPYrboOfCBxeJv1z0mi723tC0u 75rDZjF/2VN2ixsTnjJafF7awm7RtvEro4Ogx+Ur3h7/Tqxh87h8ttRj06pONo/NS+o9dt9s YPPY2Xqf1eP9vqtsHn1bVjF6rN9ylcVj8+lqj8+b5DzaD3QzBfBGcdmkpOZklqUW6dslcGWc XGNZcJK/Yte5x+wNjPN4uxg5OSQETCQ+bPrB1sXIxSEksIJR4tGD/2wgCSGBL4wS3+bxQSQ+ M0pcfzeJDaaj8eFdZojEckaJ75vWs0I4Lxgljl//w97FyMHBJqAl0djJDhIXEWhklHh/dB5Y EbPANyaJu/M2MYMUCQuESVy+nA4ylUVAVeLU4QfMIDavgKXE3BmPmCG2yUvMvPSdHcTmFLCS uH71KhtEjaDEy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9O0S9DJOrrEsOMlfsevcY/YGxnm8XYyc HBICJhKND+8ydzFycQgJLGWUmHD2BCNEQkLi9sImKFtY4s+1LjYQW0jgGaPE4Wf5XYwcHGwC WhKNnewgvSICnYwSR1ecYgFxmAWamCXeT90D1iAsECJxePpHVhCbRUBV4tThB8wgNq+ApcTc GY+YIRbIS8y89J0dxOYUsJK4fvUq1DJLiVPrJ7BD1AtKnJz5hAXEZgaqb946m3kCo8AsJKlZ SFILGJlWMYqklhbnpucWG+kVJ+YWl+al6yXn525iBEbvtmM/t+xgXPnqo94hRiYOxkOMEhzM SiK82xM7koR4UxIrq1KL8uOLSnNSiw8xmgLdPZFZSjQ5H5g+8kriDc0MTA1NzCwNTC3NjJXE eT0LOhKFBNITS1KzU1MLUotg+pg4OKUamMRqY/aauLR+bci+4n6kZ3NGJKeO/vI5S/W85oX7 s3l8u60cnb/TTmS2ROqKvayCp/b7TPasP/tvtb+r1c67y8+URZtxK53x3OKgEulkasukfPbr nTlW66ZPNS1f7X96P0vRxLfyNnINnq92ThFpz3PitDvWys7YKcT++1e7ibGPgtD+Zd/nRtT8 ucJSlV+9TC9FQl1RfmP9F+trbtdmz5vjcHdmX6H0rNdxz5Qvvr+78qNdc4LHJvHv6XnC7fMl wpdr6D20jD0bovKN/UsZu6TMnPIU2zrxlwufvc3zk3nL9mn3btd/XKttdmXeCclf+0rhzGXV yKn/2m7d+Bh4956FXqzxnnafPdv89K8fV2Ipzkg01GIuKk4EACpvuzJnAwAA X-CMS-MailID: 20220523161609eucas1p16c381cd9438240905bfdb0a739132e65 X-Msg-Generator: CA X-RootMTR: 20220523161609eucas1p16c381cd9438240905bfdb0a739132e65 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220523161609eucas1p16c381cd9438240905bfdb0a739132e65 References: <20220523161601.58078-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org A generic bdev_zone_no helper is added to calculate zone number for a given sector in a block device. This helper internally uses blk_queue_zone_no to find the zone number. Use the helper bdev_zone_no() to calculate nr of zones. This let's us make modifications to the math if needed in one place and adds now support for npo2 zone devices. Reviewed by: Adam Manzanares Reviewed-by: Bart Van Assche Reviewed-by: Hannes Reinecke Reviewed-by: Johannes Thumshirn Signed-off-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- drivers/nvme/target/zns.c | 2 +- include/linux/blkdev.h | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/target/zns.c b/drivers/nvme/target/zns.c index e34718b09550..e41b6a6ef048 100644 --- a/drivers/nvme/target/zns.c +++ b/drivers/nvme/target/zns.c @@ -243,7 +243,7 @@ static unsigned long nvmet_req_nr_zones_from_slba(struct nvmet_req *req) unsigned int sect = nvmet_lba_to_sect(req->ns, req->cmd->zmr.slba); return blkdev_nr_zones(req->ns->bdev->bd_disk) - - (sect >> ilog2(bdev_zone_sectors(req->ns->bdev))); + bdev_zone_no(req->ns->bdev, sect); } static unsigned long get_nr_zones_from_buf(struct nvmet_req *req, u32 bufsize) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index f5c7a41032ba..ed8742a72dcb 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1382,6 +1382,13 @@ static inline sector_t bdev_zone_sectors(struct block_device *bdev) return 0; } +static inline unsigned int bdev_zone_no(struct block_device *bdev, sector_t sec) +{ + struct request_queue *q = bdev_get_queue(bdev); + + return blk_queue_zone_no(q, sec); +} + static inline unsigned int bdev_max_open_zones(struct block_device *bdev) { struct request_queue *q = bdev_get_queue(bdev); From patchwork Mon May 23 16:15:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12859253 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99881C433F5 for ; Mon, 23 May 2022 16:16:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238620AbiEWQQ0 (ORCPT ); Mon, 23 May 2022 12:16:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238634AbiEWQQO (ORCPT ); Mon, 23 May 2022 12:16:14 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8E3D2CC94 for ; Mon, 23 May 2022 09:16:13 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220523161612euoutp013f84d9684958f8d942d108266d1b876b~xyB6_rX8-1771117711euoutp01O for ; Mon, 23 May 2022 16:16:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220523161612euoutp013f84d9684958f8d942d108266d1b876b~xyB6_rX8-1771117711euoutp01O DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1653322572; bh=OFfAgqCN0vZ0Zqcth1qSFEK5EzmfN28cnHFopHkhfn0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FdoBCwFkp4q28h9SbrzAMEOuZCEbIw8zjzsvXLpjZA11w8yWG3Jaac5wWpr3RmsHh l0ZHY6KfQHAiKzs6JGWu0z3+vsMAeCx3SdGFfufYlElbHjh5CMUASUjZmS8QEEVjV6 N4oxQ3CIlGJDUlSJah4l72xRfwJCC55K0BaGykps= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20220523161611eucas1p1cb228cf2f9f73b3efa1d9b2c0fb0f3ea~xyB5gEiiO2464724647eucas1p1t; Mon, 23 May 2022 16:16:11 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 78.7E.09887.A43BB826; Mon, 23 May 2022 17:16:10 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220523161610eucas1p212e81eda6b03a2d1ce8b763c9ec933ca~xyB5FGQZM1825618256eucas1p26; Mon, 23 May 2022 16:16:10 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220523161610eusmtrp2991c48c105296293b567a7e3bdadb98e~xyB5EUZl_0219002190eusmtrp2P; Mon, 23 May 2022 16:16:10 +0000 (GMT) X-AuditID: cbfec7f4-471ff7000000269f-1b-628bb34aa273 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 9C.92.09522.A43BB826; Mon, 23 May 2022 17:16:10 +0100 (BST) Received: from localhost (unknown [106.210.248.20]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220523161610eusmtip108e35c0ea0f8fe117da6b4fe20402e3b~xyB4ukA2_2143421434eusmtip1h; Mon, 23 May 2022 16:16:10 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, hch@lst.de, snitzer@redhat.com, damien.lemoal@opensource.wdc.com, hare@suse.de, Johannes.Thumshirn@wdc.com Cc: linux-nvme@lists.infradead.org, dm-devel@redhat.com, dsterba@suse.com, jiangbo.365@bytedance.com, linux-kernel@vger.kernel.org, gost.dev@samsung.com, linux-block@vger.kernel.org, jaegeuk@kernel.org, Pankaj Raghav , Luis Chamberlain Subject: [PATCH v5 5/7] null_blk: allow non power of 2 zoned devices Date: Mon, 23 May 2022 18:15:59 +0200 Message-Id: <20220523161601.58078-6-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220523161601.58078-1-p.ra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Zi9vETU38VaZR1VmdsLZt5aLeYTlD2tgK7wiNaJy1WtK3468EbMVt8u+8howybBbb6 skLf/j/5sP921OpH/s2SfSo3Ppz4/ivymKvH5JOXLohpTrSc87ZHQoVJ7FoMw8u6OLs7mYar lGb/jc9j2WvQ9T79jnhL59ZM8b5jiqwml3QXfn/9dKHvGbuTEvv7r0h6PZmw9c+3dOc8+Sf6 GQ3cWtcesx8MmPy8KdaBRVaJpTgj0VCLuag4EQAQOx/4XwMAAA== X-CMS-MailID: 20220523161610eucas1p212e81eda6b03a2d1ce8b763c9ec933ca X-Msg-Generator: CA X-RootMTR: 20220523161610eucas1p212e81eda6b03a2d1ce8b763c9ec933ca X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220523161610eucas1p212e81eda6b03a2d1ce8b763c9ec933ca References: <20220523161601.58078-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Convert the power of 2 based calculation with zone size to be generic in null_zone_no with optimization for power of 2 based zone sizes. The nr_zones calculation in null_init_zoned_dev has been replaced with a division without special handling for power of 2 based zone sizes as this function is called only during the initialization and will not invoked in the hot path. Performance Measurement: Device: zone size = 128M, blocksize=4k FIO cmd: fio --name=zbc --filename=/dev/nullb0 --direct=1 --zonemode=zbd --size=23G --io_size= --ioengine=io_uring --iodepth= --rw= --bs=4k --loops=4 The following results are an average of 4 runs on AMD Ryzen 5 5600X with 32GB of RAM: Sequential Write: x-----------------x---------------------------------x---------------------------------x | IOdepth | 8 | 16 | x-----------------x---------------------------------x---------------------------------x | | KIOPS |BW(MiB/s) | Lat(usec) | KIOPS |BW(MiB/s) | Lat(usec) | x-----------------x---------------------------------x---------------------------------x | Without patch | 578 | 2257 | 12.80 | 576 | 2248 | 25.78 | x-----------------x---------------------------------x---------------------------------x | With patch | 581 | 2268 | 12.74 | 576 | 2248 | 25.85 | x-----------------x---------------------------------x---------------------------------x Sequential read: x-----------------x---------------------------------x---------------------------------x | IOdepth | 8 | 16 | x-----------------x---------------------------------x---------------------------------x | | KIOPS |BW(MiB/s) | Lat(usec) | KIOPS |BW(MiB/s) | Lat(usec) | x-----------------x---------------------------------x---------------------------------x | Without patch | 667 | 2605 | 11.79 | 675 | 2637 | 23.49 | x-----------------x---------------------------------x---------------------------------x | With patch | 667 | 2605 | 11.79 | 675 | 2638 | 23.48 | x-----------------x---------------------------------x---------------------------------x Random read: x-----------------x---------------------------------x---------------------------------x | IOdepth | 8 | 16 | x-----------------x---------------------------------x---------------------------------x | | KIOPS |BW(MiB/s) | Lat(usec) | KIOPS |BW(MiB/s) | Lat(usec) | x-----------------x---------------------------------x---------------------------------x | Without patch | 522 | 2038 | 15.05 | 514 | 2006 | 30.87 | x-----------------x---------------------------------x---------------------------------x | With patch | 522 | 2039 | 15.04 | 523 | 2042 | 30.33 | x-----------------x---------------------------------x---------------------------------x Minor variations are noticed in Sequential write with io depth 8 and in random read with io depth 16. But overall no noticeable differences were noticed Reviewed-by: Luis Chamberlain Reviewed by: Adam Manzanares Reviewed-by: Hannes Reinecke Signed-off-by: Pankaj Raghav Reported-by: kernel test robot Reported-by: kernel test robot --- drivers/block/null_blk/main.c | 5 ++--- drivers/block/null_blk/zoned.c | 14 +++++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c index c441a4972064..1dec51d69674 100644 --- a/drivers/block/null_blk/main.c +++ b/drivers/block/null_blk/main.c @@ -1930,9 +1930,8 @@ static int null_validate_conf(struct nullb_device *dev) if (dev->queue_mode == NULL_Q_BIO) dev->mbps = 0; - if (dev->zoned && - (!dev->zone_size || !is_power_of_2(dev->zone_size))) { - pr_err("zone_size must be power-of-two\n"); + if (dev->zoned && !dev->zone_size) { + pr_err("Invalid zero zone size\n"); return -EINVAL; } diff --git a/drivers/block/null_blk/zoned.c b/drivers/block/null_blk/zoned.c index dae54dd1aeac..00c34e65ef0a 100644 --- a/drivers/block/null_blk/zoned.c +++ b/drivers/block/null_blk/zoned.c @@ -13,7 +13,10 @@ static inline sector_t mb_to_sects(unsigned long mb) static inline unsigned int null_zone_no(struct nullb_device *dev, sector_t sect) { - return sect >> ilog2(dev->zone_size_sects); + if (is_power_of_2(dev->zone_size_sects)) + return sect >> ilog2(dev->zone_size_sects); + + return div64_u64(sect, dev->zone_size_sects); } static inline void null_lock_zone_res(struct nullb_device *dev) @@ -62,10 +65,6 @@ int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q) sector_t sector = 0; unsigned int i; - if (!is_power_of_2(dev->zone_size)) { - pr_err("zone_size must be power-of-two\n"); - return -EINVAL; - } if (dev->zone_size > dev->size) { pr_err("Zone size larger than device capacity\n"); return -EINVAL; @@ -83,8 +82,9 @@ int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q) zone_capacity_sects = mb_to_sects(dev->zone_capacity); dev_capacity_sects = mb_to_sects(dev->size); dev->zone_size_sects = mb_to_sects(dev->zone_size); - dev->nr_zones = round_up(dev_capacity_sects, dev->zone_size_sects) - >> ilog2(dev->zone_size_sects); + dev->nr_zones = + div64_u64(roundup(dev_capacity_sects, dev->zone_size_sects), + dev->zone_size_sects); dev->zones = kvmalloc_array(dev->nr_zones, sizeof(struct nullb_zone), GFP_KERNEL | __GFP_ZERO); From patchwork Mon May 23 16:16:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12859254 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71C90C433EF for ; Mon, 23 May 2022 16:16:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238645AbiEWQQj (ORCPT ); Mon, 23 May 2022 12:16:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238413AbiEWQQQ (ORCPT ); Mon, 23 May 2022 12:16:16 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1166A2BB2C for ; Mon, 23 May 2022 09:16:15 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20220523161613euoutp02cf5d129e7a6142c721d4ac437ef4ff2d~xyB8NEDZ-1844818448euoutp02e for ; Mon, 23 May 2022 16:16:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20220523161613euoutp02cf5d129e7a6142c721d4ac437ef4ff2d~xyB8NEDZ-1844818448euoutp02e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1653322573; bh=fIf/6lZBIMLYnlgjkIJlslbFXYFBpGgwHc1kbNxW2m0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vMHsFW9rVTyOZMygBC1/GLnSpvbWzJm1jdrcQ8fenFlgbmnUcMzJBDHE7PdeV3hJj GybFytSWFkMqSSv/MIoA7/Tcg7kEpMAoVsemHMw9c/02aIRAo/uE0OE4JeDzCoiHqU 0WA3HRc90BS+aWkloGzfwKXOBD9/VjgbFiVAcltg= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20220523161612eucas1p1a9d5050929914d94c05669bd95e7e5c5~xyB66Yz_y1870118701eucas1p17; Mon, 23 May 2022 16:16:12 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id FA.7E.09887.C43BB826; Mon, 23 May 2022 17:16:12 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220523161612eucas1p102a76ba431c934230309042521018915~xyB6eyhDU1546315463eucas1p1U; Mon, 23 May 2022 16:16:12 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220523161612eusmtrp291363c1e24ed18c446c30856c864aca3~xyB6eBYUJ0219402194eusmtrp2L; Mon, 23 May 2022 16:16:12 +0000 (GMT) X-AuditID: cbfec7f4-471ff7000000269f-21-628bb34c5ddf Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id AE.92.09522.B43BB826; Mon, 23 May 2022 17:16:11 +0100 (BST) Received: from localhost (unknown [106.210.248.20]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220523161611eusmtip23dcc1d85f474d9be5b8476ac221bd377~xyB6E6DfN0632306323eusmtip2G; Mon, 23 May 2022 16:16:11 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, hch@lst.de, snitzer@redhat.com, damien.lemoal@opensource.wdc.com, hare@suse.de, Johannes.Thumshirn@wdc.com Cc: linux-nvme@lists.infradead.org, dm-devel@redhat.com, dsterba@suse.com, jiangbo.365@bytedance.com, linux-kernel@vger.kernel.org, gost.dev@samsung.com, linux-block@vger.kernel.org, jaegeuk@kernel.org, Pankaj Raghav , Damien Le Moal Subject: [PATCH v5 6/7] null_blk: use zone_size_sects_shift for power of 2 zoned devices Date: Mon, 23 May 2022 18:16:00 +0200 Message-Id: <20220523161601.58078-7-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220523161601.58078-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrLKsWRmVeSWpSXmKPExsWy7djP87o+m7uTDJ7skrFYfbefzeL32fPM Fq3t35gs9r6bzWpx4Ucjk8XNAzuZLPYsmsRksXL1USaLJ+tnMVv0HPjAYvG36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VC8M4uiK5Pfc7uEzSSplkXjxjEel5z6q6pU7+3J8WB317LhRocx3 2Uc8a1aGKk7b+fLuvu8PlFiKMxINtZiLihMBPcXgGmADAAA= X-CMS-MailID: 20220523161612eucas1p102a76ba431c934230309042521018915 X-Msg-Generator: CA X-RootMTR: 20220523161612eucas1p102a76ba431c934230309042521018915 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220523161612eucas1p102a76ba431c934230309042521018915 References: <20220523161601.58078-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Instead of doing is_power_of_2 and ilog2 operation for every IO, cache the zone_size_sects_shift variable and use it for power of 2 zoned devices. This variable will be set to zero for non power of 2 zoned devices. Suggested-by: Damien Le Moal Signed-off-by: Pankaj Raghav Reviewed-by: Luis Chamberlain Reviewed-by: Hannes Reinecke --- drivers/block/null_blk/null_blk.h | 6 ++++++ drivers/block/null_blk/zoned.c | 10 ++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/block/null_blk/null_blk.h b/drivers/block/null_blk/null_blk.h index 78eb56b0ca55..3d6e41a9491f 100644 --- a/drivers/block/null_blk/null_blk.h +++ b/drivers/block/null_blk/null_blk.h @@ -74,6 +74,12 @@ struct nullb_device { unsigned int imp_close_zone_no; struct nullb_zone *zones; sector_t zone_size_sects; + /* + * zone_size_sects_shift is only useful when the zone size is + * power of 2. This variable is set to zero when zone size is non + * power of 2. + */ + unsigned int zone_size_sects_shift; bool need_zone_res_mgmt; spinlock_t zone_res_lock; diff --git a/drivers/block/null_blk/zoned.c b/drivers/block/null_blk/zoned.c index 00c34e65ef0a..806bef98ac83 100644 --- a/drivers/block/null_blk/zoned.c +++ b/drivers/block/null_blk/zoned.c @@ -13,8 +13,8 @@ static inline sector_t mb_to_sects(unsigned long mb) static inline unsigned int null_zone_no(struct nullb_device *dev, sector_t sect) { - if (is_power_of_2(dev->zone_size_sects)) - return sect >> ilog2(dev->zone_size_sects); + if (dev->zone_size_sects_shift) + return sect >> dev->zone_size_sects_shift; return div64_u64(sect, dev->zone_size_sects); } @@ -82,6 +82,12 @@ int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q) zone_capacity_sects = mb_to_sects(dev->zone_capacity); dev_capacity_sects = mb_to_sects(dev->size); dev->zone_size_sects = mb_to_sects(dev->zone_size); + + if (is_power_of_2(dev->zone_size_sects)) + dev->zone_size_sects_shift = ilog2(dev->zone_size_sects); + else + dev->zone_size_sects_shift = 0; + dev->nr_zones = div64_u64(roundup(dev_capacity_sects, dev->zone_size_sects), dev->zone_size_sects); From patchwork Mon May 23 16:16:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12859255 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B3ECC433F5 for ; Mon, 23 May 2022 16:16:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238477AbiEWQQl (ORCPT ); Mon, 23 May 2022 12:16:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238643AbiEWQQS (ORCPT ); Mon, 23 May 2022 12:16:18 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B766332EE8 for ; Mon, 23 May 2022 09:16:16 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220523161615euoutp01b06f8171538ded11e1f4d4ebb2aeb450~xyB9wFCP61818718187euoutp01Z for ; Mon, 23 May 2022 16:16:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220523161615euoutp01b06f8171538ded11e1f4d4ebb2aeb450~xyB9wFCP61818718187euoutp01Z DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1653322575; bh=aLBSqS5uAesNMicTZHySwg8Swibu7HOYfUS7gR9bn94=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M7lHHDcnMiHGeh+Q+8z/MXZKknjJVpgVsRtdLQE4Nxm2DWJaInn0kZx11CyAKk9yO eaH5hMz9wMUsjETfoUO5Wr79yWkRrpdt8vxyLMwq2vAiGcYSPY7xbZHASug5xPWyM6 MlGlBQMrI4tEs1on9cIkGnHBU2NZ/Y8T5nrEGG3A= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20220523161613eucas1p14eb4dfeeca85d1b74be3a853a80b3897~xyB8L9OR_1546315463eucas1p1V; Mon, 23 May 2022 16:16:13 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 5E.7E.09887.D43BB826; Mon, 23 May 2022 17:16:13 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220523161613eucas1p256b21b1a631324b4814465decf3958ce~xyB7qut2W0957009570eucas1p2d; Mon, 23 May 2022 16:16:13 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220523161613eusmtrp2c000f1ed1707206c2a22768a34db555b~xyB7p7UDg0219002190eusmtrp2W; Mon, 23 May 2022 16:16:13 +0000 (GMT) X-AuditID: cbfec7f4-45bff7000000269f-28-628bb34de617 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 71.29.09404.D43BB826; Mon, 23 May 2022 17:16:13 +0100 (BST) Received: from localhost (unknown [106.210.248.20]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220523161612eusmtip1e2e71268148d672b0c1860ca258f8832~xyB7VIab71408314083eusmtip1g; Mon, 23 May 2022 16:16:12 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, hch@lst.de, snitzer@redhat.com, damien.lemoal@opensource.wdc.com, hare@suse.de, Johannes.Thumshirn@wdc.com Cc: linux-nvme@lists.infradead.org, dm-devel@redhat.com, dsterba@suse.com, jiangbo.365@bytedance.com, linux-kernel@vger.kernel.org, gost.dev@samsung.com, linux-block@vger.kernel.org, jaegeuk@kernel.org, Luis Chamberlain , Pankaj Raghav Subject: [PATCH v5 7/7] dm-zoned: ensure only power of 2 zone sizes are allowed Date: Mon, 23 May 2022 18:16:01 +0200 Message-Id: <20220523161601.58078-8-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220523161601.58078-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA02Sf0wTZxzG895dr0dD2VkdfCPTbV2EUGfLnISTkQUiSy5biNPELJQYqXjD BqikBxsbcYPxU1z40f1sYWIYagGxlVal7dywCXaMMQhNJ2Vxm9puRFEghWFHhFFOM/97vu/z ed/n+yQvhct+E22mtLpSTq/TFMlJCXH5enhsR7bt5OHk1XEV03uzmWSWR8dw5uqDNhEz/rAK Y/yDDoz5rtOAMd29QxgTsJhw5tPBOYJ51Pg7xlyd2s54ne0k03E2KGYmW4KICZ2pETN1FxdR Bs2u/HieZL2jZWx/zwmStXV9zLr8lSTrqP1DxM5+7yPZJnsPYi12H8HaRirYUP9Wtn7wJPZ2 tFqSfoQr0r7H6VWv50mOfj6sLjklKfff7yMqkZVqRFEU0LvggudvshFJKBltRtDg6UcRQ0Yv ILA/ekcwQgjC4yfET278YO1AgnEOgdvaKxKGaQRBc+vaQFEkrYCqyAUJtYmuQjA7dGodwu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l2CXsaUk1EF87gqbr5dy9LAuIGji5GTQ0LARGL/hvmM XYxcHEICSxklPv1qYINISEjcXtjECGELS/y51sUGUfSMUWLNi0PMXYwcHGwCWhKNnewgcRGB TkaJoytOsYA4zALLmSRuPGlhAukWFvCX2LfwPCuIzSKgKrFl1RYWEJtXwFJiw4XdUNvkJWZe +s4OYnMKWElcv3oVLC4EVHNq/QR2iHpBiZMzn4D1MgPVN2+dzTyBUWAWktQsJKkFjEyrGEVS S4tz03OLjfSKE3OLS/PS9ZLzczcxAqN127GfW3Ywrnz1Ue8QIxMH4yFGCQ5mJRHe7YkdSUK8 KYmVValF+fFFpTmpxYcYTYHunsgsJZqcD0wXeSXxhmYGpoYmZpYGppZmxkrivJ4FHYlCAumJ JanZqakFqUUwfUwcnFINTFMFpirMu1Une2/b55riPXOYGMrcpn+/Jf/G+op0mtjfZ6dV3N+n 7F8bfGnhuX8pizmN1907Erz5/MKnC6//t1ji9OeMMdOhmCsr7h0VOHK+ccGErH9GT4vMF62d +XLya47cG+YnGlQtOQ9t9ViguKlU/aPGGo+pfaKx0TVH2f+Hvm7j+/zE5s9KsW6h5W5fJta/ uC0cvVu7+k6t7XuD8FtuuifKNm48cGDatomeRxIub2PSmLGZlydD/01kQOv6xObfZVZz+y9K 1mkcs6/uDM9v8Bb0nFkTaLhZbK3p1u8matyTt2sf2rHtkp7X69tuXf9uzd+Z+P+zoijTyuM7 JzVfEmYMk+FTuMX09dneX6nHlFiKMxINtZiLihMBy1qFi18DAAA= X-CMS-MailID: 20220523161613eucas1p256b21b1a631324b4814465decf3958ce X-Msg-Generator: CA X-RootMTR: 20220523161613eucas1p256b21b1a631324b4814465decf3958ce X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220523161613eucas1p256b21b1a631324b4814465decf3958ce References: <20220523161601.58078-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Luis Chamberlain 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 Signed-off-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- drivers/md/dm-zone.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/md/dm-zone.c b/drivers/md/dm-zone.c index 57daa86c19cf..f87a1eda8252 100644 --- a/drivers/md/dm-zone.c +++ b/drivers/md/dm-zone.c @@ -231,6 +231,18 @@ 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; + char bname[BDEVNAME_SIZE]; + + zone_sectors = bdev_zone_sectors(bdev); + + if (!is_power_of_2(zone_sectors)) { + DMWARN("%s: %s only power of two zone size supported", + dm_device_name(md), + bdevname(bdev, bname)); + return -EINVAL; + } /* * Check if something changed. If yes, cleanup the current resources