From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF16225E83D; Tue, 11 Mar 2025 15:38:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741707499; cv=none; b=nzv6CKihxjx5vBNP30UAGTlCDHBKeVGy4K04QbN9w5YjRSD/LSXSVyivuMwQA2HY5IJd3MolaYGZjdeLjKMqUd5iHGj2uDiPdL9nsh5ah1TDI9eEkfB+Xi98qtzmllx4MLnLImTHhr65DA3sB8Fud8dk5X55h7RBi7oue92ZzdU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741707499; c=relaxed/simple; bh=NpcDFehDBJInQI0IU3+QJi6Ttz96QfCg0wTVrkpe46g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JAMlio8DiJOFW1VO/Uc3fNQlP4/XwlRnnwmx6rRdP6301uAPyzKdeGYsFnjRx0UBIBWeTrtJQ7pQcjx5k7rk54ByEgYfwKbFtfRsS5jF2OZS13Bh3sJWu184+IHu603CDsKIvruczBoFqGu1L9FlUzu80DfpohbiqH+MpEwYu58= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=e0dPyIlZ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="e0dPyIlZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06E52C4CEEA; Tue, 11 Mar 2025 15:38:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1741707499; bh=NpcDFehDBJInQI0IU3+QJi6Ttz96QfCg0wTVrkpe46g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e0dPyIlZ3+BED8AeHfn/SSA3KIBeXJG2LNQ7C1ztxX4BT0w7JaWCyWu15XB+Cdxoc CkfzfG0jXc982kEfiUDsKGYDoIZ8Ga+KolZYhoj3zHXZ7roSUVZoJ1ChoZeW/UpYcB YNOgkn6GRKNFD/Eh9GOocJe9T05l3hCDN6GX63eg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Meir Elisha , Sagi Grimberg , Keith Busch , Sasha Levin Subject: [PATCH 5.10 408/462] nvmet-tcp: Fix a possible sporadic response drops in weakly ordered arch Date: Tue, 11 Mar 2025 16:01:14 +0100 Message-ID: <20250311145814.448991059@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250311145758.343076290@linuxfoundation.org> References: <20250311145758.343076290@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Meir Elisha [ Upstream commit a16f88964c647103dad7743a484b216d488a6352 ] The order in which queue->cmd and rcv_state are updated is crucial. If these assignments are reordered by the compiler, the worker might not get queued in nvmet_tcp_queue_response(), hanging the IO. to enforce the the correct reordering, set rcv_state using smp_store_release(). Fixes: bdaf13279192 ("nvmet-tcp: fix a segmentation fault during io parsing error") Signed-off-by: Meir Elisha Reviewed-by: Sagi Grimberg Signed-off-by: Keith Busch Signed-off-by: Sasha Levin --- drivers/nvme/target/tcp.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c index 5655f6d81cc09..754a963867dcb 100644 --- a/drivers/nvme/target/tcp.c +++ b/drivers/nvme/target/tcp.c @@ -527,10 +527,16 @@ static void nvmet_tcp_queue_response(struct nvmet_req *req) struct nvmet_tcp_cmd *cmd = container_of(req, struct nvmet_tcp_cmd, req); 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; - if (unlikely(cmd == queue->cmd)) { + /* 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); @@ -539,7 +545,7 @@ static void nvmet_tcp_queue_response(struct nvmet_req *req) * Avoid using helpers, this might happen before * nvmet_req_init is completed. */ - if (queue->rcv_state == NVMET_TCP_RECV_PDU && + if (queue_state == NVMET_TCP_RECV_PDU && len && len <= cmd->req.port->inline_data_size && nvme_is_write(cmd->req.cmd)) return; @@ -794,8 +800,9 @@ static void nvmet_prepare_receive_pdu(struct nvmet_tcp_queue *queue) { queue->offset = 0; queue->left = sizeof(struct nvme_tcp_hdr); - queue->cmd = NULL; - queue->rcv_state = NVMET_TCP_RECV_PDU; + WRITE_ONCE(queue->cmd, NULL); + /* Ensure rcv_state is visible only after queue->cmd is set */ + smp_store_release(&queue->rcv_state, NVMET_TCP_RECV_PDU); } static void nvmet_tcp_free_crypto(struct nvmet_tcp_queue *queue) -- 2.39.5