Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp346283iog; Wed, 15 Jun 2022 03:33:23 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tiDOXUJY6n4zCpyMP1xyMvNDI4P7fgj+xaBJONmnBluOhMVkSbF3H6drSZA/4mGt+o5ktd X-Received: by 2002:a17:902:b949:b0:167:6548:2d93 with SMTP id h9-20020a170902b94900b0016765482d93mr8456497pls.131.1655289203694; Wed, 15 Jun 2022 03:33:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655289203; cv=none; d=google.com; s=arc-20160816; b=o019I8YQ6PtRQM3G6lpLsHw7Kn5bCwqvCOh3FY814xLWxnugy74nPTrMMSDEzD0/1C 6uvMdssHny0ZxHQQyRFJsH4XP5lvC+7RIGR0/nBzKVWsRCa04Gsi55m8H6hylLmx0ypJ xazxZgaUIvx0bxHRvzDfgLl7mU8TAbN6eu8+us7czP7tSGYra8ingXlTgL9pD0gn9mZx S9iAFcfihFe9ChSM3BBbogBHD2quu6NP3BMrsG3aIGXW1CSYIkH/Zi/U3oE8aNM4Y0iI njI5bRbdK23NgKL+0sYaqQ3MHA4O2L1Y8r+RQsvDTelJ5IL+k+VggWxqCT34qvR8pzpU 5PYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:cms-type:content-transfer-encoding :mime-version:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=IrOIYIqVIk7B/3DWPQ10ndq9aeC4LKt1LaG03ECSoHw=; b=W4p0xiKR9zXev1xy5KUphYk/vYR+CXV94oBlUpmzqPXheC1s/U0agvfXEwHtLn7F2M UMH4h/G06I4gYF/Di6I9uZb+vSLDIDATsTbJiBtpoL1uY22sP35l+O+/Jvx4hvOPpP/5 emxJ57MIJmpy6h0/KSLFw84xo3mB8+d0dw+1wBjlLvd01U+Vv+QhI3zojPynM3QIHAjG fB+xnXIGg7PM6btXD+lKkOIKNLv+Kj+JiUPqO8fQ/LPfe7XIAOx/EhC8FrilSNsZa9Qw hQ3YltKkpE7k+fRF1N5SHJ9YHY4us6ee8ZdFOjm7WyA7dNnwORUiJz7AFkHmQpoa4fY7 TgDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=D018ArsW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j8-20020a170902da8800b0016793c0e3dcsi1200743plx.545.2022.06.15.03.33.09; Wed, 15 Jun 2022 03:33:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=D018ArsW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347186AbiFOKTo (ORCPT + 99 others); Wed, 15 Jun 2022 06:19:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346842AbiFOKTl (ORCPT ); Wed, 15 Jun 2022 06:19:41 -0400 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F8E844A3A for ; Wed, 15 Jun 2022 03:19:35 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20220615101934euoutp0150abc9ef28a48b775a4cbd69c2265a34~4xAGRI3ho2526325263euoutp01R for ; Wed, 15 Jun 2022 10:19:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20220615101934euoutp0150abc9ef28a48b775a4cbd69c2265a34~4xAGRI3ho2526325263euoutp01R DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1655288374; bh=IrOIYIqVIk7B/3DWPQ10ndq9aeC4LKt1LaG03ECSoHw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D018ArsWozm5Ya11eT/4je5sygr8VMMcEceNOHX32Miu3hg5sgzr+G+nN06p1ZIMO OCfo/B4zKtCL3p676aYxTHyzFjJJR7wgrHlPB39w+EBnQib9RE9rTuRG6h07RHgYeg 9nmMmZUnFaz2SJXHuQ2vb/9md6oE4wZ7zeSO74Q0= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220615101932eucas1p2660b95125dabbb1744287f9d299c6460~4xAEayiPp0710307103eucas1p24; Wed, 15 Jun 2022 10:19:32 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 1D.2B.09664.332B9A26; Wed, 15 Jun 2022 11:19:32 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220615101931eucas1p15ed09ae433a2c378b599e9086130d8eb~4xAD9YEc10100501005eucas1p1N; Wed, 15 Jun 2022 10:19:31 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220615101931eusmtrp2b70e8cbdfb93fd8f578e936104ade6c6~4xAD8lqBD0308003080eusmtrp2f; Wed, 15 Jun 2022 10:19:31 +0000 (GMT) X-AuditID: cbfec7f2-d97ff700000025c0-cd-62a9b233f413 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 5B.45.09095.332B9A26; Wed, 15 Jun 2022 11:19:31 +0100 (BST) Received: from localhost (unknown [106.210.248.244]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20220615101930eusmtip20501ba33701d46b01bdb1087349cb48e~4xAC0W5x_0785907859eusmtip2G; Wed, 15 Jun 2022 10:19:30 +0000 (GMT) From: Pankaj Raghav To: hch@lst.de, snitzer@redhat.com, damien.lemoal@opensource.wdc.com, axboe@kernel.dk Cc: bvanassche@acm.org, linux-kernel@vger.kernel.org, jiangbo.365@bytedance.com, hare@suse.de, pankydev8@gmail.com, dm-devel@redhat.com, jonathan.derrick@linux.dev, gost.dev@samsung.com, dsterba@suse.com, jaegeuk@kernel.org, linux-nvme@lists.infradead.org, Johannes.Thumshirn@wdc.com, linux-block@vger.kernel.org, Pankaj Raghav , Luis Chamberlain Subject: [PATCH v7 02/13] block: allow blk-zoned devices to have non-power-of-2 zone size Date: Wed, 15 Jun 2022 12:19:09 +0200 Message-Id: <20220615101920.329421-3-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220615101920.329421-1-p.raghav@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrOKsWRmVeSWpSXmKPExsWy7djP87omm1YmGZxdxmix+m4/m8W0Dz+Z LX6fPc9ssffdbFaLCz8amSxuHtjJZLFn0SQmi5WrjzJZPFk/i9mi58AHFou/XfeAYi0PgYpv aVtc3jWHzWL+sqfsFjcmPGW0+Ly0hd1izc2nLBZtG78yOgh7XL7i7fHvxBo2j52z7rJ7XD5b 6rFpVSebx8KGqcwem5fUe+y+2QCUa73P6vF+31U2j74tqxg91m+5yuKx+XS1x+dNch7tB7qZ AvijuGxSUnMyy1KL9O0SuDJm3HnPVPBM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8eb X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20220615101931eucas1p15ed09ae433a2c378b599e9086130d8eb X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220615101931eucas1p15ed09ae433a2c378b599e9086130d8eb References: <20220615101920.329421-1-p.raghav@samsung.com> X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 8 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 06ff5bbfe..248b947e5 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -629,8 +629,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 8b0615287..7957eec04 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 39017ae9d..3c106dba1 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -692,6 +692,27 @@ static inline unsigned int blk_queue_zone_no(struct request_queue *q, return div64_u64(sector, zone_sectors); } +static inline sector_t blk_queue_offset_from_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 sec & (zone_sectors - 1); + + div64_u64_rem(sec, zone_sectors, &remainder); + return remainder; +} + +static inline bool blk_queue_is_zone_start(struct request_queue *q, sector_t sec) +{ + return blk_queue_offset_from_zone_start(q, sec) == 0; +} + static inline bool blk_queue_zone_is_seq(struct request_queue *q, sector_t sector) { @@ -738,6 +759,18 @@ static inline unsigned int blk_queue_zone_no(struct request_queue *q, { return 0; } + +static inline sector_t blk_queue_offset_from_zone_start(struct request_queue *q, + sector_t sec) +{ + 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; -- 2.25.1