Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9E065C02182 for ; Tue, 21 Jan 2025 13:47:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:content-type: Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=6HSwJ2y1LEa9x4X5pNjOCVurfeToNs9oUaMTBo+TH9U=; b=WRh24iSK6G8J8irxN943+730Di OIyLHJiJHUivIMYsO+5PB09Wwd5LKkfdvXlU/OCZwqcNfiUMO+qEHS8vUsd2vltdYWjTBpcyjPbPl +GM+iGgEKidHJLka2B9CdGzu7yt5z2x7uIye3m3dJ8BlqrXOaJV+bWbMdZVx7UShTypOFdPzNUmbs n2kXhO1C/YruBhzVIpiOhaZ62Hl3K/OKlik70X/ZcXHRribAJAUydYNdD/rguSKpRMyCN+/6ykJpF eTNxwcsJL3/tYkkM040CLxLJoXON8pyRuVzAIsrRsCTwUhlQ2W9uFNhqwDbIee560WenHgNERPj25 w8bulinA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1taEbS-000000080DQ-2Rf2; Tue, 21 Jan 2025 13:47:38 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1taEbM-000000080Ca-1qNb for linux-nvme@lists.infradead.org; Tue, 21 Jan 2025 13:47:34 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737467250; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6HSwJ2y1LEa9x4X5pNjOCVurfeToNs9oUaMTBo+TH9U=; b=IbRy8CvcyyAi2kBCyn1jqv+vm6Ualo8YvVn+mRHpF7Br+3McEpF6rrpWaukNYvDC5oighq VJhTgzUJfkvRlx4YANFA4pIRFRflJlVPXs5TpFkB4BjZkEZFezedxXLRf6fwHMNI5mC1Js RLdqPEYaeflyIsJDlZS3bpRIZ3jqSpc= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-154-Vkc-7p0eNtCf8yZi8RVBlg-1; Tue, 21 Jan 2025 08:45:48 -0500 X-MC-Unique: Vkc-7p0eNtCf8yZi8RVBlg-1 X-Mimecast-MFC-AGG-ID: Vkc-7p0eNtCf8yZi8RVBlg Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9D9D71955D61; Tue, 21 Jan 2025 13:45:44 +0000 (UTC) Received: from rocky.redhat.com (unknown [10.47.238.155]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 39C593003FD2; Tue, 21 Jan 2025 13:45:41 +0000 (UTC) From: Maurizio Lombardi To: kbusch@kernel.org Cc: hch@lst.de, sagi@grimberg.me, linux-nvme@lists.infradead.org, hare@suse.de Subject: [PATCH] nvme-tcp: Prevent infinite loop if socket closes during CONNECTING state Date: Tue, 21 Jan 2025 14:45:40 +0100 Message-ID: <20250121134540.1280828-1-mlombard@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: _U5hHLWPDr9qivYBrpuCv_YzuXMQUuinQFvFquuviNI_1737467145 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250121_054732_552686_66ED19E0 X-CRM114-Status: GOOD ( 12.15 ) X-BeenThere: linux-nvme@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-nvme" Errors-To: linux-nvme-bounces+linux-nvme=archiver.kernel.org@lists.infradead.org There is a potential race condition that can occur if the target closes the socket while the host is in the CONNECTING state. If the socket's state changes to TCP_CLOSE, the nvme_tcp_state_change() function is invoked. However, nvme_tcp_error_recovery() is unable to transition the controller state to NVME_CTRL_RESETTING because the controller is still in the CONNECTING state. As a result, error recovery is bypassed, and the controller incorrectly transitions to the LIVE state with closed sockets. Subsequent attempts by the host to communicate with the target will result in an infinite loop. Fix the bug by checking for the -EPIPE error code, which indicates that the connection was closed by the target. If this condition is detected, ensure the error recovery process is initiated to correctly handle the disconnection. Signed-off-by: Maurizio Lombardi --- drivers/nvme/host/tcp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index 841238f38fdd..d0bb225dca23 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -1261,6 +1261,8 @@ static int nvme_tcp_try_send(struct nvme_tcp_queue *queue) "failed to send request %d\n", ret); nvme_tcp_fail_request(queue->request); nvme_tcp_done_send_req(queue); + if (ret == -EPIPE) + nvme_tcp_error_recovery(&queue->ctrl->ctrl); } out: memalloc_noreclaim_restore(noreclaim_flag); -- 2.43.5