Linux block layer
 help / color / mirror / Atom feed
From: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
To: Ankit Gupta <ankit6791@gmail.com>
Cc: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org,
	 Christoph Hellwig <hch@lst.de>
Subject: Re: [PATCH blktests] nvme/080: test write zeroes larger than 65536 logical blocks
Date: Sat, 21 Nov 2026 11:05:03 +0900	[thread overview]
Message-ID: <awD6iLYWPuEgEi1C@shinmob> (raw)
In-Reply-To: <20261117052741.25471-1-ankit6791@gmail.com>

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

      parent reply	other threads:[~2026-11-21  2:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17  5:26 [PATCH blktests] nvme/080: test write zeroes larger than 65536 logical blocks Ankit Gupta
2026-11-17 19:45 ` Chaitanya Kulkarni
2026-11-21  2:05 ` Shin'ichiro Kawasaki [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=awD6iLYWPuEgEi1C@shinmob \
    --to=shinichiro.kawasaki@wdc.com \
    --cc=ankit6791@gmail.com \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox