[PATCH blktests] nvme/080: test write zeroes larger than 65536 logical blocks

Shin'ichiro Kawasaki shinichiro.kawasaki at wdc.com
Fri Nov 20 18:05:03 PST 2026


On Nov 16, 2026 / 21:26, Ankit Gupta wrote:
> 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 at gmail.com>

Ankit, thank you for the patch. Overall, it looks good to me. I also did a trial
run, and the new test case fails with the kernel v7.4-rc3, and the test case
passes with the kernel fix patch. Good.

I made minor nit comments in line below. They are not critical. If you are okay
with it, I can make the changes when I apply this patch. Or feel free to respin
the patch. Please let me know your preference.

...

> 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

Nit: blkdiscard is a part of util-linux, util-linux is the fundamental
     requirement to run blktests as noted in README.md. Then I think it is
     fine to drop the line above.

> +	_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' |

Nit: it is recommended to use the long option --bytes= instead of the short
     option -c here.

> +			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

Nit: same here, with long options, the line above can be,

        if ! blkdiscard --zeroout --offset 0 --length "${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

Nit: same here:

                        cmp --silent --bytes "$((len_mb * 1024 * 1024))" \
                            - /dev/zero; then



More information about the Linux-nvme mailing list