From patchwork Wed May 25 15:49:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12861400 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 1BDD7C433EF for ; Wed, 25 May 2022 15:50:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245301AbiEYPu2 (ORCPT ); Wed, 25 May 2022 11:50:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245363AbiEYPuH (ORCPT ); Wed, 25 May 2022 11:50:07 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CE6FAF32C for ; Wed, 25 May 2022 08:50:05 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220525155002euoutp011b6998e6d46c4b4f13ac76475e859e53~yY9o5LleK0414604146euoutp01B for ; Wed, 25 May 2022 15:50:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220525155002euoutp011b6998e6d46c4b4f13ac76475e859e53~yY9o5LleK0414604146euoutp01B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1653493802; bh=2eQZ6kViMFen5Vvv5WDxkU+VSeYRgwNz1guBAQ1Xbgw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a4r22eAsBHe0iH2u5aBM3JQS6HB6jwgo0YmhQutxHjmR0UiiixutGSD3ld4doRe9R PhqWlf3u88fSy7EPZ9iDrGHa+lyQ6/wNv2nidmXvUB/rqbKJslfjzCsxyinTbObUbm YpzULJXwsfpNVjOI3Us03oUecMShlROSIAcH65es= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220525155000eucas1p216752d9914ca37a7d223bef39c8fb758~yY9nXTACK0700607006eucas1p2H; Wed, 25 May 2022 15:50:00 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id A9.FF.10260.8205E826; Wed, 25 May 2022 16:50:00 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220525155000eucas1p200ac7e1c844980e728c9e88f51c4590e~yY9m7pDL80700607006eucas1p2G; Wed, 25 May 2022 15:50:00 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220525154959eusmtrp232e421c63a06da32f789c1209bc5a763~yY9m62BF90177001770eusmtrp2W; Wed, 25 May 2022 15:49:59 +0000 (GMT) X-AuditID: cbfec7f5-bddff70000002814-d0-628e502837bc Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id DC.8E.09404.7205E826; Wed, 25 May 2022 16:49:59 +0100 (BST) Received: from localhost (unknown [106.210.248.20]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220525154959eusmtip1b8cca573c1722645da3df92c140f2a0b~yY9mnZb3k1782817828eusmtip1W; Wed, 25 May 2022 15:49:59 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, damien.lemoal@opensource.wdc.com, snitzer@redhat.com, Johannes.Thumshirn@wdc.com, hch@lst.de, hare@suse.de Cc: dsterba@suse.com, dm-devel@redhat.com, jiangbo.365@bytedance.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, jaegeuk@kernel.org, gost.dev@samsung.com, Pankaj Raghav , Luis Chamberlain Subject: [PATCH v6 1/8] block: make blkdev_nr_zones and blk_queue_zone_no generic for npo2 zsze Date: Wed, 25 May 2022 17:49:50 +0200 Message-Id: <20220525154957.393656-2-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220525154957.393656-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrFKsWRmVeSWpSXmKPExsWy7djP87oaAX1JBhemSlisvtvPZvH77Hlm i73vZrNaXPjRyGRx88BOJos9iyYxWaxcfZTJ4sn6WcwWPQc+sFj87brHZLH3lrbF5V1z2Czm L3vKbnFjwlNGi89LW9gt2jZ+ZXQQ8Ph3Yg2bx+WzpR6bVnWyeWxeUu+x+2YDm8fO1vusHu/3 XWXz6NuyitFj/ZarLB6bT1d7fN4k59F+oJspgCeKyyYlNSezLLVI3y6BK2PaibnsBZNEKl5N 3sXYwPhQoIuRg0NCwETizJ6MLkYuDiGBFYwSi57sZuxi5ARyvjBK/G1ThUh8ZpRoeTWdFSQB 0jC59QkzRGI5o0TDil42COcFo0TX7AlMIGPZBLQkGjvZQeIiAo2MElNfnmAEcZgFZjNJzPs2 GWyHsECiRG/PHTYQm0VAVeLZm7usIM28AlYS+w5LQmyTl5h56Ts7iM0pYC0xf/9nZhCbV0BQ 4uTMJywgNjNQTfPW2WAXSQis55Q4er+DDaLZRWLpiddQtrDEq+Nb2CFsGYn/O+czQdjVEk9v /IZqbmGU6N+5ng0SMNYSfWdyQExmAU2J9bv0IcodJR4//soOUcEnceOtIMQJfBKTtk1nhgjz SnS0CUFUK0ns/PkEaqmExOWmOSwQJR4SW29bTGBUnIXkl1lIfpmFsHYBI/MqRvHU0uLc9NRi 47zUcr3ixNzi0rx0veT83E2MwOR3+t/xrzsYV7z6qHeIkYmD8RCjBAezkgjvhae9SUK8KYmV ValF+fFFpTmpxYcYpTlYlMR5kz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IQ b0piZVVqUX58UWlOavEhRlOgsycyS4km5wNTRV5JvKGZgamhiZmlgamlmbGSOK9nQUeikEB6 YklqdmpqQWoRTB8TB6dUA1PkhHXz4zKaVu72PXKjsvWD+uuOJKXKq0Z8VmEee9zfvpbiTdKT MpIqvyG85oSV4lW163f2z+ee4FHz7dRsnRbeG18DnZZJSm5R4mZ3K5acdUT7qvjyz+ZL4k5f Zf2qVMb24bXB7Yum2ryBzec3MD1Y2pN2s+8a44XVl0ymhfLqLJzmudjxdMo51szLq0/3t8xa YRTp/Nlgiv65ivc37x1wqZ0rxLyotTIlUDo1yC03XsNRUN9s0orMU3Lzfyq0tVX1r2thvLR6 WvnUR6XP7jd5fmZ9fWw+5x+b+GsebV8PvChsPrxJ/Xf8Jke76u93K+0/Z4c/n9kePvN/8Zc7 N/mzTN9EPQy69f/kx0cGYRuUWIozEg21mIuKEwGfZguQXQMAAA== X-CMS-MailID: 20220525155000eucas1p200ac7e1c844980e728c9e88f51c4590e X-Msg-Generator: CA X-RootMTR: 20220525155000eucas1p200ac7e1c844980e728c9e88f51c4590e X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220525155000eucas1p200ac7e1c844980e728c9e88f51c4590e References: <20220525154957.393656-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..8b0615287cd3 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 DIV_ROUND_UP_SECTOR_T(capacity, 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 Wed May 25 15:49:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12861405 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 D8B63C433EF for ; Wed, 25 May 2022 15:50:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245343AbiEYPua (ORCPT ); Wed, 25 May 2022 11:50:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245360AbiEYPuH (ORCPT ); Wed, 25 May 2022 11:50:07 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CD8FAF323 for ; Wed, 25 May 2022 08:50:05 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220525155003euoutp015a0561b59d3a966f0f28dfff1784a6a2~yY9qSG4pX0505805058euoutp01t for ; Wed, 25 May 2022 15:50:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220525155003euoutp015a0561b59d3a966f0f28dfff1784a6a2~yY9qSG4pX0505805058euoutp01t DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1653493803; bh=eIzmCQdaDOwFVfOZf19TLoQqXlSMlt1Y+6+A06erjss=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TumzsWDjZjeUouQQIpgf30xmF6GssRrXPZQFMkTrBxY3RtFz2svChGXPoyPbIg9Mu h+34n0fl/Sqb9c+jJu8aaJ5A60YhnB1kHq6PWbODa5a+DBfxD4EIQtBvWNykZW7yOn 2OXfXn0hQODwBKiKfUGpgmF1i24Uzq5LJEG2ZjCo= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20220525155001eucas1p1d45325ccf59057b8a8e4f7aff428fca3~yY9ouHCB01682916829eucas1p1n; Wed, 25 May 2022 15:50:01 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id FA.5B.10009.9205E826; Wed, 25 May 2022 16:50:01 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220525155001eucas1p13e64a05367144fc6965f486bb07b55a2~yY9oBV-bz1682916829eucas1p1m; Wed, 25 May 2022 15:50:01 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220525155001eusmtrp1e300515e2f759f717d24a8034d0e684c~yY9oAQs8L1510315103eusmtrp13; Wed, 25 May 2022 15:50:01 +0000 (GMT) X-AuditID: cbfec7f2-e7fff70000002719-38-628e50294712 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 19.17.09522.9205E826; Wed, 25 May 2022 16:50:01 +0100 (BST) Received: from localhost (unknown [106.210.248.20]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220525155000eusmtip14618fa38abc8c0316d04639cb06a9481~yY9nuExE31817318173eusmtip1C; Wed, 25 May 2022 15:50:00 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, damien.lemoal@opensource.wdc.com, snitzer@redhat.com, Johannes.Thumshirn@wdc.com, hch@lst.de, hare@suse.de Cc: dsterba@suse.com, dm-devel@redhat.com, jiangbo.365@bytedance.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, jaegeuk@kernel.org, gost.dev@samsung.com, Pankaj Raghav , Luis Chamberlain Subject: [PATCH v6 2/8] block: allow blk-zoned devices to have non-power-of-2 zone size Date: Wed, 25 May 2022 17:49:51 +0200 Message-Id: <20220525154957.393656-3-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220525154957.393656-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrFKsWRmVeSWpSXmKPExsWy7djPc7q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PIRTdp Ltuve5vi857s9tWfu8HYMmH5leLnVx+vfn1o48IUvofZf/Z8WftNs+JHSB2bgehytVn/g+Jc 9H3W7LjQtqWdI2j27IrVF49n71Lkapav6N0j0tFsEbxc7+4ahxf6hv7Z1UtyDn7jnaOw9aGd 0t+lWTod16b3ZT5Zt0SJpTgj0VCLuag4EQALrYxWXwMAAA== X-CMS-MailID: 20220525155001eucas1p13e64a05367144fc6965f486bb07b55a2 X-Msg-Generator: CA X-RootMTR: 20220525155001eucas1p13e64a05367144fc6965f486bb07b55a2 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220525155001eucas1p13e64a05367144fc6965f486bb07b55a2 References: <20220525154957.393656-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 Reviewed-by: Hannes Reinecke Signed-off-by: Pankaj Raghav --- block/blk-core.c | 3 +-- block/blk-zoned.c | 25 +++++++++++++++++++------ include/linux/blkdev.h | 21 +++++++++++++++++++++ 3 files changed, 41 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 8b0615287cd3..7957eec04ff6 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,27 @@ 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 Wed May 25 15:49:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12861404 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 12A8EC43219 for ; Wed, 25 May 2022 15:50:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245311AbiEYPu3 (ORCPT ); Wed, 25 May 2022 11:50:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245362AbiEYPuH (ORCPT ); Wed, 25 May 2022 11:50:07 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B8C8B042F for ; Wed, 25 May 2022 08:50:06 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220525155004euoutp01a0200fd0a573e5b66df33b4eff459828~yY9rh6cI50322203222euoutp01- for ; Wed, 25 May 2022 15:50:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220525155004euoutp01a0200fd0a573e5b66df33b4eff459828~yY9rh6cI50322203222euoutp01- DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1653493804; bh=+Hy87tAmG/yyKADBgWzp15ysBeZyafQHy3LFCyQAgp0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pSbAE9O+IMpDkfslzuGHPy9CTHc5z0NZMQWhy3cvl+dNrSgBOSDB1VTmDQxPczIt8 qFuUzjNvD29O6mOPpMG/rApSx9c9Yb0k21df6eThMnvszXWrsm5jQ6MmWdo1lW8N2q 7wVzUd+sJXRRBKr6sxWyg1Afq84EHHZqp5ncN270= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220525155003eucas1p2a7c20e3afb1e439dfd265ea1aa7fa777~yY9p0V1-R0965609656eucas1p2D; Wed, 25 May 2022 15:50:03 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id BC.5B.10009.B205E826; Wed, 25 May 2022 16:50:03 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220525155002eucas1p140ca05edf5219f38e8f1a45801c2ed62~yY9pVc3d-1064210642eucas1p1p; Wed, 25 May 2022 15:50:02 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220525155002eusmtrp1ec4acfdd9bb2e4d1110f65446f4f7953~yY9pUNjfc1510315103eusmtrp17; Wed, 25 May 2022 15:50:02 +0000 (GMT) X-AuditID: cbfec7f2-e95ff70000002719-3b-628e502babe3 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id BA.17.09522.A205E826; Wed, 25 May 2022 16:50:02 +0100 (BST) Received: from localhost (unknown [106.210.248.20]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220525155002eusmtip1994e3f4509e63f9dac1bc8358a0fcfad~yY9o4AQn_1835018350eusmtip1B; Wed, 25 May 2022 15:50:01 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, damien.lemoal@opensource.wdc.com, snitzer@redhat.com, Johannes.Thumshirn@wdc.com, hch@lst.de, hare@suse.de Cc: dsterba@suse.com, dm-devel@redhat.com, jiangbo.365@bytedance.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, jaegeuk@kernel.org, gost.dev@samsung.com, Pankaj Raghav , Luis Chamberlain Subject: [PATCH v6 3/8] nvme: zns: Allow ZNS drives that have non-power_of_2 zone size Date: Wed, 25 May 2022 17:49:52 +0200 Message-Id: <20220525154957.393656-4-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220525154957.393656-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrDKsWRmVeSWpSXmKPExsWy7djP87raAX1JBuf6WSxW3+1ns/h99jyz xd53s1ktLvxoZLK4eWAnk8WeRZOYLFauPspk8WT9LGaLngMfWCz+dt1jsth7S9vi8q45bBbz lz1lt7gx4SmjxeelLewWbRu/MjoIePw7sYbN4/LZUo9NqzrZPDYvqffYfbOBzWNn631Wj/f7 rrJ59G1ZxeixfstVFo/Np6s9Pm+S82g/0M0UwBPFZZOSmpNZllqkb5fAlbF5dz9rQaNYxa+z j5gaGPuEuhg5OSQETCT+PJjG1MXIxSEksIJRYknfanYI5wujxJmb3xlBqoQEPjNKXDsV3cXI Adbx/ZUXRM1yoJoFsxkhnBeMEls+r2YFKWIT0JJo7AQbJCLQyCgx9eUJsCJmgdlM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7fN4k59F+oJspgCdKz6Yov7QkVSEjv7jEVina0MJIz9DSQs/I xFLP0Ng81srIVEnfziYlNSezLLVI3y5BL2Pz7n7Wgkaxil9nHzE1MPYJdTFycEgImEh8f+XV xcjFISSwlFHi1LfFzF2MnEBxCYnbC5sYIWxhiT/XuthAbCGBZ4wSqw+kgfSyCWhJNHayg/SK CHQySszZ1wrmMAssZ5J4/mkR2CBhgTCJuyd62UFsFgFVibfbHoEN5RWwkti6dCUrxAJ5iZmX voPVcApYS8zf/5kZYpmVxNc7X1kh6gUlTs58wgJiMwPVN2+dzTyBUWAWktQsJKkFjEyrGEVS S4tz03OLDfWKE3OLS/PS9ZLzczcxAmN127Gfm3cwznv1Ue8QIxMH4yFGCQ5mJRHeC097k4R4 UxIrq1KL8uOLSnNSiw8xmgLdPZFZSjQ5H5gs8kriDc0MTA1NzCwNTC3NjJXEeT0LOhKFBNIT S1KzU1MLUotg+pg4OKUamPY3hSXcU3l/KfBNS/5Tfqc3E0WnLD0WOCnhsKBQ0zEJkcuHp6WE dlZGJf+XLtZziaixF/7uuYw5evnUPYcn5UjsO5G0LEAmVFjfqIUp/nuI7Z19OsZH7Ga/4uXP acmsOCi+ZlvrsdV7z3LM8Z9YsHhCnrRuaW60kIivt1b6gcMuNR1eYeebTouZHJqiUSli/Zvj eovW++2nfi1OWHlupWsFr6RZtcj6g4WdsfwdD5SNzXNOzjQ3WGUaZKyT+O7P7aCtj6caVG5K UqspOiwzV+2yRhHjlCmrvZ99s5VPyd/stGvl2idbZrftdHR8yxI1qSueIXTJOy6f5Xfel+88 HpJy/MbG05Mutz9Y88xmhxJLcUaioRZzUXEiACNXaLVeAwAA X-CMS-MailID: 20220525155002eucas1p140ca05edf5219f38e8f1a45801c2ed62 X-Msg-Generator: CA X-RootMTR: 20220525155002eucas1p140ca05edf5219f38e8f1a45801c2ed62 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220525155002eucas1p140ca05edf5219f38e8f1a45801c2ed62 References: <20220525154957.393656-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 Reviewed-by: Hannes Reinecke Signed-off-by: Pankaj Raghav --- 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 Wed May 25 15:49:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12861399 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 068BAC433F5 for ; Wed, 25 May 2022 15:50:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238860AbiEYPu1 (ORCPT ); Wed, 25 May 2022 11:50:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245369AbiEYPuI (ORCPT ); Wed, 25 May 2022 11:50:08 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8ADE3B0A56 for ; Wed, 25 May 2022 08:50:07 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220525155006euoutp01619608b3ab55e373ea35e0e454db17ab~yY9ssI5NR0415204152euoutp019 for ; Wed, 25 May 2022 15:50:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220525155006euoutp01619608b3ab55e373ea35e0e454db17ab~yY9ssI5NR0415204152euoutp019 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1653493806; bh=9W1pLbbKKEsanlon70WFxiL7DVRrcoEEPxlxXdEW3tc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EUtqN6UoLdNj6uWhYdhS76kwjBfchXAD6tXcjKypXGQ5Zor9Uv0/pySK48uRJXz2Q Mxjpz9wLtPAQAt3vBJyqK5aFYKN+YiBxC47cgh17iOxGWX9J+/YAmUi3SuV0Tl01RD OEM7kEUVkpnnfgszDWcWjmmLA/FzWiceeimxHmRk= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220525155004eucas1p2dfa1a7a6b945f9b09d92979e69409947~yY9rKj9GH0574305743eucas1p2V; Wed, 25 May 2022 15:50:04 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id D8.43.09887.C205E826; Wed, 25 May 2022 16:50:04 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220525155004eucas1p162c6f43536424f93800ba788ed045363~yY9qwmLNY1064710647eucas1p1p; Wed, 25 May 2022 15:50:04 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220525155004eusmtrp26fd7b673c6e99ce337989ba209192d6f~yY9qvwSZQ0177001770eusmtrp2Z; Wed, 25 May 2022 15:50:04 +0000 (GMT) X-AuditID: cbfec7f4-45bff7000000269f-6c-628e502c8c17 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id A0.9E.09404.B205E826; Wed, 25 May 2022 16:50:03 +0100 (BST) Received: from localhost (unknown [106.210.248.20]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220525155003eusmtip11ab0a9c1aac41be6c73f997f027f7090~yY9qdZ3lV1835018350eusmtip1C; Wed, 25 May 2022 15:50:03 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, damien.lemoal@opensource.wdc.com, snitzer@redhat.com, Johannes.Thumshirn@wdc.com, hch@lst.de, hare@suse.de Cc: dsterba@suse.com, dm-devel@redhat.com, jiangbo.365@bytedance.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, jaegeuk@kernel.org, gost.dev@samsung.com, Pankaj Raghav , Bart Van Assche , Johannes Thumshirn , Luis Chamberlain Subject: [PATCH v6 4/8] nvmet: Allow ZNS target to support non-power_of_2 zone sizes Date: Wed, 25 May 2022 17:49:53 +0200 Message-Id: <20220525154957.393656-5-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220525154957.393656-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrKKsWRmVeSWpSXmKPExsWy7djP87o6AX1JBgcOy1isvtvPZjHtw09m i99nzzNb7H03m9Xiwo9GJoubB3YyWexZNInJYuXqo0wWT9bPYrboOfCBxeJv1z0mi723tC0u 75rDZjF/2VN2ixsTnjJafF7awm7RtvEro4Ogx+Ur3h7/Tqxh87h8ttRj06pONo/NS+o9dt9s YPPY2Xqf1eP9vqtsHn1bVjF6rN9ylcVj8+lqj8+b5DzaD3QzBfBGcdmkpOZklqUW6dslcGWc XGNZcJK/Yte5x+wNjPN4uxg5OSQETCS+7VjN3sXIxSEksIJRYu+u86wQzhdGiWNrGpkhnM+M EksvdrHDtOxeepcNIrGcUeLhrP2MEM4LRom+DXOYuhg5ONgEtCQaO8Hmigg0MkpMfXkCrIhZ 4BuTxJI53Uwgo4QFwiS+vl0DNpZFQFXi6MWP7CDNvAJWEvPn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F G1oY6RlaWugZmVjqGRqbx1oZmSrp29mkpOZklqUW6dsl6GWcXGNZcJK/Yte5x+wNjPN4uxg5 OSQETCR2L73LBmILCSxllFh6IwciLiFxe2ETI4QtLPHnWhdQDRdQzTNGiYYnF4ESHBxsAloS jZ3sIHERgU5GiTn7WsEcZoEmZolzC9czgxQJC4RIvG3jABnEIqAqcfTiR3aQMK+AlcT8OVEQ 8+UlZl76zg5icwpYS8zf/5kZ4h4ria93vrKC2LwCghInZz5hAbGZgeqbt85mnsAoMAtJahaS 1AJGplWMIqmlxbnpucVGesWJucWleel6yfm5mxiBkbvt2M8tOxhXvvqod4iRiYPxEKMEB7OS CO+Fp71JQrwpiZVVqUX58UWlOanFhxhNgc6eyCwlmpwPTB15JfGGZgamhiZmlgamlmbGSuK8 ngUdiUIC6YklqdmpqQWpRTB9TBycUg1M3JOrAro0JyveN36aE7Q8uXR/7N4vigU7mxfWMifo 8r8PZFLqeBS8VmmefMwJM80HkkbLtigt8uQvyD/9bWuLKO9mLzHpxq2MnKeFXEv2CKjb/wj+ tmT2nLDoRxceKlWVXJn7ZL/vZGOf7gp/EVH5lksN/cqPXXZOritM1HjEU2j+o0Y1S3JvfuT5 qDef77y+M3vmry1lphNNfhcsc9n2/yXfrNPP4rMChefc/CeSLKMwY/muZ1xHzoa+msRTtcVl a/n/vXWGGdPaJPQ0hbWu1l5YaLn99L27CgI+LTXf2Gc7nNhfs32S0Vu5ZxXvO57FZczdvv8u Y25qV/wLmwdX/z33LPv+azO3g5aRdliMEktxRqKhFnNRcSIANKoc7WUDAAA= X-CMS-MailID: 20220525155004eucas1p162c6f43536424f93800ba788ed045363 X-Msg-Generator: CA X-RootMTR: 20220525155004eucas1p162c6f43536424f93800ba788ed045363 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220525155004eucas1p162c6f43536424f93800ba788ed045363 References: <20220525154957.393656-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 Wed May 25 15:49:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Raghav X-Patchwork-Id: 12861402 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 E2B33C4321E for ; Wed, 25 May 2022 15:50:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245364AbiEYPuc (ORCPT ); Wed, 25 May 2022 11:50:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245382AbiEYPuL (ORCPT ); Wed, 25 May 2022 11:50:11 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 550279BADD for ; Wed, 25 May 2022 08:50:09 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220525155008euoutp010ee68d1fa4e6432c3c3b53eee9f1d4e1~yY9uenqob0505405054euoutp01x for ; Wed, 25 May 2022 15:50:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220525155008euoutp010ee68d1fa4e6432c3c3b53eee9f1d4e1~yY9uenqob0505405054euoutp01x DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1653493808; bh=UGcLm4UtxsslCaJuhFs47yY8y7pVdMJ24vP/5EEnWTc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PG6IJo77NV8znK6GjAOhbXMzFHYhh1KA3BXKtLRgnC+LuvGda2sY55cuhJVfjaSpx Wfx77fIZjVPOmYy/rklqlxUCi6IGx2q3AZuGrekqM5H7t9SSj/000IZXEsYWs5Ch+8 BZ7jHueKLJu+7p/b9p0hxqsSnlNrsQnZpqNw0lNA= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220525155006eucas1p25e379a605989f2868fe409b6d38b5770~yY9sn03cL0972109721eucas1p2D; Wed, 25 May 2022 15:50:06 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 1E.FF.10260.D205E826; Wed, 25 May 2022 16:50:05 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220525155005eucas1p13b6204e84c2dbb1eeefc2645f69b45b0~yY9sEOdl30753307533eucas1p1B; Wed, 25 May 2022 15:50:05 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220525155005eusmtrp26fe67e51229f9b2089d16589ed66dcba~yY9r8yWtC0177001770eusmtrp2a; Wed, 25 May 2022 15:50:05 +0000 (GMT) X-AuditID: cbfec7f5-bf3ff70000002814-df-628e502d8a2e Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 02.9E.09404.D205E826; Wed, 25 May 2022 16:50:05 +0100 (BST) Received: from localhost (unknown [106.210.248.20]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220525155005eusmtip1df0cbeb827b7d66b92087133b328f4fd~yY9rmhWrY1837618376eusmtip1C; Wed, 25 May 2022 15:50:05 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, damien.lemoal@opensource.wdc.com, snitzer@redhat.com, Johannes.Thumshirn@wdc.com, hch@lst.de, hare@suse.de Cc: dsterba@suse.com, dm-devel@redhat.com, jiangbo.365@bytedance.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, jaegeuk@kernel.org, gost.dev@samsung.com, Pankaj Raghav , Luis Chamberlain Subject: [PATCH v6 5/8] null_blk: allow non power of 2 zoned devices Date: Wed, 25 May 2022 17:49:54 +0200 Message-Id: <20220525154957.393656-6-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220525154957.393656-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrLKsWRmVeSWpSXmKPExsWy7djPc7q6AX1JBt2nbSxW3+1ns/h99jyz xd53s1ktLvxoZLK4eWAnk8WeRZOYLFauPspk8WT9LGaLngMfWCz+dt1jsth7S9vi8q45bBbz lz1lt7gx4SmjxeelLewWbRu/MjoIePw7sYbN4/LZUo9NqzrZPDYvqffYfbOBzWNn631Wj/f7 rrJ59G1ZxeixfstVFo/Np6s9Pm+S82g/0M0UwBPFZZOSmpNZllqkb5fAlbH4yWfWgpu6FbvW zWduYFyi0sXIySEhYCLxa8561i5GLg4hgRWMEl0v1jNCOF8YJY63z2ODcD4zStxtf84O0/Jx +i1miMRyRonte/9B9b9glDj0bxpQPwcHm4CWRGMnO0hcRKCRUWLqyxNgc5kFZjNJzPs2mRFk lLCAi8TB73dZQGwWAVWJw7eXsYHYvAJWEksfvmGEWCcvMfPSd7DVnALWEvP3f2aGqBGUODnz CVgvM1BN89bZYCdJCKzmlLh5cx4TRLOLxPH+r6wQtrDEq+NboH6Qkfi/cz5UTbXE0xu/oZpb GCX6d65nA3lBAmhb35kcEJNZQFNi/S59iHJHic0bb7BAVPBJ3HgrCHECn8SkbdOZIcK8Eh1t QhDVShI7fz6BWiohcblpDlSnh8Tfn4YTGBVnIfllFpJfZiGsXcDIvIpRPLW0ODc9tdg4L7Vc rzgxt7g0L10vOT93EyMwBZ7+d/zrDsYVrz7qHWJk4mA8xCjBwawkwnvhaW+SEG9KYmVValF+ fFFpTmrxIUZpDhYlcd7kzA2JQgLpiSWp2ampBalFMFkmDk6pBqYFpttLLbu1367kuf+98Y+C W8/v1dEiRmbe99PW9n6X6LRg3zf5wsSJRb3ej+48r/YROn808Ly0zs8bt08IqnOEN92aZxab HtgjWDH32eVDT2vEg+5nTWluK407r1zBn6ITIGz0Ni7rYbydFne96K0tEcInWFZ9+W6pKKjU 0/VueQHf/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b/1p8W/xq1zvCbx zXaxW7qAca7mtuXfU9xnHJ5s+md/4vfJmwyunZ0SNbXzUH1LREr4Se+b9oluzerckt5LnLel zrrw3CLRqm1hFOfOlwK1UzeVtmw3q6lQZnD91N6Zupb/zNOejPyD9XfdFk+1vVkhPfXcp45v dfyf9mmkzZE/EJF8i6W/bAOHcZaOpe9vI56UQOXkqElz34owb9ZNWcKWdyOE8UTBv+lmDKuN kpL42hLiHYs4tfg6nQX2KrEUZyQaajEXFScCAOAQ9QRgAwAA X-CMS-MailID: 20220525155005eucas1p13b6204e84c2dbb1eeefc2645f69b45b0 X-Msg-Generator: CA X-RootMTR: 20220525155005eucas1p13b6204e84c2dbb1eeefc2645f69b45b0 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220525155005eucas1p13b6204e84c2dbb1eeefc2645f69b45b0 References: <20220525154957.393656-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 --- drivers/block/null_blk/main.c | 5 ++--- drivers/block/null_blk/zoned.c | 13 ++++++------- 2 files changed, 8 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..b79091b5e4b1 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,8 @@ 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 = DIV_ROUND_UP_SECTOR_T(dev_capacity_sects, + dev->zone_size_sects); dev->zones = kvmalloc_array(dev->nr_zones, sizeof(struct nullb_zone), GFP_KERNEL | __GFP_ZERO); From patchwork Wed May 25 15:49: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: 12861401 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 E188BC4332F for ; Wed, 25 May 2022 15:50:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245352AbiEYPuc (ORCPT ); Wed, 25 May 2022 11:50:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245385AbiEYPuL (ORCPT ); Wed, 25 May 2022 11:50:11 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1E66AF315 for ; Wed, 25 May 2022 08:50:10 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220525155009euoutp017b225b1d86353cee4fa6c72de974c4d7~yY9viB1UU0320303203euoutp01U for ; Wed, 25 May 2022 15:50:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220525155009euoutp017b225b1d86353cee4fa6c72de974c4d7~yY9viB1UU0320303203euoutp01U DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1653493809; bh=P6EDzhGk0ayJTp7pXFhq177m6nGhM9MaOSlB/71yZmo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Crr0yUXuNj30M5OPKZe8/aGWbIGby/Qq2pgTDs0eegsFYKeJDPx9uMUKCj8V0i1fZ JRijPviBNy2nN4P+7gCrTQQydUYKnL2VEx74A7P6+/TSRce0skb8m38afsM2z3TCER Whe6m44tDwy68DOWN2lu9ioYs5nw2E5BX47WVa3M= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220525155007eucas1p2185abd17ca07eb32c8ea94cfdafaacdd~yY9trtP3W2563825638eucas1p2j; Wed, 25 May 2022 15:50:07 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 2A.43.09887.F205E826; Wed, 25 May 2022 16:50:07 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220525155006eucas1p13888214b1d9e23a26d04a75fbc5bf72b~yY9tDdGgB0654006540eucas1p1F; Wed, 25 May 2022 15:50:06 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220525155006eusmtrp1449a627ca162306b71ed53844a557768~yY9tCXqfN1510315103eusmtrp1H; Wed, 25 May 2022 15:50:06 +0000 (GMT) X-AuditID: cbfec7f4-45bff7000000269f-70-628e502ff18c Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 2E.17.09522.E205E826; Wed, 25 May 2022 16:50:06 +0100 (BST) Received: from localhost (unknown [106.210.248.20]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220525155006eusmtip1be55a7f5deec1bf03df36d46d1ca929d~yY9suny0c1835018350eusmtip1E; Wed, 25 May 2022 15:50:06 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, damien.lemoal@opensource.wdc.com, snitzer@redhat.com, Johannes.Thumshirn@wdc.com, hch@lst.de, hare@suse.de Cc: dsterba@suse.com, dm-devel@redhat.com, jiangbo.365@bytedance.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, jaegeuk@kernel.org, gost.dev@samsung.com, Pankaj Raghav , Damien Le Moal , Luis Chamberlain Subject: [PATCH v6 6/8] null_blk: use zone_size_sects_shift for power of 2 zoned devices Date: Wed, 25 May 2022 17:49:55 +0200 Message-Id: <20220525154957.393656-7-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220525154957.393656-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrPKsWRmVeSWpSXmKPExsWy7djP87r6AX1JBr9mc1isvtvPZvH77Hlm i9b2b0wWe9/NZrW48KORyeLmgZ1MFnsWTWKyWLn6KJPFk/WzmC16DnxgsfjbdQ+o7pa2xeVd c9gs5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n/eigi9eJPf3jb7doTcoQsrNvntdvs9RyFAK/zVRL7Pd2o2 zDp3R5X34NoXX69/dL2rxlGsxFKckWioxVxUnAgA+pWRW2MDAAA= X-CMS-MailID: 20220525155006eucas1p13888214b1d9e23a26d04a75fbc5bf72b X-Msg-Generator: CA X-RootMTR: 20220525155006eucas1p13888214b1d9e23a26d04a75fbc5bf72b X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220525155006eucas1p13888214b1d9e23a26d04a75fbc5bf72b References: <20220525154957.393656-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 Reviewed-by: Hannes Reinecke Reviewed-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- drivers/block/null_blk/null_blk.h | 6 ++++++ drivers/block/null_blk/zoned.c | 11 ++++++++--- 2 files changed, 14 insertions(+), 3 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 b79091b5e4b1..a8be1011def5 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,9 +82,14 @@ 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 = DIV_ROUND_UP_SECTOR_T(dev_capacity_sects, dev->zone_size_sects); - dev->zones = kvmalloc_array(dev->nr_zones, sizeof(struct nullb_zone), GFP_KERNEL | __GFP_ZERO); if (!dev->zones) From patchwork Wed May 25 15:49: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: 12861406 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 22118C43217 for ; Wed, 25 May 2022 15:50:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245345AbiEYPua (ORCPT ); Wed, 25 May 2022 11:50:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245387AbiEYPuM (ORCPT ); Wed, 25 May 2022 11:50:12 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C8A2AF32C for ; Wed, 25 May 2022 08:50:11 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20220525155009euoutp02bfd0b150b8e4124577596de5322efca6~yY9wJ781_0326303263euoutp02L for ; Wed, 25 May 2022 15:50:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20220525155009euoutp02bfd0b150b8e4124577596de5322efca6~yY9wJ781_0326303263euoutp02L DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1653493809; bh=tYOWZPnjW65XI4l1LBGIm3u73JaE/GHPi+tZ/3A+qe8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O6Qu77Ihzkt1GlD+/w1r6xsFi0DjhWf0LS8zQ02zrZFUAQJQSkLNGON7uOAQkzL8Q D2u5pYxAI/iMQTb4XxWU9rhFAB89YAJnksRXjL7ogJ/A37COGSEge2szTP5PRYSVij AUlAa0yF2biAZ7CZqPWAoL8W9LB3wrQB4eFgW9f4= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220525155008eucas1p21392109a809e41d5bb99c4abd0256de8~yY9uxB_mn0700707007eucas1p2J; Wed, 25 May 2022 15:50:08 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id EF.FF.10260.0305E826; Wed, 25 May 2022 16:50:08 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220525155007eucas1p1b7fc82f9e42be028e8f00109d55e6a62~yY9uK4vp20770307703eucas1p1D; Wed, 25 May 2022 15:50:07 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220525155007eusmtrp18bb3a95ccc378c2b11588ec51e84a10d~yY9uKGJTE1510315103eusmtrp1K; Wed, 25 May 2022 15:50:07 +0000 (GMT) X-AuditID: cbfec7f5-bddff70000002814-e4-628e503011b6 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id AF.17.09522.F205E826; Wed, 25 May 2022 16:50:07 +0100 (BST) Received: from localhost (unknown [106.210.248.20]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220525155007eusmtip1f0d8c7ef887e2d198cd3b081ecc69235~yY9t1swVE1835018350eusmtip1F; Wed, 25 May 2022 15:50:07 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, damien.lemoal@opensource.wdc.com, snitzer@redhat.com, Johannes.Thumshirn@wdc.com, hch@lst.de, hare@suse.de Cc: dsterba@suse.com, dm-devel@redhat.com, jiangbo.365@bytedance.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, jaegeuk@kernel.org, gost.dev@samsung.com, Luis Chamberlain , Pankaj Raghav Subject: [PATCH v6 7/8] dm-zoned: ensure only power of 2 zone sizes are allowed Date: Wed, 25 May 2022 17:49:56 +0200 Message-Id: <20220525154957.393656-8-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220525154957.393656-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrLKsWRmVeSWpSXmKPExsWy7djPc7oGAX1JBk92C1qsvtvPZvH77Hlm i73vZrNaXPjRyGRx88BOJos9iyYxWaxcfZTJ4sn6WcwWPQc+sFj87brHZLH3lrbF5V1z2Czm L3vKbnFjwlNGi89LW9gt2jZ+ZXQQ8Ph3Yg2bx+WzpR6bVnWyeWxeUu+x+2YDm8fO1vusHu/3 XWXz6NuyitFj/ZarLB6bT1d7fN4k59F+oJspgCeKyyYlNSezLLVI3y6BK2NJ1wuWgkeCFVfe r2JqYDzO18XIySEhYCKxY+k0ti5GLg4hgRWMEs+v74JyvjBK7Pq3iAnC+cwocXHia6AMB1jL /Y28EPHljBKLX+5ghXBeMEqs6gTp4OBgE9CSaOxkB4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Hu/3 XWXz6NuyitFj/ZarLB6bT1d7fN4k59F+oJspgCdKz6Yov7QkVSEjv7jEVina0MJIz9DSQs/I xFLP0Ng81srIVEnfziYlNSezLLVI3y5BL2NJ1wuWgkeCFVfer2JqYDzO18XIwSEhYCJxfyNv FyMnh5DAUkaJtrUiILaEgITE7YVNjBC2sMSfa11sXYxcQDXPGCW6l/9kB+llE9CSaOxkB4mL CHQySszZ1wrmMAssZ5LYfLKPGaRbWMBfouXMMSYQm0VAVeLMysdsIDavgJXE/QVboDbIS8y8 9J0dxOYUsJaYv/8zM8RFVhJf73xlhagXlDg58wkLiM0MVN+8dTbzBEaBWUhSs5CkFjAyrWIU SS0tzk3PLTbUK07MLS7NS9dLzs/dxAiM1W3Hfm7ewTjv1Ue9Q4xMHIyHGCU4mJVEeC887U0S 4k1JrKxKLcqPLyrNSS0+xGgKdPdEZinR5HxgssgriTc0MzA1NDGzNDC1NDNWEuf1LOhIFBJI TyxJzU5NLUgtgulj4uCUamDSKX5zfkJJl16syLXyyb5/dPxP9WltURf8sFly00HtcE/huJbe +p/1j1fVuOs8k3WafuvG7TuGXxUs79W8vOuoGrqVifenyTqNRwu7btx8Xh3ja/h5dkpDSu2T 2xkhFcH/rN8xbds98+J0M+n8zGsnDQXD48L8+f/N6bnQ9VTx1t6VYqU1Hak/M/W53vB1/knf sfSlWNOz6OM9BySlegOf3/Ge8Dv5e3XRzvz8V5VS99/fC/ZbnPP7G69a1oeUVJ9+xhVi/ZVq iudvPGN59DQitSioIVqy/WTo9/71GiGvNdoy4jaKLn/m8tJvInvFmrWi6eeuZB1Z/T5dJ2VB ycp/anOknO4lL7gnsNlzSrcSS3FGoqEWc1FxIgBTZtA4XgMAAA== X-CMS-MailID: 20220525155007eucas1p1b7fc82f9e42be028e8f00109d55e6a62 X-Msg-Generator: CA X-RootMTR: 20220525155007eucas1p1b7fc82f9e42be028e8f00109d55e6a62 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220525155007eucas1p1b7fc82f9e42be028e8f00109d55e6a62 References: <20220525154957.393656-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 | 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) { From patchwork Wed May 25 15:49: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: 12861403 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 C4928C433F5 for ; Wed, 25 May 2022 15:50:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241874AbiEYPud (ORCPT ); Wed, 25 May 2022 11:50:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245395AbiEYPuN (ORCPT ); Wed, 25 May 2022 11:50:13 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60C3B9BADD for ; Wed, 25 May 2022 08:50:12 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220525155011euoutp018e316d89dda29a359779bd45ec8583d7~yY9xPnxHL0835508355euoutp01K for ; Wed, 25 May 2022 15:50:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220525155011euoutp018e316d89dda29a359779bd45ec8583d7~yY9xPnxHL0835508355euoutp01K DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1653493811; bh=sJcs4ay0hQ3CcXQiFMNDhZ8v6ROIy7WSZthy8VqD664=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YNX5bjAYu1tkdf73vb1Q6Y2iZVDfyvK1dzG3KioR/JgvD6R6huel8XduDAfAjWAck 45SpJaqIQL2540ce0/C+Q879AkQa94bFYOGEgYzzUppq8V6+jlDQFWywS1Y0XqM17R JJy45bq/3KxdcdycoqNOYKv2sVhv0kkMXta7X1MI= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220525155009eucas1p2d4bd13415b909eaaf6c6ca7e53c3fdb0~yY9vmoDnt0522505225eucas1p2N; Wed, 25 May 2022 15:50:09 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id F0.00.10260.1305E826; Wed, 25 May 2022 16:50:09 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20220525155008eucas1p2c843cc9098f2920e961f80ffaf535789~yY9vPWFha2575925759eucas1p23; Wed, 25 May 2022 15:50:08 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220525155008eusmtrp1a64719bbb66a103e535236dc149d926e~yY9vMaFka1510315103eusmtrp1M; Wed, 25 May 2022 15:50:08 +0000 (GMT) X-AuditID: cbfec7f5-bddff70000002814-e6-628e503101f0 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id F0.27.09522.0305E826; Wed, 25 May 2022 16:50:08 +0100 (BST) Received: from localhost (unknown [106.210.248.20]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220525155008eusmtip1a64c0e3e336ababa11af2ab44dfa7e53~yY9u2GdvG1782817828eusmtip1c; Wed, 25 May 2022 15:50:08 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, damien.lemoal@opensource.wdc.com, snitzer@redhat.com, Johannes.Thumshirn@wdc.com, hch@lst.de, hare@suse.de Cc: dsterba@suse.com, dm-devel@redhat.com, jiangbo.365@bytedance.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, jaegeuk@kernel.org, gost.dev@samsung.com, Pankaj Raghav Subject: [PATCH v6 8/8] dm: ensure only power of 2 zone sizes are allowed Date: Wed, 25 May 2022 17:49:57 +0200 Message-Id: <20220525154957.393656-9-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220525154957.393656-1-p.raghav@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrOKsWRmVeSWpSXmKPExsWy7djPc7qGAX1JBsdu8FmsvtvPZvH77Hlm i73vZrNaXPjRyGRx88BOJos9iyYxWaxcfZTJ4sn6WcwWPQc+sFj87brHZLH3lrbF5V1z2Czm L3vKbvF5aQu7RdvGr4wO/B7/Tqxh87h8ttRj06pONo/NS+o9dt9sYPPY2Xqf1eP9vqtsHn1b VjF6rN9ylcVj8+lqj8+b5DzaD3QzBfBEcdmkpOZklqUW6dslcGXMW/eGreAbe0XXa7MGxnVs XYycHBICJhJ/T9xh72Lk4hASWMEosf7NXEYI5wujxImtHWwQzmdGiS0HX8G1PH97kRkisZxR ou/iFhaQhJDAC0aJKYtquhg5ONgEtCQaO8HGigg0MkpMfXkCbCyzwFdGiRsHnzOCNAgLeEp0 N04Dm8oioCox+fJ7sEG8AlYSLQveM0Nsk5eYeek7O4jNKWAtMX//Z2aIGkGJkzOfgNUzA9U0 b50NdpGEwGJOiaN7rkCd6iKx+OITJghbWOLV8S3sELaMxOnJPSwQdrXE0xu/oZpbGCX6d65n A3lBAmhb35kcEJNZQFNi/S59iHJHiZ+N15ghKvgkbrwVhDiBT2LStulQYV6JjjYhiGoliZ0/ n0AtlZC43DQHaqmHxJSTF1gmMCrOQvLMLCTPzELYu4CReRWjeGppcW56arFxXmq5XnFibnFp Xrpecn7uJkZg2jv97/jXHYwrXn3UO8TIxMF4iFGCg1lJhP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793LyDcd6rj3qHGJk4GA8xSnAwK4nwXnjamyTEm5JYWZValB9f VJqTWnyI0RTo7onMUqLJ+cAUkVcSb2hmYGpoYmZpYGppZqwkzutZ0JEoJJCeWJKanZpakFoE 08fEwSnVwLT8TdKR9fHVn7LiXvbuO/F603rt914ZSf9WP+KKPLZwilHkxQfNRlP0w5Zu/8Ne F6WX6a3lrOYjpjZB5fZZdUmD7Aa1f1cncGZ+vGv2x97q1aufmzzYr7YkfDu2tW1Ww4lEv3Yf fZ3Drp9uCX7X9IndVbN95aWK0j1LXI593+0Y01nmtWfTBbXDHM/s/t1QTWq18g4/MtNfaPIp jrQnukVzJvs+m1Whttwr0/6VjHReo0tK5I2Y/3J2jVXuDxx3Pv603vSSe/HMvninLXmGm+LX TFvna3TNaea2M2t790UFXcq4vLLo6Mq+ktdWXW9368wt8DXbsOef5skakSDLwBm7p6yS/RJQ 2P1ue9Wn43uVWIozEg21mIuKEwHyFF8FWQMAAA== X-CMS-MailID: 20220525155008eucas1p2c843cc9098f2920e961f80ffaf535789 X-Msg-Generator: CA X-RootMTR: 20220525155008eucas1p2c843cc9098f2920e961f80ffaf535789 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220525155008eucas1p2c843cc9098f2920e961f80ffaf535789 References: <20220525154957.393656-1-p.raghav@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Ensure that only power of 2 zoned devices are enabled for dm targets that supports zoned devices. This constraint can be relaxed once non power of 2 zone size support is added to the DM layer. Signed-off-by: Pankaj Raghav --- drivers/md/dm-table.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index 03541cfc2317..2a8af70d1d4a 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -251,6 +251,12 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev, if (bdev_is_zoned(bdev)) { unsigned int 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(ti->table->md), bdev); + return 1; + } + if (start & (zone_sectors - 1)) { DMWARN("%s: start=%llu not aligned to h/w zone size %u of %pg", dm_device_name(ti->table->md),