* [PATCH blktests v3 0/2] Add an NBD performance test
@ 2026-11-29 23:52 Bart Van Assche
2026-11-29 23:52 ` [PATCH blktests v3 1/2] nbd/rc: Declare the loop variables of the wait helpers local Bart Van Assche
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Bart Van Assche @ 2026-11-29 23:52 UTC (permalink / raw)
To: Shin'ichiro Kawasaki; +Cc: linux-block, Bart Van Assche
Hi Shin'ichiro,
This patch series adds an NBD performance test. Please consider it for
inclusion in blktests.
Thanks,
Bart.
Changes compared to v2:
- Detect Unix domain socket support also if "nbd-client --help" only
mentions the -u option.
- Removed the _init_null_blk call since _configure_null_blk loads the
null_blk driver if necessary.
- Enable io_uring while fio runs since some test environments disable
io_uring by default.
- Use long grep options instead of short options.
- See also
https://lore.kernel.org/linux-block/20261120213434.2945873-1-bvanassche@acm.org/
Changes compared to v1:
- Added queue depth one tests.
- Added a bug fix for tests/nbd/rc.
Bart Van Assche (2):
nbd/rc: Declare the loop variables of the wait helpers local
nbd/006: Measure NBD IOPS with a null_blk backing device
tests/nbd/006 | 199 ++++++++++++++++++++++++++++++++++++++++++++++
tests/nbd/006.out | 2 +
tests/nbd/rc | 4 +
3 files changed, 205 insertions(+)
create mode 100755 tests/nbd/006
create mode 100644 tests/nbd/006.out
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH blktests v3 1/2] nbd/rc: Declare the loop variables of the wait helpers local
2026-11-29 23:52 [PATCH blktests v3 0/2] Add an NBD performance test Bart Van Assche
@ 2026-11-29 23:52 ` Bart Van Assche
2026-11-29 23:52 ` [PATCH blktests v3 2/2] nbd/006: Measure NBD IOPS with a null_blk backing device Bart Van Assche
2026-12-03 0:23 ` [PATCH blktests v3 0/2] Add an NBD performance test Shin'ichiro Kawasaki
2 siblings, 0 replies; 5+ messages in thread
From: Bart Van Assche @ 2026-11-29 23:52 UTC (permalink / raw)
To: Shin'ichiro Kawasaki; +Cc: linux-block, Bart Van Assche
_wait_for_nbd_connect() and _wait_for_nbd_disconnect() use the variable
"i" without declaring it local. Since bash uses dynamic scoping, these
functions modify the variable "i" of their caller, or the global variable
"i" if the caller did not declare one. Declare "i" and "sz" local to
prevent this.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
tests/nbd/rc | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tests/nbd/rc b/tests/nbd/rc
index 6205c4938b7c..9a68c2c9abd4 100644
--- a/tests/nbd/rc
+++ b/tests/nbd/rc
@@ -42,6 +42,8 @@ _have_nbd_netlink() {
}
_wait_for_nbd_connect() {
+ local i sz
+
for ((i = 0; i < 3; i++)); do
sz=$(lsblk --raw --noheadings -o SIZE /dev/nbd0)
if [ "$sz" != "0B" ]; then
@@ -53,6 +55,8 @@ _wait_for_nbd_connect() {
}
_wait_for_nbd_disconnect() {
+ local i
+
for ((i = 0; i < 3; i++)); do
if [[ ! -e /sys/kernel/debug/nbd/nbd0/tasks ]]; then
return 0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH blktests v3 2/2] nbd/006: Measure NBD IOPS with a null_blk backing device
2026-11-29 23:52 [PATCH blktests v3 0/2] Add an NBD performance test Bart Van Assche
2026-11-29 23:52 ` [PATCH blktests v3 1/2] nbd/rc: Declare the loop variables of the wait helpers local Bart Van Assche
@ 2026-11-29 23:52 ` Bart Van Assche
2026-12-03 0:23 ` [PATCH blktests v3 0/2] Add an NBD performance test Shin'ichiro Kawasaki
2 siblings, 0 replies; 5+ messages in thread
From: Bart Van Assche @ 2026-11-29 23:52 UTC (permalink / raw)
To: Shin'ichiro Kawasaki; +Cc: linux-block, Bart Van Assche
Add a test that measures the random read and random write IOPS that the
NBD driver can achieve, both for a single outstanding request and for
the maximum achievable parallelism. Such a test is useful to detect
latency and throughput regressions in the NBD driver and to evaluate NBD
performance optimizations.
Minimize the overhead outside the NBD driver as follows:
- Back the NBD export with a 1 GiB null_blk device that is tuned for
maximum IOPS: no memory backing, immediate completion, a 4 KiB logical
block size, one hardware queue per CPU and a hardware queue depth of
1024. Keep the device small because nbd-server opens the exported
device without O_DIRECT and hence all NBD I/O passes through the page
cache of the null_blk device.
- Select the "none" I/O scheduler for the null_blk device and disable
readahead such that each 4 KiB NBD read results in a single 4 KiB read
of the null_blk device.
- Connect nbd-client and nbd-server over a Unix domain socket if
nbd-client supports the -unix (-u) option and nbd-server supports the
"unixsock" configuration option. Fall back to a TCP connection over
the loopback interface otherwise or if the Unix domain socket does not
appear.
- Use one NBD connection per CPU, with a maximum of 16 connections.
- Measure the IOPS with fio using the io_uring I/O engine, the "none" I/O
scheduler for the NBD device, direct I/O and 4 KiB requests. Enable
io_uring while fio runs since some test environments disable it.
Run fio four times, each run taking a quarter of the test time:
- Random reads and random writes with a single job and a queue depth of
one. These results reflect the NBD round-trip latency.
- Random reads and random writes with one job per NBD connection and a
queue depth of 64. These results reflect the maximum NBD throughput.
Report the results via the "read iops" and "write iops" performance
fields, prefixed with "numjobs=<n> iodepth=<d> " to tell the two
configurations apart.
Note: since nbd-server performs buffered writes, the write IOPS mainly
reflect how fast nbd-server can dirty pages in the page cache.
Fail the test if configuring the null_blk request queue fails or if
nbd-server does not start listening on the TCP port in time. Fall back
to TCP instead of failing if the Unix domain socket does not appear in
time.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
tests/nbd/006 | 199 ++++++++++++++++++++++++++++++++++++++++++++++
tests/nbd/006.out | 2 +
2 files changed, 201 insertions(+)
create mode 100755 tests/nbd/006
create mode 100644 tests/nbd/006.out
diff --git a/tests/nbd/006 b/tests/nbd/006
new file mode 100755
index 000000000000..03fd4befeb3c
--- /dev/null
+++ b/tests/nbd/006
@@ -0,0 +1,199 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2026 Google LLC
+#
+# Measure the random read and random write IOPS of an NBD device that is backed
+# by a null_blk device. Use a Unix domain socket for the NBD connections if
+# supported by nbd-client and nbd-server and TCP otherwise.
+
+. tests/nbd/rc
+. common/null_blk
+
+DESCRIPTION="measure NBD read and write IOPS with null_blk as backing device"
+TIMED=1
+
+requires() {
+ _have_nbd
+ _have_null_blk
+ _have_fio
+}
+
+# Whether both nbd-client and nbd-server support Unix domain sockets:
+# nbd-client must support the -unix or -u option and nbd-server must recognize
+# the "unixsock" configuration option. Some nbd-client versions only mention -u
+# in their help text. Since nbd-server does not report which configuration
+# options it supports, look for the option name in the nbd-server executable.
+_nbd_have_unix_socket() {
+ local server
+
+ nbd-client --help 2>&1 |
+ grep --quiet --extended-regexp -- \
+ '(^|[^[:alnum:]-])-u(nix)?([^[:alnum:]-]|$)' || return 1
+ server=$(type -P nbd-server) || return 1
+ grep --text --word-regexp --quiet unixsock "$server"
+}
+
+# Undo those setup steps of test() that have been completed. Uses the local
+# variables of test() via dynamic scoping.
+cleanup() {
+ local -i j
+ local pid
+
+ if ((nbd_connected)); then
+ nbd-client -d "$nbd_dev" >> "$FULL" 2>&1
+ _wait_for_nbd_disconnect
+ fi
+ if [[ -s "$pid_file" ]]; then
+ pid=$(<"$pid_file")
+ kill -SIGTERM "$pid"
+ # Wait until nbd-server has exited such that it no longer keeps
+ # the null_blk device open.
+ for ((j = 0; j < 100; j++)); do
+ kill -0 "$pid" 2>/dev/null || break
+ sleep .1
+ done
+ fi
+ rm -f "$pid_file" "$sock"
+ udevadm settle
+ _exit_null_blk
+}
+
+test() {
+ local nullb=nullb1 nullb_dev=/dev/nullb1 nbd_dev=/dev/nbd0
+ local sock="${TMPDIR}/nbd.sock" pid_file="${TMPDIR}/nbd.pid"
+ local conf="${TMPDIR}/nbd.conf"
+ local -i nr_cpus nr_conns i use_unix=0
+ local -a connect_args
+ # Setup progress, used by cleanup().
+ local -i nbd_connected=0
+
+ echo "Running ${TEST_NAME}"
+
+ nr_cpus=$(nproc)
+ nr_conns=$((nr_cpus < 16 ? nr_cpus : 16))
+
+ # Create a null_blk device via configfs that is tuned for maximum IOPS:
+ # no memory backing, immediate completion and one hardware queue per
+ # CPU. _configure_null_blk loads the null_blk driver if necessary.
+ local nullb_params=(
+ blocksize=4096
+ completion_nsec=0
+ hw_queue_depth=1024
+ irqmode=0
+ memory_backed=0
+ queue_mode=2
+ size=1024 # MiB
+ submit_queues="$nr_cpus"
+ power=1
+ )
+ if ! _configure_null_blk "$nullb" "${nullb_params[@]}"; then
+ echo "Configuring null_blk failed"
+ cleanup
+ return 1
+ fi
+ # nbd-server opens the exported device without O_DIRECT. Disable
+ # readahead such that each NBD read causes a single 4 KiB read of the
+ # null_blk device.
+ if ! _write_queue_sched none "/sys/block/${nullb}/queue/scheduler" ||
+ ! grep --quiet '\[none\]' "/sys/block/${nullb}/queue/scheduler" ||
+ ! echo 0 > "/sys/block/${nullb}/queue/read_ahead_kb"; then
+ echo "Configuring the ${nullb} request queue failed"
+ cleanup
+ return 1
+ fi
+
+ _nbd_have_unix_socket && use_unix=1
+
+ {
+ echo "[generic]"
+ echo "allowlist=true"
+ if ((use_unix)); then
+ echo "unixsock=${sock}"
+ fi
+ echo "[export]"
+ echo "exportname=${nullb_dev}"
+ } > "$conf"
+ cat "$conf" >> "$FULL"
+
+ if ! nbd-server -p "$pid_file" -C "$conf" >> "$FULL" 2>&1; then
+ echo "Starting nbd-server failed"
+ cleanup
+ return 1
+ fi
+
+ # Wait until nbd-server listens on the Unix domain socket. Fall back to
+ # TCP if the Unix domain socket does not show up.
+ if ((use_unix)); then
+ for ((i = 0; i < 100; i++)); do
+ [[ -S "$sock" ]] && break
+ sleep .1
+ done
+ if ((i >= 100)); then
+ echo "${sock} did not appear; falling back to TCP" >> "$FULL"
+ use_unix=0
+ fi
+ fi
+ if ((use_unix)); then
+ echo "Using Unix domain socket ${sock}" >> "$FULL"
+ connect_args=(-unix "$sock")
+ else
+ echo "Using TCP socket" >> "$FULL"
+ connect_args=(localhost)
+ for ((i = 0; i < 100; i++)); do
+ nbd-client -l localhost >> "$FULL" 2>&1 && break
+ sleep .1
+ done
+ if ((i >= 100)); then
+ echo "Timeout while waiting for nbd-server"
+ cleanup
+ return 1
+ fi
+ fi
+
+ # Use -connections instead of -C because some nbd-client versions
+ # do not declare that -C takes an argument and pass a NULL pointer
+ # to strtol() if -C is used.
+ nbd_connected=1
+ if ! nbd-client -L -N export -connections "$nr_conns" -b 4096 \
+ "${connect_args[@]}" "$nbd_dev" >> "$FULL" 2>&1 ||
+ ! _wait_for_nbd_connect; then
+ echo "Connecting to nbd-server failed"
+ cleanup
+ return 1
+ fi
+ udevadm settle
+
+ # Measure the read and write IOPS twice: once with a single job and
+ # queue depth one and once with the parameters that maximize the IOPS.
+ # _run_fio passes --group_reporting=1 and --runtime="$TIMEOUT" to fio.
+ : "${TIMEOUT:=60}"
+ _divide_timeout 4
+
+ local fio_params=(
+ --bs=4k
+ --direct=1
+ --filename="$nbd_dev"
+ --ioengine=io_uring
+ --ioscheduler=none
+ --norandommap
+ --time_based=1
+ )
+ local rw numjobs iodepth numjobs_iodepth
+ # Some test environments disable io_uring by default.
+ _io_uring_enable
+ for numjobs_iodepth in "1 1" "${nr_conns} 64"; do
+ read -r numjobs iodepth <<< "$numjobs_iodepth"
+ FIO_PERF_PREFIX="numjobs=${numjobs} iodepth=${iodepth} "
+ for rw in read write; do
+ FIO_PERF_FIELDS=("${rw} iops")
+ _fio_perf --name="nbd-${rw}-iops" --rw="rand${rw}" \
+ --numjobs="$numjobs" --iodepth="$iodepth" \
+ "${fio_params[@]}"
+ done
+ done
+ _io_uring_restore
+
+ cleanup
+
+ echo "Test complete"
+}
diff --git a/tests/nbd/006.out b/tests/nbd/006.out
new file mode 100644
index 000000000000..acc8af5bfb2e
--- /dev/null
+++ b/tests/nbd/006.out
@@ -0,0 +1,2 @@
+Running nbd/006
+Test complete
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH blktests v3 0/2] Add an NBD performance test
2026-11-29 23:52 [PATCH blktests v3 0/2] Add an NBD performance test Bart Van Assche
2026-11-29 23:52 ` [PATCH blktests v3 1/2] nbd/rc: Declare the loop variables of the wait helpers local Bart Van Assche
2026-11-29 23:52 ` [PATCH blktests v3 2/2] nbd/006: Measure NBD IOPS with a null_blk backing device Bart Van Assche
@ 2026-12-03 0:23 ` Shin'ichiro Kawasaki
2026-12-03 0:31 ` Bart Van Assche
2 siblings, 1 reply; 5+ messages in thread
From: Shin'ichiro Kawasaki @ 2026-12-03 0:23 UTC (permalink / raw)
To: Bart Van Assche; +Cc: linux-block
On Nov 29, 2026 / 15:52, Bart Van Assche wrote:
> Hi Shin'ichiro,
>
> This patch series adds an NBD performance test. Please consider it for
> inclusion in blktests.
>
> Thanks,
>
> Bart.
>
> Changes compared to v2:
> - Detect Unix domain socket support also if "nbd-client --help" only
> mentions the -u option.
> - Removed the _init_null_blk call since _configure_null_blk loads the
> null_blk driver if necessary.
> - Enable io_uring while fio runs since some test environments disable
> io_uring by default.
> - Use long grep options instead of short options.
> - See also
> https://lore.kernel.org/linux-block/20261120213434.2945873-1-bvanassche@acm.org/
Thanks, I applied the series. Of note is that I renumbered the new test case
from nbd/006 to nbd/005.
BTW, I found that this test case causes a lockdep WARN below. In that sense,
this test case is good not only for performance testing, but also exercising
block layer. The WARN was observed with v7.4-rc5 and v7.3 kernels. I'm not sure
who to ask, but help to avoid the WARN will be appreciated.
[ 91.130638] [ T1076] run blktests nbd/005 at 2026-12-03 09:12:45.185630199
[ 91.257005] [ T1076] null_blk: disk nullb1 created
[ 91.751364] [ T1145] nbd0: detected capacity change from 0 to 2097152
[ 93.662037] [ T1160] ======================================================
[ 93.663326] [ T1160] WARNING: possible circular locking dependency detected
[ 93.664473] [ T1160] 7.4.0-rc5 #506 Not tainted
[ 93.665284] [ T1160] ------------------------------------------------------
[ 93.666446] [ T1160] fio/1160 is trying to acquire lock:
[ 93.667351] [ T1160] ffff88812f7762a8 (&q->elevator_lock){+.+.}-{4:4}, at: elevator_change+0x197/0x500
[ 93.668870] [ T1160]
but task is already holding lock:
[ 93.670060] [ T1160] ffff88812f775d80 (&q->q_usage_counter(io)#23){++++}-{0:0}, at: blk_mq_freeze_queue_nomemsave+0x12/0x20
[ 93.671863] [ T1160]
which lock already depends on the new lock.
[ 93.673544] [ T1160]
the existing dependency chain (in reverse order) is:
[ 93.675267] [ T1160]
-> #5 (&q->q_usage_counter(io)#23){++++}-{0:0}:
[ 93.676989] [ T1160] blk_alloc_queue+0x605/0x7a0
[ 93.678052] [ T1160] blk_mq_alloc_queue+0x168/0x270
[ 93.679154] [ T1160] __blk_mq_alloc_disk+0x14/0xd0
[ 93.680251] [ T1160] nbd_dev_add+0x3fa/0xa70 [nbd]
[ 93.681352] [ T1160] 0xffffffffc0dfe169
[ 93.682253] [ T1160] do_one_initcall+0x11a/0x540
[ 93.683291] [ T1160] do_init_module+0x2b3/0x8a0
[ 93.684319] [ T1160] load_module+0x5e05/0x73d0
[ 93.685346] [ T1160] init_module_from_file+0x11f/0x1a0
[ 93.686502] [ T1160] idempotent_init_module+0x37f/0x7c0
[ 93.687531] [ T1160] __x64_sys_finit_module+0xdb/0x190
[ 93.688497] [ T1160] do_syscall_64+0xf4/0x6b0
[ 93.689339] [ T1160] entry_SYSCALL_64_after_hwframe+0x76/0x7e
[ 93.690418] [ T1160]
-> #4 (fs_reclaim){+.+.}-{0:0}:
[ 93.691611] [ T1160] fs_reclaim_acquire+0xd5/0x120
[ 93.692524] [ T1160] kmem_cache_alloc_noprof+0x70/0x6a0
[ 93.693459] [ T1160] alloc_empty_file+0x56/0x180
[ 93.694655] [ T1160] dentry_open+0x38/0x90
[ 93.695759] [ T1160] pidfs_alloc_file+0x102/0x1c0
[ 93.696959] [ T1160] pidfd_prepare+0xb9/0x160
[ 93.698067] [ T1160] scm_pidfd_recv+0x12c/0x260
[ 93.699102] [ T1160] scm_recv_unix+0x202/0x310
[ 93.700120] [ T1160] __unix_dgram_recvmsg+0x655/0xb80
[ 93.701232] [ T1160] sock_recvmsg+0x167/0x1c0
[ 93.702253] [ T1160] ____sys_recvmsg+0x192/0x570
[ 93.703282] [ T1160] ___sys_recvmsg+0x160/0x1f0
[ 93.704243] [ T1160] __sys_recvmsg+0x125/0x1d0
[ 93.705192] [ T1160] do_syscall_64+0xf4/0x6b0
[ 93.706109] [ T1160] entry_SYSCALL_64_after_hwframe+0x76/0x7e
[ 93.707209] [ T1160]
-> #3 (&u->iolock){+.+.}-{4:4}:
[ 93.708686] [ T1160] __mutex_lock+0x1a9/0x2550
[ 93.709619] [ T1160] unix_stream_read_generic+0x34d/0x2b30
[ 93.710668] [ T1160] unix_stream_recvmsg+0x162/0x210
[ 93.711655] [ T1160] sock_recvmsg+0x167/0x1c0
[ 93.712573] [ T1160] __sock_xmit+0x3ea/0x5b0 [nbd]
[ 93.713546] [ T1160] nbd_handle_reply+0x6fd/0xe80 [nbd]
[ 93.714568] [ T1160] recv_work+0x214/0x770 [nbd]
[ 93.715511] [ T1160] process_one_work+0x96a/0x1790
[ 93.716466] [ T1160] worker_thread+0x5fd/0xfe0
[ 93.717378] [ T1160] kthread+0x36d/0x470
[ 93.718217] [ T1160] ret_from_fork+0x653/0x9d0
[ 93.719114] [ T1160] ret_from_fork_asm+0x1a/0x30
[ 93.720030] [ T1160]
-> #2 (&cmd->lock){+.+.}-{4:4}:
[ 93.721415] [ T1160] __mutex_lock+0x1a9/0x2550
[ 93.722307] [ T1160] nbd_queue_rq+0xc7/0xe00 [nbd]
[ 93.723241] [ T1160] blk_mq_dispatch_rq_list+0x3e0/0x2400
[ 93.724243] [ T1160] __blk_mq_sched_dispatch_requests+0xb0e/0x15d0
[ 93.725338] [ T1160] blk_mq_sched_dispatch_requests+0xab/0x150
[ 93.726395] [ T1160] blk_mq_run_work_fn+0x130/0x2e0
[ 93.727370] [ T1160] process_one_work+0x96a/0x1790
[ 93.728314] [ T1160] worker_thread+0x5fd/0xfe0
[ 93.729203] [ T1160] kthread+0x36d/0x470
[ 93.730016] [ T1160] ret_from_fork+0x653/0x9d0
[ 93.730887] [ T1160] ret_from_fork_asm+0x1a/0x30
[ 93.731774] [ T1160]
-> #1 (set->srcu){.+.+}-{0:0}:
[ 93.733138] [ T1160] __synchronize_srcu+0xe1/0x340
[ 93.734051] [ T1160] elevator_switch+0x13b/0x670
[ 93.734942] [ T1160] elevator_change+0x2e7/0x500
[ 93.735829] [ T1160] elevator_set_default+0x293/0x350
[ 93.736761] [ T1160] blk_register_queue+0x436/0x5e0
[ 93.737696] [ T1160] __add_disk+0x6a3/0xe30
[ 93.738555] [ T1160] add_disk_fwnode+0x11e/0x480
[ 93.739461] [ T1160] nbd_dev_add+0x6a5/0xa70 [nbd]
[ 93.740391] [ T1160] 0xffffffffc0dfe169
[ 93.741207] [ T1160] do_one_initcall+0x11a/0x540
[ 93.742125] [ T1160] do_init_module+0x2b3/0x8a0
[ 93.743046] [ T1160] load_module+0x5e05/0x73d0
[ 93.743925] [ T1160] init_module_from_file+0x11f/0x1a0
[ 93.744877] [ T1160] idempotent_init_module+0x37f/0x7c0
[ 93.745833] [ T1160] __x64_sys_finit_module+0xdb/0x190
[ 93.746777] [ T1160] do_syscall_64+0xf4/0x6b0
[ 93.747651] [ T1160] entry_SYSCALL_64_after_hwframe+0x76/0x7e
[ 93.748689] [ T1160]
-> #0 (&q->elevator_lock){+.+.}-{4:4}:
[ 93.750168] [ T1160] __lock_acquire+0xe68/0x2490
[ 93.751072] [ T1160] lock_acquire+0x1b1/0x340
[ 93.751959] [ T1160] __mutex_lock+0x1a9/0x2550
[ 93.752956] [ T1160] elevator_change+0x197/0x500
[ 93.753860] [ T1160] elv_iosched_store+0x364/0x410
[ 93.754775] [ T1160] queue_attr_store+0x25f/0x3e0
[ 93.755707] [ T1160] kernfs_fop_write_iter+0x3d6/0x5e0
[ 93.756710] [ T1160] vfs_write+0x4b3/0xf30
[ 93.757584] [ T1160] ksys_write+0x112/0x250
[ 93.758457] [ T1160] do_syscall_64+0xf4/0x6b0
[ 93.759338] [ T1160] entry_SYSCALL_64_after_hwframe+0x76/0x7e
[ 93.760371] [ T1160]
other info that might help us debug this:
[ 93.762329] [ T1160] Chain exists of:
&q->elevator_lock --> fs_reclaim --> &q->q_usage_counter(io)#23
[ 93.764766] [ T1160] Possible unsafe locking scenario:
[ 93.766282] [ T1160] CPU0 CPU1
[ 93.767221] [ T1160] ---- ----
[ 93.768156] [ T1160] lock(&q->q_usage_counter(io)#23);
[ 93.769075] [ T1160] lock(fs_reclaim);
[ 93.770156] [ T1160] lock(&q->q_usage_counter(io)#23);
[ 93.771410] [ T1160] lock(&q->elevator_lock);
[ 93.772249] [ T1160]
*** DEADLOCK ***
[ 93.773979] [ T1160] locks held by fio/1160: 6, on CPU#1:
[ 93.774895] [ T1160] #0: ffff888103714478 (sb_writers#4){.+.+}-{0:0}, at: ksys_write+0x112/0x250
[ 93.776257] [ T1160] #1: ffff88813617dc80 (&of->mutex#2){+.+.}-{4:4}, at: kernfs_fop_write_iter+0x257/0x5e0
[ 93.777744] [ T1160] #2: ffff88811cc1d2d8 (kn->active#79){.+.+}-{0:0}, at: kernfs_fop_write_iter+0x2ad/0x5e0
[ 93.779244] [ T1160] #3: ffff8881263b49c0 (&set->update_nr_hwq_lock){++++}-{4:4}, at: elv_iosched_store+0x283/0x410
[ 93.780854] [ T1160] #4: ffff88812f775d80 (&q->q_usage_counter(io)#23){++++}-{0:0}, at: blk_mq_freeze_queue_nomemsave+0x12/0x20
[ 93.782558] [ T1160] #5: ffff88812f775db8 (&q->q_usage_counter(queue)#15){+.+.}-{0:0}, at: blk_mq_freeze_queue_nomemsave+0x12/0x20
[ 93.784319] [ T1160]
stack backtrace:
[ 93.785619] [ T1160] CPU: 1 UID: 0 PID: 1160 Comm: fio Not tainted 7.4.0-rc5 #506 PREEMPT(full)
[ 93.786694] [ T1160] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.17.0-10.fc44 06/10/2025
[ 93.787908] [ T1160] Call Trace:
[ 93.788314] [ T1160] <TASK>
[ 93.788673] [ T1160] dump_stack_lvl+0x6a/0x90
[ 93.789253] [ T1160] print_circular_bug.cold+0x189/0x1eb
[ 93.789942] [ T1160] check_noncircular+0x173/0x1a0
[ 93.790543] [ T1160] __lock_acquire+0xe68/0x2490
[ 93.791140] [ T1160] lock_acquire+0x1b1/0x340
[ 93.791690] [ T1160] ? elevator_change+0x197/0x500
[ 93.792348] [ T1160] ? __pfx___might_resched+0x10/0x10
[ 93.793013] [ T1160] ? __pfx___flush_work+0x10/0x10
[ 93.793626] [ T1160] __mutex_lock+0x1a9/0x2550
[ 93.794213] [ T1160] ? elevator_change+0x197/0x500
[ 93.794813] [ T1160] ? elevator_change+0x197/0x500
[ 93.795440] [ T1160] ? __pfx___mutex_lock+0x10/0x10
[ 93.796072] [ T1160] ? enable_work+0x156/0x200
[ 93.796630] [ T1160] ? enable_work+0x156/0x200
[ 93.797205] [ T1160] ? __pfx_enable_work+0x10/0x10
[ 93.797806] [ T1160] ? __pfx___might_resched+0x10/0x10
[ 93.798479] [ T1160] ? cancel_delayed_work_sync+0x85/0xa0
[ 93.799167] [ T1160] ? blk_mq_cancel_work_sync+0x102/0x2c0
[ 93.799864] [ T1160] ? elevator_change+0x197/0x500
[ 93.800475] [ T1160] elevator_change+0x197/0x500
[ 93.801083] [ T1160] elv_iosched_store+0x364/0x410
[ 93.801684] [ T1160] ? __pfx_elv_iosched_store+0x10/0x10
[ 93.802358] [ T1160] ? lock_acquire+0x1b1/0x340
[ 93.802941] [ T1160] ? kernfs_fop_write_iter+0x257/0x5e0
[ 93.803600] [ T1160] ? __pfx___might_resched+0x10/0x10
[ 93.804265] [ T1160] ? __pfx_sysfs_kf_write+0x10/0x10
[ 93.804921] [ T1160] queue_attr_store+0x25f/0x3e0
[ 93.805512] [ T1160] ? __pfx_queue_attr_store+0x10/0x10
[ 93.806189] [ T1160] ? lock_acquire+0x1b1/0x340
[ 93.806757] [ T1160] ? lock_acquire+0x1c1/0x340
[ 93.807355] [ T1160] ? find_held_lock+0x2b/0x80
[ 93.807950] [ T1160] ? sysfs_file_kobj+0xaf/0x1b0
[ 93.808539] [ T1160] ? lock_release+0x1b5/0x340
[ 93.809133] [ T1160] ? sysfs_file_kobj+0xb9/0x1b0
[ 93.809740] [ T1160] ? sysfs_kf_write+0x61/0x160
[ 93.810344] [ T1160] ? __pfx_queue_attr_store+0x10/0x10
[ 93.811019] [ T1160] kernfs_fop_write_iter+0x3d6/0x5e0
[ 93.811658] [ T1160] ? __pfx_kernfs_fop_write_iter+0x10/0x10
[ 93.812387] [ T1160] vfs_write+0x4b3/0xf30
[ 93.812937] [ T1160] ? __pfx_vfs_write+0x10/0x10
[ 93.813516] [ T1160] ? lock_acquire+0x1b1/0x340
[ 93.814117] [ T1160] ? __pfx_folio_remove_rmap_ptes+0x10/0x10
[ 93.814963] [ T1160] ? lock_release+0x1b5/0x340
[ 93.815656] [ T1160] ? find_held_lock+0x2b/0x80
[ 93.816247] [ T1160] ksys_write+0x112/0x250
[ 93.816772] [ T1160] ? __pfx_ksys_write+0x10/0x10
[ 93.817390] [ T1160] ? do_wp_page+0xe4e/0x36d0
[ 93.817979] [ T1160] ? rcu_is_watching+0x12/0xb0
[ 93.818559] [ T1160] do_syscall_64+0xf4/0x6b0
[ 93.819120] [ T1160] ? __pfx_do_wp_page+0x10/0x10
[ 93.819709] [ T1160] ? lock_acquire+0x1b1/0x340
[ 93.820294] [ T1160] ? __pfx_do_raw_spin_lock+0x10/0x10
[ 93.820963] [ T1160] ? __pfx_pte_write+0x10/0x10
[ 93.821541] [ T1160] ? __handle_mm_fault+0x14b3/0x20c0
[ 93.822201] [ T1160] ? __lock_acquire+0x54a/0x2490
[ 93.822798] [ T1160] ? __pfx___css_rstat_updated+0x10/0x10
[ 93.823509] [ T1160] ? lock_acquire+0x1b1/0x340
[ 93.824101] [ T1160] ? rcu_is_watching+0x12/0xb0
[ 93.824681] [ T1160] ? count_memcg_events+0x10f/0x4c0
[ 93.825337] [ T1160] ? find_held_lock+0x2b/0x80
[ 93.825922] [ T1160] ? rcu_read_unlock+0x17/0x60
[ 93.826502] [ T1160] ? lock_release+0x1b5/0x340
[ 93.827092] [ T1160] ? find_held_lock+0x2b/0x80
[ 93.827662] [ T1160] ? exc_page_fault+0x94/0x140
[ 93.828265] [ T1160] ? lock_release+0x1b5/0x340
[ 93.828841] [ T1160] ? rcu_is_watching+0x12/0xb0
[ 93.829422] [ T1160] ? do_syscall_64+0x2d/0x6b0
[ 93.830023] [ T1160] ? trace_hardirqs_off_finish+0x139/0x180
[ 93.830747] [ T1160] ? lockdep_hardirqs_off+0xaf/0xf0
[ 93.831388] [ T1160] ? do_syscall_64+0x60/0x6b0
[ 93.831981] [ T1160] entry_SYSCALL_64_after_hwframe+0x76/0x7e
[ 93.832692] [ T1160] RIP: 0033:0x7fc8a2d75e32
[ 93.833244] [ T1160] Code: 08 0f 85 91 41 ff ff 49 89 fb 48 89 f0 48 89 d7 48 89 ce 4c 89 c2 4d 89 ca 4c 8b 44 24 08 4c 8b 4c 24 10 4c 89 5c 24 08 0f 05 <c3> 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 00 f3 0f 1e fa 55 bf 01 00
[ 93.835614] [ T1160] RSP: 002b:00007ffde4e5cdb8 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
[ 93.836648] [ T1160] RAX: ffffffffffffffda RBX: 0000000030c56430 RCX: 00007fc8a2d75e32
[ 93.837630] [ T1160] RDX: 0000000000000004 RSI: 0000000030cb1a90 RDI: 0000000000000007
[ 93.838602] [ T1160] RBP: 00007ffde4e5cde0 R08: 0000000000000000 R09: 0000000000000000
[ 93.839598] [ T1160] R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000004
[ 93.840574] [ T1160] R13: 0000000000000004 R14: 0000000030cb1a90 R15: 0000000000000000
[ 93.841557] [ T1160] </TASK>
[ 155.641594] [ T1388] block nbd0: NBD_DISCONNECT
[ 155.642118] [ T1388] block nbd0: Disconnected due to user request.
[ 155.644143] [ T1388] block nbd0: shutting down sockets
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH blktests v3 0/2] Add an NBD performance test
2026-12-03 0:23 ` [PATCH blktests v3 0/2] Add an NBD performance test Shin'ichiro Kawasaki
@ 2026-12-03 0:31 ` Bart Van Assche
0 siblings, 0 replies; 5+ messages in thread
From: Bart Van Assche @ 2026-12-03 0:31 UTC (permalink / raw)
To: Shin'ichiro Kawasaki; +Cc: linux-block
On 12/2/26 4:23 PM, Shin'ichiro Kawasaki wrote:
> BTW, I found that this test case causes a lockdep WARN below. In that sense,
> this test case is good not only for performance testing, but also exercising
> block layer. The WARN was observed with v7.4-rc5 and v7.3 kernels. I'm not sure
> who to ask, but help to avoid the WARN will be appreciated.
The LLM that I asked to take a look at the lockdep complaint proposed
the patch below. This patch has not yet been tested. I will do that as
soon as I have the time to do this.
Bart.
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -33,6 +33,7 @@
#include <linux/kernel.h>
#include <linux/slab.h>
#include <net/sock.h>
+#include <net/af_unix.h>
#include <linux/net.h>
#include <linux/kthread.h>
#include <linux/types.h>
@@ -1241,6 +1242,7 @@ static struct socket *nbd_get_socket(str
#ifdef CONFIG_DEBUG_LOCK_ALLOC
static struct lock_class_key nbd_key[3];
static struct lock_class_key nbd_slock_key[3];
+static struct lock_class_key nbd_unix_iolock_key;
static void nbd_reclassify_socket(struct socket *sock)
{
@@ -1267,6 +1269,14 @@ static void nbd_reclassify_socket(struct
&nbd_slock_key[2],
"sk_lock-AF_UNIX-NBD",
&nbd_key[2]);
+ /*
+ * The AF_UNIX receive paths serialize on unix_sock::iolock
+ * instead of sk_lock. Do not reclassify a held mutex.
+ */
+ if (!mutex_is_locked(&unix_sk(sk)->iolock))
+ lockdep_set_class_and_name(&unix_sk(sk)->iolock,
+ &nbd_unix_iolock_key,
+ "iolock-AF_UNIX-NBD");
break;
}
}
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-03 0:31 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 23:52 [PATCH blktests v3 0/2] Add an NBD performance test Bart Van Assche
2026-11-29 23:52 ` [PATCH blktests v3 1/2] nbd/rc: Declare the loop variables of the wait helpers local Bart Van Assche
2026-11-29 23:52 ` [PATCH blktests v3 2/2] nbd/006: Measure NBD IOPS with a null_blk backing device Bart Van Assche
2026-12-03 0:23 ` [PATCH blktests v3 0/2] Add an NBD performance test Shin'ichiro Kawasaki
2026-12-03 0:31 ` Bart Van Assche
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox