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 63FDF606A336 for ; Fri, 4 Dec 2026 14:28:07 +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=Z2NACtgs; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=EmvlgZGf 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=lrxJVBkNBwIORvahNCsRChl0EG+CWjW1anKKDGInX/g=; b=Z2NACtgsHoOke6qXrUycfSHzye 82Ads558lPyuX2DoCq+4QdWBfqwfZlK2jTo5kxjUvaaeZtfRoh5wkAjG4KpoYPwIe4NMnAsEACjxI j1M3Mk4dNRQysX6mVNPeuL3pEF0ZShhe4YwFgnqHGyv2LWIqWQPVRWd1j8AaZCJaJ4OPS8JYyh3sF iK0yJGPVh9ucNedJeIPTJAizyf3yYueMDmsUYdCSFkUnapzhzHBtXwSVWBf1UOF8upNP9Vw6Sm128 EKK2sLFPC7Q++oFUX8eys3+skWDDvg5CDnuocrH+Kw0ayxRuQqkCisq+JXCnkxoCMF2Xc74ybN581 knbH2mJA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZUGb-00000000ZtH-0wjg; Fri, 04 Dec 2026 14:28:05 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZUGX-00000000Zsf-3dUk for linux-nvme@lists.infradead.org; Fri, 04 Dec 2026 14:28:04 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 06511601FF; Fri, 4 Dec 2026 14:28:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F0A71F000CE; Fri, 4 Dec 2026 14:28:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796394480; bh=lrxJVBkNBwIORvahNCsRChl0EG+CWjW1anKKDGInX/g=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=EmvlgZGfKfdz4LpLXvu8pVSWMmIhkOeAxdB00LjFkjkdqe7g0ptHcd8Bx4lg4omW8 GjF54FigJsbAhGplrGoimahbds9+FfAkHG7Wxavt2WLrkrseFQt07HCEBAj6J0SH1t DMGP0kbYRhA9xPpy6o/S/qoCLdKouRsCsHAwjOda9SKlwM75JLyLvDRww7qcAExknF pS7I/j1ODmdMGyD3jY6A3XEtk2AOgsOr0pmDyHjkt/dg9OmI7q+fzpaY4g/Mx4pCe6 Gs8AlpNJRQF9tK5kTvqxzY5HfmbfuL2ozwHdFDBTBRLSwWwugTk24J45b1AoEn+83J d8cdOeoBwcOTw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v5 1/2] nvme-fabrics: do not leave a timed-out command's id resolvable To: "Yehyeong Lee" Cc: linux-nvme@lists.infradead.org In-Reply-To: <20261204135345.2994739-2-yhlee@isslab.korea.ac.kr> References: <20261204135345.2994739-1-yhlee@isslab.korea.ac.kr> <20261204135345.2994739-2-yhlee@isslab.korea.ac.kr> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 14:28:00 +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=-16.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,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 2 potential issues to consider: - [Medium] nvme-fabrics: unsynchronized nr->genctr++ in nvmf_retire_timed_out_command() - [Low] nvme-fabrics: Fixes tag cites refactor 93ba75c90524 instead of e4fdb2b167ed -- commit d42cf469d2abf13e2a74d2e7aa0bac5c918cf7ba Author: Yehyeong Lee > nvme-fabrics: do not leave a timed-out command's id resolvable > > nvmf_complete_timed_out_request() ends the request with > blk_mq_complete_request() instead of nvme_try_complete_req(), which is the > only place the host advances the generation counter that nvme_find_rq() > checks a command id against. The id goes back to the tagset while the > controller may still answer it, so a late response, R2T or C2HData for it > resolves onto a request that is no longer in flight and completes it a > second time. > > Stopping the queue first is no barrier: SHUT_RD does not discard what the > socket has already received, and a queue that never reached > NVME_TCP_Q_LIVE - the one carrying a connect or an in-band authentication > command - is not stopped at all, so it keeps a working socket and a > running io_work. > > Advance the generation where the host gives up, under the same quirk test > nvme_try_complete_req() uses, and split it out as > nvmf_retire_timed_out_command() for a transport that keeps using the queue > after giving up and has to retire the id earlier than the completion. > Advancing a monotonic counter twice is harmless, and a retry is a new > dispatch through nvme_setup_cmd(), which recomputes the id from the > current generation. > > Fixes: 93ba75c90524 ("nvme-fabrics: add a request timeout helper") > Cc: stable@vger.kernel.org > Signed-off-by: Yehyeong Lee [Severity: Low] Should the Fixes tag cite commit e4fdb2b167ed ("nvme: increment request genctr on completion") instead? Commit 93ba75c90524 ("nvme-fabrics: add a request timeout helper") only extracted the existing TCP and RDMA timeout completion code into nvmf_complete_timed_out_request() without changing behavior. It was the earlier commit that moved the genctr increment exclusively into nvme_try_complete_req() while those timeout paths kept calling blk_mq_complete_request() directly. > diff --git a/drivers/nvme/host/fabrics.h b/drivers/nvme/host/fabrics.h > index caf5503d08332..07db19fc85a29 100644 > --- a/drivers/nvme/host/fabrics.h > +++ b/drivers/nvme/host/fabrics.h > @@ -202,9 +202,18 @@ static inline char *nvmf_ctrl_subsysnqn(struct nvme_= ctrl *ctrl) > return ctrl->subsys->subnqn; > } > =20 > +static inline void nvmf_retire_timed_out_command(struct request *rq) > +{ > + struct nvme_request *nr =3D nvme_req(rq); > + > + if (!(nr->ctrl->quirks & NVME_QUIRK_SKIP_CID_GEN)) > + nr->genctr++; > +} > + > static inline void nvmf_complete_timed_out_request(struct request *rq) > { > if (blk_mq_request_started(rq) && !blk_mq_request_completed(rq)) { > + nvmf_retire_timed_out_command(rq); > nvme_req(rq)->status =3D NVME_SC_HOST_ABORTED_CMD; > blk_mq_complete_request(rq); > } [Severity: Medium] Can the unlocked nr->genctr++ in nvmf_retire_timed_out_command() race with active RX, TX, or CQ paths on another CPU? genctr is a plain u8 that was previously only updated on the serialized completion path. When a connect or authentication command times out on nvme-rdma before NVME_RDMA_Q_LIVE is set, nvme_rdma_stop_queue() is a no-op and the CQ handler runs concurrently: CPU0 (timeout work) CPU1 (RDMA CQ) nvme_rdma_complete_timed_out() nvme_rdma_stop_queue() nvmf_complete_timed_out_request() nvmf_retire_timed_out_command() nr->genctr++ nvme_rdma_recv_done() nvme_rdma_process_nvme_rsp() nvme_find_rq() reads nr->genctr <-- data race ... nvme_try_complete_req() rq->genctr++ <-- data race This is a KCSAN data race against the plain reads in nvme_find_rq() and the plain increment in nvme_try_complete_req(), and without atomic or memory-ordered access a racing RX/CQ CPU on a weakly ordered architecture is not guaranteed to observe the retired generation counter. In commit "nvme-tcp: do not leave a timed-out request reachable from its queue", nvme_tcp_complete_timed_out() also calls this helper before stopping the queue or taking send_mutex/lock_sock(sk), which can race with nvme_tcp_setup_h2c_data_pdu() and mismatch an H2CData command_id. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204135345.2994= 739-1-yhlee@isslab.korea.ac.kr?part=3D1