Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2560312ioo; Tue, 24 May 2022 00:08:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuhjcr5uoELZut5SDsAdikzW0Njb7mfaXFvfC65Lh2E6NIv9npTl5mgZfdDLZzNtuL82e1 X-Received: by 2002:a05:6a00:170a:b0:50d:3e40:9e0 with SMTP id h10-20020a056a00170a00b0050d3e4009e0mr26956499pfc.48.1653376136248; Tue, 24 May 2022 00:08:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653376136; cv=none; d=google.com; s=arc-20160816; b=NkoM7M4QQfR4lHk+jigakkIvxdS7VLSYnfvYUKPOqAJ4AmnuBtwP7O1QPEaxJMnmpd qyRCe3GwtAgM0WMyWoGLZoCTYTqQrer5+h7+F+MnF0rvTlvOtdSWnpSvM3yRGXSEUBYf RRSpDzGxXoK9SKpz5JbX0ebNzwdas0hOWxG9RW7/haRYROs9yoLyfSh+AF35m2rBgOL+ GxbRMPkVftg9ewmz/hoOvbXw/fThBEg+VR+ThPo/qbF5KetZZK9ef4ELQOfJpagZnjUO YQ9DG9UyELBor2DfXJw23TAp+t6CXuXyK+I80NbO1g1J/0LUM14LjcgGI5v4KxqX50ig vPxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-signature; bh=flGSVkIMGN+G3GNFtIm3sUyOrdA78aoQUZy5O/sykLk=; b=l/tfLtCA975DMSELUVKw5olovawjyY29PrUrcDnL8jPMjyJepxmsKJC4HJemML4+c/ CmwqzgFmet2gzYe5PvqqDZZbKPqt4jfquxEJ0S4qooWuEgBXZAPnW2yFib4TzJ8zy0sn WJA5qVsZsJKs/9D3ZGyxmuMgyP336rDqTUTNcuLA1p5LA9SUMkEugWebDZd6OYRnxzD0 XZY3nwuoayhX7LNh5tTe19H87kRQsSRLhmHZlC+om1Kk3pFyfukYARY22iRUA6UnYNDf P2HjumtX37/4YjYVpllQjb02iyKrs5F1a+xOrURacccBqpRMPoS5z9Icq1/Fe1UmfeAx jf9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=wuXSm4Df; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=Uc6F1sOJ; 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=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j38-20020a635966000000b003faa80f15f9si1976012pgm.728.2022.05.24.00.08.42; Tue, 24 May 2022 00:08:56 -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=@suse.de header.s=susede2_rsa header.b=wuXSm4Df; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=Uc6F1sOJ; 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=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233485AbiEXFTd (ORCPT + 99 others); Tue, 24 May 2022 01:19:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230201AbiEXFTb (ORCPT ); Tue, 24 May 2022 01:19:31 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A525F73560; Mon, 23 May 2022 22:19:28 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 2F2DC1F8DB; Tue, 24 May 2022 05:19:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1653369567; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=flGSVkIMGN+G3GNFtIm3sUyOrdA78aoQUZy5O/sykLk=; b=wuXSm4Dfh+1+Lod5N2TptPnZkYqXYkq0qidBiIo5/8vL/8nqhlTWvaJIdQFq59SlN0UmFC zObxjoE77r0/tZFbiUQ9CIWDlGBZmr+XIFdTxMi2APbgktga+xfiEuoEjXqh5jqIDv49n6 Rryle27S8ur96ucZfjVt8pTr2BVsQA0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1653369567; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=flGSVkIMGN+G3GNFtIm3sUyOrdA78aoQUZy5O/sykLk=; b=Uc6F1sOJ72J2ECePenVMJcXt7cfLQnRl3WNd2T73iv7eI+iinY/eCejoRIub2vWGO0UegX KaY2Is5u56SFGmBA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id B775713ADF; Tue, 24 May 2022 05:19:26 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id jK6VK95qjGIlGgAAMHmgww (envelope-from ); Tue, 24 May 2022 05:19:26 +0000 Message-ID: Date: Tue, 24 May 2022 07:19:26 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH v5 2/7] block: allow blk-zoned devices to have non-power-of-2 zone size Content-Language: en-US To: Pankaj Raghav , axboe@kernel.dk, hch@lst.de, snitzer@redhat.com, damien.lemoal@opensource.wdc.com, 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 References: <20220523161601.58078-1-p.raghav@samsung.com> <20220523161601.58078-3-p.raghav@samsung.com> From: Hannes Reinecke In-Reply-To: <20220523161601.58078-3-p.raghav@samsung.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,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 On 5/23/22 18:15, Pankaj Raghav wrote: > 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; > + Not sure if we need this here; surely blk_queue_zone_sectors() will already barf, and none of the callers did this check. > + 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; Otherwise looks good. Cheers, Hannes -- Dr. Hannes Reinecke Kernel Storage Architect hare@suse.de +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Ivo Totev, Andrew Myers, Andrew McDonald, Martje Boudien Moerman