* [PATCH blktests] nvme/080: test write zeroes larger than 65536 logical blocks
@ 2026-11-17 5:26 Ankit Gupta
0 siblings, 0 replies; only message in thread
From: Ankit Gupta @ 2026-11-17 5:26 UTC (permalink / raw)
To: linux-block, Shin'ichiro Kawasaki
Cc: Ankit Gupta, linux-nvme, Christoph Hellwig
The NVMe Write Zeroes command encodes the number of logical blocks in a
zero-based 16-bit field. When the controller reports neither MDTS nor
WZSL, as nvmet-tcp does by default, the host advertised an unbounded
write zeroes limit, truncated the block count when building the command
and completed the request successfully after zeroing only a prefix.
Add a regression test for the kernel patch "nvme: limit Write Zeroes to
65536 logical blocks" [1]. Fill 65536 logical blocks plus 1 MiB with a
non-zero pattern, zero that range with blkdiscard -z and check that the
whole range reads back as zeroes. The length scales with the logical
block size, so the test covers both 512-byte and 4096-byte namespaces.
[1] https://lore.kernel.org/linux-nvme/20261117011230.10288-1-ankit6791@gmail.com/
Signed-off-by: Ankit Gupta <ankit6791@gmail.com>
---
Tested on arm64 with v7.4-rc3 (aebb72744764), NVMET_TRTYPES="loop tcp"
and NVMET_BLKDEV_TYPES="device file". Without the kernel patch the test
fails for tcp with both block device types ("zeroed range still contains
non-zero data"). With the patch it passes for tcp and loop with both
types. The device type gives 512-byte logical blocks (33 MiB zeroed) and
the file type 4096-byte logical blocks (257 MiB zeroed). With
NVME_IMG_SIZE=64m the device type still runs and the file type is
skipped.
Claude and Codex assisted with writing and validating this test.
tests/nvme/080 | 90 ++++++++++++++++++++++++++++++++++++++++++++++
tests/nvme/080.out | 2 ++
2 files changed, 92 insertions(+)
create mode 100755 tests/nvme/080
create mode 100644 tests/nvme/080.out
diff --git a/tests/nvme/080 b/tests/nvme/080
new file mode 100755
index 0000000..bbd3031
--- /dev/null
+++ b/tests/nvme/080
@@ -0,0 +1,90 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2026 Ankit Gupta
+#
+# Test that a Write Zeroes request larger than a single NVMe Write Zeroes
+# command can describe zeroes the whole requested range. The command encodes
+# the number of logical blocks in a zero-based 16-bit field, so one command
+# covers at most 65536 logical blocks. When the controller reports neither
+# MDTS nor WZSL, as nvmet-tcp does by default, the host used to advertise an
+# unbounded write zeroes limit, truncate the block count when building the
+# command and complete the request successfully after zeroing only a prefix.
+#
+# Regression test for the patch "nvme: limit Write Zeroes to 65536 logical
+# blocks".
+
+. tests/nvme/rc
+
+DESCRIPTION="test write zeroes larger than 65536 logical blocks"
+QUICK=1
+
+requires() {
+ _nvme_requires
+ _have_loop
+ _have_program blkdiscard
+ _require_nvme_trtype_is_fabrics
+}
+
+set_conditions() {
+ _set_combined_conditions _set_nvme_trtype _set_nvmet_blkdev_type "$@"
+}
+
+test_write_zeroes() {
+ local ns dev bs size len_mb
+
+ if ! ns=$(_find_nvme_ns "${def_subsys_uuid}"); then
+ echo "FAIL: failed to find the namespace"
+ return 1
+ fi
+ dev="/dev/${ns}"
+
+ if ! bs=$(blockdev --getss "${dev}") ||
+ ! size=$(blockdev --getsize64 "${dev}"); then
+ echo "FAIL: failed to get the namespace block size and capacity"
+ return 1
+ fi
+
+ # 65536 logical blocks plus 1 MiB: 33 MiB with 512-byte logical blocks
+ # and 257 MiB with 4096-byte logical blocks.
+ len_mb=$((bs * 65536 / 1024 / 1024 + 1))
+ if ((len_mb * 1024 * 1024 > size)); then
+ SKIP_REASONS+=("namespace is smaller than ${len_mb} MiB")
+ return 1
+ fi
+
+ # Fill the range with non-zero data so that stale data is detectable.
+ if ! head -c "${len_mb}M" /dev/zero | tr '\0' '\377' |
+ dd of="${dev}" bs=1M iflag=fullblock oflag=direct \
+ status=none; then
+ echo "FAIL: failed to fill ${len_mb} MiB with a pattern"
+ fi
+
+ if ! blkdiscard -z -o 0 -l "${len_mb}M" "${dev}"; then
+ echo "FAIL: blkdiscard -z failed"
+ fi
+
+ if ! dd if="${dev}" bs=1M count="${len_mb}" iflag=direct status=none |
+ cmp -s -n "$((len_mb * 1024 * 1024))" - /dev/zero; then
+ echo "FAIL: zeroed range still contains non-zero data"
+ fi
+}
+
+test() {
+ echo "Running ${TEST_NAME}"
+
+ _setup_nvmet
+
+ _nvmet_target_setup
+
+ if _nvme_connect_subsys; then
+ test_write_zeroes
+ else
+ echo "FAIL: failed to connect to the subsystem"
+ fi
+
+ _nvme_disconnect_subsys
+
+ _nvmet_target_cleanup
+
+ echo "Test complete"
+}
diff --git a/tests/nvme/080.out b/tests/nvme/080.out
new file mode 100644
index 0000000..15119b8
--- /dev/null
+++ b/tests/nvme/080.out
@@ -0,0 +1,2 @@
+Running nvme/080
+Test complete
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-17 5:28 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 5:26 [PATCH blktests] nvme/080: test write zeroes larger than 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