Skip to contentSkip to conversation

*** Test the NVMe reservation feature ***

PATCH Superseded Guixin Liu 3 participants 7 messages Jan 17, 2024 – Jan 31, 2024

Subsystems (2)

v2 of 19 Superseded Latest is v19 →

lore
Share & tools
lore

Guixin Liu

author
#0 lore raw

v2 cover *** Test the NVMe reservation feature ***

Changes from v1 to v2:
- Add a new patch to add a optinal argument --resv_enable.

- Make resv-report fit the new --eds argument.

- Filter the hosid output to make the new test case independent from hostid.

- Change the new test case name to "Test the NVMe reservation feature".

Guixin Liu (2):
nvme/{rc,002,016,017,030,031}: introduce --resv_enable argument test/nvme/050: test the reservation feature

 tests/nvme/002     |   3 +-
 tests/nvme/016     |   7 ++-
 tests/nvme/017     |  10 +++--
 tests/nvme/030     |   6 ++-
 tests/nvme/031     |   3 +-
 tests/nvme/050     |  96 ++++++++++++++++++++++++++++++++++++++++
 tests/nvme/050.out | 108 +++++++++++++++++++++++++++++++++++++++++++++
 tests/nvme/rc      | 100 ++++++++++++++++++++++++++++++++++-------
 8 files changed, 308 insertions(+), 25 deletions(-)
 create mode 100644 tests/nvme/050
 create mode 100644 tests/nvme/050.out
Signature · 1 line
2.30.1 (Apple Git-130)
author
#1 lore raw

PATCH v2 1/2 nvme/{rc,002,016,017,030,031}: introduce --resv_enable argument

Add an optional argument --resv_enable to _nvmet_target_setup() and propagate it to _create_nvmet_subsystem() and _create_nvmet_ns().

One can call functions with --resv_enable to enable reservation feature on a specific namespace.

---
 tests/nvme/002 |   3 +-
 tests/nvme/016 |   7 +++-
 tests/nvme/017 |  10 +++--
 tests/nvme/030 |   6 ++-
 tests/nvme/031 |   3 +-
 tests/nvme/rc  | 100 +++++++++++++++++++++++++++++++++++++++++--------
 6 files changed, 104 insertions(+), 25 deletions(-)
tests/nvme/002 +2 -1
index 6b84848..37c719b 100755
@@ -30,7 +30,8 @@ test() {
 	local genctr=1
 
 	for ((i = 0; i < iterations; i++)); do
-		_create_nvmet_subsystem "blktests-subsystem-$i" "${loop_dev}"
+		_create_nvmet_subsystem --subsysnqn "blktests-subsystem-$i" \
+					--blkdev "${loop_dev}"
 		_add_nvmet_subsys_to_port "${port}" "blktests-subsystem-$i"
 	done
 
tests/nvme/016 +5 -2
index 908abbd..ba700d1 100755
@@ -25,10 +25,13 @@ test() {
 	loop_dev="$(losetup -f)"
 	local genctr=1
 
-	_create_nvmet_subsystem "${def_subsysnqn}" "${loop_dev}"
+	_create_nvmet_subsystem --subsysnqn "${def_subsysnqn}" \
+				--blkdev "${loop_dev}"
 
 	for ((i = 2; i <= iterations; i++)); do
-		_create_nvmet_ns "${def_subsysnqn}" "${i}" "${loop_dev}"
+		_create_nvmet_ns --subsysnqn "${def_subsysnqn}" \
+				 --nsid "${i}" \
+				 --blkdev "${loop_dev}"
 	done
 
 	port="$(_create_nvmet_port "${nvme_trtype}")"
tests/nvme/017 +6 -4
index c8d9b32..d9fbd38 100755
@@ -25,12 +25,14 @@ test() {
 
 	local genctr=1
 
-	_create_nvmet_subsystem "${def_subsysnqn}" "$(_nvme_def_file_path)" \
-		"${def_subsys_uuid}"
+	_create_nvmet_subsystem --subsysnqn "${def_subsysnqn}" \
+				--blkdev "$(_nvme_def_file_path)" \
+				--uuid "${def_subsys_uuid}"
 
 	for ((i = 2; i <= iterations; i++)); do
-		_create_nvmet_ns "${def_subsysnqn}" "${i}" \
-				 "$(_nvme_def_file_path)"
+		_create_nvmet_ns --subsysnqn "${def_subsysnqn}" \
+				 --nsid "${i}" \
+				 --blkdev "$(_nvme_def_file_path)"
 	done
 
 	port="$(_create_nvmet_port "${nvme_trtype}")"
tests/nvme/030 +4 -2
index 9251e17..8802b16 100755
@@ -26,13 +26,15 @@ test() {
 
 	port="$(_create_nvmet_port "${nvme_trtype}")"
 
-	_create_nvmet_subsystem "${subsys}1" "$(losetup -f)"
+	_create_nvmet_subsystem --subsysnqn "${subsys}1" \
+				--blkdev "$(losetup -f)"
 	_add_nvmet_subsys_to_port "${port}" "${subsys}1"
 	_create_nvmet_host "${subsys}1" "${def_hostnqn}"
 
 	genctr=$(_discovery_genctr)
 
-	_create_nvmet_subsystem "${subsys}2" "$(losetup -f)"
+	_create_nvmet_subsystem --subsysnqn "${subsys}2" \
+				--blkdev "$(losetup -f)"
 	_add_nvmet_subsys_to_port "${port}" "${subsys}2"
 
 	genctr=$(_check_genctr "${genctr}" "adding a subsystem to a port")
tests/nvme/031 +2 -1
index ed5f196..191ce72 100755
@@ -40,7 +40,8 @@ test() {
 	port="$(_create_nvmet_port "${nvme_trtype}")"
 
 	for ((i = 0; i < iterations; i++)); do
-		_create_nvmet_subsystem "${subsys}$i" "${loop_dev}"
+		_create_nvmet_subsystem --subsysnqn "${subsys}$i" \
+					--blkdev "${loop_dev}"
 		_add_nvmet_subsys_to_port "${port}" "${subsys}$i"
 		_create_nvmet_host "${subsys}$i" "${def_hostnqn}"
 		_nvme_connect_subsys "${nvme_trtype}" "${subsys}$i"
tests/nvme/rc +85 -15

137 lines not on this page · raw message

Signature · 1 line
2.30.1 (Apple Git-130)
#2 lore raw

Re: [PATCH V2 1/2] nvme/{rc,002,016,017,030,031}: introduce --resv_enable argument

Quoted 7 lines · Guixin Liu

Add an optional argument --resv_enable to _nvmet_target_setup() and propagate it to _create_nvmet_subsystem() and _create_nvmet_ns().

One can call functions with --resv_enable to enable reservation feature on a specific namespace.

Thanks, looks good to me.

Daniel, could you take a look in this patch? I think it is consistent with your work on _nvme_connect_subsys() and _nvmet_target_setup() in the past.

Reviewed-by
#3 lore raw

Re: Re: [PATCH V2 1/2] nvme/{rc,002,016,017,030,031}: introduce --resv_enable argument

Quoted 7 lines · Shinichiro Kawasaki
Quoted 6 lines · Guixin Liu

Add an optional argument --resv_enable to _nvmet_target_setup() and propagate it to _create_nvmet_subsystem() and _create_nvmet_ns().

One can call functions with --resv_enable to enable reservation feature on a specific namespace.

Quoted 6 lines
Quoted 1 line

Thanks, looks good to me.

Daniel, could you take a look in this patch? I think it is consistent with your work on _nvme_connect_subsys() and _nvmet_target_setup() in the past.

It teaches _create_nvmet_ns and _create_nvmet_subsystem to parse for arguments as we have for the function you named. This makes these function a bit more flexible to use. Looks good to me. Thanks!

author
#4 lore raw

PATCH v2 2/2 test/nvme/050: test the reservation feature

In reply to Guixin Liu

Test the reservation feature, includes register, acquire, release and report.

---
 tests/nvme/050     |  96 ++++++++++++++++++++++++++++++++++++++++
 tests/nvme/050.out | 108 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 204 insertions(+)
 create mode 100644 tests/nvme/050
 create mode 100644 tests/nvme/050.out
tests/nvme/050 new file +96 -0
new file mode 100644
index 0000000..7e59de4
@@ -0,0 +1,96 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2024 Guixin Liu
+# Copyright (C) 2024 Alibaba Group.
+#
+# Test the NVMe reservation feature
+#
+. tests/nvme/rc
+
+DESCRIPTION="test the reservation feature"
+QUICK=1
+
+requires() {
+	_nvme_requires
+}
+
+resv_report() {
+	local nvmedev=$1
+
+	if nvme resv-report --help 2>&1 | grep -- '--eds' > /dev/null; then
+		nvme resv-report "/dev/${nvmedev}n1" --eds | grep -v "hostid"
+	else
+		nvme resv-report "/dev/${nvmedev}n1" --cdw11=1 | grep -v "hostid"
+	fi
+}
+
+test_resv() {
+	local nvmedev=$1
+
+	echo "Register"
+	resv_report "${nvmedev}"
+	nvme resv-register "/dev/${nvmedev}n1" --nrkey=4 --rrega=0
+	resv_report "${nvmedev}"
+
+	echo "Replace"
+	nvme resv-register "/dev/${nvmedev}n1" --crkey=4 --nrkey=5 --rrega=2
+	resv_report "${nvmedev}"
+
+	echo "Unregister"
+	nvme resv-register "/dev/${nvmedev}n1" --crkey=5 --rrega=1
+	resv_report "${nvmedev}"
+
+	echo "Acquire"
+	nvme resv-register "/dev/${nvmedev}n1" --nrkey=4 --rrega=0
+	nvme resv-acquire "/dev/${nvmedev}n1" --crkey=4 --rtype=1 --racqa=0
+	resv_report "${nvmedev}"
+
+	echo "Preempt"
+	nvme resv-acquire "/dev/${nvmedev}n1" --crkey=4 --rtype=2 --racqa=1
+	resv_report "${nvmedev}"
+
+	echo "Release"
+	nvme resv-release "/dev/${nvmedev}n1" --crkey=4 --rtype=2 --rrela=0
+	resv_report "${nvmedev}"
+
+	echo "Clear"
+	nvme resv-register "/dev/${nvmedev}n1" --nrkey=4 --rrega=0
+	nvme resv-acquire "/dev/${nvmedev}n1" --crkey=4 --rtype=1 --racqa=0
+	resv_report "${nvmedev}"
+	nvme resv-release "/dev/${nvmedev}n1" --crkey=4 --rrela=1
+}
+
+test() {
+	echo "Running ${TEST_NAME}"
+
+	_setup_nvmet
+
+	local nvmedev
+	local skipped=false
+	local subsys_path=""
+	local ns_path=""
+
+	_nvmet_target_setup --blkdev file --resv_enable
+	subsys_path="${NVMET_CFS}/subsystems/${def_subsysnqn}"
+	ns_path="${subsys_path}/namespaces/1"
+
+	if [[ -f "${ns_path}/resv_enable" ]] ; then
+		_nvme_connect_subsys "${nvme_trtype}" "${def_subsysnqn}"
+
+		nvmedev=$(_find_nvme_dev "${def_subsysnqn}")
+
+		test_resv "${nvmedev}"
+		_nvme_disconnect_subsys "${def_subsysnqn}"
+	else
+		SKIP_REASONS+=("missing reservation feature")
+		skipped=true
+	fi
+
+	_nvmet_target_cleanup
+
+	if [[ "${skipped}" = true ]] ; then
+		return 1
+	fi
+
+	echo "Test complete"
+}
tests/nvme/050.out new file +108 -0

108 lines not on this page · raw message

Signature · 1 line
2.30.1 (Apple Git-130)
#5 lore raw

Re: [PATCH V2 2/2] test/nvme/050: test the reservation feature

Quoted 4 lines · Guixin Liu

Test the reservation feature, includes register, acquire, release and report.

Thanks for this v2. I ran it with kernel side v4 patch [1], enabling lockdep. And I observed lockdep WARN [2]. For your reference, I attached the WARN at the end of this e-mail.

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

This blktests patch looks almost good for me. Please find minor nit comments in line.

Quoted 23 lines
---
 tests/nvme/050     |  96 ++++++++++++++++++++++++++++++++++++++++
 tests/nvme/050.out | 108 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 204 insertions(+)
 create mode 100644 tests/nvme/050
 create mode 100644 tests/nvme/050.out
tests/nvme/050 new file +10 -0
new file mode 100644
index 0000000..7e59de4
@@ -0,0 +1,96 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2024 Guixin Liu
+# Copyright (C) 2024 Alibaba Group.
+#
+# Test the NVMe reservation feature
+#
+. tests/nvme/rc
+
+DESCRIPTION="test the reservation feature"

tests/nvme/050 line 20

Quoted 10 lines
tests/nvme/050 new file +10 -0
+QUICK=1
+
+requires() {
+	_nvme_requires
+}
+
+resv_report() {
+	local nvmedev=$1
+
+	if nvme resv-report --help 2>&1 | grep -- '--eds' > /dev/null; then

It feels costly to call "resv-report --help" multiple times. I suggest to call it only once at the beginning of test_resv(). Based on the check result, a local variable can be set up and passed to resv_report().

tests/nvme/050 line 23

Quoted 3 lines
tests/nvme/050 new file +3 -0
+		nvme resv-report "/dev/${nvmedev}n1" --eds | grep -v "hostid"
+	else
+		nvme resv-report "/dev/${nvmedev}n1" --cdw11=1 | grep -v "hostid"

The two lines above are almost same. I think they can be unified with the variable passed from the caller.

tests/nvme/050 line 26

Quoted 3 lines
tests/nvme/050 new file +3 -0
+	fi
+}
+

[...]

[2]

run blktests nvme/050 at 2024-01-23 19:05:08
nvmet: adding nsid 1 to subsystem blktests-subsystem-1
nvmet: creating nvm controller 1 for subsystem blktests-subsystem-1 for NQN nqn.2014-08.org.nvmexpress:uuid:0f01fb42-9f7f-4856-b0b3-51e60b8de349. nvme nvme1: Please enable CONFIG_NVME_MULTIPATH for full support of multi-port devices.
nvme nvme1: creating 4 I/O queues.
nvme nvme1: new ctrl: "blktests-subsystem-1"
nvme nvme1: Removing ctrl: NQN "blktests-subsystem-1"

======================================================
WARNING: possible circular locking dependency detected
6.7.0+ #142 Not tainted
------------------------------------------------------
check/1061 is trying to acquire lock:
ffff888139743a78 (&ns->pr.pr_lock){+.+.}-{3:3}, at: nvmet_pr_exit_ns+0x2e/0x230 [nvmet]

but task is already holding lock:
ffff888110cf7070 (&subsys->lock#2){+.+.}-{3:3}, at: nvmet_ns_disable+0x2a2/0x4a0 [nvmet]

which lock already depends on the new lock.

the existing dependency chain (in reverse order) is:

-> #1 (&subsys->lock#2){+.+.}-{3:3}:

       __mutex_lock+0x185/0x18c0
       nvmet_pr_send_resv_released+0x57/0x220 [nvmet]
       nvmet_pr_preempt+0x651/0xc80 [nvmet]
       nvmet_execute_pr_acquire+0x26f/0x5c0 [nvmet]
       process_one_work+0x74c/0x1260
       worker_thread+0x723/0x1300
       kthread+0x2f1/0x3d0
       ret_from_fork+0x30/0x70
       ret_from_fork_asm+0x1b/0x30

-> #0 (&ns->pr.pr_lock){+.+.}-{3:3}:

       __lock_acquire+0x2e96/0x5f40
       lock_acquire+0x1a9/0x4e0
       __mutex_lock+0x185/0x18c0
       nvmet_pr_exit_ns+0x2e/0x230 [nvmet]
       nvmet_ns_disable+0x313/0x4a0 [nvmet]
       nvmet_ns_enable_store+0x8a/0xe0 [nvmet]
       configfs_write_iter+0x2ae/0x460
       vfs_write+0x540/0xd90
       ksys_write+0xf7/0x1d0
       do_syscall_64+0x60/0xe0
       entry_SYSCALL_64_after_hwframe+0x6e/0x76

other info that might help us debug this:

Possible unsafe locking scenario:
       CPU0                    CPU1
       ----                    ----
  lock(&subsys->lock#2);
                               lock(&ns->pr.pr_lock);
                               lock(&subsys->lock#2);

lock(&ns->pr.pr_lock);

*** DEADLOCK ***

4 locks held by check/1061:
#0: ffff88813a8e8418 (sb_writers#14){.+.+}-{0:0}, at: ksys_write+0xf7/0x1d0 #1: ffff88811e893a88 (&buffer->mutex){+.+.}-{3:3}, at: configfs_write_iter+0x73/0x460 #2: ffff88812e673978 (&p->frag_sem){++++}-{3:3}, at: configfs_write_iter+0x1db/0x460 #3: ffff888110cf7070 (&subsys->lock#2){+.+.}-{3:3}, at: nvmet_ns_disable+0x2a2/0x4a0 [nvmet]

stack backtrace:
CPU: 0 PID: 1061 Comm: check Not tainted 6.7.0+ #142
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-1.fc39 04/01/2014
Call Trace:
 <TASK>
 dump_stack_lvl+0x57/0x90
 check_noncircular+0x309/0x3f0
 ? __pfx_check_noncircular+0x10/0x10
 ? lockdep_lock+0xca/0x1c0
 ? __pfx_lockdep_lock+0x10/0x10
 ? lock_release+0x378/0x650
 ? __stack_depot_save+0x246/0x470
 __lock_acquire+0x2e96/0x5f40
 ? __pfx___lock_acquire+0x10/0x10
 lock_acquire+0x1a9/0x4e0
 ? nvmet_pr_exit_ns+0x2e/0x230 [nvmet]
 ? __pfx_lock_acquire+0x10/0x10
 ? lock_is_held_type+0xce/0x120
 ? __pfx_lock_acquire+0x10/0x10
 ? __pfx___might_resched+0x10/0x10
 __mutex_lock+0x185/0x18c0
 ? nvmet_pr_exit_ns+0x2e/0x230 [nvmet]
 ? nvmet_pr_exit_ns+0x2e/0x230 [nvmet]
 ? rcu_is_watching+0x11/0xb0
 ? __mutex_lock+0x2a2/0x18c0
 ? __pfx___mutex_lock+0x10/0x10
 ? nvmet_pr_exit_ns+0x2e/0x230 [nvmet]
 nvmet_pr_exit_ns+0x2e/0x230 [nvmet]
 nvmet_ns_disable+0x313/0x4a0 [nvmet]
 ? __pfx_nvmet_ns_disable+0x10/0x10 [nvmet]
 nvmet_ns_enable_store+0x8a/0xe0 [nvmet]
 ? __pfx_nvmet_ns_enable_store+0x10/0x10 [nvmet]
 configfs_write_iter+0x2ae/0x460
 vfs_write+0x540/0xd90
 ? __pfx_vfs_write+0x10/0x10
 ? __pfx___lock_acquire+0x10/0x10
 ? __handle_mm_fault+0x12c5/0x1870
 ? __fget_light+0x51/0x220
 ksys_write+0xf7/0x1d0
 ? __pfx_ksys_write+0x10/0x10
 ? syscall_enter_from_user_mode+0x22/0x90
 do_syscall_64+0x60/0xe0
 ? __pfx_lock_release+0x10/0x10
 ? count_memcg_events.constprop.0+0x4a/0x60
 ? handle_mm_fault+0x1b1/0x9d0
 ? exc_page_fault+0xc0/0x100
 ? rcu_is_watching+0x11/0xb0
 ? asm_exc_page_fault+0x22/0x30
 ? lockdep_hardirqs_on+0x7d/0x100
 entry_SYSCALL_64_after_hwframe+0x6e/0x76
RIP: 0033:0x7f604525ac34
Code: c7 00 16 00 00 00 b8 ff ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 f3 0f 1e fa 80 3d 35 77 0d 00 00 74 13 b8 01 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 54 c3 0f 1f 00 55 48 89 e5 48 83 ec 20 48 89
RSP: 002b:00007ffec7fd6ce8 EFLAGS: 00000202 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 0000000000000002 RCX: 00007f604525ac34
RDX: 0000000000000002 RSI: 0000562b0cd805a0 RDI: 0000000000000001
RBP: 00007ffec7fd6d10 R08: 0000000000001428 R09: 0000000100000000
R10: 0000000000000000 R11: 0000000000000202 R12: 0000000000000002
R13: 0000562b0cd805a0 R14: 00007f604532b5c0 R15: 00007f6045328f20
 </TASK>
author
#6 lore raw

Re: [PATCH V2 2/2] test/nvme/050: test the reservation feature

Quoted 42 lines · Shinichiro Kawasaki
Quoted 4 lines · Guixin Liu

Test the reservation feature, includes register, acquire, release and report.

Thanks for this v2. I ran it with kernel side v4 patch [1], enabling lockdep. And I observed lockdep WARN [2]. For your reference, I attached the WARN at the end of this e-mail.

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

This blktests patch looks almost good for me. Please find minor nit comments in line.

Quoted 28 lines
---
  tests/nvme/050     |  96 ++++++++++++++++++++++++++++++++++++++++
  tests/nvme/050.out | 108 +++++++++++++++++++++++++++++++++++++++++++++
  2 files changed, 204 insertions(+)

create mode 100644 tests/nvme/050
create mode 100644 tests/nvme/050.out

tests/nvme/050 new file +15 -0
new file mode 100644
index 0000000..7e59de4
@@ -0,0 +1,96 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2024 Guixin Liu
+# Copyright (C) 2024 Alibaba Group.
+#
+# Test the NVMe reservation feature
+#
+. tests/nvme/rc
+
+DESCRIPTION="test the reservation feature"
+QUICK=1
+
+requires() {
+	_nvme_requires
+}
Quoted 8 lines

tests/nvme/050 line 20

Quoted 5 lines
tests/nvme/050 new file +5 -0
+
+resv_report() {
+	local nvmedev=$1
+
+	if nvme resv-report --help 2>&1 | grep -- '--eds' > /dev/null; then

It feels costly to call "resv-report --help" multiple times. I suggest to call it only once at the beginning of test_resv(). Based on the check result, a local variable can be set up and passed to resv_report().

OK, I will change it in v3.

Quoted 5 lines

tests/nvme/050 line 23

Quoted 3 lines
tests/nvme/050 new file +3 -0
+		nvme resv-report "/dev/${nvmedev}n1" --eds | grep -v "hostid"
+	else
+		nvme resv-report "/dev/${nvmedev}n1" --cdw11=1 | grep -v "hostid"

The two lines above are almost same. I think they can be unified with the variable passed from the caller.

OK, I will change it in v3.

Quoted 125 lines

tests/nvme/050 line 26

Quoted 4 lines
tests/nvme/050 new file +3 -0
+	fi
+}
+

[...]

[2]

run blktests nvme/050 at 2024-01-23 19:05:08
nvmet: adding nsid 1 to subsystem blktests-subsystem-1
nvmet: creating nvm controller 1 for subsystem blktests-subsystem-1 for NQN nqn.2014-08.org.nvmexpress:uuid:0f01fb42-9f7f-4856-b0b3-51e60b8de349. nvme nvme1: Please enable CONFIG_NVME_MULTIPATH for full support of multi-port devices.
nvme nvme1: creating 4 I/O queues.
nvme nvme1: new ctrl: "blktests-subsystem-1"
nvme nvme1: Removing ctrl: NQN "blktests-subsystem-1"

======================================================
WARNING: possible circular locking dependency detected
6.7.0+ #142 Not tainted
------------------------------------------------------
check/1061 is trying to acquire lock:
ffff888139743a78 (&ns->pr.pr_lock){+.+.}-{3:3}, at: nvmet_pr_exit_ns+0x2e/0x230 [nvmet]

but task is already holding lock:
ffff888110cf7070 (&subsys->lock#2){+.+.}-{3:3}, at: nvmet_ns_disable+0x2a2/0x4a0 [nvmet]

which lock already depends on the new lock.

the existing dependency chain (in reverse order) is:

-> #1 (&subsys->lock#2){+.+.}-{3:3}:

        __mutex_lock+0x185/0x18c0
        nvmet_pr_send_resv_released+0x57/0x220 [nvmet]
        nvmet_pr_preempt+0x651/0xc80 [nvmet]
        nvmet_execute_pr_acquire+0x26f/0x5c0 [nvmet]
        process_one_work+0x74c/0x1260
        worker_thread+0x723/0x1300
        kthread+0x2f1/0x3d0
        ret_from_fork+0x30/0x70
        ret_from_fork_asm+0x1b/0x30

-> #0 (&ns->pr.pr_lock){+.+.}-{3:3}:

        __lock_acquire+0x2e96/0x5f40
        lock_acquire+0x1a9/0x4e0
        __mutex_lock+0x185/0x18c0
        nvmet_pr_exit_ns+0x2e/0x230 [nvmet]
        nvmet_ns_disable+0x313/0x4a0 [nvmet]
        nvmet_ns_enable_store+0x8a/0xe0 [nvmet]
        configfs_write_iter+0x2ae/0x460
        vfs_write+0x540/0xd90
        ksys_write+0xf7/0x1d0
        do_syscall_64+0x60/0xe0
        entry_SYSCALL_64_after_hwframe+0x6e/0x76

other info that might help us debug this:

Possible unsafe locking scenario:
        CPU0                    CPU1
        ----                    ----
   lock(&subsys->lock#2);
                                lock(&ns->pr.pr_lock);
                                lock(&subsys->lock#2);

lock(&ns->pr.pr_lock);

*** DEADLOCK ***

4 locks held by check/1061:
#0: ffff88813a8e8418 (sb_writers#14){.+.+}-{0:0}, at: ksys_write+0xf7/0x1d0 #1: ffff88811e893a88 (&buffer->mutex){+.+.}-{3:3}, at: configfs_write_iter+0x73/0x460 #2: ffff88812e673978 (&p->frag_sem){++++}-{3:3}, at: configfs_write_iter+0x1db/0x460 #3: ffff888110cf7070 (&subsys->lock#2){+.+.}-{3:3}, at: nvmet_ns_disable+0x2a2/0x4a0 [nvmet]

stack backtrace:
CPU: 0 PID: 1061 Comm: check Not tainted 6.7.0+ #142
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-1.fc39 04/01/2014
Call Trace:
  <TASK>
  dump_stack_lvl+0x57/0x90
  check_noncircular+0x309/0x3f0
  ? __pfx_check_noncircular+0x10/0x10
  ? lockdep_lock+0xca/0x1c0
  ? __pfx_lockdep_lock+0x10/0x10
  ? lock_release+0x378/0x650
  ? __stack_depot_save+0x246/0x470
  __lock_acquire+0x2e96/0x5f40
  ? __pfx___lock_acquire+0x10/0x10
  lock_acquire+0x1a9/0x4e0
  ? nvmet_pr_exit_ns+0x2e/0x230 [nvmet]
  ? __pfx_lock_acquire+0x10/0x10
  ? lock_is_held_type+0xce/0x120
  ? __pfx_lock_acquire+0x10/0x10
  ? __pfx___might_resched+0x10/0x10
  __mutex_lock+0x185/0x18c0
  ? nvmet_pr_exit_ns+0x2e/0x230 [nvmet]
  ? nvmet_pr_exit_ns+0x2e/0x230 [nvmet]
  ? rcu_is_watching+0x11/0xb0
  ? __mutex_lock+0x2a2/0x18c0
  ? __pfx___mutex_lock+0x10/0x10
  ? nvmet_pr_exit_ns+0x2e/0x230 [nvmet]
  nvmet_pr_exit_ns+0x2e/0x230 [nvmet]
  nvmet_ns_disable+0x313/0x4a0 [nvmet]
  ? __pfx_nvmet_ns_disable+0x10/0x10 [nvmet]
  nvmet_ns_enable_store+0x8a/0xe0 [nvmet]
  ? __pfx_nvmet_ns_enable_store+0x10/0x10 [nvmet]
  configfs_write_iter+0x2ae/0x460
  vfs_write+0x540/0xd90
  ? __pfx_vfs_write+0x10/0x10
  ? __pfx___lock_acquire+0x10/0x10
  ? __handle_mm_fault+0x12c5/0x1870
  ? __fget_light+0x51/0x220
  ksys_write+0xf7/0x1d0
  ? __pfx_ksys_write+0x10/0x10
  ? syscall_enter_from_user_mode+0x22/0x90
  do_syscall_64+0x60/0xe0
  ? __pfx_lock_release+0x10/0x10
  ? count_memcg_events.constprop.0+0x4a/0x60
  ? handle_mm_fault+0x1b1/0x9d0
  ? exc_page_fault+0xc0/0x100
  ? rcu_is_watching+0x11/0xb0
  ? asm_exc_page_fault+0x22/0x30
  ? lockdep_hardirqs_on+0x7d/0x100
  entry_SYSCALL_64_after_hwframe+0x6e/0x76
RIP: 0033:0x7f604525ac34
Quoted 8 lines
Code: c7 00 16 00 00 00 b8 ff ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 f3 0f 1e fa 80 3d 35 77 0d 00 00 74 13 b8 01 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 54 c3 0f 1f 00 55 48 89 e5 48 83 ec 20 48 89
RSP: 002b:00007ffec7fd6ce8 EFLAGS: 00000202 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 0000000000000002 RCX: 00007f604525ac34
RDX: 0000000000000002 RSI: 0000562b0cd805a0 RDI: 0000000000000001
RBP: 00007ffec7fd6d10 R08: 0000000000001428 R09: 0000000100000000
R10: 0000000000000000 R11: 0000000000000202 R12: 0000000000000002
R13: 0000562b0cd805a0 R14: 00007f604532b5c0 R15: 00007f6045328f20
  </TASK>

Thanks a lot, I will fix this in my reservation patch set v5.

Best regards,

Guixin Liu