public inbox for linux-nvme@lists.infradead.org
 help / color / mirror / Atom feed
From: Maurizio Lombardi <mlombard@redhat.com>
To: linux-nvme@lists.infradead.org
Cc: hch@lst.de, sagi@grimberg.me, chaitanya.kulkarni@wdc.com
Subject: [PATCH V2 2/3] nvmet-tcp: fix a race condition between release_queue and io_work
Date: Mon, 15 Nov 2021 17:31:13 +0100	[thread overview]
Message-ID: <20211115163114.48716-3-mlombard@redhat.com> (raw)
In-Reply-To: <20211115163114.48716-1-mlombard@redhat.com>

If the initiator executes a reset controller operation while
performing I/O, the target kernel will crash because of a race condition
between release_queue and io_work;
nvmet_tcp_uninit_data_in_cmds() may be executed while io_work
is running, calling flush_work() was not sufficient to
prevent this because io_work could requeue itself.

Fix this bug by using cancel_work_sync() to prevent io_work
from requeuing itself and set rcv_state to NVMET_TCP_RECV_ERR to
make sure we don't receive any more data from the socket.

Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
---
 drivers/nvme/target/tcp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c
index 9aa81af84efa..028b47ff0f0f 100644
--- a/drivers/nvme/target/tcp.c
+++ b/drivers/nvme/target/tcp.c
@@ -1447,7 +1447,9 @@ static void nvmet_tcp_release_queue_work(struct work_struct *w)
 	mutex_unlock(&nvmet_tcp_queue_mutex);
 
 	nvmet_tcp_restore_socket_callbacks(queue);
-	flush_work(&queue->io_work);
+	cancel_work_sync(&queue->io_work);
+	/* stop accepting incoming data */
+	queue->rcv_state = NVMET_TCP_RECV_ERR;
 
 	nvmet_tcp_uninit_data_in_cmds(queue);
 	nvmet_sq_destroy(&queue->nvme_sq);
-- 
2.27.0



  parent reply	other threads:[~2021-11-15 16:32 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-15 16:31 [PATCH V2 0/3] Fix a race condition when performing a controller reset Maurizio Lombardi
2021-11-15 16:31 ` [PATCH V2 1/3] nvmet-tcp: add an helper to free the iovec Maurizio Lombardi
2021-11-16  9:00   ` Sagi Grimberg
2021-11-16  9:05     ` Maurizio Lombardi
2021-11-15 16:31 ` Maurizio Lombardi [this message]
2021-11-16  8:57   ` [PATCH V2 2/3] nvmet-tcp: fix a race condition between release_queue and io_work Sagi Grimberg
2021-11-15 16:31 ` [PATCH V2 3/3] nvmet-tcp: fix memory leak when performing a controller reset Maurizio Lombardi
2021-11-16  9:07   ` Sagi Grimberg
2021-11-16  9:22     ` Maurizio Lombardi
2021-11-16 10:11       ` 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=20211115163114.48716-3-mlombard@redhat.com \
    --to=mlombard@redhat.com \
    --cc=chaitanya.kulkarni@wdc.com \
    --cc=hch@lst.de \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    /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