From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D5F2606A31A for ; Wed, 2 Dec 2026 03:59:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=HQWH+fis; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=TZZ6zmw8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Date: Content-Transfer-Encoding:Content-Type:References:In-Reply-To:Cc:To:Subject: From:Message-ID:MIME-Version:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=WYtxwoGT+RzakVfWICG8Ia+4W+2QsMmxp4No83TnjYw=; b=HQWH+fisOCKoCbGSNgTJGLOOXC A6fiHwxMrKDyGA/h7VAjTJRXmgIWJ48JKEerD6+Ez4V6YQxmcgRSU3DHPvUX5YFUnZkTFLAL6UAMH 94Gw07HO1Xy4d2XwFiKC1HXrJLrnL7XqHnUmYjzkPRncpXqw6i160vEym5pyClDV1O+aUraBxiOH1 /OSKwHKxjGlqcA610Fkpfi9KImIOVqInlLekzMsp5CN1njAT2xYISPWha9RqvgQJtIqeyr+B1vxhT +td27QiUQiqGTzKr673St/3OgTqPAk7Awoi7BI7rrBw3T/1XX7+QBv8o9kXHaeJT+pwE5AH5F1gNw 5Aq/PrTA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYbVa-0000000A9aJ-32VL; Wed, 02 Dec 2026 03:59:54 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYbVY-0000000A9Zk-41dD for linux-nvme@lists.infradead.org; Wed, 02 Dec 2026 03:59:53 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id D5DB062167; Wed, 2 Dec 2026 03:59:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 802341F000C1; Wed, 2 Dec 2026 03:59:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796183983; bh=WYtxwoGT+RzakVfWICG8Ia+4W+2QsMmxp4No83TnjYw=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=TZZ6zmw8COX+y6ztWouUG3Xxw1zi3ILtzbsLlgMa01mNKNSfQWy1B3G426gqZVXjy XvNA53OWqomTeuIMewmdYgEEl7Erjqev7E7ckx11fW8oHAfSlkWZ2qZG7h3ht9kxsN XLUGQlS0iWwD6BDPMMJ84dBc7nHPjMt5NlK7BdKngLK23mXeKMOHUkSBMqaF+2EwlP mUJ/fbeYBG/ZFpnq6qN4N6+JB1rnXgbWtvUAM03PHpvGiiaie7nAvg+1x9GsDcu68k RUL0OZX/Ms7fDaY/mV+5fDGa+Nnwl5WqJ0owj4bjmEs7/4CJYyVfS4tuyQHeA4eMlI x9xe4s2YlOTqA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 3/4] nvmet: snapshot the passthru command before completing the request To: "Guixin Liu" Cc: linux-nvme@lists.infradead.org In-Reply-To: <20261202034707.3844378-4-kanie@linux.alibaba.com> References: <20261202034707.3844378-1-kanie@linux.alibaba.com> <20261202034707.3844378-4-kanie@linux.alibaba.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 03:59:43 +0000 X-BeenThere: linux-nvme@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "Linux-nvme" X-Spam-Status: No, score=-10.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: 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 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/passthr= u.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 wo= rk_struct *w) > struct request *rq =3D req->p.rq; > struct nvme_ctrl *ctrl =3D nvme_req(rq)->ctrl; > struct nvme_ns *ns =3D rq->q->queuedata; > + struct nvme_command cmd; > u32 effects; > int status; > =20 > @@ -247,12 +248,19 @@ static void nvmet_passthru_execute_cmd_work(struct = work_struct *w) > } else if (status < 0) > status =3D NVME_SC_INTERNAL; > =20 > + /* > + * 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 =3D *req->cmd; > req->cqe->result =3D nvme_req(rq)->result; > nvmet_req_complete(req, status); > blk_mq_free_request(rq); > =20 > 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_wor= k) 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202034707.3844= 378-1-kanie@linux.alibaba.com?part=3D3