* [PATCH v2] nvme: limit Write Zeroes to 65536 logical blocks
@ 2026-11-17 1:10 Ankit Gupta
0 siblings, 0 replies; only message in thread
From: Ankit Gupta @ 2026-11-17 1:10 UTC (permalink / raw)
To: linux-nvme
Cc: Ankit Gupta, Keith Busch, Jens Axboe, Christoph Hellwig,
Sagi Grimberg, Chaitanya Kulkarni, stable
With nvme-tcp connected to nvmet-tcp at default settings, the target
reports MDTS 0 and WZSL 0. A 33 MiB Write Zeroes request on a
512-byte-LBA namespace then completes successfully after zeroing only
the first 1 MiB.
The native Write Zeroes command encodes the number of logical blocks
in a zero-based 16-bit field. The namespace queue can advertise a
larger limit, either through the MDTS fallback or through WZSL. In
that case the host truncates the count when building the command and
reports success after zeroing only part of the requested range.
Cap the native Write Zeroes limit at the number of logical blocks the
command can encode. Convert that limit to sectors for each namespace
and retain any smaller controller limit. The DSM deallocation quirk
continues to use its own limit.
Fixes: b94e8cd2e6a9 ("nvme: fix Write Zeroes limitations")
Cc: stable@vger.kernel.org
Signed-off-by: Ankit Gupta <ankit6791@gmail.com>
---
Tested on arm64 at v7.4-rc3 (aebb72744764), over TCP with the stock
nvmet target. Full-range read-back passed for 1, 32, 33, 64, 256 and
1024 MiB with 512-byte LBAs, and 256, 257, 512 and 1024 MiB with
4 KiB LBAs. Host and target traces confirmed the expected command
splitting. A smaller 1 MiB MDTS-derived limit was preserved, and XFS
formatted and mounted successfully.
Claude and Codex assisted with the investigation, patch preparation,
and validation. I also reproduced the 33 MiB failure and checked the
trace by hand on an unpatched kernel.
I will follow up with a blktests regression test for this, as
Christoph suggested.
Changes since v1 (sent to the maintainers off-list):
- Move the calculation into nvme_max_write_zeroes_sectors() and
derive the maximum block count from the command's length field.
- Describe the affected configuration and Cc stable.
drivers/nvme/host/core.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index f4aa02869b79..441d70001920 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -2093,6 +2093,16 @@ static void nvme_set_ctrl_limits(struct nvme_ctrl *ctrl,
lim->dma_alignment = 3;
}
+static sector_t nvme_max_write_zeroes_sectors(struct nvme_ns *ns)
+{
+ const size_t nlb_bytes =
+ sizeof_field(struct nvme_write_zeroes_cmd, length);
+ const u64 max_lbas = BIT_ULL(BYTES_TO_BITS(nlb_bytes));
+
+ return min_t(sector_t, ns->ctrl->max_zeroes_sectors,
+ nvme_lba_to_sect(ns->head, max_lbas));
+}
+
static bool nvme_update_disk_info(struct nvme_ns *ns, struct nvme_id_ns *id,
struct nvme_id_ns_nvm *nvm, struct queue_limits *lim)
{
@@ -2143,7 +2153,8 @@ static bool nvme_update_disk_info(struct nvme_ns *ns, struct nvme_id_ns *id,
(ctrl->oncs & NVME_CTRL_ONCS_DSM))
lim->max_write_zeroes_sectors = UINT_MAX;
else
- lim->max_write_zeroes_sectors = ctrl->max_zeroes_sectors;
+ lim->max_write_zeroes_sectors =
+ nvme_max_write_zeroes_sectors(ns);
if (ctrl->dmrsl && ctrl->dmrsl <= nvme_sect_to_lba(ns->head, UINT_MAX))
lim->max_hw_discard_sectors =
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-17 1:13 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 1:10 [PATCH v2] nvme: limit Write Zeroes to 65536 logical blocks Ankit Gupta
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox