From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796381299; b=3C0D0mbhSi0UNwXeUXuxf3lXg9yRJberLWu5rHfNFIY7drL3luNbD+K7hI+JKbrSZv7O +FWjsyVRLK7ypv+uNRCUj/DOlG9R0fkcHfxqoHqUaO9O2C5i81CA7ESdmFR8EJtNAOMdf da+AooBKKOUtKCaRGvSblIt53qSukRCK9SWgQYUk3fWItjnHUnyQPtZYC7Rny45QPOZKr cvF97PBdyEtAX4yyHEsd2gLQBS7l+wJQklTtct0WJ3uivGm64jqCSemcdJth5Ryyr48CR nxUNdypnwEhSztKs1Yhd3ftpHMkFeDd+vBwPfUpQe5EQTM9gBRzIZL2f6kjWIUZjGaw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381299; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=1eVmIPPeqGit/8Dwi8ui4hjAK3m9GMDg8WLZDErRvI0=; b=DCzFN8Xk3sqsxjbuJBuyM8b8kWBNIl1YeXeTitWAnjoN9hbyB2sqGC0X8fGkT38ORzpP InBTHG2pIam7kTlrF7sYlJchpAkfZib4wcP1H0c+ixOGA0546sw2wntypnCEYE8DuzJ1b ArAwzKZb+8onS03Iprx+zQS4TtghZNTDp4UPYXxcptf9XXzgCNsV1QwClGyOMirgESGjD es6pIKLiT6B1pizda3sA1yRoR8vYy6NE8ZiEdT3JJcIVBb31GwIzVcVShWc4Q5kTUeMLO MhG7CDsxHP7lalj/XRYiXuI0v96L45x0nY3JBK+vBN022jTlwT1GU6s4W32pDmsLgUA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=2YEqDU3F; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 95587606A32C; Fri, 4 Dec 2026 10:48:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=2YEqDU3F Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE4731F000C2; Fri, 4 Dec 2026 10:48:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381299; bh=1eVmIPPeqGit/8Dwi8ui4hjAK3m9GMDg8WLZDErRvI0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=2YEqDU3FaW6l5AAUwp+tmtL6U43+BPoWHoqTqSnR0p+xMILipjP0MBzdatmc4q2qU aY9oXOCCHKWg+8/b+EceU05gXr869koBrXHnxYLlDcL28khFwwRRd/x9StsxO6FH8I eMrlXn8S069IdUatDeAVo2Qj4ZP7Xm7171Ykh7dQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Shao Mingyin , Keith Busch Subject: [PATCH 7.3 643/742] nvmet-tcp: only wait for in-capsule data for inline SGLs Date: Fri, 4 Dec 2026 19:08:27 +0900 Message-ID: <20261204100652.173176741@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Shao Mingyin commit 9dac3b1aa2a99e126a5504b7f5bc781c8b2771e0 upstream. nvmet-tcp decides whether to wait for in-capsule data using only the write direction and SGL length. A write using a transport SGL can fit within inline_data_size without carrying any in-capsule data. The response path then withholds its R2T, leaving the command stuck. If request initialization fails, the same length-only test both withholds the error response and attempts to drain inline data that will never arrive. This can also consume the following PDU as data or a digest. Require an offset data-block SGL in both checks. Share a helper that only uses command and port fields, as the completion callback can run before nvmet_req_init() has finished. Fixes: bdaf13279192 ("nvmet-tcp: fix a segmentation fault during io parsing error") Fixes: 872d26a391da ("nvmet-tcp: add NVMe over TCP target driver") Cc: stable@vger.kernel.org Signed-off-by: Shao Mingyin Signed-off-by: Keith Busch Signed-off-by: Greg Kroah-Hartman --- drivers/nvme/target/tcp.c | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) --- a/drivers/nvme/target/tcp.c +++ b/drivers/nvme/target/tcp.c @@ -270,6 +270,30 @@ static inline bool nvmet_tcp_has_inline_ !cmd->rbytes_done; } +/* + * Check whether the SGL of @cmd carries in-capsule data that the host + * will send right after the command PDU. Only the offset form of the + * data block descriptor is in-capsule; a regular transport SGL is + * fetched through an R2T instead. + */ +static inline bool nvmet_tcp_sgl_is_inline(struct nvmet_tcp_cmd *cmd) +{ + struct nvme_sgl_desc *sgl = &cmd->req.cmd->common.dptr.sgl; + u32 len = le32_to_cpu(sgl->length); + + if (sgl->type != ((NVME_SGL_FMT_DATA_DESC << 4) | + NVME_SGL_FMT_OFFSET)) + return false; + + if (!nvme_is_write(cmd->req.cmd)) + return false; + + if (!len) + return false; + + return len <= cmd->req.port->inline_data_size; +} + static inline struct nvmet_tcp_cmd * nvmet_tcp_get_cmd(struct nvmet_tcp_queue *queue) { @@ -626,25 +650,19 @@ static void nvmet_tcp_queue_response(str struct nvmet_tcp_queue *queue = cmd->queue; enum nvmet_tcp_recv_state queue_state; struct nvmet_tcp_cmd *queue_cmd; - struct nvme_sgl_desc *sgl; - u32 len; /* Pairs with store_release in nvmet_prepare_receive_pdu() */ queue_state = smp_load_acquire(&queue->rcv_state); queue_cmd = READ_ONCE(queue->cmd); if (unlikely(cmd == queue_cmd)) { - sgl = &cmd->req.cmd->common.dptr.sgl; - len = le32_to_cpu(sgl->length); - /* - * Wait for inline data before processing the response. - * Avoid using helpers, this might happen before - * nvmet_req_init is completed. + * Wait for in-capsule data before processing the response. + * This can happen before nvmet_req_init() has completed, so + * only look at the SGL descriptor itself. */ if (queue_state == NVMET_TCP_RECV_PDU && - len && len <= cmd->req.port->inline_data_size && - nvme_is_write(cmd->req.cmd)) + nvmet_tcp_sgl_is_inline(cmd)) return; } @@ -982,7 +1000,6 @@ static int nvmet_tcp_handle_icreq(struct static int nvmet_tcp_handle_req_failure(struct nvmet_tcp_queue *queue, struct nvmet_tcp_cmd *cmd, struct nvmet_req *req) { - size_t data_len = le32_to_cpu(req->cmd->common.dptr.sgl.length); int ret; /* @@ -992,8 +1009,7 @@ static int nvmet_tcp_handle_req_failure( * otherwise we will need to prepare a buffer and receive the * stale data before continuing forward. */ - if (!nvme_is_write(cmd->req.cmd) || !data_len || - data_len > cmd->req.port->inline_data_size) { + if (!nvmet_tcp_sgl_is_inline(cmd)) { nvmet_prepare_receive_pdu(queue); return 0; }