Skip to contentSkip to conversation

block/044, scsi/012: Add tests for support for segments smaller than the page size

PATCH In review Bart Van Assche 2 participants 4 messages Mar 23 – Mar 26 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block/044, scsi/012: Add tests for support for segments smaller than the page size

Linux kernel commit 889c57066cee ("block: make segment size limit workable for > 4K PAGE_SIZE") was merged about one year ago and adds support for DMA segments that are smaller than the virtual memory page size. This is important for devices that do not support DMA segments larger. This patch tests the code paths added by that Linux kernel commit.

---

Please note that this patch depends on two block layer and one SCSI patches that have not yet been merged.

 tests/block/044     | 58 +++++++++++++++++++++++++++++++++++++++++++++
 tests/block/044.out |  2 ++
 tests/scsi/012      | 56 +++++++++++++++++++++++++++++++++++++++++++
 tests/scsi/012.out  |  4 ++++
 4 files changed, 120 insertions(+)
 create mode 100755 tests/block/044
 create mode 100644 tests/block/044.out
 create mode 100755 tests/scsi/012
 create mode 100644 tests/scsi/012.out
tests/block/044 new file +58 -0
new file mode 100755
index 000000000000..e2ca2d9aea3a
@@ -0,0 +1,58 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright 2026 Google LLC
+#
+# Test support for DMA segment sizes less than 4096 bytes. See also commit
+# 889c57066cee ("block: make segment size limit workable for > 4K PAGE_SIZE").
+
+. tests/block/rc
+. common/null_blk
+
+DESCRIPTION="do IO on null-blk with 512 byte segments"
+TIMED=1
+
+requires() {
+	_have_fio
+	_have_kver 6 14
+	_have_null_blk
+}
+
+test() {
+	local bs=4096
+
+	echo "Running ${TEST_NAME}"
+
+	if ! _init_null_blk nr_devices=0; then
+		echo "Loading null_blk failed"
+		return 1
+	fi
+	if ! grep -qw max_segment_size /sys/kernel/config/nullb/features; then
+		SKIP_REASONS+=("max_segment_size parameter is not supported")
+		return 1
+	fi
+	local nullb_params=(
+		blocksize="$bs"      # bytes
+		completion_nsec=0
+		max_segment_size=512 # bytes
+		memory_backed=1
+		size=1               # MiB
+		submit_queues=1
+		power=1
+	)
+	if ! _configure_null_blk nullb0 "${nullb_params[@]}"; then
+		echo "Configuring null_blk failed"
+		return 1
+	fi
+	fio --verify=md5 --rw=randwrite --bs=$bs --ioengine=psync --thread \
+		--group_reporting --sync=1 --direct=1 \
+		--name=block-044 --filename=/dev/nullb0 \
+		--output="${RESULTS_DIR}/block/fio-output-block-044.txt" \
+		>>"$FULL"
+	local fio_status=$?
+	rmdir /sys/kernel/config/nullb/nullb0
+	_exit_null_blk
+	case $fio_status in
+		0) echo "Passed";;
+		*) echo "Failed (fio status = $fio_status)";;
+	esac
+}
tests/block/044.out new file +2 -0
new file mode 100644
index 000000000000..4718ff7bd595
@@ -0,0 +1,2 @@
+Running block/044
+Passed
tests/scsi/012 new file +56 -0

56 lines not on this page · raw message

tests/scsi/012.out new file +4 -0
new file mode 100644
index 000000000000..9c85da01e04e
@@ -0,0 +1,4 @@
+Running scsi/012
+psync
+sg
+Passed
#1 lore raw
Quoted 8 lines · Bart Van Assche

Linux kernel commit 889c57066cee ("block: make segment size limit workable for > 4K PAGE_SIZE") was merged about one year ago and adds support for DMA segments that are smaller than the virtual memory page size. This is important for devices that do not support DMA segments larger. This patch tests the code paths added by that Linux kernel commit.

Hi Bart, thanks for the patch. Please find my comments in line.

I think it's fine to keep the two new testcases in this single patch, but if the kernel side patches go into upstream in different timings, it would be the better to separate this patch into two patches for each testcase.

[...]

tests/block/044 line 2

Quoted 8 lines
tests/block/044 new file +2 -0
new file mode 100755
index 000000000000..e2ca2d9aea3a
@@ -0,0 +1,58 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0

Nit: many of blktests files have license GPL-3.0+ or GPL-2.0+. If you do not have specific reason, I suggest GPL-3.0+.

tests/block/044 line 12

Quoted 10 lines
tests/block/044 new file +10 -0
+# Copyright 2026 Google LLC
+#
+# Test support for DMA segment sizes less than 4096 bytes. See also commit
+# 889c57066cee ("block: make segment size limit workable for > 4K PAGE_SIZE").
+
+. tests/block/rc
+. common/null_blk
+
+DESCRIPTION="do IO on null-blk with 512 byte segments"
+TIMED=1

This new test case doesn't look referring to TIMEOUT. I suggest to drop "TIMED=1". When I ran this test case, it completed within a second, so I think QUICK=1 can be specified here.

tests/block/044 line 16

Quoted 4 lines
tests/block/044 new file +4 -0
+
+requires() {
+	_have_fio
+	_have_kver 6 14

Do we really need this kernel version check here? The test case checks that the null_blk implements "max_segment_size" feature. Assuming this feature is introeuced kernel versions 7.1+, I think we can drop the check above.

tests/block/044 line 29

Quoted 13 lines
tests/block/044 new file +13 -0
+	_have_null_blk
+}
+
+test() {
+	local bs=4096
+
+	echo "Running ${TEST_NAME}"
+
+	if ! _init_null_blk nr_devices=0; then
+		echo "Loading null_blk failed"
+		return 1
+	fi
+	if ! grep -qw max_segment_size /sys/kernel/config/nullb/features; then

The five lines above can be replaced with below one line:

if ! _have_null_blk_feature max_segment_size; then

tests/block/044 line 42

Quoted 13 lines
tests/block/044 new file +13 -0
+		SKIP_REASONS+=("max_segment_size parameter is not supported")
+		return 1
+	fi
+	local nullb_params=(
+		blocksize="$bs"      # bytes
+		completion_nsec=0
+		max_segment_size=512 # bytes
+		memory_backed=1
+		size=1               # MiB
+		submit_queues=1
+		power=1
+	)
+	if ! _configure_null_blk nullb0 "${nullb_params[@]}"; then

When null_blk driver is built-in, null_blk device name nullb0 is not available. I suggest to use nullb1 instead of nullb0.

tests/block/044 line 48

Quoted 6 lines
tests/block/044 new file +6 -0
+		echo "Configuring null_blk failed"
+		return 1
+	fi
+	fio --verify=md5 --rw=randwrite --bs=$bs --ioengine=psync --thread \
+		--group_reporting --sync=1 --direct=1 \
+		--name=block-044 --filename=/dev/nullb0 \

Same here: s/nullb0/nullb1/

tests/block/044 line 52

Quoted 4 lines
tests/block/044 new file +4 -0
+		--output="${RESULTS_DIR}/block/fio-output-block-044.txt" \
+		>>"$FULL"
+	local fio_status=$?
+	rmdir /sys/kernel/config/nullb/nullb0

The line aobve is not required since the directory is removed by the line below.

Quoted 20 lines
tests/block/044 new file +6 -0
+	_exit_null_blk
+	case $fio_status in
+		0) echo "Passed";;
+		*) echo "Failed (fio status = $fio_status)";;
+	esac
+}
tests/block/044.out new file +2 -0
new file mode 100644
index 000000000000..4718ff7bd595
@@ -0,0 +1,2 @@
+Running block/044
+Passed
tests/scsi/012 new file +0 -0
new file mode 100755
index 000000000000..a2043f95deaa

tests/scsi/012 line 2

Quoted 2 lines
tests/scsi/012 new file +2 -0
@@ -0,0 +1,56 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0

Nit: in the same manner as the null_blk test case, I suggest GPL-3.0+.

tests/scsi/012 line 12

Quoted 10 lines
tests/scsi/012 new file +10 -0
+# Copyright 2026 Google LLC
+#
+# Test support for DMA segment sizes less than 4096 bytes. See also commit
+# 889c57066cee ("block: make segment size limit workable for > 4K PAGE_SIZE").
+
+. tests/block/rc
+. common/scsi_debug
+
+DESCRIPTION="do IO on scsi_debug with 512 byte segments"
+TIMED=1

s/TIMED/QUICK/

tests/scsi/012 line 16

Quoted 4 lines
tests/scsi/012 new file +4 -0
+
+requires() {
+	_have_fio
+	_have_kver 6 14

With the same reason as the null_blk test case, I suspect this kernel version check is not required.

tests/scsi/012 line 17

Quoted 1 line
tests/scsi/012 new file +1 -0
+	_have_scsi_debug

The line above checks that scsi_debug driver exists, regardless whether it is built-in or lodable. When scsi_debug is built-in, the parameter sector_size can not be modified, and this case won't work. I suggest to replace the line above with "_have_module scsi_debug" to confirm that loadable scsi_debug is available.

When the patch series "Skip tests if scsi_debug module is already loaded and in use" [1] gets applied, the check above should be replaced with "_have_loadable_scsi_debug". I can amend this change if it is required.

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

Also, I suggest to add one more check in requires().

_have_module_param scsi_debug max_segment_size

to simplify the parameter check in test().

tests/scsi/012 line 28

Quoted 11 lines
tests/scsi/012 new file +11 -0
+}
+
+test() {
+	local bs=4096
+
+	echo "Running ${TEST_NAME}"
+	local scsi_debug_params=(
+		add_host=1
+		clustering=1
+		delay=0
+		sector_size="$bs"      # bytes

I suggest to add the paremeter below,

max_segment_size=512 # bytes

because the added _have_module_param check in requires() will ensure that the parameter is available.

tests/scsi/012 line 33

Quoted 5 lines
tests/scsi/012 new file +5 -0
+	)
+	if _have_module_param scsi_debug max_segment_size; then
+		scsi_debug_params+=(max_segment_size=512) # bytes
+		echo "Segment size = 512" >>"$FULL"
+	fi

With the _have_module_param check in requires(), four lines above will not be required.

#2 lore raw
Quoted 7 lines · Shin'ichiro Kawasaki
Quoted 6 lines · Bart Van Assche

Linux kernel commit 889c57066cee ("block: make segment size limit workable for > 4K PAGE_SIZE") was merged about one year ago and adds support for DMA segments that are smaller than the virtual memory page size. This is important for devices that do not support DMA segments larger. This patch tests the code paths added by that Linux kernel commit.

Quoted 8 lines
Quoted 2 lines

Hi Bart, thanks for the patch. Please find my comments in line.

I think it's fine to keep the two new testcases in this single patch, but if the kernel side patches go into upstream in different timings, it would be the better to separate this patch into two patches for each testcase.

Today, I reran the new testcases and noticed they leave fio verify state files in the current directory. It would be the better to add --verify_state_save=0 option, or use _run_fio_verify_io() helper function in common/fio.

#3 lore raw
Quoted 3 lines · Shinichiro Kawasaki

Today, I reran the new testcases and noticed they leave fio verify state files in the current directory. It would be the better to add --verify_state_save=0 option, or use _run_fio_verify_io() helper function in common/fio.

Hi Shinichiro,

The detailed feedback is appreciated. I plan to address this feedback after the kernel patches these tests rely on have been merged.

Thanks,

Bart.