* [PATCH v1 1/1] nvme: zns: cap zone report nr_zones by DMA buffer size
2026-06-23 9:35 [PATCH v1 0/1] nvme: zns: cap zone report nr_zones by DMA buffer size Xixin Liu
@ 2026-06-23 9:35 ` Xixin Liu
0 siblings, 0 replies; 9+ messages in thread
From: Xixin Liu @ 2026-06-23 9:35 UTC (permalink / raw)
To: linux-nvme; +Cc: kbusch, axboe, hch, sagi, linux-kernel, liuxixin
With Partial Report (PR=1), the Number of Zones (NZ) field in the report
header must equal the number of zone descriptors fully transferred in the
DMA buffer (ZNS Command Set Specification Rev 1.2, section 3.4.2).
nvme_ns_report_zones() does not cap the parse loop by max_in_buf derived
from buflen. Cap nz with min3() over the device-reported count, nr_zones -
zone_idx, and max_in_buf.
Signed-off-by: Xixin Liu <liuxixin@kylinos.cn>
---
drivers/nvme/host/zns.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/drivers/nvme/host/zns.c b/drivers/nvme/host/zns.c
index 8ed1b6a33454..2a152e87bd76 100644
--- a/drivers/nvme/host/zns.c
+++ b/drivers/nvme/host/zns.c
@@ -155,7 +155,8 @@ static int nvme_zone_parse_entry(struct nvme_ns *ns,
struct blk_zone zone = { };
if ((entry->zt & 0xf) != NVME_ZONE_TYPE_SEQWRITE_REQ) {
- dev_err(ns->ctrl->device, "invalid zone type %#x\n", entry->zt);
+ dev_err(ns->ctrl->device, "invalid zone type %#x at zone %u\n",
+ entry->zt, idx);
return -EINVAL;
}
@@ -178,7 +179,7 @@ int nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector,
struct nvme_zone_report *report;
struct nvme_command c = { };
int ret, zone_idx = 0;
- unsigned int nz, i;
+ unsigned int max_in_buf, nz, i;
size_t buflen;
if (ns->head->ids.csi != NVME_CSI_ZNS)
@@ -188,6 +189,9 @@ int nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector,
if (!report)
return -ENOMEM;
+ max_in_buf = (buflen - sizeof(struct nvme_zone_report)) /
+ sizeof(struct nvme_zone_descriptor);
+
c.zmr.opcode = nvme_cmd_zone_mgmt_recv;
c.zmr.nsid = cpu_to_le32(ns->head->ns_id);
c.zmr.numd = cpu_to_le32(nvme_bytes_to_numd(buflen));
@@ -207,7 +211,8 @@ int nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector,
goto out_free;
}
- nz = min((unsigned int)le64_to_cpu(report->nr_zones), nr_zones);
+ nz = min3((unsigned int)le64_to_cpu(report->nr_zones),
+ nr_zones - zone_idx, max_in_buf);
if (!nz)
break;
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v1 0/1] nvme: zns: cap zone report nr_zones by DMA buffer size
@ 2026-06-24 5:53 Xixin Liu
2026-06-24 5:53 ` [PATCH v1 1/1] " Xixin Liu
2026-06-25 2:00 ` [PATCH v2 0/2] " Xixin Liu
0 siblings, 2 replies; 9+ messages in thread
From: Xixin Liu @ 2026-06-24 5:53 UTC (permalink / raw)
To: linux-nvme; +Cc: kbusch, axboe, hch, sagi, linux-kernel, liuxixin
Hi,
The ZNS host driver issues Zone Management Receive with Partial Report
(PR=1) fixed. The Number of Zones (NZ) field in the report header must
reflect the zone descriptors actually transferred in the DMA buffer (ZNS
Command Set Specification Rev 1.2, section 3.4.2).
nvme_ns_report_zones() caps the parse loop by the device-reported NZ and
the caller's nr_zones limit, but not by the number of descriptors that fit
in buflen. Cap nz with min3(device NZ, nr_zones - zone_idx, max_in_buf).
Thanks,
Xixin Liu
---
Xixin Liu (1):
nvme: zns: cap zone report nr_zones by DMA buffer size
drivers/nvme/host/zns.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v1 1/1] nvme: zns: cap zone report nr_zones by DMA buffer size
2026-06-24 5:53 [PATCH v1 0/1] nvme: zns: cap zone report nr_zones by DMA buffer size Xixin Liu
@ 2026-06-24 5:53 ` Xixin Liu
2026-06-25 11:59 ` Christoph Hellwig
2026-06-25 2:00 ` [PATCH v2 0/2] " Xixin Liu
1 sibling, 1 reply; 9+ messages in thread
From: Xixin Liu @ 2026-06-24 5:53 UTC (permalink / raw)
To: linux-nvme; +Cc: kbusch, axboe, hch, sagi, linux-kernel, liuxixin
With Partial Report (PR=1), the Number of Zones (NZ) field in the report
header must equal the number of zone descriptors fully transferred in the
DMA buffer (ZNS Command Set Specification Rev 1.2, section 3.4.2).
nvme_ns_report_zones() does not cap the parse loop by max_in_buf derived
from buflen. Cap nz with min3() over the device-reported count, nr_zones -
zone_idx, and max_in_buf.
Signed-off-by: Xixin Liu <liuxixin@kylinos.cn>
---
drivers/nvme/host/zns.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/drivers/nvme/host/zns.c b/drivers/nvme/host/zns.c
index 8ed1b6a33454..2a152e87bd76 100644
--- a/drivers/nvme/host/zns.c
+++ b/drivers/nvme/host/zns.c
@@ -155,7 +155,8 @@ static int nvme_zone_parse_entry(struct nvme_ns *ns,
struct blk_zone zone = { };
if ((entry->zt & 0xf) != NVME_ZONE_TYPE_SEQWRITE_REQ) {
- dev_err(ns->ctrl->device, "invalid zone type %#x\n", entry->zt);
+ dev_err(ns->ctrl->device, "invalid zone type %#x at zone %u\n",
+ entry->zt, idx);
return -EINVAL;
}
@@ -178,7 +179,7 @@ int nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector,
struct nvme_zone_report *report;
struct nvme_command c = { };
int ret, zone_idx = 0;
- unsigned int nz, i;
+ unsigned int max_in_buf, nz, i;
size_t buflen;
if (ns->head->ids.csi != NVME_CSI_ZNS)
@@ -188,6 +189,9 @@ int nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector,
if (!report)
return -ENOMEM;
+ max_in_buf = (buflen - sizeof(struct nvme_zone_report)) /
+ sizeof(struct nvme_zone_descriptor);
+
c.zmr.opcode = nvme_cmd_zone_mgmt_recv;
c.zmr.nsid = cpu_to_le32(ns->head->ns_id);
c.zmr.numd = cpu_to_le32(nvme_bytes_to_numd(buflen));
@@ -207,7 +211,8 @@ int nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector,
goto out_free;
}
- nz = min((unsigned int)le64_to_cpu(report->nr_zones), nr_zones);
+ nz = min3((unsigned int)le64_to_cpu(report->nr_zones),
+ nr_zones - zone_idx, max_in_buf);
if (!nz)
break;
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 0/2] nvme: zns: cap zone report nr_zones by DMA buffer size
2026-06-24 5:53 [PATCH v1 0/1] nvme: zns: cap zone report nr_zones by DMA buffer size Xixin Liu
2026-06-24 5:53 ` [PATCH v1 1/1] " Xixin Liu
@ 2026-06-25 2:00 ` Xixin Liu
2026-06-25 2:00 ` [PATCH v2 1/2] " Xixin Liu
2026-06-25 2:00 ` [PATCH v2 2/2] nvme: zns: include zone index in invalid zone type error Xixin Liu
1 sibling, 2 replies; 9+ messages in thread
From: Xixin Liu @ 2026-06-25 2:00 UTC (permalink / raw)
To: linux-nvme; +Cc: kbusch, axboe, hch, sagi, linux-kernel, liuxixin
Hi Christoph,
Thanks for the review. Split the zone index logging change into its
own patch (2/2). The nr_zones / buflen fix is unchanged in 1/2.
Thanks,
Xixin Liu
---
Xixin Liu (2):
nvme: zns: cap zone report nr_zones by DMA buffer size
nvme: zns: include zone index in invalid zone type error
drivers/nvme/host/zns.c | 12 ++++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 1/2] nvme: zns: cap zone report nr_zones by DMA buffer size
2026-06-25 2:00 ` [PATCH v2 0/2] " Xixin Liu
@ 2026-06-25 2:00 ` Xixin Liu
2026-06-26 4:49 ` Christoph Hellwig
2026-06-25 2:00 ` [PATCH v2 2/2] nvme: zns: include zone index in invalid zone type error Xixin Liu
1 sibling, 1 reply; 9+ messages in thread
From: Xixin Liu @ 2026-06-25 2:00 UTC (permalink / raw)
To: linux-nvme; +Cc: kbusch, axboe, hch, sagi, linux-kernel, liuxixin
With Partial Report (PR=1), the Number of Zones (NZ) field in the report
header must equal the number of zone descriptors fully transferred in the
DMA buffer (ZNS Command Set Specification Rev 1.2, section 3.4.2).
nvme_ns_report_zones() does not cap the parse loop by max_in_buf derived
from buflen. Cap nz with min3() over the device-reported count, nr_zones -
zone_idx, and max_in_buf.
Signed-off-by: Xixin Liu <liuxixin@kylinos.cn>
---
drivers/nvme/host/zns.c | 9 ++++++++---
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/nvme/host/zns.c b/drivers/nvme/host/zns.c
index 8ed1b6a33454..a1b2c3d4e5f6 100644
--- a/drivers/nvme/host/zns.c
+++ b/drivers/nvme/host/zns.c
@@ -178,7 +179,7 @@ int nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector,
struct nvme_zone_report *report;
struct nvme_command c = { };
int ret, zone_idx = 0;
- unsigned int nz, i;
+ unsigned int max_in_buf, nz, i;
size_t buflen;
if (ns->head->ids.csi != NVME_CSI_ZNS)
@@ -188,6 +189,9 @@ int nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector,
if (!report)
return -ENOMEM;
+ max_in_buf = (buflen - sizeof(struct nvme_zone_report)) /
+ sizeof(struct nvme_zone_descriptor);
+
c.zmr.opcode = nvme_cmd_zone_mgmt_recv;
c.zmr.nsid = cpu_to_le32(ns->head->ns_id);
c.zmr.numd = cpu_to_le32(nvme_bytes_to_numd(buflen));
@@ -207,7 +211,8 @@ int nvme_ns_report_zones(struct nvme_ns *ns, sector_t sector,
goto out_free;
}
- nz = min((unsigned int)le64_to_cpu(report->nr_zones), nr_zones);
+ nz = min3((unsigned int)le64_to_cpu(report->nr_zones),
+ nr_zones - zone_idx, max_in_buf);
if (!nz)
break;
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 2/2] nvme: zns: include zone index in invalid zone type error
2026-06-25 2:00 ` [PATCH v2 0/2] " Xixin Liu
2026-06-25 2:00 ` [PATCH v2 1/2] " Xixin Liu
@ 2026-06-25 2:00 ` Xixin Liu
2026-06-26 4:50 ` Christoph Hellwig
1 sibling, 1 reply; 9+ messages in thread
From: Xixin Liu @ 2026-06-25 2:00 UTC (permalink / raw)
To: linux-nvme; +Cc: kbusch, axboe, hch, sagi, linux-kernel, liuxixin
Include the zone index when reporting an invalid zone type during zone
descriptor parsing.
Signed-off-by: Xixin Liu <liuxixin@kylinos.cn>
---
drivers/nvme/host/zns.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/nvme/host/zns.c b/drivers/nvme/host/zns.c
index 8ed1b6a33454..b2c3d4e5f6a7 100644
--- a/drivers/nvme/host/zns.c
+++ b/drivers/nvme/host/zns.c
@@ -155,7 +155,8 @@ static int nvme_zone_parse_entry(struct nvme_ns *ns,
struct blk_zone zone = { };
if ((entry->zt & 0xf) != NVME_ZONE_TYPE_SEQWRITE_REQ) {
- dev_err(ns->ctrl->device, "invalid zone type %#x\n", entry->zt);
+ dev_err(ns->ctrl->device, "invalid zone type %#x at zone %u\n",
+ entry->zt, idx);
return -EINVAL;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v1 1/1] nvme: zns: cap zone report nr_zones by DMA buffer size
2026-06-24 5:53 ` [PATCH v1 1/1] " Xixin Liu
@ 2026-06-25 11:59 ` Christoph Hellwig
0 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2026-06-25 11:59 UTC (permalink / raw)
To: Xixin Liu; +Cc: linux-nvme, kbusch, axboe, hch, sagi, linux-kernel
On Wed, Jun 24, 2026 at 01:53:40PM +0800, Xixin Liu wrote:
> With Partial Report (PR=1), the Number of Zones (NZ) field in the report
> header must equal the number of zone descriptors fully transferred in the
> DMA buffer (ZNS Command Set Specification Rev 1.2, section 3.4.2).
>
> nvme_ns_report_zones() does not cap the parse loop by max_in_buf derived
> from buflen. Cap nz with min3() over the device-reported count, nr_zones -
> zone_idx, and max_in_buf.
>
> Signed-off-by: Xixin Liu <liuxixin@kylinos.cn>
> ---
> drivers/nvme/host/zns.c | 11 ++++++++---
> 1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/nvme/host/zns.c b/drivers/nvme/host/zns.c
> index 8ed1b6a33454..2a152e87bd76 100644
> --- a/drivers/nvme/host/zns.c
> +++ b/drivers/nvme/host/zns.c
> @@ -155,7 +155,8 @@ static int nvme_zone_parse_entry(struct nvme_ns *ns,
> struct blk_zone zone = { };
>
> if ((entry->zt & 0xf) != NVME_ZONE_TYPE_SEQWRITE_REQ) {
> - dev_err(ns->ctrl->device, "invalid zone type %#x\n", entry->zt);
> + dev_err(ns->ctrl->device, "invalid zone type %#x at zone %u\n",
> + entry->zt, idx);
> return -EINVAL;
> }
This looks fine, but unrelated. Please split it into a separate patch.
The rest looks good as well.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 1/2] nvme: zns: cap zone report nr_zones by DMA buffer size
2026-06-25 2:00 ` [PATCH v2 1/2] " Xixin Liu
@ 2026-06-26 4:49 ` Christoph Hellwig
0 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2026-06-26 4:49 UTC (permalink / raw)
To: Xixin Liu; +Cc: linux-nvme, kbusch, axboe, hch, sagi, linux-kernel
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 2/2] nvme: zns: include zone index in invalid zone type error
2026-06-25 2:00 ` [PATCH v2 2/2] nvme: zns: include zone index in invalid zone type error Xixin Liu
@ 2026-06-26 4:50 ` Christoph Hellwig
0 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2026-06-26 4:50 UTC (permalink / raw)
To: Xixin Liu; +Cc: linux-nvme, kbusch, axboe, hch, sagi, linux-kernel
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-06-26 4:50 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-24 5:53 [PATCH v1 0/1] nvme: zns: cap zone report nr_zones by DMA buffer size Xixin Liu
2026-06-24 5:53 ` [PATCH v1 1/1] " Xixin Liu
2026-06-25 11:59 ` Christoph Hellwig
2026-06-25 2:00 ` [PATCH v2 0/2] " Xixin Liu
2026-06-25 2:00 ` [PATCH v2 1/2] " Xixin Liu
2026-06-26 4:49 ` Christoph Hellwig
2026-06-25 2:00 ` [PATCH v2 2/2] nvme: zns: include zone index in invalid zone type error Xixin Liu
2026-06-26 4:50 ` Christoph Hellwig
-- strict thread matches above, loose matches on Subject: below --
2026-06-23 9:35 [PATCH v1 0/1] nvme: zns: cap zone report nr_zones by DMA buffer size Xixin Liu
2026-06-23 9:35 ` [PATCH v1 1/1] " Xixin Liu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.