From nobody Fri Dec 19 07:55:09 2025 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 927D2C6FA8A for ; Tue, 13 Sep 2022 14:24:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233475AbiIMOYd (ORCPT ); Tue, 13 Sep 2022 10:24:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233139AbiIMOXb (ORCPT ); Tue, 13 Sep 2022 10:23:31 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E433861701; Tue, 13 Sep 2022 07:15:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id C9484CE1275; Tue, 13 Sep 2022 14:13:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C41AAC433D6; Tue, 13 Sep 2022 14:13:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663078436; bh=1ME5e66fVDTdP1+yLfK6JdLvd1xQYZ9E8X3oa+BdnZI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=quVTk97uTwh2aVJVL+hFdDfj3ONfzbhk7A/5mymve3x/l72yYqGLo57FvpQk2fc9d YciTroujvjGnhPGcAkFb8oQ8tErCnC+FeRH9ebnlSCZM+Ifc86E7EBVeQhmoUzVUMI 25UpJjvhDIDsahh81zKX6kYx/Rxx86Jg8BacDsz0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Niklas Cassel , Dennis Maisenbacher , Chaitanya Kulkarni , Christoph Hellwig , Sasha Levin Subject: [PATCH 5.19 139/192] nvmet: fix mar and mor off-by-one errors Date: Tue, 13 Sep 2022 16:04:05 +0200 Message-Id: <20220913140416.942610283@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140410.043243217@linuxfoundation.org> References: <20220913140410.043243217@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Dennis Maisenbacher [ Upstream commit b7e97872a65e1d57b4451769610554c131f37a0a ] Maximum Active Resources (MAR) and Maximum Open Resources (MOR) are 0's based vales where a value of 0xffffffff indicates that there is no limit. Decrement the values that are returned by bdev_max_open_zones and bdev_max_active_zones as the block layer helpers are not 0's based. A 0 returned by the block layer helpers indicates no limit, thus convert it to 0xffffffff (U32_MAX). Fixes: aaf2e048af27 ("nvmet: add ZBD over ZNS backend support") Suggested-by: Niklas Cassel Signed-off-by: Dennis Maisenbacher Reviewed-by: Chaitanya Kulkarni Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- drivers/nvme/target/zns.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/nvme/target/zns.c b/drivers/nvme/target/zns.c index 82b61acf7a72b..1956be87ac5ff 100644 --- a/drivers/nvme/target/zns.c +++ b/drivers/nvme/target/zns.c @@ -100,6 +100,7 @@ void nvmet_execute_identify_cns_cs_ns(struct nvmet_req = *req) struct nvme_id_ns_zns *id_zns; u64 zsze; u16 status; + u32 mar, mor; =20 if (le32_to_cpu(req->cmd->identify.nsid) =3D=3D NVME_NSID_ALL) { req->error_loc =3D offsetof(struct nvme_identify, nsid); @@ -130,8 +131,20 @@ void nvmet_execute_identify_cns_cs_ns(struct nvmet_req= *req) zsze =3D (bdev_zone_sectors(req->ns->bdev) << 9) >> req->ns->blksize_shift; id_zns->lbafe[0].zsze =3D cpu_to_le64(zsze); - id_zns->mor =3D cpu_to_le32(bdev_max_open_zones(req->ns->bdev)); - id_zns->mar =3D cpu_to_le32(bdev_max_active_zones(req->ns->bdev)); + + mor =3D bdev_max_open_zones(req->ns->bdev); + if (!mor) + mor =3D U32_MAX; + else + mor--; + id_zns->mor =3D cpu_to_le32(mor); + + mar =3D bdev_max_active_zones(req->ns->bdev); + if (!mar) + mar =3D U32_MAX; + else + mar--; + id_zns->mar =3D cpu_to_le32(mar); =20 done: status =3D nvmet_copy_to_sgl(req, 0, id_zns, sizeof(*id_zns)); --=20 2.35.1