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=1796384069; b=yIpxq96aq56fEj4CB9RYwwzCg/ffqWjFs4UgUsXo49WvpgqoSZJOba9ZtWqHKQGEJcbS /gCmo5uzL1pptVdSvSQ/dQT+Ga8H76rKLbkL98r0Ak0+7GPqDRwrccBbOOSNEBFRTmjiE UG3K3oSsFrO9VQjNtgrhhziS6HNRP0Nra1RKNOP/QkvAExzD8RHAA4dlxq7+rWCDkgwqP fWwF+R2GqejGn/QA5nEIpxd+mB2Quoem7HAf0clYjJjq7n7kfeAolaYCqANHtvmVlhu6k 0iXok7w6pOoQvKVNq4lB9WSiWgpGtnI1NhS8Cp+drbK6Ho7NUHTKafSPAYY6hlLEwSQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384069; 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=lv/PLPiibHje2wiECrN5mu44h8H/+ars2e9Sp4dE4bQ=; b=I7KrMMDJE9NZG9oMianvk5ksSSqIGVfG77/5NM76ZJoFx4mDmaCN2Z+t8YWSTCHE+HcJ MIvFx6tZYTyWsG3n6LAGQiMeELt1tYommyKVo57nOqBAvBaarOVQxArg5t5uMfRaviMfL dFDvoBgyelKimr+4mV2JAV2DULe0Y70O0gpkvgWAmsV8S1TiVm0zkQPqMeLA8bzNmDom6 9F40B48UEvY0w0YlkHm+87SvICzI4mG3gK/qK0qBUW2oEg12VwnEmXV142LjPuc5irZK/ Y9L/ilxoSf+H6TyqKT2zeoOMNw9vZ8R/6w/ktOnuptr4t0J0ztQMO4AybStSF+eEhpg== 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=YEW2iyLd; 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 354C0606A32D; Fri, 4 Dec 2026 11:34:29 +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=YEW2iyLd Received: by smtp.kernel.org (Postfix) with ESMTPSA id A59731F000C2; Fri, 4 Dec 2026 11:34:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384069; bh=lv/PLPiibHje2wiECrN5mu44h8H/+ars2e9Sp4dE4bQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=YEW2iyLdZ1YY++uWEGdFGWw4C8/l4cZ+XTEkFQ5NaRcAFEOBtE2J0+2FWI+vl+grw Dt6FhI4jVJthfGoc8bbNs77WYGFbQho+/33ZGZPswOp0LdJe2cPAUmTRQuluWujxsq UgHaTu63jvq6ubDjBFYeMBpiLXnsrs9eg3FpvUKk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Shao Mingyin , Keith Busch Subject: [PATCH 6.12 482/555] nvmet-tcp: only wait for in-capsule data for inline SGLs Date: Fri, 4 Dec 2026 19:08:45 +0900 Message-ID: <20261204100627.518801812@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-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 @@ -273,6 +273,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) { @@ -635,25 +659,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; } @@ -1033,7 +1051,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; /* @@ -1043,8 +1060,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; }