[PATCH] nvme: requeue keep-alive work when a Keep Alive fails

sashiko-bot at kernel.org sashiko-bot at kernel.org
Wed Dec 2 09:13:21 PST 2026


Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] nvme: zero-delay ka_work loop in nvme_keep_alive_end_io() when
  deadline is 0
- [High] nvme: nvme_keep_alive_end_io() re-arms ka_work after
  nvme_stop_keep_alive()
- [Medium] nvme: uncleared comp_seen on error in
  nvme_keep_alive_end_io() skips retry
--

commit df70267c1d3880bdae24c7ceb3c48d593ea8973c
Author: Andrew Stellman <astellman at stellman-greene.com>

nvme: requeue keep-alive work when a Keep Alive fails

This commit requeues ctrl->ka_work in nvme_keep_alive_end_io() when a
Keep Alive command completes with an error while the controller is in
NVME_CTRL_LIVE or NVME_CTRL_CONNECTING.

> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index f43582e5f6c4a..ca04ff0f437d6 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -1387,6 +1387,8 @@ static enum rq_end_io_ret nvme_keep_alive_end_io(struct request *rq,
>  		dev_err(ctrl->device,
>  			"failed nvme_keep_alive_end_io error=%d\n",
>  				status);
> +		if (state == NVME_CTRL_LIVE || state == NVME_CTRL_CONNECTING)
> +			queue_delayed_work(nvme_wq, &ctrl->ka_work, delay);
>  		return RQ_END_IO_NONE;
>  	}
>  

[Severity: High]
Can this spin in a zero-delay workqueue loop on nvme_wq if the request
fails before nvme_start_request() sets rq->deadline?

Keep Alive requests carry REQ_FAILFAST_DRIVER, so when ->queue_rq rejects
a command on an unquiesced non-ready admin queue via
nvme_fail_nonready_command() (for example in nvme_tcp_queue_rq() after
nvme_tcp_complete_timed_out() stops queue 0 while in
NVME_CTRL_CONNECTING), the request completes immediately with
rq->deadline still 0.  nvme_keep_alive_end_io() then computes rtt as
jiffies + rq->timeout, logs an unratelimited warning, sets delay = 0, and
requeues ctrl->ka_work with a delay of 0.

[Severity: High]
Can this re-arm ctrl->ka_work after nvme_stop_keep_alive() has already
returned during admin queue teardown in NVME_CTRL_CONNECTING?

In nvme_tcp_setup_ctrl() and nvme_rdma_setup_ctrl(), the destroy_admin
error path (as well as the TLS secure concatenation admin queue restart)
calls nvme_stop_keep_alive() before tearing down the admin queue:

drivers/nvme/host/tcp.c:nvme_tcp_setup_ctrl() {
    ...
destroy_admin:
	nvme_stop_keep_alive(ctrl);
	nvme_tcp_teardown_admin_queue(ctrl, new);
	return ret;
}

If a Keep Alive request is already in flight when nvme_stop_keep_alive()
runs, cancel_delayed_work_sync(&ctrl->ka_work) returns while the request
is still outstanding.  nvme_tcp_teardown_admin_queue() then calls
nvme_cancel_admin_tagset(), completing the request with
NVME_SC_HOST_ABORTED_CMD while ctrl->state is still NVME_CTRL_CONNECTING,
which now queues ctrl->ka_work again on the torn-down admin queue.

[Severity: Medium]
Should the error path also clear ctrl->comp_seen (or update
ctrl->ka_last_check_time) before requeueing ctrl->ka_work?

When the Keep Alive request completes with an error, __nvme_complete_rq()
still sets ctrl->comp_seen = true because rq->deadline - rq->timeout >=
ctrl->ka_last_check_time:

drivers/nvme/host/core.c:__nvme_complete_rq() {
    ...
	if (ctrl->kas &&
	    req->deadline - req->timeout >= ctrl->ka_last_check_time)
		ctrl->comp_seen = true;
    ...
}

Returning before ctrl->comp_seen = false leaves comp_seen set on
controllers with NVME_CTRL_ATTR_TBKAS enabled, so the next run of
nvme_keep_alive_work() treats the failed Keep Alive completion itself as
I/O traffic, skips sending a retry, and defers for another period, which
can still let the target's keep-alive timer expire.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202164944.49770-1-bugs@stellman-greene.com?part=1



More information about the Linux-nvme mailing list