Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1945096iob; Thu, 5 May 2022 11:29:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw1BNjwCf2ng3v5EvNXJXfTbZ0CRkc0CxSlSaY/mbQtLCKi8ALv8ZwHWdSI7nLc/76c9sOs X-Received: by 2002:a17:902:6bc9:b0:158:a0d3:d080 with SMTP id m9-20020a1709026bc900b00158a0d3d080mr29184702plt.24.1651775357939; Thu, 05 May 2022 11:29:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651775357; cv=none; d=google.com; s=arc-20160816; b=SvWX9jLH+tI+TKe80Q0JBgCGYA4QccI+yC6mAZEr2igOLUXiRmhQmMV8S3kwhElKnD 5TXnc2HpKaqZIDiOkCcjIkqeCTh0eMIaDJEuT2qZ3gS45iv7h01HQDH3eoyRDtYHmOHL 8vZhEyY8Gqd59UxBA4iRJdgl/OFxVeF/lKuyIJTqI8iyduxawHnvhIv9KB36KhsuaQbT gNtwKH+iTI9ojD8c/nmd+pWCqAbLZD7XRjkcZdhFi+0WoUBJaKmSfzNlAhyb2rW7Clej sEDPW/fYjnXujuHaVMhuXF3WICa5pE3nOecHtlpJJnRtkbsNOaXpHwo+BQ79mOo20hGa 6Jiw== 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=IJFvu7Txlqq4QbkiUAdYp5LUxrFDgYD73zO+DTftg+Q=; b=sjKl5WBgLaXlHqj8UUGU5lJc0bi0RGkO+jU42WZ4UFDgKSdVnRCAavWvPj7Yq4OBnv qx8pDix3nPnKmjSwhWAhS1ZgVW8+az3MTLsEeDT44IA9Aziu/JA4Y4qeW4xqAaNfF9Lo stk1eSV0nKGJU3Db4WLnvH06XpsYZvVWv4WDZ0a5/fnP35D9xljU6D8AqSPmFFGxJshy 4udiMqdSByqbNsyLPh2x9KltZDRtKlDwQq7rIPJwjosiZcmIIzxYNKucmGkeDiCGC7ws m1hPYzPJSdfeKbS9PKEDASBlTjp5++JdepEvzRVm4nK2RcfHBkdAyAWSWu7FhGMlacvW +tJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=bZrDyGsf; 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 x10-20020a63f70a000000b003c63d17fb2fsi126620pgh.125.2022.05.05.11.29.00; Thu, 05 May 2022 11:29:17 -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=bZrDyGsf; 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 S231919AbiEENy6 (ORCPT + 99 others); Thu, 5 May 2022 09:54:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380139AbiEENyr (ORCPT ); Thu, 5 May 2022 09:54:47 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2932856FBF for ; Thu, 5 May 2022 06:51:06 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20220505135104euoutp02b129fe3e00244ff3ac7bb5e82fd38697~sOcEDc9752801028010euoutp02i for ; Thu, 5 May 2022 13:51:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20220505135104euoutp02b129fe3e00244ff3ac7bb5e82fd38697~sOcEDc9752801028010euoutp02i DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1651758664; bh=IJFvu7Txlqq4QbkiUAdYp5LUxrFDgYD73zO+DTftg+Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bZrDyGsfs+3P/kQAlBt5QaftuKlo9xZ5lneMVHI5aug1TG6fS7V9kYpRQH1zJp0TX aQS0mDw4Na5Vep/j9UFtkx51ev8HWoPYDdLkzsFpQn0MX3dfLYYu+m7pnzUaRYcDb9 /7tJSbSgkhqZGCIeAHuUffcELHFXuTEwOESNLwA8= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20220505135102eucas1p28ebe907946ee0fe0ae28eddb6534ce59~sOcB9o7Gb3221632216eucas1p2u; Thu, 5 May 2022 13:51:02 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id BA.AC.09887.646D3726; Thu, 5 May 2022 14:51:02 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220505135101eucas1p10477067397a4fdadf9fe7adbb26d1edc~sOcBPoXs42590725907eucas1p14; Thu, 5 May 2022 13:51:01 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220505135101eusmtrp2ec25bb53c2cf3e4bc870f4128d9dc4a1~sOcBMyvg22658826588eusmtrp2A; Thu, 5 May 2022 13:51:01 +0000 (GMT) X-AuditID: cbfec7f4-45bff7000000269f-e5-6273d6462c82 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id DA.F2.09522.546D3726; Thu, 5 May 2022 14:51:01 +0100 (BST) Received: from localhost (unknown [106.210.248.170]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220505135100eusmtip1e415b7e73e2fcc5131f9d700d68c3549~sOcAzCwSG0095700957eusmtip1E; Thu, 5 May 2022 13:51:00 +0000 (GMT) From: Pankaj Raghav To: axboe@kernel.dk, hch@lst.de, damien.lemoal@opensource.wdc.com, dsterba@suse.com, jaegeuk@kernel.org, bvanassche@acm.org, hare@suse.de Cc: jonathan.derrick@linux.dev, jiangbo.365@bytedance.com, matias.bjorling@wdc.com, gost.dev@samsung.com, pankydev8@gmail.com, Pankaj Raghav , Luis Chamberlain , Keith Busch , Jens Axboe , Sagi Grimberg , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 03/11] nvme: zns: Allow ZNS drives that have non-power_of_2 zone size Date: Thu, 5 May 2022 15:47:03 +0200 Message-Id: <20220505134710.132630-4-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220505134710.132630-1-p.raghav@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA02Sf0xTVxTHc997fX1tVnwWAjewjK1GzUiobizuOslEGeZlM25z2ZaQ7Eer L9hQStNamLBlBaqzuAAjjIUOg5oyhbJWfqiUoWIRO0ehxjIorjA0rVOLK6U4qUwZ5WHmf59z zvec7zk3l8LFejKZUqj2sxqVTCkhhcTZK1F3+o5RrXxj/ywPLfZeIZFloppE9TNRHC0MuXF0 bb4MQ+N9dgz1nqjFUItlAEN+mwlH3/bNEKjFcBNHtY5RgDw9jSRq+inARzWHHuDIWxMAKNJs 4KO28QCBrMEQkRXPeEbeYZ782kYy31X8zWfspgk+455sJxjPkI7paDW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477067397a4fdadf9fe7adbb26d1edc X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20220505135101eucas1p10477067397a4fdadf9fe7adbb26d1edc X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220505135101eucas1p10477067397a4fdadf9fe7adbb26d1edc References: <20220505134710.132630-1-p.raghav@samsung.com> X-Spam-Status: No, score=-7.7 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 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. Reviewed-by: Luis Chamberlain Reviewed by: Adam Manzanares Signed-off-by: Pankaj Raghav --- drivers/nvme/host/zns.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/nvme/host/zns.c b/drivers/nvme/host/zns.c index 9f81beb4d..65d2aa68a 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,14 @@ 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); + /* + * rounddown the sector value to the nearest zone size. roundown macro + * provided in math.h will not work for 32 bit architectures. + * Division is used here with no special handling for power of 2 + * zone sizes as this function is not invoked in a hot path + */ + div64_u64_rem(sector, ns->zsze, &remainder); + sector -= remainder; while (zone_idx < nr_zones && sector < get_capacity(ns->disk)) { memset(report, 0, buflen); -- 2.25.1