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=1796382706; b=nAPMvONiKorFZJ5obAiY42MVerGa4sLUPUgBeDpN8C+9ofmfgrhCLbQosrHKw6RihQ8y SXuFvy7akc13EcQLlOzVY+txi6BfMSE9zb2VTHNqdJ/E7+DWF9QaR0PtIPbVlMiXQaXfs Qrqw58VZSBcC4qVY+vPmFh2wmg43eKB/1i+ZrbWJnm8WZZpMmDqxClUOecI1rOrsmv8e3 q3tnsH9ohIt1k9EIp8nb9FljsBBmfs8cF/VbrfelVFu3BmVcsfGmuscXZh+8HntYRkxDA 0QyvqLxjHVBIE1H3g3iyIujiN6qOffK3T70zN7Qbd3ZZjoCX1yhI3TGfAenLcZdkllQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382706; 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=456nUn+7PPKFHyEPnTya2rxqOwFU10ifT+RZMBdRhhY=; b=xi5Gc8j/FCB1MQ1Sa8yNCHVwSD8f6UExUu3F0Lye1CwZxSMFZ4Vfw19R9dxBy7Em0qS8 X7rUDqkFMQmLz/vqlYNE9yHR5wauDjOl3W58EExjERbGOAbP3bGcW23ehD4JgpQcAiU3q X6Q4GvPEENCHIqQtTXXcTubjN76IZQ4tG8tBjf8cL75mqIVh8mtOiEzmSPE5k1ENHH2wo ixf5Zwv8dxiohmveMG4xqdno99s4EUV19X6Zg+eSpsm6QsgbftDu/1G8E7A82UlPEVrCK XPZt+aij6YrApLXWnxs5rW3kSCUXnmcmF7M19hpMjWu20or5fORD348QKJ4dWfrATFQ== 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="0aD/EWFZ"; 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 2E860606A32C; Fri, 4 Dec 2026 11:11:46 +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=0aD/EWFZ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B4B41F000C2; Fri, 4 Dec 2026 11:11:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382706; bh=456nUn+7PPKFHyEPnTya2rxqOwFU10ifT+RZMBdRhhY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=0aD/EWFZZ9G7wEjlMpwhqhTmxTvVV54qDUSmM0I4QSab1HnUDX65KAfT5Du/pNgNj lFwKFQfSh2My+0x2cv6q0c5f//FNPOdtLNSjCoAcQl9VJNUTjeEASxVkJx9TqZjla/ Q++9Tfueawqe57Y2IiAehlmXkqO3BUaCncEu2bm4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Shao Mingyin , Keith Busch Subject: [PATCH 6.18 568/703] nvmet-tcp: only wait for in-capsule data for inline SGLs Date: Fri, 4 Dec 2026 19:07:47 +0900 Message-ID: <20261204100642.877485687@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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.18-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) { @@ -637,25 +661,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; } @@ -994,7 +1012,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; /* @@ -1004,8 +1021,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; }