Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2063695ioo; Mon, 23 May 2022 09:17:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwsZcAz0IpsERXAZLu5XTEVLq3o7PNgqQ5vDNxxdze0eHgOYDlMM70JhCw+p4FASrCBRX/S X-Received: by 2002:a17:902:d4d2:b0:161:b4f7:385b with SMTP id o18-20020a170902d4d200b00161b4f7385bmr23360445plg.5.1653322640719; Mon, 23 May 2022 09:17:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653322640; cv=none; d=google.com; s=arc-20160816; b=ptsAUERhPRo99cChuwWh5Pe3qCKnGl6CNGIds8dGwHoTPDndt/afkAlllVJ2mBQnqN n6qRb39620y9nCDAAq+gHKYjC2MhUGdOI4JVq37qC3+/+4MY49ghdgqEjE6N7FqLfPGp bu2+lgTUW1GZjl6y5JXwDpjlZ8VGym/3EUQ3ackPoW2jN1OO2NZK81ZNCpA5wnSKUKlp LzCBb8U6Fo8Z0x1RlsKsPlwaYbQsFOToaz0LlLYNb6uI1WY1FasC7J52AdytodOHEfyk pUxKyQDYofFfBqTaxnJmEu7E+JUHAaQakfMN/hUB+ihwYuEINVwyDC1T57QCJgjwlfxL lTNg== 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=7nBkOw49ughyqfbdOIrZLw3Pc1ezYb+68acQMGQePkk=; b=hhEyVdZGDUHeycYbSUaTbDzywvGfqSkunDu3WhVGSjea6Kxf5xgf5y1D1EDXV302wJ azqeWXxJD2MMMe1iE+I4UtpOqDcTHSTzZAXjVAuG6ndS7u49A7X3g2jUn+tSnKRStZ9J oAjYF6eZ8bUM2n+bbRK7xfjFCPYKtt0Wh6eC5wMYLRPIORft+p7DmmvswpkhmWMC6IGw mkcsnGdeIsaQ9CmwZmUz/YR391yH0J2a6/11hsbWjMNJL7yYMoxcopQHco9MVAQbOJrE KXV+Yeg3wllKg2oLo6afsRo+3qeQY52s9L0h5Fp58NaKpIwY2pq/Pf/1As1Bp97VSHt/ 0fxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=IabzlFPl; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id d131-20020a636889000000b003c6273d32e0si9150060pgc.625.2022.05.23.09.17.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 09:17:20 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=IabzlFPl; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0C6516622C; Mon, 23 May 2022 09:16:53 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238635AbiEWQQe (ORCPT + 99 others); Mon, 23 May 2022 12:16:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238522AbiEWQQM (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 C9F462B1A7 for ; Mon, 23 May 2022 09:16:09 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20220523161608euoutp02f65750438261f07364c803229d4d360b~xyB249ulK1865718657euoutp02K for ; Mon, 23 May 2022 16:16:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20220523161608euoutp02f65750438261f07364c803229d4d360b~xyB249ulK1865718657euoutp02K 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 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrNKsWRmVeSWpSXmKPExsWy7djPc7pum7uTDA5NUbVYfbefzeL32fPM FnvfzWa1uPCjkcni5oGdTBZ7Fk1isli5+iiTxZP1s5gteg58YLH423WPyWLvLW2Ly7vmsFnM X/aU3eLGhKeMFp+XtrBbtG38yugg4PHvxBo2j8tnSz02repk89i8pN5j980GNo+drfdZPd7v u8rm0bdlFaPH+i1XWTw2n672+LxJzqP9QDdTAE8Ul01Kak5mWW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161606eucas1p2676c4d47f9fcb145f69b29db1f04fe6e X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20220523161606eucas1p2676c4d47f9fcb145f69b29db1f04fe6e X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220523161606eucas1p2676c4d47f9fcb145f69b29db1f04fe6e References: <20220523161601.58078-1-p.raghav@samsung.com> X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Signed-off-by: Pankaj Raghav --- 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; -- 2.25.1