linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Maurizio Lombardi <mlombard@redhat.com>
To: kbusch@meta.com
Cc: hare@kernel.org, sagi@grimberg.me,
	linux-nvme@lists.infradead.org, mlombard@bsdbackstore.eu,
	zhang.guanghui@cestc.cn, loberman@redhat.com
Subject: [PATCH V4 1/2] nvme-tcp: Prevent infinite loop if socket closes during CONNECTING state
Date: Fri,  4 Apr 2025 10:28:00 +0200	[thread overview]
Message-ID: <20250404082801.1614252-2-mlombard@redhat.com> (raw)
In-Reply-To: <20250404082801.1614252-1-mlombard@redhat.com>

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 initiating the error recovery process to correctly
handle the disconnection in case we missed this event
while transitioning from CONNECTING to LIVE.

Tested-by: Laurence Oberman <loberman@redhat.com>
Fixes: 3f2304f8c6d6 ("nvme-tcp: add NVMe over TCP host driver")
Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
---
 drivers/nvme/host/tcp.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
index 26c459f0198d..f1e2b0417b39 100644
--- a/drivers/nvme/host/tcp.c
+++ b/drivers/nvme/host/tcp.c
@@ -1329,6 +1329,7 @@ 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);
+		nvme_tcp_error_recovery(&queue->ctrl->ctrl);
 	}
 out:
 	memalloc_noreclaim_restore(noreclaim_flag);
-- 
2.43.5



  reply	other threads:[~2025-04-04  8:28 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-04  8:27 [PATCH V4 0/2] Fix race conditions in the nvme-tcp driver Maurizio Lombardi
2025-04-04  8:28 ` Maurizio Lombardi [this message]
2025-04-05 23:22   ` [PATCH V4 1/2] nvme-tcp: Prevent infinite loop if socket closes during CONNECTING state Keith Busch
2025-04-07  6:11   ` Hannes Reinecke
2025-04-13 22:44   ` Sagi Grimberg
2025-04-14  7:25     ` Maurizio Lombardi
2025-04-14 21:35       ` Sagi Grimberg
2025-04-17 13:04         ` Maurizio Lombardi
2025-04-18 11:14           ` Sagi Grimberg
2025-06-10 12:50             ` Maurizio Lombardi
2025-06-10 14:29               ` Sagi Grimberg
     [not found]                 ` <202510211137214079503@cestc.cn>
2025-10-21  6:05                   ` [PATCH V4 1/2] nvme-tcp: Prevent infinite loop if socket closes during CONNECTING state【请注意,邮件由sagigrim@gmail.com代发】 Maurizio Lombardi
2025-10-21  6:14                     ` Maurizio Lombardi
2025-04-04  8:28 ` [PATCH V4 2/2] nvme-tcp: do not complete the request if send operation fails Maurizio Lombardi
2025-04-05 23:23   ` Keith Busch
2025-04-07  6:13   ` Hannes Reinecke
2025-04-11 12:26 ` [PATCH V4 0/2] Fix race conditions in the nvme-tcp driver Maurizio Lombardi
2025-04-13 22:42 ` Sagi Grimberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250404082801.1614252-2-mlombard@redhat.com \
    --to=mlombard@redhat.com \
    --cc=hare@kernel.org \
    --cc=kbusch@meta.com \
    --cc=linux-nvme@lists.infradead.org \
    --cc=loberman@redhat.com \
    --cc=mlombard@bsdbackstore.eu \
    --cc=sagi@grimberg.me \
    --cc=zhang.guanghui@cestc.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).