From: sashiko-bot@kernel.org
To: "Guixin Liu" <kanie@linux.alibaba.com>
Cc: linux-nvme@lists.infradead.org
Subject: Re: [PATCH 3/4] nvmet: snapshot the passthru command before completing the request
Date: Wed, 02 Dec 2026 03:59:43 +0000 [thread overview]
Message-ID: <sashiko-outbox-244819@kernel.org> (raw)
In-Reply-To: <20261202034707.3844378-4-kanie@linux.alibaba.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] nvmet: premature nvmet_req_complete() in
nvmet_passthru_execute_cmd_work()
--
commit 188f07fd6a69f723caceb270fb65872dac163f43
Author: Guixin Liu <kanie@linux.alibaba.com>
nvmet: snapshot the passthru command before completing the request
This commit copies req->cmd onto the stack before nvmet_req_complete() in
nvmet_passthru_execute_cmd_work() so nvme_passthru_end() does not read
req->cmd after the target request may have been freed.
> diff --git a/drivers/nvme/target/passthru.c b/drivers/nvme/target/passthru.c
> index 32ae4b6b59bf0..791540bc8fce0 100644
> --- a/drivers/nvme/target/passthru.c
> +++ b/drivers/nvme/target/passthru.c
> @@ -226,6 +226,7 @@ static void nvmet_passthru_execute_cmd_work(struct work_struct *w)
> struct request *rq = req->p.rq;
> struct nvme_ctrl *ctrl = nvme_req(rq)->ctrl;
> struct nvme_ns *ns = rq->q->queuedata;
> + struct nvme_command cmd;
> u32 effects;
> int status;
>
> @@ -247,12 +248,19 @@ static void nvmet_passthru_execute_cmd_work(struct work_struct *w)
> } else if (status < 0)
> status = NVME_SC_INTERNAL;
>
> + /*
> + * nvmet_req_complete() may free req synchronously (e.g. the loop
> + * transport), so snapshot the command for nvme_passthru_end(),
> + * which must run after completion to avoid deadlocking against a
> + * concurrent reset.
> + */
> + cmd = *req->cmd;
> req->cqe->result = nvme_req(rq)->result;
> nvmet_req_complete(req, status);
> blk_mq_free_request(rq);
>
> if (effects)
> - nvme_passthru_end(ctrl, ns, effects, req->cmd, status);
> + nvme_passthru_end(ctrl, ns, effects, &cmd, status);
> }
[Severity: Medium]
Should nvmet_req_complete(req, status) be moved after
nvme_passthru_end() instead of copying req->cmd?
Commit bc8fb906b0ff ("nvme: handle effects after freeing the request")
required nvme_passthru_end() to run after blk_mq_free_request(rq) so the
host request rq transitions to MQ_RQ_IDLE before flush_work(&ctrl->scan_work)
waits on a quiesced admin queue during a reset of ctrl. It did not require
nvmet_req_complete() to run before nvme_passthru_end().
Calling nvmet_req_complete() early drops passthru->ref via
__nvmet_req_complete() -> nvmet_put_passthru_ref() while ctrl is still in
use, and signals completion to the initiator while ctrl is still frozen or
before ctrl->scan_work has finished updating namespaces:
CPU0 (nvmet_wq) CPU1
nvmet_passthru_execute_cmd_work()
nvmet_req_complete(req, status)
...
nvmet_put_passthru_ref()
__nvmet_passthru_ctrl_disable()
wait_for_completion(&passthru->disable_done)
...
nvme_put_ctrl(passthru->ctrl)
blk_mq_free_request(rq)
/* host ctrl removal frees ctrl */
nvme_passthru_end(ctrl, ...) <-- use-after-free on ctrl
Moving nvmet_req_complete(req, status) after blk_mq_free_request(rq) and
nvme_passthru_end() avoids the reset deadlock on rq, keeps req->cmd and
passthru->ref alive across nvme_passthru_end(), and completes the target
request only after command effects have been applied.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202034707.3844378-1-kanie@linux.alibaba.com?part=3
next prev parent reply other threads:[~2026-12-02 3:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 3:47 [PATCH 0/4] nvme: target and host fixes from a drivers/nvme audit Guixin Liu
2026-12-02 3:47 ` [PATCH 1/4] nvme: mask the status before checking for Host Identifier Inconsistent Guixin Liu
2026-12-02 3:47 ` [PATCH 2/4] nvmet: read CRTO from the capability register Guixin Liu
2026-12-02 3:47 ` [PATCH 3/4] nvmet: snapshot the passthru command before completing the request Guixin Liu
2026-12-02 3:59 ` sashiko-bot [this message]
2026-12-02 3:47 ` [PATCH 4/4] nvmet-auth: select the configured DH group from the host's list Guixin Liu
2026-12-02 4:01 ` sashiko-bot
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-244819@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kanie@linux.alibaba.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