nvmet: fix mar and mor off-by-one errors
authorDennis Maisenbacher <dennis.maisenbacher@wdc.com>
Tue, 6 Sep 2022 07:39:28 +0000 (09:39 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 15 Sep 2022 09:30:06 +0000 (11:30 +0200)
[ 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 <niklas.cassel@wdc.com>
Signed-off-by: Dennis Maisenbacher <dennis.maisenbacher@wdc.com>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/nvme/target/zns.c

index 2355533..1466698 100644 (file)
@@ -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;
 
        if (le32_to_cpu(req->cmd->identify.nsid) == NVME_NSID_ALL) {
                req->error_loc = offsetof(struct nvme_identify, nsid);
@@ -126,8 +127,20 @@ void nvmet_execute_identify_cns_cs_ns(struct nvmet_req *req)
        zsze = (bdev_zone_sectors(req->ns->bdev) << 9) >>
                                        req->ns->blksize_shift;
        id_zns->lbafe[0].zsze = cpu_to_le64(zsze);
-       id_zns->mor = cpu_to_le32(bdev_max_open_zones(req->ns->bdev));
-       id_zns->mar = cpu_to_le32(bdev_max_active_zones(req->ns->bdev));
+
+       mor = bdev_max_open_zones(req->ns->bdev);
+       if (!mor)
+               mor = U32_MAX;
+       else
+               mor--;
+       id_zns->mor = cpu_to_le32(mor);
+
+       mar = bdev_max_active_zones(req->ns->bdev);
+       if (!mar)
+               mar = U32_MAX;
+       else
+               mar--;
+       id_zns->mar = cpu_to_le32(mar);
 
 done:
        status = nvmet_copy_to_sgl(req, 0, id_zns, sizeof(*id_zns));