nvmet-tcp: fix a hang on queue teardown with data digest
Subsystems (3)
PATCH 1/1 nvmet-tcp: fix a hang on queue teardown with data digest
With data digest on, a command that has received all its data waits for the digest in NVMET_TCP_RECV_DDGST. has_data_in() is already false there, so need_data_in() is too, and nvmet_tcp_uninit_data_in_cmds() skips it on teardown even though it still holds the nvmet_req_init() reference. The SQ percpu_ref never drains, nvmet_sq_destroy() blocks forever in wait_for_completion(), and the nvmet-wq release worker is stuck.
An unauthenticated host on an allow_any_host subsystem hits this by negotiating data digest, sending a write's data but not the trailing digest, and closing the connection. Each leaked command wedges a release worker; a few stall queue teardown entirely, and with hung_task_panic the box goes down.
Drop the reference for a command left in RECV_DDGST from nvmet_tcp_release_queue_work(), before rcv_state is cleared. A command that failed nvmet_req_init() never took one, so skip it.
--- drivers/nvme/target/tcp.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/nvme/target/tcp.c +13 -0
@@ -1640,6 +1640,19 @@nvmet_tcp_restore_socket_callbacks (queue);cancel_delayed_work_sync (&queue->tls_handshake_tmo_work);cancel_work_sync (&queue->io_work); + +/* +* A command that has received all of its data and is only waiting +* for the data digest sits in RECV_DDGST: need_data_in() is already +* false, so nvmet_tcp_uninit_data_in_cmds() below skips it, yet it +* still holds the reference from nvmet_req_init(). Drop it here, +* while rcv_state still reflects it, so the SQ percpu_ref can drain +* and nvmet_sq_destroy() can complete. INIT_FAILED took no ref. +*/ +if (queue->rcv_state ==NVMET_TCP_RECV_DDGST && queue->cmd && + !(queue->cmd->flags &NVMET_TCP_F_INIT_FAILED )) +nvmet_req_uninit (&queue->cmd->req); +/* stop accepting incoming data */ queue->rcv_state =NVMET_TCP_RECV_ERR ;
Signature · 1 line
2.34.1
Quoted 49 lines · Shivam Kumar
With data digest on, a command that has received all its data waits for the digest in
NVMET_TCP_RECV_DDGST.has_data_in()is already false there, soneed_data_in()is too, andnvmet_tcp_uninit_data_in_cmds()skips it on teardown even though it still holds thenvmet_req_init()reference. The SQpercpu_refnever drains,nvmet_sq_destroy()blocks forever inwait_for_completion(), and the nvmet-wq release worker is stuck.An unauthenticated host on an
allow_any_hostsubsystem hits this by negotiating data digest, sending a write's data but not the trailing digest, and closing the connection. Each leaked command wedges a release worker; a few stall queue teardown entirely, and withhung_task_panicthe box goes down.Drop the reference for a command left in
RECV_DDGSTfromnvmet_tcp_release_queue_work(), beforercv_stateis cleared. A command that failednvmet_req_init()never took one, so skip it.Fixes 872d26a391da ("nvmet-tcp: add NVMe over TCP target driver")Signed-off-by Shivam Kumar <[email protected]>Assisted-by Claude--- drivers/nvme/target/tcp.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)drivers/nvme/target/tcp.c +13
-1@@ -1640,6 +1640,19 @@nvmet_tcp_restore_socket_callbacks (queue);cancel_delayed_work_sync (&queue->tls_handshake_tmo_work);cancel_work_sync (&queue->io_work); + +/* +* A command that has received all of its data and is only waiting +* for the data digest sits in RECV_DDGST: need_data_in() is already +* false, so nvmet_tcp_uninit_data_in_cmds() below skips it, yet it +* still holds the reference from nvmet_req_init(). Drop it here, +* while rcv_state still reflects it, so the SQ percpu_ref can drain +* and nvmet_sq_destroy() can complete. INIT_FAILED took no ref. +*/ +if (queue->rcv_state ==NVMET_TCP_RECV_DDGST && queue->cmd && + !(queue->cmd->flags &NVMET_TCP_F_INIT_FAILED )) +nvmet_req_uninit (&queue->cmd->req); +/* stop accepting incoming data */ queue->rcv_state =NVMET_TCP_RECV_ERR ; --
Quoted 1 line
2.34.1
Gentle ping on this one.
Keith Busch
maintainerQuoted 13 lines · Shivam Kumar
With data digest on, a command that has received all its data waits for the digest in
NVMET_TCP_RECV_DDGST.has_data_in()is already false there, soneed_data_in()is too, andnvmet_tcp_uninit_data_in_cmds()skips it on teardown even though it still holds thenvmet_req_init()reference. The SQpercpu_refnever drains,nvmet_sq_destroy()blocks forever inwait_for_completion(), and the nvmet-wq release worker is stuck.An unauthenticated host on an
allow_any_hostsubsystem hits this by negotiating data digest, sending a write's data but not the trailing digest, and closing the connection. Each leaked command wedges a release worker; a few stall queue teardown entirely, and withhung_task_panicthe box goes down.
Quoted 3 lines
Drop the reference for a command left in
RECV_DDGSTfromnvmet_tcp_release_queue_work(), beforercv_stateis cleared. A command that failednvmet_req_init()never took one, so skip it.
"I have made this letter longer than usual because I lack the time to make it shorter." - Blaise Pascal
Take some time to actually write your own (and hopefully more concise) message to demonstrate you understand what you're changing. AI messages are overly verbose.
drivers/nvme/target/tcp.c line 1651
Quoted 8 lines
drivers/nvme/target/tcp.c +8
-0+/* +* A command that has received all of its data and is only waiting +* for the data digest sits in RECV_DDGST: need_data_in() is already +* false, so nvmet_tcp_uninit_data_in_cmds() below skips it, yet it +* still holds the reference from nvmet_req_init(). Drop it here, +* while rcv_state still reflects it, so the SQ percpu_ref can drain +* and nvmet_sq_destroy() can complete. INIT_FAILED took no ref. +*/
Same here.
drivers/nvme/target/tcp.c line 1654
Quoted 3 lines
drivers/nvme/target/tcp.c +3
-0+if (queue->rcv_state ==NVMET_TCP_RECV_DDGST && queue->cmd && + !(queue->cmd->flags &NVMET_TCP_F_INIT_FAILED )) +nvmet_req_uninit (&queue->cmd->req);
I don't think this criteria is even correct. RECV_DDGST doesn't mean the command has all its data since that state is per-PDU. nvmet_tcp_try_recv_data() enters that state at every H2C boundary, not just the last one.
Sagi Grimberg
maintainerQuoted 4 lines · Shivam Kumar
With data digest on, a command that has received all its data waits for the digest in
NVMET_TCP_RECV_DDGST.has_data_in()is already false there, soneed_data_in()is too, andnvmet_tcp_uninit_data_in_cmds()skips it on teardown even though it still holds thenvmet_req_init()reference.
So nvmet_tcp_uninit_data_in_cmds is where this should be addressed.
PATCH v2 1/1 nvmet-tcp: fix a hang on queue teardown with data digest
A command that has received all its data but whose data digest is still outstanding is stalled in NVMET_TCP_RECV_DDGST, where nvmet_tcp_need_data_in() is false. nvmet_tcp_uninit_data_in_cmds() therefore skips it during teardown, leaking its submission queue reference, and nvmet_sq_destroy() then blocks forever waiting on it.
Release such a command in nvmet_tcp_uninit_data_in_cmds(), and reset rcv_state after that call.
--- drivers/nvme/target/tcp.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/nvme/target/tcp.c +8 -2
@@ -1608,6 +1608,11 @@ static void nvmet_tcp_uninit_data_in_cmds(struct nvmet_tcp_queue *queue)nvmet_req_uninit (&cmd->req); } +if (queue->rcv_state ==NVMET_TCP_RECV_DDGST && queue->cmd && + !nvmet_tcp_need_data_in (queue->cmd) && + !(queue->cmd->flags &NVMET_TCP_F_INIT_FAILED )) +nvmet_req_uninit (&queue->cmd->req); +if (!queue->nr_cmds &&nvmet_tcp_need_data_in (&queue->connect)) {/* failed in connect */ nvmet_req_uninit (&queue->connect.req);
@@ -1636,11 +1641,12 @@ static void nvmet_tcp_release_queue_work(struct work_struct *w)nvmet_tcp_restore_socket_callbacks (queue);cancel_delayed_work_sync (&queue->tls_handshake_tmo_work);cancel_work_sync (&queue->io_work); -/* stop accepting incoming data */ - queue->rcv_state =NVMET_TCP_RECV_ERR ;nvmet_sq_put_tls_key (&queue->nvme_sq);nvmet_tcp_uninit_data_in_cmds (queue); +/* stop accepting incoming data */ + queue->rcv_state =NVMET_TCP_RECV_ERR ; +nvmet_sq_destroy (&queue->nvme_sq);nvmet_cq_put (&queue->nvme_cq);cancel_work_sync (&queue->io_work);
Signature · 1 line
2.53.0
Quoted 49 lines · Shivam Kumar
A command that has received all its data but whose data digest is still outstanding is stalled in
NVMET_TCP_RECV_DDGST, wherenvmet_tcp_need_data_in()is false.nvmet_tcp_uninit_data_in_cmds()therefore skips it during teardown, leaking its submission queue reference, andnvmet_sq_destroy()then blocks forever waiting on it.Release such a command in
nvmet_tcp_uninit_data_in_cmds(), and resetrcv_stateafter that call.Fixes 872d26a391da ("nvmet-tcp: add NVMe over TCP target driver")Signed-off-by Shivam Kumar <[email protected]>--- drivers/nvme/target/tcp.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)drivers/nvme/target/tcp.c +8
-3@@ -1608,6 +1608,11 @@ static void nvmet_tcp_uninit_data_in_cmds(struct nvmet_tcp_queue *queue)nvmet_req_uninit (&cmd->req); } +if (queue->rcv_state ==NVMET_TCP_RECV_DDGST && queue->cmd && + !nvmet_tcp_need_data_in (queue->cmd) && + !(queue->cmd->flags &NVMET_TCP_F_INIT_FAILED )) +nvmet_req_uninit (&queue->cmd->req); +if (!queue->nr_cmds &&nvmet_tcp_need_data_in (&queue->connect)) {/* failed in connect */ nvmet_req_uninit (&queue->connect.req);@@ -1636,11 +1641,12 @@ static void nvmet_tcp_release_queue_work(struct work_struct *w)nvmet_tcp_restore_socket_callbacks (queue);cancel_delayed_work_sync (&queue->tls_handshake_tmo_work);cancel_work_sync (&queue->io_work); -/* stop accepting incoming data */ - queue->rcv_state =NVMET_TCP_RECV_ERR ;nvmet_sq_put_tls_key (&queue->nvme_sq);nvmet_tcp_uninit_data_in_cmds (queue); +/* stop accepting incoming data */ + queue->rcv_state =NVMET_TCP_RECV_ERR ; +nvmet_sq_destroy (&queue->nvme_sq);nvmet_cq_put (&queue->nvme_cq);cancel_work_sync (&queue->io_work); --
Quoted 2 lines
2.53.0
Gentle ping on this one.
Quoted 43 lines · Shivam Kumar
Quoted 40 lines · Shivam Kumar
A command that has received all its data but whose data digest is still outstanding is stalled in
NVMET_TCP_RECV_DDGST, wherenvmet_tcp_need_data_in()is false.nvmet_tcp_uninit_data_in_cmds()therefore skips it during teardown, leaking its submission queue reference, andnvmet_sq_destroy()then blocks forever waiting on it.Release such a command in
nvmet_tcp_uninit_data_in_cmds(), and resetrcv_stateafter that call.Fixes 872d26a391da ("nvmet-tcp: add NVMe over TCP target driver")Signed-off-by Shivam Kumar <[email protected]>--- drivers/nvme/target/tcp.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)drivers/nvme/target/tcp.c +5
-2@@ -1608,6 +1608,11 @@ static void nvmet_tcp_uninit_data_in_cmds(struct nvmet_tcp_queue *queue)nvmet_req_uninit (&cmd->req); } +if (queue->rcv_state ==NVMET_TCP_RECV_DDGST && queue->cmd && + !nvmet_tcp_need_data_in (queue->cmd) && + !(queue->cmd->flags &NVMET_TCP_F_INIT_FAILED )) +nvmet_req_uninit (&queue->cmd->req); +if (!queue->nr_cmds &&nvmet_tcp_need_data_in (&queue->connect)) {/* failed in connect */ nvmet_req_uninit (&queue->connect.req);@@ -1636,11 +1641,12 @@ static void nvmet_tcp_release_queue_work(struct work_struct *w)nvmet_tcp_restore_socket_callbacks (queue);cancel_delayed_work_sync (&queue->tls_handshake_tmo_work);cancel_work_sync (&queue->io_work); -/* stop accepting incoming data */ - queue->rcv_state =NVMET_TCP_RECV_ERR ;
Quoted 12 lines
Quoted 11 lines
drivers/nvme/target/tcp.c +3
-1nvmet_sq_put_tls_key (&queue->nvme_sq);nvmet_tcp_uninit_data_in_cmds (queue); +/* stop accepting incoming data */ + queue->rcv_state =NVMET_TCP_RECV_ERR ; +nvmet_sq_destroy (&queue->nvme_sq);nvmet_cq_put (&queue->nvme_cq);cancel_work_sync (&queue->io_work); --2.53.0
Gentle ping on this one.
Gentle ping.