Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvmet: don't abort the preempting host itself
@ 2026-11-20  8:06 Guixin Liu
  2026-11-20  8:18 ` sashiko-bot
  2026-11-20 17:24 ` Christoph Hellwig
  0 siblings, 2 replies; 4+ messages in thread
From: Guixin Liu @ 2026-11-20  8:06 UTC (permalink / raw)
  To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
	Nilay Shroff, Daniel Wagner, Hannes Reinecke
  Cc: linux-nvme

When a host issues a Reservation Acquire with the Preempt and Abort
action and its own reservation key matches the Preempt Reservation Key
(PRKEY), the host unregisters itself as the specification requires:
all paths in NVMe Base Specification section 8.1.25.7 that unregister
registrants by PRKEY (no reservation held, All Registrants types with
a non-zero PRKEY, and a PRKEY that does not match the holder's key)
apply to every registrant whose key matches, without excluding the
host that issued the command.

But nvmet also adds the issuing host's controllers to the abort set.
The abort flow kills the per-controller ref of every controller in the
set and waits for their counts to drop to zero before completing the
preempt command.  The preempt command itself holds a reference on its
own controller's per-controller ref until it completes, so the abort
flow ends up waiting for the very command it is supposed to complete
afterwards.  The namespace's pr_sem is never released and all further
reservation commands on the namespace hang.

The abort of commands as a side effect of preempting a reservation is
best effort, so skip the issuing host's controllers and just unregister
the registrant.

Fixes: 5a47c2080a73 ("nvmet: support reservation feature")
Cc: stable@vger.kernel.org
Signed-off-by: Guixin Liu <kanie@linux.alibaba.com>
---
 drivers/nvme/target/pr.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/target/pr.c b/drivers/nvme/target/pr.c
index 8c818f24815b..ed530d7362f5 100644
--- a/drivers/nvme/target/pr.c
+++ b/drivers/nvme/target/pr.c
@@ -502,7 +502,14 @@ static u16 nvmet_pr_unreg_all_host_by_prkey(struct nvmet_req *req, u64 prkey,
 		if (reg->rkey == prkey) {
 			status = NVME_SC_SUCCESS;
 			uuid_copy(&hostid, &reg->hostid);
-			if (abort)
+			/*
+			 * Aborting is best effort (NVMe Base Specification
+			 * section 8.1.25.7): skip the issuing host, as the
+			 * abort flow would otherwise wait for the preempt
+			 * command itself, which holds a reference on its
+			 * controller's per-controller ref until it completes.
+			 */
+			if (abort && !uuid_equal(&hostid, send_hostid))
 				nvmet_pr_set_ctrl_to_abort(req, &hostid);
 			nvmet_pr_unregister_one(pr, reg);
 			if (!uuid_equal(&hostid, send_hostid))
-- 
2.43.7



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] nvmet: don't abort the preempting host itself
  2026-11-20  8:06 [PATCH] nvmet: don't abort the preempting host itself Guixin Liu
@ 2026-11-20  8:18 ` sashiko-bot
  2026-11-20  8:32   ` Guixin Liu
  2026-11-20 17:24 ` Christoph Hellwig
  1 sibling, 1 reply; 4+ messages in thread
From: sashiko-bot @ 2026-11-20  8:18 UTC (permalink / raw)
  To: Guixin Liu; +Cc: linux-nvme

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] nvmet: nvmet_pr_unreg_all_host_by_prkey() skips abort on
  false pc_ref premise
--

commit 07f50eedfd5f5e5d148cd9fefe65d629fc37077e
Author: Guixin Liu <kanie@linux.alibaba.com>

nvmet: don't abort the preempting host itself

This commit skips calling nvmet_pr_set_ctrl_to_abort() for the issuing
host in nvmet_pr_unreg_all_host_by_prkey() when handling a Reservation
Acquire command with the Preempt and Abort action.

> diff --git a/drivers/nvme/target/pr.c b/drivers/nvme/target/pr.c
> index 8c818f24815bd..ed530d7362f5b 100644
> --- a/drivers/nvme/target/pr.c
> +++ b/drivers/nvme/target/pr.c
> @@ -502,7 +502,14 @@ static u16 nvmet_pr_unreg_all_host_by_prkey(struct nvmet_req *req, u64 prkey,
>  		if (reg->rkey == prkey) {
>  			status = NVME_SC_SUCCESS;
>  			uuid_copy(&hostid, &reg->hostid);
> -			if (abort)
> +			/*
> +			 * Aborting is best effort (NVMe Base Specification
> +			 * section 8.1.25.7): skip the issuing host, as the
> +			 * abort flow would otherwise wait for the preempt
> +			 * command itself, which holds a reference on its
> +			 * controller's per-controller ref until it completes.
> +			 */
> +			if (abort && !uuid_equal(&hostid, send_hostid))
>  				nvmet_pr_set_ctrl_to_abort(req, &hostid);
>  			nvmet_pr_unregister_one(pr, reg);
>  			if (!uuid_equal(&hostid, send_hostid))

[Severity: Medium]
Does a Reservation Acquire command actually hold a reference on pc_ref?

In nvmet_parse_io_cmd(), nvmet_parse_pr_cmd() returns 0 for reservation
opcodes and returns early before reaching nvmet_pr_get_ns_pc_ref():

drivers/nvme/target/core.c:nvmet_parse_io_cmd() {
	...
	if (req->ns->pr.enable) {
		ret = nvmet_parse_pr_cmd(req);
		if (!ret)
			return ret;
	}
	...
	if (req->ns->pr.enable) {
		ret = nvmet_pr_check_cmd_access(req);
		if (ret)
			return ret;

		ret = nvmet_pr_get_ns_pc_ref(req);
	}
	...
}

Because that is the only caller of nvmet_pr_get_ns_pc_ref(), the preempt
command itself never holds a reference on pc_ref->ref and cannot cause the
self-deadlock described here.  Skipping nvmet_pr_set_ctrl_to_abort() for
send_hostid instead stops nvmet from waiting for in-flight I/O commands on
the newly unregistered issuing host's controllers to drain before
completing the Preempt and Abort command.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261120080642.1179691-1-kanie@linux.alibaba.com?part=1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] nvmet: don't abort the preempting host itself
  2026-11-20  8:18 ` sashiko-bot
@ 2026-11-20  8:32   ` Guixin Liu
  0 siblings, 0 replies; 4+ messages in thread
From: Guixin Liu @ 2026-11-20  8:32 UTC (permalink / raw)
  To: sashiko-reviews; +Cc: linux-nvme



在 2026/11/20 16:18, sashiko-bot@kernel.org 写道:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Medium] nvmet: nvmet_pr_unreg_all_host_by_prkey() skips abort on
>   false pc_ref premise
> --
>
> commit 07f50eedfd5f5e5d148cd9fefe65d629fc37077e
> Author: Guixin Liu <kanie@linux.alibaba.com>
>
> nvmet: don't abort the preempting host itself
>
> This commit skips calling nvmet_pr_set_ctrl_to_abort() for the issuing
> host in nvmet_pr_unreg_all_host_by_prkey() when handling a Reservation
> Acquire command with the Preempt and Abort action.
>
>> diff --git a/drivers/nvme/target/pr.c b/drivers/nvme/target/pr.c
>> index 8c818f24815bd..ed530d7362f5b 100644
>> --- a/drivers/nvme/target/pr.c
>> +++ b/drivers/nvme/target/pr.c
>> @@ -502,7 +502,14 @@ static u16 nvmet_pr_unreg_all_host_by_prkey(struct nvmet_req *req, u64 prkey,
>>  		if (reg->rkey == prkey) {
>>  			status = NVME_SC_SUCCESS;
>>  			uuid_copy(&hostid, &reg->hostid);
>> -			if (abort)
>> +			/*
>> +			 * Aborting is best effort (NVMe Base Specification
>> +			 * section 8.1.25.7): skip the issuing host, as the
>> +			 * abort flow would otherwise wait for the preempt
>> +			 * command itself, which holds a reference on its
>> +			 * controller's per-controller ref until it completes.
>> +			 */
>> +			if (abort && !uuid_equal(&hostid, send_hostid))
>>  				nvmet_pr_set_ctrl_to_abort(req, &hostid);
>>  			nvmet_pr_unregister_one(pr, reg);
>>  			if (!uuid_equal(&hostid, send_hostid))
> [Severity: Medium]
> Does a Reservation Acquire command actually hold a reference on pc_ref?
>
> In nvmet_parse_io_cmd(), nvmet_parse_pr_cmd() returns 0 for reservation
> opcodes and returns early before reaching nvmet_pr_get_ns_pc_ref():
>
> drivers/nvme/target/core.c:nvmet_parse_io_cmd() {
> 	...
> 	if (req->ns->pr.enable) {
> 		ret = nvmet_parse_pr_cmd(req);
> 		if (!ret)
> 			return ret;
> 	}
> 	...
> 	if (req->ns->pr.enable) {
> 		ret = nvmet_pr_check_cmd_access(req);
> 		if (ret)
> 			return ret;
>
> 		ret = nvmet_pr_get_ns_pc_ref(req);
> 	}
> 	...
> }
>
> Because that is the only caller of nvmet_pr_get_ns_pc_ref(), the preempt
> command itself never holds a reference on pc_ref->ref and cannot cause the
> self-deadlock described here.  Skipping nvmet_pr_set_ctrl_to_abort() for
> send_hostid instead stops nvmet from waiting for in-flight I/O commands on
> the newly unregistered issuing host's controllers to drain before
> completing the Preempt and Abort command.
Sashiko is right, Please ignore this patch.
>



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] nvmet: don't abort the preempting host itself
  2026-11-20  8:06 [PATCH] nvmet: don't abort the preempting host itself Guixin Liu
  2026-11-20  8:18 ` sashiko-bot
@ 2026-11-20 17:24 ` Christoph Hellwig
  1 sibling, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2026-11-20 17:24 UTC (permalink / raw)
  To: Guixin Liu
  Cc: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
	Nilay Shroff, Daniel Wagner, Hannes Reinecke, linux-nvme

Sashiko thing we don't actually have a reference.  Or does the comment
refer to a different reference?



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-20 17:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20  8:06 [PATCH] nvmet: don't abort the preempting host itself Guixin Liu
2026-11-20  8:18 ` sashiko-bot
2026-11-20  8:32   ` Guixin Liu
2026-11-20 17:24 ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox