Skip to contentSkip to conversation

block tests: nvme metadata passthrough

PATCH In review Keith Busch 3 participants 4 messages Jun 9, 2025 – Jun 11, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 block tests: nvme metadata passthrough

From: Keith Busch <[email protected]>

Get more coverage on nvme metadata passthrough. Specifically in this test, read-only metadata is targeted as this had been a gap in previous test coveraged.

---

This one should fail on 6.15 and pass on 6.16.

v1->v2:

Correctly used the "test_device()" function name instead of "test()".

Use the NSID value we got from the device instead of assuming 1.

Fixed the logic for which command is expected to fail when given read-only memory.

 src/Makefile                |   1 +
 src/nvme-passthrough-meta.c | 230 ++++++++++++++++++++++++++++++++++++
 tests/nvme/064              |  24 ++++
 tests/nvme/064.out          |   2 +
 4 files changed, 257 insertions(+)
 create mode 100644 src/nvme-passthrough-meta.c
 create mode 100755 tests/nvme/064
 create mode 100644 tests/nvme/064.out
src/Makefile +1 -0
index a94e5f2..f91ac62 100644
@@ -13,6 +13,7 @@ C_TARGETS := \
 	loop_change_fd \
 	loop_get_status_null \
 	mount_clear_sock \
+	nvme-passthrough-meta \
 	nbdsetsize \
 	openclose \
 	sg/dxfer-from-dev \
src/nvme-passthrough-meta.c new file +230 -0

230 lines not on this page · raw message

tests/nvme/064 new file +24 -0
new file mode 100755
index 0000000..fd72d4a
@@ -0,0 +1,24 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2025 Keith Busch <[email protected]>
+#
+# Test out metadata through the passthrough interfaces
+
+. tests/nvme/rc
+
+requires() {
+	_nvme_requires
+}
+
+DESCRIPTION="exercise the nvme metadata usage with passthrough commands"
+QUICK=1
+
+test_device() {
+	echo "Running ${TEST_NAME}"
+
+	if src/nvme-passthrough-meta "${TEST_DEV}"; then
+		echo "src/nvme-passthrough-meta failed"
+	fi
+
+	echo "Test complete"
+}
tests/nvme/064.out new file +2 -0
new file mode 100644
index 0000000..5b34d4e
@@ -0,0 +1,2 @@
+Running nvme/064
+Test complete
Signature · 1 line
2.47.1
#1 lore raw

On Jun 09, 2025 / 08:41, Keith Busch wrote:
...

Quoted 5 lines
tests/nvme/064 new file +0 -0
new file mode 100755
index 0000000..fd72d4a

...

tests/nvme/064

Quoted 4 lines
tests/nvme/064 new file +4 -0
+test_device() {
+	echo "Running ${TEST_NAME}"
+
+	if src/nvme-passthrough-meta "${TEST_DEV}"; then

I think the check logic above should be inverted:

	if ! src/nvme-passthrough-meta "${TEST_DEV}"; then

Thanks for this v2. With the fix above, I was able to confirme that the test case passes with v6.16-rc1 kernel. When I reverted the kernel commit below, it failed. It looks working good as the fix confirmation.

43a67dd812c5 ("block: flip iter directions in blk_rq_integrity_map_user()")

To run the test case, I tried QEMU nvme emulation devices with some different options. I found that the namespace should have format with metadata, and extended LBA should be disabled. IOW, QEMU -drive option should have value "pi=1,pil=1,ms=8" for the namespace.

I suggest to describe the device requirements in the test case comment. Also, I suggest to check the requirements for the test case, and skip if the requirements are not fulfilled. FYI, I prototyped such change as the patch below. Please let me know what your think. If you are okay with it, I will repost your patch together with my patch for common/rc and tests/nvme/rc as the v3 series.

common/rc +8 -0
index ff3f0a3..7155233 100644
@@ -422,6 +422,14 @@ _test_dev_is_partition() {
 	[[ -n ${TEST_DEV_PART_SYSFS} ]]
 }
 
+_test_dev_has_metadata() {
+	if (( ! $(<"${TEST_DEV_SYSFS}/metadata_bytes") )); then
+		SKIP_REASONS+=("$TEST_DEV does not have metadata")
+		return 1
+	fi
+	return 0
+}
+
 _min_io() {
 	local path_or_dev=$1
 	local min_io
src/nvme-passthrough-meta.c +4 -2
index d19ee25..29980a2 100644
@@ -139,8 +139,10 @@ int main(int argc, char **argv)
 	meta_size = lbaf.ms;
 
 	/* format not appropriate for this test */
-	if (meta_size == 0)
-		return 0;
+	if (meta_size == 0) {
+		fprintf(stderr, "Device format does not have metadata\n");
+		return -EINVAL;
+	}
 
 	blocks = BUFFER_SIZE / block_size;
 	meta_buffer_size = blocks * meta_size;
tests/nvme/064 +12 -2
index fd72d4a..eb9ca50 100755
@@ -2,7 +2,12 @@
 # SPDX-License-Identifier: GPL-3.0+
 # Copyright (C) 2025 Keith Busch <[email protected]>
 #
-# Test out metadata through the passthrough interfaces
+# Test out metadata through the passthrough interfaces. This test confirms the
+# fix by the kernel commit 43a67dd812c5 ("block: flip iter directions in
+# blk_rq_integrity_map_user()"). This test requires TEST_DEV as a namespace
+# formatted with metadata, and extended LBA disabled. Such namespace can be
+# prepared with QEMU NVME emulation specifying -device option with
+# "pi=1,pil=1,ms=8" values.
 
 . tests/nvme/rc
 
@@ -10,13 +15,18 @@ requires() {
 	_nvme_requires
 }
 
+device_requires() {
+	_test_dev_has_metadata
+	_require_test_dev_extended_lba_off
+}
+
 DESCRIPTION="exercise the nvme metadata usage with passthrough commands"
 QUICK=1
 
 test_device() {
 	echo "Running ${TEST_NAME}"
 
-	if src/nvme-passthrough-meta "${TEST_DEV}"; then
+	if ! src/nvme-passthrough-meta "${TEST_DEV}"; then
 		echo "src/nvme-passthrough-meta failed"
 	fi
 
tests/nvme/rc +15 -0
index 9dbd1ce..f69ceb9 100644
@@ -153,6 +153,21 @@ _require_test_dev_is_not_nvme_multipath() {
 	return 0
 }
 
+_require_test_dev_extended_lba_off() {
+	local flbas
+
+	if ! flbas=$(nvme id-ns "$TEST_DEV" | grep flbas | \
+			     sed --quiet 's/.*: \(.*\)/\1/p'); then
+		SKIP_REASONS+=("$TEST_DEV does not have namespace flbas field")
+		return 1
+	fi
+	if (( ${flbas} & 0x10 )); then
+		SKIP_REASONS+=("$TEST_DEV has NVME_NS_FLBAS_META_EXT on")
+		return 1
+	fi
+	return 0
+}
+
 _require_nvme_test_img_size() {
 	local require_sz_mb
 	local nvme_img_size_mb
maintainer
#2 lore raw
Quoted 5 lines · Shinichiro Kawasaki

Thanks for this v2. With the fix above, I was able to confirme that the test case passes with v6.16-rc1 kernel. When I reverted the kernel commit below, it failed. It looks working good as the fix confirmation.

43a67dd812c5 ("block: flip iter directions in blk_rq_integrity_map_user()")

We should probably put a "Link:" tag in the commit message for this:

https://lore.kernel.org/linux-block/[email protected]/

Quoted 4 lines

To run the test case, I tried QEMU nvme emulation devices with some different options. I found that the namespace should have format with metadata, and extended LBA should be disabled. IOW, QEMU -drive option should have value "pi=1,pil=1,ms=8" for the namespace.

That's fine, though you don't need to set protection information capabilities for this. The test will still run if you enable it, but it's probably better if you just let it be opaque metadata. You can also test with ms=16 or ms=64 as both are supported by qemu's nvme device.

Quoted 6 lines

I suggest to describe the device requirements in the test case comment. Also, I suggest to check the requirements for the test case, and skip if the requirements are not fulfilled. FYI, I prototyped such change as the patch below. Please let me know what your think. If you are okay with it, I will repost your patch together with my patch for common/rc and tests/nvme/rc as the v3 series.

Your changes look good. Thank you for the suggestions!

#3 lore raw
Quoted 16 lines · Keith Busch
Quoted 5 lines · Shinichiro Kawasaki

Thanks for this v2. With the fix above, I was able to confirme that the test case passes with v6.16-rc1 kernel. When I reverted the kernel commit below, it failed. It looks working good as the fix confirmation.

43a67dd812c5 ("block: flip iter directions in blk_rq_integrity_map_user()")

We should probably put a "Link:" tag in the commit message for this:

https://lore.kernel.org/linux-block/[email protected]/

Quoted 4 lines

To run the test case, I tried QEMU nvme emulation devices with some different options. I found that the namespace should have format with metadata, and extended LBA should be disabled. IOW, QEMU -drive option should have value "pi=1,pil=1,ms=8" for the namespace.

Quoted 4 lines

That's fine, though you don't need to set protection information capabilities for this. The test will still run if you enable it, but it's probably better if you just let it be opaque metadata. You can also test with ms=16 or ms=64 as both are supported by qemu's nvme device.

Ah, I see. I confirmed that the QEMU -drive option values "pi=1,pil=1" are not required. Also, I confirmed that "ms=16" and "ms=64" work. Will reflect it to the patch series to post.

Quoted 9 lines
Quoted 7 lines

I suggest to describe the device requirements in the test case comment. Also, I suggest to check the requirements for the test case, and skip if the requirements are not fulfilled. FYI, I prototyped such change as the patch below. Please let me know what your think. If you are okay with it, I will repost your patch together with my patch for common/rc and tests/nvme/rc as the v3 series.

Your changes look good. Thank you for the suggestions!

Sounds, good. Will post the series within a few days.