Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Andrew Stellman" <bugs@stellman-greene.com>
Cc: linux-nvme@lists.infradead.org
Subject: Re: [PATCH v2] nvme: requeue keep-alive work when a Keep Alive fails
Date: Wed, 02 Dec 2026 19:46:58 +0000	[thread overview]
Message-ID: <sashiko-outbox-246563@kernel.org> (raw)
In-Reply-To: <20261202192236.88068-1-bugs@stellman-greene.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] nvme: missing comp_seen reset on error in
  nvme_keep_alive_end_io()
- [Medium] nvme: TOCTOU race and early blk_mq_free_request() in
  nvme_keep_alive_end_io()
--

commit 236de8328119255613d8447e380cbb58332dc209
Author: Andrew Stellman <astellman@stellman-greene.com>

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

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

> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index f43582e5f6c4a..58bae0e85a012 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)
> +			nvme_queue_keep_alive_work(ctrl);
>  		return RQ_END_IO_NONE;
>  	}

[Severity: Medium]
Should the error path also reset ctrl->comp_seen = false before calling
nvme_queue_keep_alive_work(ctrl), as the success path does?

__nvme_complete_rq() sets ctrl->comp_seen = true for any completing
request started at or after ctrl->ka_last_check_time, including a failed
Keep Alive request.  When NVME_CTRL_ATTR_TBKAS is enabled, the next run
of nvme_keep_alive_work() sees ctrl->comp_seen == true, treats the failed
Keep Alive completion as I/O traffic, and defers sending the retry Keep
Alive for another work period, which can still let the target's keep-alive
timer expire.

[Severity: Medium]
Can checking the entry snapshot of state after blk_mq_free_request(rq)
requeue ctrl->ka_work on a controller that is already resetting or
deleting?

nvme_keep_alive_end_io() snapshots state at function entry and frees rq
before dev_err() and this check.  Once blk_mq_free_request(rq) releases
the admin tag and queue reference, a concurrent reset or teardown is no
longer blocked in nvme_cancel_admin_tagset() or blk_mq_destroy_queue():

CPU0                                    CPU1
nvme_keep_alive_end_io()
  state = nvme_ctrl_state(ctrl)
    // NVME_CTRL_LIVE
  blk_mq_free_request(rq)
                                        nvme_remove_admin_tag_set()
                                          nvme_stop_keep_alive(ctrl)
                                          blk_mq_destroy_queue(ctrl->admin_q)
  dev_err(...)
  if (state == NVME_CTRL_LIVE)
    nvme_queue_keep_alive_work(ctrl)
                                        nvme_keep_alive_work()
                                          ...  <-- use-after-free on admin_q

Re-reading nvme_ctrl_state(ctrl) before requeueing and freeing rq after
handling the completion would narrow this window.

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


      reply	other threads:[~2026-12-02 19:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 19:22 [PATCH v2] nvme: requeue keep-alive work when a Keep Alive fails Andrew Stellman
2026-12-02 19:46 ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-246563@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bugs@stellman-greene.com \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox