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+r2YFKWIT0JJo7AQbJCLQyCgx9eUJsCJmgdlMEvO+TQab KiwQIdE3ZQEziM0ioCrxdtsjsDivgJXE1qUrWSHuk5eYeek7O4jNKWAtMX//Z2aIGkGJkzOf sIDYzEA1zVtnM4MskBBYzSnx8vRMZohmF4lTL2ZBDRKWeHV8CzuELSNxenIPC4RdLfH0xm+o 5hZGif6d69kg/rSW6DuTA2IyC2hKrN+lD1HuKHHqai8rRAWfxI23ghAn8ElM2jadGSLMK9HR Bg1dJYmdP59ALZWQuNw0B2qph8TRE22MExgVZyF5ZhaSZ2Yh7F3AyLyKUTy1tDg3PbXYMC+1 XK84Mbe4NC9dLzk/dxMjMAGe/nf80w7Gua8+6h1iZOJgPMQowcGsJMJ74WlvkhBvSmJlVWpR fnxRaU5q8SFGaQ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FGCQ5mJRHeC097k4R4 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);