Skip to content

Commit be74413

Browse files
committed
nvme-tcp: fix premature queue removal and I/O failover
jira LE-4649 Rebuild_History Non-Buildable kernel-5.14.0-570.60.1.el9_6 commit-author Michael Liang <mliang@purestorage.com> commit 77e40bb This patch addresses a data corruption issue observed in nvme-tcp during testing. In an NVMe native multipath setup, when an I/O timeout occurs, all inflight I/Os are canceled almost immediately after the kernel socket is shut down. These canceled I/Os are reported as host path errors, triggering a failover that succeeds on a different path. However, at this point, the original I/O may still be outstanding in the host's network transmission path (e.g., the NIC’s TX queue). From the user-space app's perspective, the buffer associated with the I/O is considered completed since they're acked on the different path and may be reused for new I/O requests. Because nvme-tcp enables zero-copy by default in the transmission path, this can lead to corrupted data being sent to the original target, ultimately causing data corruption. We can reproduce this data corruption by injecting delay on one path and triggering i/o timeout. To prevent this issue, this change ensures that all inflight transmissions are fully completed from host's perspective before returning from queue stop. To handle concurrent I/O timeout from multiple namespaces under the same controller, always wait in queue stop regardless of queue's state. This aligns with the behavior of queue stopping in other NVMe fabric transports. Fixes: 3f2304f ("nvme-tcp: add NVMe over TCP host driver") Signed-off-by: Michael Liang <mliang@purestorage.com> Reviewed-by: Mohamed Khalfella <mkhalfella@purestorage.com> Reviewed-by: Randy Jennings <randyj@purestorage.com> Reviewed-by: Sagi Grimberg <sagi@grimberg.me> Signed-off-by: Christoph Hellwig <hch@lst.de> (cherry picked from commit 77e40bb) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent be7ef41 commit be74413

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

drivers/nvme/host/tcp.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,7 +1862,7 @@ static void __nvme_tcp_stop_queue(struct nvme_tcp_queue *queue)
18621862
cancel_work_sync(&queue->io_work);
18631863
}
18641864

1865-
static void nvme_tcp_stop_queue(struct nvme_ctrl *nctrl, int qid)
1865+
static void nvme_tcp_stop_queue_nowait(struct nvme_ctrl *nctrl, int qid)
18661866
{
18671867
struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(nctrl);
18681868
struct nvme_tcp_queue *queue = &ctrl->queues[qid];
@@ -1878,6 +1878,31 @@ static void nvme_tcp_stop_queue(struct nvme_ctrl *nctrl, int qid)
18781878
mutex_unlock(&queue->queue_lock);
18791879
}
18801880

1881+
static void nvme_tcp_wait_queue(struct nvme_ctrl *nctrl, int qid)
1882+
{
1883+
struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(nctrl);
1884+
struct nvme_tcp_queue *queue = &ctrl->queues[qid];
1885+
int timeout = 100;
1886+
1887+
while (timeout > 0) {
1888+
if (!test_bit(NVME_TCP_Q_ALLOCATED, &queue->flags) ||
1889+
!sk_wmem_alloc_get(queue->sock->sk))
1890+
return;
1891+
msleep(2);
1892+
timeout -= 2;
1893+
}
1894+
dev_warn(nctrl->device,
1895+
"qid %d: timeout draining sock wmem allocation expired\n",
1896+
qid);
1897+
}
1898+
1899+
static void nvme_tcp_stop_queue(struct nvme_ctrl *nctrl, int qid)
1900+
{
1901+
nvme_tcp_stop_queue_nowait(nctrl, qid);
1902+
nvme_tcp_wait_queue(nctrl, qid);
1903+
}
1904+
1905+
18811906
static void nvme_tcp_setup_sock_ops(struct nvme_tcp_queue *queue)
18821907
{
18831908
write_lock_bh(&queue->sock->sk->sk_callback_lock);
@@ -1944,7 +1969,9 @@ static void nvme_tcp_stop_io_queues(struct nvme_ctrl *ctrl)
19441969
int i;
19451970

19461971
for (i = 1; i < ctrl->queue_count; i++)
1947-
nvme_tcp_stop_queue(ctrl, i);
1972+
nvme_tcp_stop_queue_nowait(ctrl, i);
1973+
for (i = 1; i < ctrl->queue_count; i++)
1974+
nvme_tcp_wait_queue(ctrl, i);
19481975
}
19491976

19501977
static int nvme_tcp_start_io_queues(struct nvme_ctrl *ctrl,

0 commit comments

Comments
 (0)